0
在規格/功能/ posts_spec.rb我的測試代碼如下所示水豚功能規格只有工作,如果JS:真
require 'spec_helper'
feature 'Posts' do
scenario 'Editing of Micropost', js: true do
visit '/signin'
fill_in 'Email', with: '[email protected]
...
代碼工作正常js: true
。但是,如果我拿出js: true
,測試失敗在fill_in 'Email'
,如果我用save_and_open_page此行前夕我看到
Not Found: /signin
我的理解是,我不應該把js: true
,除非我需要測試javascript函數和默認rack_test
驅動程序應該工作。出了什麼問題?我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
你使用'database_cleaner'嗎?你可以粘貼其配置的內容嗎 – itsnikolay
你是否嘗試過在停用JavaScript的情況下手動做同樣的事情? –
如何在rspec中禁用Javascript? – Obromios