https://github.com/cucumber/cucumber/wiki/Calling-Steps-from-Step-Definitions#calling-steps-with-multiline-step-arguments
使用多行步骤参数调用步骤
有时您想调用一个设计为采用多行步骤参数的步骤,例如:
# ruby
Given /^an expense report for (.*) with the following posts:$/ do |date, posts_table|
# The posts_table variable is an instance of Cucumber::Ast::Table
end
这可以很容易地从这样的纯文本步骤中调用:
# feature
Given an expense report for Jan 2009 with the following posts:
| account | description | amount |
| INT-100 | Taxi | 114 |
| CUC-101 | Peeler | 22 |
但是,如果您想从步骤定义中调用它怎么办?有几种方法可以做到这一点:
# ruby
Given /A simple expense report/ do
step "an expense report for Jan 2009 with the following posts:", table(%{
| account | description | amount |
| INT-100 | Taxi | 114 |
| CUC-101 | Peeler | 22 |
})
end
或者,如果您更喜欢程序化方法:
# ruby
Given /A simple expense report/ do
step "an expense report for Jan 2009 with the following posts:", table([
%w{ account description amount },
%w{ INT-100 Taxi 114 },
%w{ CUC-101 Peeler 22 }
])
end