我的rspec测试不会通过:Michael Hartl的rails教程
||
我在第五章的末尾进行练习。我应该测试链接是否转到正确的页面。这是我的测试代码。
require \'spec_helper\'
describe \"LayoutLinks\" do
it \"should have the right links on the layout\" do
visit root_path
click_link \"About\"
response.should have_selector(\'title\', :content => \"About\")
click_link \"Home\"
response.should have_selector(\'title\', :content => \"Home\")
click_link \"Help\"
response.should have_selector(\'title\', :content => \"Help\")
click_link \"Contact\"
response.should have_selector(\'title\', :content => \"Contact\")
click_link \"Sign up now!\"
response.should have_selector(\'title\', :content => \"Sign up\")
end
end
除了最后的测试,一切都通过了。它说找不到文本为“立即注册!”的链接。我知道页面上确实有一个“立即注册!”链接。我以为它在源代码中的呈现方式可能有所不同,但是当我查看源代码时,它看起来很正常(即1)。据我了解,应该单击链接,然后测试标题是否与:content符号匹配。我误会了吗?
这是我得到的错误:
Failures:
1) LayoutLinks should have the right links on the layout
Failure/Error: click_link \"Sign up now!\"
Webrat::NotFoundError:
Could not find link with text or title or id \"Sign up now!\"
没有找到相关结果
已邀请:
3 个回复
泻伴墓荒
之前添加一个
,它可能会起作用。 更好的测试是让该程序签入专门与主页相关的独立测试。
香腔弥胯瓤
如果在此页面之前访问的页面是
,则不需要回答answer3ѭ的建议。
呕蹿尉
至少,这就是为什么我的测试没有通过的原因。 我在这个论坛上找到了解决方案