我有以下测试适用于Rack :: Test但不使用Selenium。即如果我将, js: true
添加到describe块,我会在Firefox中收到一条错误消息:couldn't find the License with id=
(id @l
)
describe "should hide allocation rule # for pdf & clickthrough licenses" do
it "reads current state and shows/hides fields appropriately" do
@l = FactoryGirl.create(:license:,
way: License::CLICK_WAY)
visit edit_admin_license_path(@l)
end
end
为什么?我必须缺少某些内容。我可以使用Sequel Pro验证使用js: true
时是否未保存记录。
我需要在Selenium中运行此规范,因为我有javascript要测试。
答案 0 :(得分:0)
简单的解决方案是关闭交易设备。
Why does my Cucumber test fail when run with Selenium?
spec / spec_helper.rb中的:
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before :each do
if Capybara.current_driver == :rack_test
DatabaseCleaner.strategy = :transaction
else
DatabaseCleaner.strategy = :truncation
end
DatabaseCleaner.start
end
config.after do
DatabaseCleaner.clean
end
end
并在Gemfile中,测试部分
gem 'database_cleaner'