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

을 당신이 당신의 코드를 게시 할 필요를 "그리고 그 특징에는 문제가있다."단계 정의. –

답변

0

작동하지 않는 것입니다 귀하의 단계를 권장합니다. 그것은 그들이 서로에 의존하게 만든다.

난 (사이비 틱 코드)이처럼 단계를 써서 :

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 

그런 다음 오이 기능은 더 나은이 같은 읽을 것이다 :

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. | 
관련 문제