Matt Westlake
Matt Westlake

Reputation: 3651

Ruby, cucumber, calling a step within a step, within an if statement

In a process of making Gherkin a little more readable, I'm trying to call a step within a step.

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

Neither of these will work, however if I do only

 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

This works perfectly.

Any reason why I cannot call another step within an "if" statement?

Upvotes: 0

Views: 1086

Answers (1)

Tsagadai
Tsagadai

Reputation: 887

Capture the number with (\d+) instead of (.*).

Upvotes: 1

Related Questions