0

I have a spec that passes but when I add js: true it fails.

It fails because before visit survey_path(survey) there's a survey and an account then it tries to run that line visit survey_path(survey) and I get undefined method surveys for nil:NilClass because there's no account or survey.

It's like everything was deleted from the database.

I have a react component inside the view so I want to write feature specs for it hence the reason I need js: true.

Anyone know why the database doesn't have a survey and an account when I have js: true?

 describe '#edit', js: true do let(:new_survey_name) { 'new survey name' } context 'authenticated user' do before do login_as user # Here there is an account and survey. # Then inside the code when Survey#show is hit there is # no account or survey visit survey_path(survey) end it 'can edit survey' do click_link 'Settings' fill_in 'survey[name]', with: new_survey_name click_button 'Save' visit survey_path(survey) expect(page).to have_content(new_survey_name) expect(page).not_to have_content('Status') end end 

The rails helper file has this inside it

RSpec.configure do |config| config.include FactoryGirl::Syntax::Methods config.use_transactional_fixtures = true config.infer_spec_type_from_file_location! config.filter_rails_from_backtrace! config.include RequestSpecHelper, type: :request config.include Warden::Test::Helpers config.use_transactional_fixtures = false config.before(:each) do DatabaseCleaner.strategy = :transaction end config.around(:each) do |example| DatabaseCleaner.cleaning do example.run end end config.before(:suite) do begin DatabaseCleaner.clean_with(:truncation) ensure DatabaseCleaner.clean end end end Capybara.register_driver :chrome do |app| Capybara::Selenium::Driver.new(app, browser: :chrome) end Capybara.register_driver :headless_chrome do |app| capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( chromeOptions: { args: %w(headless disable-gpu) } ) Capybara::Selenium::Driver.new app, browser: :chrome, desired_capabilities: capabilities end Capybara.configure do |config| config.default_max_wait_time = 5 config.javascript_driver = :headless_chrome config.server_host = 'localhost' config.server_port = 54_321 end 

1 Answer 1

1

When you're running feature tests, it's recommended to use :truncation clean method. Just add something like this to your database_cleaner config:

config.before(:each, type: :feature) do driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test DatabaseCleaner.strategy = :truncation if !driver_shares_db_connection_with_specs end 

Source: https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.