RSpec controller testing - blank response.body
By default, rspec-rails hacks into Rails to prevent it from actually rendering view templates. You should only test the behavior of your actions & filters your controller tests, not the outcome of template rendering — that's what view specs are for.
However, if you wish to make your controller specs render templates as the app normally would, use the render_views
directive:
describe YourController do render_views ...end
RSpec 2+: If you want to check end to end - url to response body - use a request spec instead of a controller spec.
As I worked with a similar problem (that led me to this question), it occurred to me that there are different ways to skin the same cat. In other words, rather than checking for the body text, you might be able to check the content of the flash.
response.body.should =~ /Invalid email or password/
might be an equivalent check to:
flash[:alert].should == "Invalid email or password"
To me the latter seems a bit more flexible as it will run either way, but it may not be appropriate in all cases.
Cheers,
John