I’m attempting to learn how to use Cucumber and creating steps using the following scenario (I’ve got a model called “Vegetable,” and I’ve added a new attribute called “color”):
Scenario: add color to existing vegetable
When I go to the edit page for "Potato"
And I fill in "Color" with "Brown"
And I press "Update Vegetable Info"
Then the color of "Potato" should be "Brown"
I’m currently using “training-wheels” so I have a web step (web_steps.rb):
When /^(?:|I )go to (.+)?/ do |page_name|
visit path_to(page_name)
end
Now I understand how this works with a simple page navigation such as “When I go to the vegetable home page.” All I have to do is add a path to paths.rb:
When /^the vegetable home page/
'/vegetables'
However, with the above example I need to go to a particular path with a particular vegetable “/vegetables/1” (Potato url).
I’m not sure how to do this, so I tried created my own step:
When /I go to the edit page for "(.*)"/ do |vegetable_name|
flunk "Unimplemented"
end
But I get the error:
Ambiguous match of "I go to the edit page for "Potato"":
features/step_definitions/vegetable_steps.rb:15:in `/go to the edit page for "(.*)"/'
features/step_definitions/web_steps.rb:48:in `/^(?:|I )go to (.+)$/'
You can run again with --guess to make Cucumber be more smart about it
(Cucumber::Ambiguous)
Is this how I’m supposed to do this? Or do I just use the web_steps “go to” step and provide the id somehow in the paths.rb file? I’m just trying to figure out how to start this after hours of reading various Cucumber tutorials.
As DVG stated, it’s because I had the matching step in two places that I was receiving the error. To answer my own question I can just lean on the “web_step” that is already provided:
Once I added the following code to paths.rb:
I was able to get this to work properly.