2013-07-20 40 views
4

我正在學習使用幾年前的guide來測試使用Aruba的CLI。我發現了一個錯誤如何解決Cucumber ::在Aruba中測試CLI時模糊匹配錯誤

Cucumber::Ambiguous match error 

通過這種錯誤的幾個例子看後,我仍然不知道該怎麼辦纔好。

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. 
     """ 
features/step_definitions/extra_aruba_steps.rb

我有這個增加的步驟:

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

有人能解釋這個錯誤,並做什麼不同的解決它。提前

感謝

更新後,彼得Alfrin的評論:

我已經包括阿魯巴/黃瓜它可以訪問all these pre-defined steps

完整的錯誤輸出:

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 
+0

你有沒有其他的步驟定義可以匹配測試中的'Then'子句? –

+0

@PeterAlfvin看看更新後的問題。有一個鏈接到其他包含的步驟。首先,我本應該足夠聰明。感謝您的幫助 – fontno

+0

您是否因錯誤獲得了額外的輸出?我搜查了黃瓜/黃瓜資源庫,看起來'Ambiguous'總是會增加額外的輸出。 –

回答

3

這話題被直截了當地在https://github.com/cucumber/cucumber/wiki/Step-Definitions#ambiguous-steps

如果黃瓜步驟的文本由兩個或更多個步驟定義圖案匹配,那麼黃瓜將提高Ambiguous除非指定了--guess選項時,在這種情況下,將黃瓜選擇一個任意。

另外,如果您可以在任何SO問題中提供完整的錯誤消息文本,特別是當錯誤消息包含如此多信息時,這很有幫助。

+0

@PeterAlfrin,我在發佈問題之前閱讀了該鏈接。但是,在我在'aruba_ext_steps'中添加了額外的模糊步驟之前,沒有使用預定義步驟中的步驟。爲什麼是這樣?換句話說,預定義的步驟應該起作用了?它沒有。現在當我添加額外的步驟時,我得到一個模糊的匹配,因爲它看到相同的步驟定義。我沒有道理。這是問題.....而且我嘗試了'--guess'並得到了同樣的錯誤。 – fontno

+0

您嘗試使用附加步驟定義的「--guess」,並且它仍然引發'Ambiguous'或者您嘗試了'--guess' *而沒有*額外的步驟定義,但它仍未找到匹配的定義? –

+0

另外,你是否嘗試用'aruba_ext_steps'執行,但沒有在該文件中匹配的步驟定義?我知道這不應該是必要的,我只是想孤立這個問題。 –

相關問題