2012-05-03 176 views
0

我有一個失敗的步驟定義。黃瓜步驟定義失敗

從功能下面我有它未能在「這功能有問題」(在標題未定義的局部變量)

Feature: Viewing issue 
In order to view the issues for a feature 
As a user 
I want to see them on that feature's page 
Background:  
    Given there is a release called "Confluence" 
    And that release has a feature: 
     | title    | description | 
     | Make it shiny!  | Gradients! Starbursts! Oh my! | 
    And that feature has a issue: 
     | title    | description | 
     | First Issue   | This is a first issue. | 
    And I am on the homepage 

    Scenario: Viewing issue for a given feature 
    When I follow "Confluence" 
    Then I should see "Standards compliance" 
    When I follow "Standards compliance" 
    Then I should see "First Issue" 
    And I should see "This is a first issue." 

我如何爲它編寫傢伙步驟定義。

這就是我對功能的定義和它的偉大工程,但我已經嘗試做同樣的問題的對象和它不工作

Given /^that release has a feature:$/ do |table| 
    table.hashes.each do |attributes| 
    @release.features.create!(attributes) 
    end 
end 
+2

Given there is a release called <name> # create model Given release <name> has a feature <table> release = Release.find_by_name(<name>) # rest of your code here is fine, but reference 'release' instead of '@release' Given release <name>'s <feature_name> has issues <table> release = Release.find_by_name(<name>) feature = release.features.find_by_name(<feature_name>) table.hashes.each do |attributes| # create issue end 

那麼你的黃瓜功能會這樣寫的更好「該功能有問題」的步驟定義。 –

回答

0

在你不應該使用實例變量的步驟,作爲最佳實踐。它使他們相互依賴。

我會寫你的步驟是這樣的(在僞代碼ISH):您需要發佈您的代碼爲

Given there is a release called "Confluence" 
And release "Confluence" has a feature: 
    | title    | description | 
    | Make it shiny!  | Gradients! Starbursts! Oh my! | 
And release "Confluence"'s "Make it shiny!" feature has issues 
    | title    | description | 
    | First Issue   | This is a first issue. |