Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 207
Dragan Nikolic Avatar asked Sep 08 '25 12:09

Dragan Nikolic


1 Answers

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".

like image 138
max pleaner Avatar answered Sep 10 '25 12:09

max pleaner