2012-05-01 100 views
0

我有一個簡單的功能:BDD測試與cabybara:按鈕找不到

Feature: User can see the welcome page 
Scenario: User can see the worker page 
    Given I am on the welcome page 
    Then I should see the Worker button 
    When I click on the Worker button 
    Then I should be on the Worker page 

Scenario: User can see the requester page 
    Given I am on the welcome page 
    Then I should see the Requester button 
    When I click on the Requester button 
    Then I should be on the Requester page 

奇怪的是,我可以通過那我應該看到,工人按鈕,但無法通過測試上的點擊。

這是我的步驟定義

Then /^I should see the (.+) button$/ do |button_name| 
    page.has_button? button_name 
end 

When /^I click on the (.*) button$/ do |button_name| 
    #page.has_button? button_name 
    click_on button_name 
end 

這是我的歡迎頁面

div.row 
    %div.span6 
     = button_to 'Worker', workers_path, :class => "btn btn-large btn-primary" 
    %div.span6     
     = button_to 'Requester', requesters_path, :class => "btn btn-large btn-primary" 

是在has_button? Cabybara或黃瓜的方法?

回答

1

你然後一步將始終無論在頁面上什麼的傳球,因爲has_button?返回true或false,兩者都不會使你的黃瓜步驟就是失敗的。爲了實現這一點,您必須拋出一個異常,最好通過以下方式實現:

page.should have_button button_name 
0

has_button?是水豚提供的一種方法。據記載here

而不是click_on button_name嘗試click_button button_name