2012-05-03 51 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. |