Как повторно использовать определение шага огурца с таблицей для последнего параметра? - PullRequest
7 голосов
/ 27 октября 2010

Этот код:

Then %{I should see the following data in the "Feeds" data grid:
                                                   |   Name   |
                                                   | #{name}  |}

И этот:

Then "I should see the following data in the \"Feeds\" data grid:
|   Name   |
| #{name}  |"

И это:

  Then "I should see the following data in the \"Feeds\" data grid:\n|   Name   |\n| #{name}  |"

И даже это:

Then <<EOS
I should see the following data in the "Feeds" data grid:
|   Name   |
| #{name}  |
EOS

Дает мне:

Your block takes 2 arguments, but the Regexp matched 1 argument.
(Cucumber::ArityMismatchError)
  tests/endtoend/step_definitions/instruments_editor_steps.rb:29:in `/^the editor shows "([^"]*)" in the feeds list$/'
  melomel-0.6.0/lib/melomel/cucumber/data_grid_steps.rb:59:in `/^I should see the following data in the "([^"]*)" data grid:$/'
  tests/endtoend/instruments_editor.feature:11:in `And the editor shows "myFeed" in the feeds list

Этот:

Then "I should see the following data in the \"Feeds\" data grid: |   Name   || #{name}  |"

А этот:

Then "I should see the following data in the \"Feeds\" data grid:|   Name   || #{name}  |"

Дает:

Undefined step: "I should see the following data in the "Feeds" data grid:|   Name   || myFeed  |" (Cucumber::Undefined)
  ./tests/endtoend/step_definitions/instruments_editor_steps.rb:31:in `/^the editor shows "([^"]*)" in the feeds list$/'
  tests/endtoend/instruments_editor.feature:11:in `And the editor shows "myFeed" in the feeds list'

Ответы [ 4 ]

6 голосов
/ 27 октября 2010

Я нашел ответ сам:

steps %Q{
Then I should see the following data in the "Feeds" data grid:
                                                |   Name   |
                                                | #{name}  |
}
3 голосов
/ 01 июня 2011

Вы также можете написать это так, используя #table

Then /^some other step$/ do
  Then %{I should see the following data in the "Feeds" data grid:}, table(%{
    | Name    |
    | #{name} |
  })
end
3 голосов
/ 01 июня 2011

ПРИМЕЧАНИЕ НА ВЫШЕ: может показаться очевидным, но новая строка после первого '{' оооочень важна

Другой способ:

Given /^My basic step:$/ do |table|
  #do table operation
end


Given /^My referring step:$/ do |table|
  table.hashes.each do |row|    
    row_as_table = %{
      |prop1|prop2|
      |#{row[:prop1]}|#{row[:prop2]}|
    }
    Given %{My basic step:}, Cucumber::Ast::Table.parse(row_as_table, "", 0)
  end
end
0 голосов
/ 26 августа 2011

Рассмотрите возможность использования

Given /^events with:-$/ do |table|
  Given %{I am on the event admin page}
  table.hashes.each do |row|
    Given %{an event with:-}, Cucumber::Ast::Table.new([row]).transpose
  end
end

Я считаю, что это намного элегантнее, чем строить стол вручную.

событий с: - получает такую ​​таблицу

| Form | Element | Label |
| foo  | bar     | baz   |

и событие с: - получает таблицу типа

| Form    | foo |
| Element | bar |
| Label   | baz |
...