Capybara + RSpec sees only blank pages in controller specifications. What for?

I am trying to write a controller specification for a simple controller. However, Capybara does not see the contents of the page. However, looking at the site pages in my browser, everything is fine. What am I doing wrong?

T. Hanks!

My controller specification

My spec_helper.rb

My gemfile

+6
source share
1 answer

You need to explicitly specify the specifications of your controller so that you display the views for this to work. Update your specification to look like this:

require 'spec_helper' describe PostsController do render_views # Render this controller views during spec execution. before do @post = Fabricate :post end # ... end 

This is described in the rspec readme . See rspec-rails oucum for "render_views" for a more detailed overview.

Just one word of caution with this. There are reasons why this behavior is not default:

  • Perhaps you are confusing the two issues by checking views simultaneously with controllers. Ryan Bigg (see Comments) suggests that your tests be better analyzed as integration tests, which usually live in spec/integration rather than spec/controller .
  • Rendering views can significantly slow down your tests.

... Without saying that you should not do this, just say that you should understand why you are.

Hope this helps.

+14
source

Source: https://habr.com/ru/post/887590/


All Articles