← Back to Upcase

Rspec/Capybara not showing Rails errors?


(Nathaniel Watts) #1

I watched through Ben’s ‘TDD in Rails’ video, and found it very informative - as well as encouraging that my mentalities in testing aren’t off kilter.

One thing I wasn’t sure about - is when he runs his specs going through his TDD process - You can see that the specs fail for “Rails reasons” - meaning that it fails because he’s missing a controller, controller action, view template, etc. Here’s a screenshot: bit.ly/1bRtoMo

Recently I’ve gone through a similar process. Fresh Rails 4.0.2 app with rspec/capybara - and was going through the same outside-in approach that he describes.

The problem that I’ve had, though, is that I can’t get the specs to fail for those same Rails reasons - they instead fail because missing markup on the view template (which, makes sense because if the controller doesn’t exist - there’s no action to render the view that has the markup, etc).

Here’s a screenshot: bit.ly/LoM2E9

I’ve watched the video over, and can’t find anything special that he did to output those errors, nor could I find anything on stack overflow that wouldn’t require me to monkey patch something.

Am I missing something?

Thanks!


(Ben Orenstein) #2

It could be that Rails is rendering an error template instead of re-raising the exception for your tests to see.

Something to check: do you have a line like config.action_dispatch.show_exceptions = false in your config/environments/test.rb file?

If so, try setting that to true instead and see if you get the error you’re expecting.


(Nathaniel Watts) #3

Hey @benorenstein! Thanks for your response!

Unfortunately, setting that flag in the config/environments/test.rb did not change the error that’s being output.

What’s odd, is that last week - while building a Rails engine - I was able to TDD it the same way that you do in your video. However, with this app I can’t. In fact, the past few vanilla Rails apps that I’ve worked on using capybara/rspec, they’ve failed to show the Rails type errors.

Fresh Rails app - added capybara/rspec to the spec_helper file, added a test under features/ and I can’t get seem to get those errors to show up :frowning:


(Dolph Mullen) #4

Hey Nathaniel,

Is there any way you could link to the repo in question?


(Nathaniel Watts) #5

Hey @benorenstein and @dolphorama!

So, I found out the issue.

I had grouped the better_errors gem into both development and test in my Gemfile.

As such, better_errors was intercepting.
What’s interesting, is that if you try to use better_errors while running in test mode: rails s -e test, it doesn’t work, and you get errors directly from the server…

Anyways, my apologies to both of you for wasting your time!
Thanks again for taking a moment to help!


(Ben Orenstein) #6

No worries.

By the way, one good way to debug stuff like this is with good old-fashioned puts.

I like to do puts page.body right before the line where it blows up. In this case, you would have seen that better_errors was capturing things pretty much right away.


(Nathaniel Watts) #7

Great advice! Will most definitely remember that for next time :smile:

BTW - thanks for taking the time to chat with Bryana here at gSchool. It means a lot when other developers give of themselves to invest into us students!


(Ben Orenstein) #8

My pleasure! I love helping out gSchoolers, and not just 'cause Jeff is a damn nice guy.


(Saron Yitbarek) #9

Had the exact same problem, was driving me crazy! Thanks for posting your solution :slight_smile:


(Justin Cypret) #10

I ran into the same issue, but with the “web-console” gem being included in both environments. Removing it from the test group fixed it. Thanks for pointing me in the right direction!


(Philip Bradley) #11

Just a quick thanks to this thread. solved my headache.


(Nathaniel Watts) #12

Hey no problemo! :smile: glad I could help!