1

私はレールに非常に慣れておらず、BDDにも慣れていません。私はDRY方法論に固執しようとしましたが、ここでは何かが正しくありません。

特徴

  Scenario: Add a new vehicle with valid data
    Given I exist as a user
      And I am logged in
      And I am on the Create New Vehicle page
    When I fill out the form with the following attributes:
      | vehicle_make    | DODGE       |
      | vehicle_model   | RAM 1500    |
      | vehicle_year    | 2005        |
      | vehicle_engine  | 5.7L        |
      | vehicle_color   | Black       |
      And I click the Create Vehicle button
    Then I should see Vehicle was successfully created.

ステップ定義

    ## this is in common_steps.rb

    When /^I fill out the form with the following attributes:$/ do |table|
      puts table.rows_hash
      criteria = table.rows_hash.each do |field, value|
        fill_in field.to_sym, :with => value
      end
    end
    When /^I click the (.*?) button$/ do |button|
      click_button button
    end

試験結果

## seems that its not filling the form out as im getting
## "cannot be blank" validation errors

  Scenario: Add a new vehicle with valid data               # features/vehicles/vehicle_new.feature:12
    Given I exist as a user                                 # features/step_definitions/user_steps.rb:42
    And I am logged in                                      # features/step_definitions/common_steps.rb:18
    And I am on the Create New Vehicle page                 # features/step_definitions/common_steps.rb:22
    When I fill out the form with the following attributes: # features/step_definitions/common_steps.rb:33
      {"vehicle_make"=>"DODGE", "vehicle_model"=>"RAM 1500", "vehicle_year"=>"2005", "vehicle_engine"=>"5.7L", "vehicle_color"=>"Black"}
      | vehicle_make   | DODGE    |
      | vehicle_model  | RAM 1500 |
      | vehicle_year   | 2005     |
      | vehicle_engine | 5.7L     |
      | vehicle_color  | Black    |
    And I click the Create Vehicle button                   # features/step_definitions/common_steps.rb:39
    Then I should see Vehicle was successfully created.     # features/step_definitions/common_steps.rb:47
      expected there to be content "Vehicle was successfully created." in "GasLoggr | Create New Vehicle\n  \n      \n          Gasloggr\n          \n            \n            \n            \n          \n              Welcome Back Test User\n              \n            Home\n    About\n\n        \n      \n    \n  \n    Vehicles\n        Fillups\n        Edit Profile\n    Logout\n        \n\n  \n    \n      \n        \n          Create New Vehicle\n      \n      \n        \n          \n    NAVIGATION\n            Vehicles\n            Fillups\n            Edit Profile\n    \n        \n        \n          \n          \n\t\n\t\t\n\t\t\t\n    \n      4 errors prohibited this vehicle from being saved:\n\n      Color can't be blank\n        Engine can't be blank\n        Model can't be blank\n        Year can't be blank\n      \n  \n      Make\n      \n        \n    \n    \n      Model\n      \n        \n      \n    \n    \n      Year\n      \n        \n      \n    \n    \n      Engine\n      \n        \n      \n    \n    \n      Color\n      \n        \n      \n    \n    \n      Image\n      \n        \n    \n    \n      Description\n      \n        \n    \n    \n      Cancel\n    \n  \n\t\t\n\t\t\n\t\t\tLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\n\t\t\ttempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\n\t\t\tquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\n\t\t\tconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\n\t\t\tcillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\n\t\t\tproident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\t\t\n\t\n\n        \n      " (RSpec::Expectations::ExpectationNotMetError)
      ./features/step_definitions/common_steps.rb:48:in `/^I should see (.*?)$/'
      features/vehicles/vehicle_new.feature:23:in `Then I should see Vehicle was successfully created.'

私が知ることができるすべてから、ステップ定義はフォームに記入していませんが、フォーム値は結果からのこの行に従って適切に存在します。{"vehicle_make"=>"DODGE", "vehicle_model"=>"RAM 1500", "vehicle_year"=>"2005", "vehicle_engine"=>"5.7L", "vehicle_color"=>"Black"}

4

2 に答える 2

2

問題は次の行でした。

fill_in field.to_sym, :with => value

具体的に.to_symは、フォーム フィールドに適切な値を渡さなかったことが原因でした。の削除.to_symと作成:

fill_in field, :with => value

問題を修正し、DRY 方法論に固執しながらテストに合格するようになりました

于 2012-10-02T16:24:36.503 に答える
0
Scenario: Add a new vehicle with valid data
    Given I exist as a user
    And I am logged in
    And I am on the Create New Vehicle page
    When I fill out the form with the following attributes:
      | attribute_name  | attribute_name | // write attribute name here 
      | vehicle_make    | DODGE          |
      | vehicle_model   | RAM 1500       |
      | vehicle_year    | 2005           |
      | vehicle_engine  | 5.7L           |
      | vehicle_color   | Black          |
    And I click the Create Vehicle button
    Then I should see Vehicle was successfully created.

例えば

| name      | display_name | // name and display_name it's a attribute name
| Ollie     | ollie        |
| David     | player       |
| Victoria  | Victoria     |
于 2012-10-04T12:37:32.977 に答える