I'm trying to write a controller spec for a simple controller. However, Capybara isn't seeing any page content. However, looking at the site's pages in my browser works just fine. What am I doing wrong?
T. Hanks!
My controller spec
My spec_helper.rb
My Gemfile
You need to explicitly tell your controller spec that you want it to render views in order for this to work. Update your spec to look like this:
require 'spec_helper'
describe PostsController do
render_views # Render this controller's views during spec execution.
before do
@post = Fabricate :post
end
# ...
end
This is described in rspec's readme. For a more detailed view, see rspec-rails' cucumber feature for 'render_views'.
Just one word of caution with this. There are reasons why this isn't default behaviour:
spec/integration
rather than spec/controller
.... Not saying you shouldn't do this, just saying you should be clear why you are.
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With