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
4

1 に答える 1

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

次に、Cucumber 機能は次のように読みやすくなります。

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. |
于 2012-05-15T16:51:16.007 に答える