Cómo reutilizar pepino definición de paso con una mesa para el último parámetro?

StackOverflow https://stackoverflow.com/questions/4033182

  •  26-09-2019
  •  | 
  •  

Pregunta

Este código:

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

Y éste:

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

Y esto:

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

Y aunque esto:

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

Me da:

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

Éste:

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

Y éste:

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

Da:

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'
¿Fue útil?

Solución

he encontrado la respuesta a mí mismo:

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

Otros consejos

NOTA SOBRE LA ANTERIOR: Puede parecer obvio, pero la nueva línea después de la primera '{' es importante taaaaaaaaaaaaaaaan

Otra forma:

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

También puede escribir de esta manera, utilizando #table

Then /^some other step$/ do
  Then %{I should see the following data in the "Feeds" data grid:}, table(%{
    | Name    |
    | #{name} |
  })
end

Considere el uso

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

Me parece que mucho más elegante que la construcción de la mesa con la mano.

eventos con: - se pone una tabla como ésta

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

y un evento con: - crear una tabla como

| Form    | foo |
| Element | bar |
| Label   | baz |
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top