page.html
will show a huge amorphous blob of a stack trace. Annoying to debug, but it's something. So far so good.
Now imagine you've fixed whatever that first problem was, and you're merrily testing away, writing feature tests to ensure different bits of the page behave as they should. You arrive at a form, perhaps one which communicates with the server and spits back more page content. You write the relevant bits of form general-mess-about-y code using Capybara's Action methods, write a test to ensure the page content gets updated the way you think it should and run the test. Bam.
The test fails - the page content is unchanged.
Why? The server didn't spit out a stack trace. Is there something wrong with the browser response, then? You check the Javascript console messages - a tad difficult, considering you're doing headless browser testing, but with Capybara-webkit, simply check the
page.driver.console_messages
variable, which now surely is crammed with informative messages telling you what went wrong. Nothing again. How odd. Okay then, is the response executing at all? Add a
console.log("Hey, I'm alive!");
call or two to it. Test. Nothing. I went through all this and more. I added an
ap params
to the start of the Ajax controller response, and that worked just fine, so clearly the test form submission itself was working. (And by the way, you should totally check out the fantastic gem awesome_print). I spent several hours tearing my hair out, trying to figure out why the hell code would apparently silently fail like this. Finally, of course, I realised that there are two separate controller calls here, the initial browser page load and the Ajax response, and only the first shows stack traces in response to code errors. The second just glares at you, as I found to my cost. To find the problem, you could try wrapping the entire controller method in a begin/rescue/end block, just while you're troubleshooting, and printing the exception message. Crude but effective.
1 2 3 4 5 6 7 | def create begin # Your incredibly insolent Rails code goes here rescue e ap e.message # Caught you end end |