我正在做第五章的练习。我应该测试链接到正确的页面。这是我的测试代码。我的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
除了最后一次测试之外,一切都通过了。它说它无法找到与文本“注册吧!”的链接。我知道该网页确实有“立即注册!”链接。我认为它可能在源代码中有不同的表现,但是当我查看源代码时,它看起来很正常<a href="/signup" class="signup_button round">Sign up now!</a>
。根据我的理解,应该点击链接,然后测试标题是否与内容符号匹配。我误解了什么吗?
这里是我得到的错误:“立即注册”
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!"
我也试着设置:“立即注册”内容=>只是为了试验,但问题似乎是找到root_path上的链接而不是响应。 – 2011-03-19 12:04:09
长镜头,但如果您删除感叹号,它会工作。 'click_link“立即注册”' – lebreeze 2011-03-19 12:10:30
刚刚尝试过。它给了我同样的错误。我也尝试过!脱离链接。 – 2011-03-19 12:38:51