我一直在努力使用ruby/rspec/capybara/devise来测试我的代码。一个简单的测试,我想写的,用于登录我有一个合法的用户登录,并期望看到如下面的代码中定义一个h1标签:你如何得到rspec输出它遇到的而不是它“没有找到预期的结果”?
describe "Authentication" do
subject { page }
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before { sign_in_with user.email }
it { should have_css('h1', text: "Welcome to the Test") }
end
end
问题是,我得到的回报是:
1) Authentication signin page with valid information
Failure/Error: it { should have_css('h1', text: "Welcome to the Test") }
expected css "h1" with text "Welcome to the Test" to return something
# ./spec/requests/authentication_pages_spec.rb:34:in `block (4 levels) in <top (required)>'
有没有办法输出什么样的测试中发现的H1(或者说,它没有找到它呢?),而不是它没有找到什么期待?有一个很好的机会,我的sign_in方法不起作用,但我无法验证,因为我不确定在执行sign_in_with之后测试看到的是什么。
非常感谢并乐于提供更多的上下文,如果有帮助的话。
编辑 更新代码以反映测试主题。
我跑进唯一要注意的是,'save_and_open_page'需要的是在它的声明:HTTP :/ /stackoverflow.com/questions/12608976/save-and-open-page-capybara-launchy-stopped-working-in-a-project-error – Ryan 2013-04-08 17:12:15
@Ryan好赶上,我已经更新了我的答案。 – Stefan 2013-04-09 08:09:07