My test code in the spec/features/posts_spec.rb looks like this
require 'spec_helper'
feature 'Posts' do
scenario 'Editing of Micropost', js: true do
visit '/signin'
fill_in 'Email', with: '[email protected]
...
The code works fine with js: true
. However if I take out js: true
, the test fails at the fill_in 'Email'
and if I use save_and_open_page immediately prior to this line I see
Not Found: /signin
My understanding is that I should not have to put the js: true
unless I need to test a javascript function and the default rack_test
driver should work. What is going wrong? My spec_helper file is as follows
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
The solution was to delete the line
Capybara.default_host = 'www.example.com'
I am not sure why this was causing the problem.