2012-03-15 40 views
1

我得到以下警告使用此代碼然後棄用:鑑於/時/黃瓜

WARNING: Using 'Given/When/Then' in step definitions is deprecated, use 'step' to call other steps instead 

我如何糾正呢?

代碼:

Feature: Viewing tickets 
In order to view the tickets for a project 
As a user 
I want to see them on that project's page 

Background: 
Given there is a project called "TextMate 2" 
And that project has a ticket: 
| title   | description     | 
| Make it shiny! | Gradients! Starbursts! Oh my! | 
And there is a project called "Internet Explorer" 
And that project has a ticket: 
| title    | description | 
| Standards compliance | Isn't a joke. | 
And I am on the homepage 

Scenario: Viewing tickets for a given project 
    When I follow "TextMate 2" 
    Then I should see "Make it shiny!" 
    And I should not see "Standards compliance" 
    When I follow "Make it shiny!" 
    Then I should see "Make it shiny" within "#ticket h2" 
    And I should see "Gradients! Starbursts! Oh my!" 

    When I am on the homepage 
    And I follow "Internet Explorer" 
    Then I should see "Standards compliance" 
    And I should not see "Make it shiny!" 
    When I follow "Standards compliance" 
    Then I should see "Standards compliance" within "#ticket h2" 
    And I should see "Isn't a joke. 

非常感謝!

+0

這將是由於步驟的定義,而不是功能文件代碼 - 你可以發佈你的步驟定義代碼? – 2012-03-16 00:38:23

+0

您可以將步驟方法用於單個步驟或多個步驟。看到我的答案在這裏http://stackoverflow.com/questions/918066/reuse-cucumber-steps/8395715#8395715 – michaeltwofish 2012-03-17 02:22:50

回答

7

某處步驟定義你使用以下建築:

Then "a file named '#{want_file}' should exist" 

,而不是你應該使用

step("a file named '#{want_file}' should exist") 

或(首選,我認爲) - 避免調用從另一個一步都沒有。重構定義並將通用部分提取到單獨的類或方法中會更好。

+0

如果前綴是「步驟」,黃瓜如何知道如果我指的是'給定''什麼時候'或'然後'? – Edmund 2013-05-01 19:39:20

1

替換這個(功能/ step_definitions/web_steps.rb,行35-37):

When /^(.*) within (.*[^:])$/ do |step, parent| 
    with_scope(parent) { When step } 
end 

像這樣的東西:

When /^(.*) within (.*[^:])$/ do |the_step, parent| 
    with_scope(parent) { step the_step } 
end 

爲我工作!