如何让rspec输出遇到的内容,而不是“找不到预期的内容”? [英] How do you get rspec to output what it encountered rather than it "didn't find what it expected"?
问题描述
我一直在努力使用ruby / rspec / capybara / devise来测试我的代码。我正在尝试写一个简单的测试是登录。我有一个有效的用户登录,并希望看到如下代码中定义的h1标签:
I have been struggling to using ruby/rspec/capybara/devise to test my code. A simple test I am trying to write is for signing in. I have a valid user sign in and expect to see an h1 tag as defined in the following code:
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
问题是我得到这个回报:
Problem is that I get this in return:
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执行后测试看到什么。
Is there a way to output what the test found in the h1 (or that it didn't find it at all?) instead of it didn't find what it expected? There is a good chance my sign_in method is not working, but I can't validate that because I'm not sure what the test sees after sign_in_with executes.
谢谢
编辑
更新代码以反映测试题目。
EDIT Updated code to reflect subject of tests.
推荐答案
...我不知道在sign_in_with执行后测试看到的是什么。
... I'm not sure what the test sees after sign_in_with executes.
您可以使用打开当前页面的快照 save_and_open_page
:
You can open a snapshot of the current page with save_and_open_page
:
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before { sign_in_with user.email }
it { save_and_open_page; should have_css('h1', text: "Welcome to the Test") }
end
这篇关于如何让rspec输出遇到的内容,而不是“找不到预期的内容”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!