我正在使用calabash-android来测试我的应用。
我创造了自己的一步:
Then /^There should be (\d+) customers$/ do |nr_of_customers|
...
end
之后,我创建了另一个步骤,需要调用上面的现有步骤,我知道我可以使用宏,所以我尝试了这个:
Given /^I hosted (\d+) customers$/ do |nr_of_customers|
#How to pass the nr_of_customers to the macro???
macro 'There should be nr_of_customers'
...
end
但是,如何将参数nr_of_customers
传递给调用其他步骤函数的宏?
答案 0 :(得分:3)
不要在步骤中调用步骤,如果你这样做,你最终会得到一堆意大利面条代码。而是从步骤定义中提取辅助方法,然后调用它们。
e.g。
Then /^There should be (\d+) customers$/ do |nr_of_customers|
expect(customer_count).to be nr_of_customers
end
Given /^I hosted (\d+) customers$/ do |nr_of_customers|
# do some stuff to set up the customers
expect(customer_count).to be nr_of_customers
...
module StepHelpers
def customer_count
....
此外,在Givens中嵌入then语句也是不好的做法。 Givens关于设置状态而不是测试结果,所以你的确给出的应该是
Given /^I hosted (\d+) customers$/ do |nr_of_customers|
nr_of_customers.times do
host_customer
end
当您编写表明可以托管客户的方案时,host_customer
应该是您创建的帮助。