4

I'm learning to test a CLI with Aruba using this guide that is a few years old. I'm getting an error

Cucumber::Ambiguous match error

After looking through several examples of this kind of error, I'm still not sure what to do about it.

  Scenario: Recipes
    When I run `foodie recipe dinner steak`
    Then the following files should exist:
      | dinner/steak.txt |
    Then the file "dinner/steak.txt" should contain:
      """
      ##### Ingredients #####
      Ingredients for delicious steak go here.


      ##### Instructions #####
      Tips on how to make delicious steak go here.
      """

in features/step_definitions/extra_aruba_steps.rb I have this added step:

Then /^the file "([^"]*)" should contain:$/ do |file, content|
  check_file_content(file, content, true)
end

Can someone explain this error and what to do different to fix it.

Thanks in advance

Update after Peter Alfrin's comment:

I have aruba/cucumber included which gives access to all these pre-defined steps

Full error output:

Then the file "dinner/steak.txt" should contain: # features/generator.feature:10
      """
      ##### Ingredients #####
      Ingredients for delicious steak go here.


      ##### Instructions #####
      Tips on how to make delicious steak go here.
      """
      Ambiguous match of "the file "dinner/steak.txt" should contain:":

      aruba-0.5.3/lib/aruba/cucumber.rb:300:in `/^the file "([^"]*)" should contain:$/'
      features/step_definitions/aruba_ext_steps.rb:1:in `/^the file "([^"]*)" should contain:$/'

      You can run again with --guess to make Cucumber be more smart about it
       (Cucumber::Ambiguous)
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:147:in `step_match_without_cache'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:138:in `step_match'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:68:in `step_match'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_invocation.rb:83:in `find_step_match!'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_invocation.rb:56:in `invoke'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_invocation.rb:38:in `accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:106:in `block in visit_step'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:105:in `visit_step'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_collection.rb:19:in `block in accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_collection.rb:18:in `each'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/step_collection.rb:18:in `accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:100:in `block in visit_steps'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:99:in `visit_steps'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:15:in `block in execute'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:82:in `block (2 levels) in with_hooks'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:98:in `before_and_after'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:81:in `block in with_hooks'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:120:in `call'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:120:in `block (3 levels) in around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:9:in `block in around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:97:in `call'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:97:in `execute_around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/language_support/language_methods.rb:8:in `around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:119:in `block (2 levels) in around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:123:in `call'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime/support_code.rb:123:in `around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:93:in `around'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:80:in `with_hooks'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:13:in `execute'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/scenario.rb:32:in `block in accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/scenario.rb:79:in `with_visitor'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/scenario.rb:31:in `accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:58:in `block in visit_feature_element'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:57:in `visit_feature_element'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/feature.rb:38:in `block in accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/feature.rb:37:in `each'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/feature.rb:37:in `accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:27:in `block in visit_feature'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:26:in `visit_feature'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:28:in `block in accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:17:in `each'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:17:in `each'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/features.rb:27:in `accept'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:21:in `block in visit_features'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:170:in `broadcast'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/ast/tree_walker.rb:20:in `visit_features'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/runtime.rb:48:in `run!'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/lib/cucumber/cli/main.rb:47:in `execute!'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/gems/cucumber-1.3.4/bin/cucumber:13:in `<top (required)>'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/cucumber:23:in `load'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/cucumber:23:in `<main>'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval'
      /Users/Brian/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>'
      features/generator.feature:10:in `Then the file "dinner/steak.txt" should contain:'

Failing Scenarios:
cucumber features/generator.feature:6 # Scenario: Recipes
fontno
  • 6,642
  • 6
  • 36
  • 43
  • Do you have any other step definitions that could match the `Then` clause in your test? – Peter Alfvin Jul 20 '13 at 23:09
  • @PeterAlfvin Take a look at the updated question. There is a link to the other included steps. I should have been smart enough to include in the first place. Thanks for your help – fontno Jul 21 '13 at 19:39
  • Are you getting additional output with the error? I searched the cucumber/cucumber repository and it appears that `Ambiguous` is always raised with additional output. – Peter Alfvin Jul 22 '13 at 01:33
  • @PeterAlfvin after looking at the pre defined steps it looks like the step I added is already in there. `Then /^the file "([^"]*)" should contain "([^"]*)"$/ do |file, partial_content|; check_file_content(file, partial_content, true); end;`. However, it did not pick it up the first time and asked me to define the step. Not sure why – fontno Jul 22 '13 at 20:20
  • That's what I suspected, but I'm still wondering about the error output. Would you mind sharing the full error message? – Peter Alfvin Jul 22 '13 at 21:13
  • @PeterAlfvin I added to the error message. Let me know if there is anything else. thanks – fontno Jul 22 '13 at 23:14

1 Answers1

4

This topic is covered straightforwardly in https://github.com/cucumber/cucumber/wiki/Step-Definitions#ambiguous-steps

If the text of a Cucumber step is matched by the pattern of two or more step definitions, then Cucumber will raise Ambiguous unless the --guess option is specified, in which case Cucumber will pick one arbitrarily.

As an aside, it's helpful if you can present the full error message text in any SO question, particularly when the error message contains so much information as in this case.

Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
  • @PeterAlfrin, right I read that link before I posted the question. However, before I added the extra ambiguous step in `aruba_ext_steps` the step in the pre-defined steps was not used. Why is this? In other words, the predefined step should have worked? it didn't. Now when I add the extra step I get an ambiguous match because it sees to of the same step definitions. I doesn't make sense. This is the question..... And also I tried `--guess` and got the same error. – fontno Jul 23 '13 at 19:40
  • You tried `--guess` with the additional step definition and it still raised `Ambiguous` or you tried `--guess` *without* the additional step definition and it still didn't find a matching definition? – Peter Alfvin Jul 23 '13 at 20:11
  • Also, did you try executing with `aruba_ext_steps` but without a step definition in that file that matches? I know this shouldn't be necessary, I'm just trying to isolate the problem. – Peter Alfvin Jul 23 '13 at 20:15
  • @PeterAlfrin I just tried it without the `aruba_ext_steps` and its passing. It is picking up the step definition that was pre-defined now but for whatever reason it didn't before. Thanks for your help – fontno Jul 23 '13 at 21:02