2010-09-12 48 views
0

我在rails 2.3.9應用程序中使用黃瓜黃瓜。如何驗證鏈接指向正確的圖像,並有正確的目標和標題

這裏是我的html代碼

<a href="http://twitter.com/dorelal" target="_blank" title="twitter"> 
    <img alt="twitter" src="/images/social/twitter.png?1284129939" /> 
</a> 

我想確認下列各項

image should be ending with twitter.png 
image alt should be "twitter" 
link should have href "http://twitter.com/dorelal" 
link should have target "_blank" 
link should have title "twitter" 

回答

0

驗證鏈接,最好的辦法是讓你的驅動程序單擊它,然後檢查它去到正確的頁面。這會讓你更加確信你的應用不會錯誤地發生錯誤,重定向等。對於單擊測試中的鏈接不太明智的例外情況(例如:如果鏈接不在現場),我使用以下步驟:

Then I should see a link titled "foo" 
Then I should see a link titled "foo" that goes to "http://www.example.org" 

Then /^I should see a link titled "(.+?)"(?: that goes to "(.+)")?$/ do |title, target| 
    if target.blank? 
    page.should have_link(title) 
    else 
    page.should have_link(title, :href => target) 
    end 
end 

如果您得到「錯誤的參數數量(2爲1)」,更新您的水豚版本。最近添加了:'href =>'bar'選項。