如何使用最后一个参数的表重用 Cucumber 步骤定义?

发布于 2024-09-29 06:52:15 字数 1766 浏览 3 评论 0原文

这段代码:

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'

This code:

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

And this one:

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

And this:

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

And even this:

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

Gives me:

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

This one:

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

And this one:

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

Gives:

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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

人海汹涌 2024-10-06 06:52:15

我自己找到了答案:

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

I've found the answer myself:

steps %Q{
Then I should see the following data in the "Feeds" data grid:
                                                |   Name   |
                                                | #{name}  |
}
眼眸印温柔 2024-10-06 06:52:15

上面的注释:可能看起来很明显,但是第一个“{”之后的新行非常重要

另一种方式:

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

NOTE ON THE ABOVE: might seem obvious, but the new line after the first '{' is soooooo important

Another way:

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
简单爱 2024-10-06 06:52:15

你也可以这样写,使用#table

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

You can also write it this way, using #table

Then /^some other step$/ do
  Then %{I should see the following data in the "Feeds" data grid:}, table(%{
    | Name    |
    | #{name} |
  })
end
浊酒尽余欢 2024-10-06 06:52:15

考虑使用

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 |

Consider using

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

I find that much more elegant that building up the table by hand.

events with:- gets a table like this

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

and an event with:- gets a table like

| Form    | foo |
| Element | bar |
| Label   | baz |
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文