RSpec-rails-capybara - different failures with :js => true and without

前端 未结 1 1618
深忆病人
深忆病人 2021-02-06 04:41

I\'m building a setup screen for billing of individuals. The controller/views are in the Admin namespace.

When run the first test without :js => true I get one failure,

1条回答
  •  生来不讨喜
    2021-02-06 04:59

    You probably have config.use_transactional_fixtures = true in your spec_helper.rb. It doesn't work with Capybara javascript specs because the server and the browser client run on separate threads. Due to the fact that database transactions on the server are not visible to the client, the client has no clue about the user you created in the let!(), therefore the user cannot login to the system.

    You need to turn off transactional fixtures and clean your database before/after each run (consider the gem database_cleaner) for your js specs.

    RSpec.configure do |config|
      config.use_transactional_fixtures = false
    
      config.before(:suite) do
        DatabaseCleaner.clean_with :truncation
      end
    
      config.before(:each) do
        if example.metadata[:js]
          DatabaseCleaner.strategy = :truncation
        else
          DatabaseCleaner.strategy = :transaction
        end
        DatabaseCleaner.start
      end
    
      config.after(:each) do
        DatabaseCleaner.clean
      end
    end
    

    The above code snippet is taken from the contact manager app readme and slightly modified

    0 讨论(0)
提交回复
热议问题