0
我有一個規格,通過但當我加js: true
它失敗。無頭Chrome與Rspec數據庫連接不工作
它失敗,因爲visit survey_path(survey)
之前有一個survey
和account
然後嘗試運行該行visit survey_path(survey)
,我得到undefined method surveys for nil:NilClass
因爲沒有賬戶或調查。
這就像所有東西都從數據庫中刪除。
我有一個視圖內的反應組件,所以我想寫它的功能規格,因此我需要js: true
的原因。
任何人都知道爲什麼數據庫沒有調查和帳戶,當我有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
導軌幫助文件有這個裏面
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