Dragan Nikolic
Dragan Nikolic

Reputation: 1766

Why do I get 'Undefined dynamic step' in Cucumber?

I have following step definitions (just to illustrate my problem):

When(/^the calculator is run$/) do
  step %{When xxx the calculator is run xxx}
end

When(/^xxx the calculator is run xxx$/) do
  @output = `ruby calc.rb #{@input}` 
  raise('Command failed!') unless $?.success?
end

In my feature file, when I call:

When the calculator is run

I got the error message:

Undefined dynamic step: "When xxx the calculator is run xxx" (Cucumber::UndefinedDynamicStep)
./features/step_definitions/calculator_steps_when.rb:2:in `/^the calculator is run$/'
features/adding.feature:11:in `When the calculator is run'
features/adding.feature:6:in `When the calculator is run'

According to the documentation this should work. Initially I had the steps in different files, and thought maybe I had to provide some include directive, but now it happens even when steps are in the same file. What am I missing?

Thanks

Upvotes: 4

Views: 3427

Answers (1)

max pleaner
max pleaner

Reputation: 26758

In this line:

  step %{When xxx the calculator is run xxx}

Remove the "When" and it should work correctly.

You can check this in the cucumber docs. The step example they give doesn't include the word "When".

Upvotes: 14

Related Questions