我正在做第五章的練習。我應該測試鏈接到正確的頁面。這是我的測試代碼。我的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