【发布时间】:2011-03-19 12:00:56
【问题描述】:
我在第五章的末尾做练习。我应该测试链接到正确的页面。这是我的测试代码。
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> 。据我了解,它应该单击链接,然后测试标题是否与 :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!"
【问题讨论】:
-
我也尝试设置 :content => "立即注册!"只是为了试验,但问题似乎是在 root_path 上而不是在响应中找到链接。
-
长镜头,但如果您删除感叹号,它是否有效。
click_link "Sign up now" -
刚刚试过。它给了我同样的错误。我也试过服用!脱离链接。
-
FWIW,我不喜欢该教程的少数几件事之一是对控制器规格的依赖。黄瓜故事效果更好。
标签: ruby-on-rails tdd rspec