【发布时间】:2015-12-15 01:22:42
【问题描述】:
我今天和一位同事进行了深入的讨论。调用另一个步骤是否被认为是最佳实践? 所以,例如:
Given /a turtle/ do
puts "turtle!"
end
Given /two turtles/ do
step "a turtle"
step "a turtle"
end
在我看来,这意味着您不能在不检查整个项目的情况下更改功能文件。因此,如果我想保持 DRY,我更喜欢使用从这些步骤调用的“代码”函数(即在 Ruby 中)。
def turtle do
puts "turtle!"
end
Given /a turtle/ do
turtle
end
Given /two turtles/ do
turtle
turtle
end
如果没有选择,我什至更喜欢复制代码而不是调用其他步骤。
Given /a turtle/ do
puts "turtle!"
end
Given /two turtles/ do
puts "turtle!"
puts "turtle!"
end
什么是最佳实践,为什么?
【问题讨论】:
-
你说的是
nested steps?如果可能,我建议发布示例代码。 -
我经常听到在步骤中使用调用函数,并在更通用的步骤中使用多个函数调用。