From 1a5ddb3bf852f759a11bf8ee00cf956bfe4eaaef Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Sun, 25 Jun 2017 14:37:51 +0100 Subject: [PATCH 01/11] Adds scenario for the ambiguous step reporting --- .../defining_steps/ambiguous_steps.feature | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 features/docs/defining_steps/ambiguous_steps.feature diff --git a/features/docs/defining_steps/ambiguous_steps.feature b/features/docs/defining_steps/ambiguous_steps.feature new file mode 100644 index 0000000000..f22c0ac818 --- /dev/null +++ b/features/docs/defining_steps/ambiguous_steps.feature @@ -0,0 +1,63 @@ +Feature: Ambiguous Steps + + Scenario: Ambiguous steps + + Given a file named "features/ambiguous.feature" with: + """ + Feature: + + Scenario: test 1 + * a step + * an ambiguous step + + Scenario: test 2 + * step 1 + * step 2 + + """ + And a file named "features/step_definitions.rb" with: + """ + When(/^a.*step$/) do + 'foo' + end + + When(/^an ambiguous step$/) do + 'bar' + end + + When(/^step 1$/) do + 'baz' + end + + When(/^step 2$/) do + 'buzz' + end + """ + When I run `cucumber` + Then it should fail with exactly: + """ + Feature: + + Scenario: test 1 # features/ambiguous.feature:3 + * a step # features/step_definitions.rb:1 + * an ambiguous step # features/step_definitions.rb:5 + Error matching steps. + Step text "an ambiguous step" would be match by + - /^a.*step$/ at ./features/step_definitions.rb:1 + - /^an ambiguous step$/ at ./features/step_definitions.rb:6 + (Cucumber::Ambiguous) + -e:1:in `load' + -e:1:in `
' + features/ambiguous.feature:5:in `* an ambiguous step' + + Scenario: test 2 # features/ambiguous.feature:7 + * step 1 # features/step_definitions.rb:9 + * step 2 # features/step_definitions.rb:13 + + Failing Scenarios: + cucumber features/ambiguous.feature:3 # Scenario: test 1 + + 2 scenarios (1 failed, 1 passed) + 4 steps (1 failed, 3 passed) + 0m0.012s + """ From 452e2cdb608bb8444274bbf5f1a228c07fe13090 Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Sat, 1 Jul 2017 13:47:13 +0200 Subject: [PATCH 02/11] Adds @wip tag --- features/docs/defining_steps/ambiguous_steps.feature | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/docs/defining_steps/ambiguous_steps.feature b/features/docs/defining_steps/ambiguous_steps.feature index f22c0ac818..0af16012c0 100644 --- a/features/docs/defining_steps/ambiguous_steps.feature +++ b/features/docs/defining_steps/ambiguous_steps.feature @@ -1,5 +1,6 @@ Feature: Ambiguous Steps - + + @wip Scenario: Ambiguous steps Given a file named "features/ambiguous.feature" with: From 77ebe87eccfeffc5e3c72d29d28ae78c6d53937d Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Sat, 1 Jul 2017 13:49:28 +0200 Subject: [PATCH 03/11] Adds feature documentation --- features/docs/defining_steps/ambiguous_steps.feature | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/features/docs/defining_steps/ambiguous_steps.feature b/features/docs/defining_steps/ambiguous_steps.feature index 0af16012c0..2192420d14 100644 --- a/features/docs/defining_steps/ambiguous_steps.feature +++ b/features/docs/defining_steps/ambiguous_steps.feature @@ -1,5 +1,13 @@ Feature: Ambiguous Steps + When Cucumber searches for a step definition for a step, it might find multiple step + definitions that could match. In that case, it will give you an error that the step + definitions are ambiguous. + + You can also use a `--guess` mode, where it uses magic powers to try and figure + out which of those two step definitions is most likely to be the one you meant it + to use. Use it with caution! + @wip Scenario: Ambiguous steps From af9a5aba20a210ae05fb5063e7e4173d0d74ebad Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Sat, 1 Jul 2017 14:00:55 +0200 Subject: [PATCH 04/11] Simplifies tests scenarios by removing the scenario name --- features/docs/defining_steps/ambiguous_steps.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/docs/defining_steps/ambiguous_steps.feature b/features/docs/defining_steps/ambiguous_steps.feature index 2192420d14..fd85b2d5a1 100644 --- a/features/docs/defining_steps/ambiguous_steps.feature +++ b/features/docs/defining_steps/ambiguous_steps.feature @@ -15,11 +15,11 @@ Feature: Ambiguous Steps """ Feature: - Scenario: test 1 + Scenario: * a step * an ambiguous step - Scenario: test 2 + Scenario: * step 1 * step 2 From d98034675a2f20c1037b9d6ee7adcd478dc80066 Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Mon, 3 Jul 2017 20:39:46 +0200 Subject: [PATCH 05/11] Adds ambiguous tests with guess mode scenario --- .../defining_steps/ambiguous_steps.feature | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/features/docs/defining_steps/ambiguous_steps.feature b/features/docs/defining_steps/ambiguous_steps.feature index fd85b2d5a1..c6c582e954 100644 --- a/features/docs/defining_steps/ambiguous_steps.feature +++ b/features/docs/defining_steps/ambiguous_steps.feature @@ -70,3 +70,39 @@ Feature: Ambiguous Steps 4 steps (1 failed, 3 passed) 0m0.012s """ + + + Scenario: Ambiguous steps with guess mode + + Given a file named "features/ambiguous.feature" with: + """ + Feature: + + Scenario: + * a step + * an ambiguous step + """ + And a file named "features/step_definitions.rb" with: + """ + When(/^a.*step$/) do + 'foo' + end + + When(/^an ambiguous step$/) do + 'bar' + end + """ + When I run `cucumber -g` + Then it should pass with exactly: + """ + Feature: + + Scenario: # features/ambiguous.feature:3 + * a step # features/step_definitions.rb:1 + * an ambiguous step # features/step_definitions.rb:5 + + 1 scenario (1 passed) + 2 steps (2 passed) + 0m0.012s + + """ \ No newline at end of file From 5242c69eb1123bf1316d65f0ee940dce6fbdae4f Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Mon, 3 Jul 2017 21:04:56 +0200 Subject: [PATCH 06/11] Simplifies ambiguous steps scenario --- .../defining_steps/ambiguous_steps.feature | 45 ++++--------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/features/docs/defining_steps/ambiguous_steps.feature b/features/docs/defining_steps/ambiguous_steps.feature index c6c582e954..64ebbf6998 100644 --- a/features/docs/defining_steps/ambiguous_steps.feature +++ b/features/docs/defining_steps/ambiguous_steps.feature @@ -8,7 +8,7 @@ Feature: Ambiguous Steps out which of those two step definitions is most likely to be the one you meant it to use. Use it with caution! - @wip + Scenario: Ambiguous steps Given a file named "features/ambiguous.feature" with: @@ -19,10 +19,6 @@ Feature: Ambiguous Steps * a step * an ambiguous step - Scenario: - * step 1 - * step 2 - """ And a file named "features/step_definitions.rb" with: """ @@ -34,41 +30,18 @@ Feature: Ambiguous Steps 'bar' end - When(/^step 1$/) do - 'baz' - end - - When(/^step 2$/) do - 'buzz' - end """ When I run `cucumber` - Then it should fail with exactly: + Then it should fail with: """ - Feature: + Ambiguous match of "an ambiguous step": + + features/step_definitions.rb:1:in `/^a.*step$/' + features/step_definitions.rb:5:in `/^an ambiguous step$/' + + You can run again with --guess to make Cucumber be more smart about it + (Cucumber::Ambiguous) - Scenario: test 1 # features/ambiguous.feature:3 - * a step # features/step_definitions.rb:1 - * an ambiguous step # features/step_definitions.rb:5 - Error matching steps. - Step text "an ambiguous step" would be match by - - /^a.*step$/ at ./features/step_definitions.rb:1 - - /^an ambiguous step$/ at ./features/step_definitions.rb:6 - (Cucumber::Ambiguous) - -e:1:in `load' - -e:1:in `
' - features/ambiguous.feature:5:in `* an ambiguous step' - - Scenario: test 2 # features/ambiguous.feature:7 - * step 1 # features/step_definitions.rb:9 - * step 2 # features/step_definitions.rb:13 - - Failing Scenarios: - cucumber features/ambiguous.feature:3 # Scenario: test 1 - - 2 scenarios (1 failed, 1 passed) - 4 steps (1 failed, 3 passed) - 0m0.012s """ From c2334502f17f45636f2ce3e67e1c0894fd9e8a90 Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Tue, 4 Jul 2017 22:04:21 +0200 Subject: [PATCH 07/11] Improves test scenarios by adding keywords --- .../defining_steps/ambiguous_steps.feature | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/features/docs/defining_steps/ambiguous_steps.feature b/features/docs/defining_steps/ambiguous_steps.feature index 64ebbf6998..e801fcd4ba 100644 --- a/features/docs/defining_steps/ambiguous_steps.feature +++ b/features/docs/defining_steps/ambiguous_steps.feature @@ -16,8 +16,8 @@ Feature: Ambiguous Steps Feature: Scenario: - * a step - * an ambiguous step + When a step + Then an ambiguous step """ And a file named "features/step_definitions.rb" with: @@ -26,7 +26,7 @@ Feature: Ambiguous Steps 'foo' end - When(/^an ambiguous step$/) do + Then(/^an ambiguous step$/) do 'bar' end @@ -52,8 +52,8 @@ Feature: Ambiguous Steps Feature: Scenario: - * a step - * an ambiguous step + When a step + Then an ambiguous step """ And a file named "features/step_definitions.rb" with: """ @@ -61,18 +61,18 @@ Feature: Ambiguous Steps 'foo' end - When(/^an ambiguous step$/) do + Then(/^an ambiguous step$/) do 'bar' end """ When I run `cucumber -g` Then it should pass with exactly: """ - Feature: + Feature: - Scenario: # features/ambiguous.feature:3 - * a step # features/step_definitions.rb:1 - * an ambiguous step # features/step_definitions.rb:5 + Scenario: # features/ambiguous.feature:3 + When a step # features/step_definitions.rb:1 + Then an ambiguous step # features/step_definitions.rb:5 1 scenario (1 passed) 2 steps (2 passed) From f3660a11f5a9cefd5737e7af0197ceb293741705 Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Wed, 5 Jul 2017 22:12:20 +0200 Subject: [PATCH 08/11] Adds summary report to ambiguous steps scenario --- features/docs/defining_steps/ambiguous_steps.feature | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/features/docs/defining_steps/ambiguous_steps.feature b/features/docs/defining_steps/ambiguous_steps.feature index e801fcd4ba..239227bb98 100644 --- a/features/docs/defining_steps/ambiguous_steps.feature +++ b/features/docs/defining_steps/ambiguous_steps.feature @@ -42,6 +42,10 @@ Feature: Ambiguous Steps You can run again with --guess to make Cucumber be more smart about it (Cucumber::Ambiguous) + 1 scenario (1 failed) + 2 steps (1 failed, 1 passed) + 0m0.012s + """ From e1c1200db631abaedad164560f24c31fea711f1f Mon Sep 17 00:00:00 2001 From: Gloria Hornero Date: Wed, 5 Jul 2017 22:13:52 +0200 Subject: [PATCH 09/11] Adds @wip tag to ambiguous steps scenario --- features/docs/defining_steps/ambiguous_steps.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/features/docs/defining_steps/ambiguous_steps.feature b/features/docs/defining_steps/ambiguous_steps.feature index 239227bb98..917d9101bb 100644 --- a/features/docs/defining_steps/ambiguous_steps.feature +++ b/features/docs/defining_steps/ambiguous_steps.feature @@ -9,6 +9,7 @@ Feature: Ambiguous Steps to use. Use it with caution! + @wip Scenario: Ambiguous steps Given a file named "features/ambiguous.feature" with: From b39f24fdedaf39f67c0dc989bc2ee05548cbd2fa Mon Sep 17 00:00:00 2001 From: Eric Kessler Date: Sun, 9 Jul 2017 17:03:29 -0400 Subject: [PATCH 10/11] Add ambiguous step matching Taught Cucumber how to match against ambiguous steps. --- lib/cucumber/filters/activate_steps.rb | 7 ++++++- lib/cucumber/step_match.rb | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/cucumber/filters/activate_steps.rb b/lib/cucumber/filters/activate_steps.rb index 8fe7ad97cd..14773c41e0 100644 --- a/lib/cucumber/filters/activate_steps.rb +++ b/lib/cucumber/filters/activate_steps.rb @@ -43,7 +43,12 @@ def initialize(step_match_search, configuration, test_step) end def result - return NoStepMatch.new(test_step.source.last, test_step.name) unless matches.any? + begin + return NoStepMatch.new(test_step.source.last, test_step.name) unless matches.any? + rescue Cucumber::Ambiguous => e + return AmbiguousStepMatch.new(e) + end + configuration.notify :step_activated, test_step, match return SkippingStepMatch.new if configuration.dry_run? match diff --git a/lib/cucumber/step_match.rb b/lib/cucumber/step_match.rb index 50f8846a85..d8c8c038c3 100644 --- a/lib/cucumber/step_match.rb +++ b/lib/cucumber/step_match.rb @@ -139,4 +139,17 @@ def activate(test_step) return test_step end end + + class AmbiguousStepMatch + + def initialize(error) + @error = error + end + + def activate(test_step) + return test_step.with_action { raise Core::Test::Result::Ambiguous.new(@error.message) } + end + + end + end From 041536a7ab89d06d2a321fd30dc4a1b07efca414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Rasmusson?= Date: Wed, 2 Aug 2017 15:15:27 +0200 Subject: [PATCH 11/11] Fix the feature and implementation of ambiguous steps. --- .../defining_steps/ambiguous_steps.feature | 19 +++++++++++-------- lib/cucumber/step_match.rb | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/features/docs/defining_steps/ambiguous_steps.feature b/features/docs/defining_steps/ambiguous_steps.feature index 917d9101bb..8606f54577 100644 --- a/features/docs/defining_steps/ambiguous_steps.feature +++ b/features/docs/defining_steps/ambiguous_steps.feature @@ -9,7 +9,6 @@ Feature: Ambiguous Steps to use. Use it with caution! - @wip Scenario: Ambiguous steps Given a file named "features/ambiguous.feature" with: @@ -35,13 +34,17 @@ Feature: Ambiguous Steps When I run `cucumber` Then it should fail with: """ - Ambiguous match of "an ambiguous step": - - features/step_definitions.rb:1:in `/^a.*step$/' - features/step_definitions.rb:5:in `/^an ambiguous step$/' - - You can run again with --guess to make Cucumber be more smart about it - (Cucumber::Ambiguous) + Ambiguous match of "an ambiguous step": + + features/step_definitions.rb:1:in `/^a.*step$/' + features/step_definitions.rb:5:in `/^an ambiguous step$/' + + You can run again with --guess to make Cucumber be more smart about it + (Cucumber::Ambiguous) + features/ambiguous.feature:5:in `Then an ambiguous step' + + Failing Scenarios: + cucumber features/ambiguous.feature:3 # Scenario: 1 scenario (1 failed) 2 steps (1 failed, 1 passed) diff --git a/lib/cucumber/step_match.rb b/lib/cucumber/step_match.rb index d8c8c038c3..5404381e11 100644 --- a/lib/cucumber/step_match.rb +++ b/lib/cucumber/step_match.rb @@ -147,7 +147,7 @@ def initialize(error) end def activate(test_step) - return test_step.with_action { raise Core::Test::Result::Ambiguous.new(@error.message) } + return test_step.with_action { raise @error } end end