Spe*_*ley 7 tdd rspec ruby-on-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
Run Code Online (Sandbox Code Playgroud)
除了最后一次测试外,一切都过去了.它说找不到与"立即注册!"文本的链接..我知道该页面确实有"立即注册!" 链接.我认为它可能在源代码中呈现不同,但是当我查看源代码时它看起来很正常<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!"
Run Code Online (Sandbox Code Playgroud)
我相信问题在于"立即注册!" 事实上,链接并非在所有页面上都有,并且此测试实际上导航了页面.
至少在我之前运行的本教程版本中,该链接仅在主页上.
如果你visit root_path在最后一次之前添加一个click_link它可能会起作用.
更好的测试将检查与主页相关的独立测试.
| 归档时间: |
|
| 查看次数: |
2268 次 |
| 最近记录: |