Capybara 功能规范仅在 js: true 时有效

Capybara feature specs only working if js: true

我在 spec/features/posts_spec.rb 中的测试代码如下所示

require 'spec_helper'
feature 'Posts' do
  scenario 'Editing of Micropost', js: true do
     visit '/signin'
     fill_in 'Email', with: 'user@example.com
...

该代码在 js: true 上运行良好。但是,如果我取出 js: true,测试会在 fill_in 'Email' 处失败,如果我在该行之前立即使用 save_and_open_page,我会看到

Not Found: /signin

我的理解是,除非我需要测试 javascript 函数并且默认的 rack_test 驱动程序应该可以工作,否则我不必放置 js: true。出了什么问题?我的spec_helper文件如下

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'capybara'
require 'capybara/rails'
require 'capybara/rspec'
require 'capybara-screenshot'
require 'capybara-screenshot/rspec'
require 'capybara/poltergeist'
require 'pp'
require Rails.root.join('app/services/dbg').to_s
require 'database_cleaner_support'
require 'shoulda_matchers_support'
require 'chris_matchers_support'
require 'chris_helpers_support'
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
Capybara.default_host = 'www.example.com'
RSpec.configure do |config|
  Capybara.default_driver = :rack_test
  Capybara.javascript_driver = :poltergeist
  Capybara::Webkit.configure(&:block_unknown_urls)
  Capybara::Screenshot.prune_strategy = { keep: 20 }
  Capybara::Screenshot.append_timestamp = false
  config.include Capybara::UserAgent::DSL
  config.include Rails.application.routes.url_helpers
  config.include ApplicationHelper
  config.include AccountsHelper
  config.mock_with :rspec
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = false
  config.filter_run focus: true
  config.run_all_when_everything_filtered = true
  ActiveRecord::Migration.maintain_test_schema! # dont need db:test:prepare
end
RSpec.configure do |config|
  config.before(:suite) do
    DatabaseCleaner.clean_with(:truncation)
  end
  config.before(:suite) do
    DatabaseCleaner.strategy = :transaction
  end
  # config.before(:each, :js => true) do
  #     DatabaseCleaner.strategy = :truncation
  # end
  config.before(:each) do |example|
    if example.example.metadata[:js]
      DatabaseCleaner.strategy = :truncation
    else
      DatabaseCleaner.strategy = :transaction
    end
    DatabaseCleaner.start
  end
  config.after(:each) do
    DatabaseCleaner.clean
  end
end

解决方案是删除行

Capybara.default_host = 'www.example.com'

我不确定为什么会出现这个问题。