Ruby,黄瓜,在if语句中调用步骤

时间:2013-04-22 19:12:37

标签: ruby cucumber

在让Gherkin更具可读性的过程中,我试图在一步中迈出一步。

Given /^I am a user with a case with (.*) properties with X enabled$/ do |number|
  if number == 2
    step "I login as a, 1, 2 user with X num_of_properties_2"
    puts "prop2"
  elsif number == 1
    step "I login as a, 1, 2 user with X num_of_properties_1"
    puts "prop1"
  end
end

如果我只做

,这些都不会起作用
 Given /^I am a user with a case with (.*) properties with X enabled$/ do |number|
     step "I login as a, 1, 2 user with X num_of_properties_2"
 end

这很有效。

我无法在"中提出另一个步骤的原因。声明?

1 个答案:

答案 0 :(得分:1)

使用(\ d +)而不是(。*)来捕获数字。