在带有 Rspec 2.12.0 的 capybara 2.1.0 上:
如果我运行 $ rspec spec/features/user_sees_leaderboard_spec.rb
,规范通过。
如果我运行 $ rspec spec/features/*
,测试失败,声明:
Capybara::ElementNotFound:
Unable to find css "#flash"
如果我执行 save_and_open_page
,#flash 会出现并且可见。
这是发生故障的助手:
def sign_in_as(user)
visit new_user_session_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign In"
flash = find("#flash")
flash.should have_content "You are now signed in."
end
有什么想法吗?我是 Capybara 的新手,所以不确定从哪里开始。谢谢!
编辑/更新:
通过对一组在一起运行时失败的规范执行 save_and_open_page
,我能够看到一系列成功,然后是一系列页面,除了 body 标签中的“Not Found”之外什么也没有说。谷歌没有发现任何东西——想法?
更新 #2
我注意到 BODY 中的“未找到”内容是在使用 capybara-webkit 运行 javascript 的规范之后开始的。即使在 after(:all) block 中显式重置 Capybara.current_driver = :rack_test 也不能解决问题,但我认为这是相关的。
最佳答案
虽然仍然不能 100% 确定是什么原因造成的,但使用 capybara-webkit 从测试中删除 Capybara.automatic_reload = false
解决了这个问题。
关于rspec - 为什么在每个规范都成功时一系列规范会失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16678691/