Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 53 additions & 5 deletions features/docs/defining_steps/ambiguous_steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ 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.
definitions are ambiguous. Also when skipping an ambiguous step the error will occur
so ambiguous steps are not hidden by earlier failures.

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
Expand Down Expand Up @@ -40,14 +41,14 @@ Feature: Ambiguous Steps
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)
(Cucumber::Core::Test::Result::Ambiguous)
features/ambiguous.feature:5:in `an ambiguous step'

Failing Scenarios:
Ambiguous Scenarios:
cucumber features/ambiguous.feature:3 # Scenario:

1 scenario (1 failed)
2 steps (1 failed, 1 passed)
1 scenario (1 ambiguous)
2 steps (1 ambiguous, 1 passed)
0m0.012s

"""
Expand Down Expand Up @@ -86,3 +87,50 @@ Feature: Ambiguous Steps
0m0.012s

"""

Scenario: Ambiguous steps after failed steps

Given a file named "features/ambiguous.feature" with:
"""
Feature:

Scenario:
When a failed step
Then an ambiguous step

"""
And a file named "features/step_definitions.rb" with:
"""
When(/^a.*step$/) do
raise 'error'
end

Then(/^an ambiguous step$/) do
'bar'
end

"""
When I run `cucumber`
Then it should fail with:
"""
When a failed step # features/step_definitions.rb:1
error (RuntimeError)
./features/step_definitions.rb:2:in `/^a.*step$/'
features/ambiguous.feature:4:in `a failed step'
Then an ambiguous step # features/ambiguous.feature:5
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::Core::Test::Result::Ambiguous)

Failing Scenarios:
cucumber features/ambiguous.feature:3 # Scenario:

1 scenario (1 failed)
2 steps (1 failed, 1 ambiguous)
0m0.012s

"""
3 changes: 3 additions & 0 deletions lib/cucumber/formatter/ansicolor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ module Formatter
# * <tt>flaky_param</tt> - defaults to <tt>yellow,bold</tt>
# * <tt>failed</tt> - defaults to <tt>red</tt>
# * <tt>failed_param</tt> - defaults to <tt>red,bold</tt>
# * <tt>ambiguous</tt> - defaults to <tt>red</tt>
# * <tt>abmiguous_param</tt> - defaults to <tt>red,bold</tt>
# * <tt>passed</tt> - defaults to <tt>green</tt>
# * <tt>passed_param</tt> - defaults to <tt>green,bold</tt>
# * <tt>outline</tt> - defaults to <tt>cyan</tt>
Expand All @@ -72,6 +74,7 @@ module ANSIColor
'pending' => 'yellow',
'flaky' => 'yellow',
'failed' => 'red',
'ambiguous' => 'red',
'passed' => 'green',
'outline' => 'cyan',
'skipped' => 'cyan',
Expand Down
2 changes: 2 additions & 0 deletions lib/cucumber/formatter/duration_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def passed(*) end

def failed(*) end

def ambiguous(*) end

def undefined(*) end

def skipped(*) end
Expand Down
29 changes: 1 addition & 28 deletions lib/cucumber/formatter/junit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def create_output_string(test_case, scenario, result, row_name)
end

def build_testcase(result, scenario_designation, output)
duration = ResultBuilder.new(result).test_case_duration
duration = DurationExtractor.new(result).result_duration
@current_feature_data[:time] += duration
classname = @current_feature_data[:feature].name
filename = @current_feature_data[:uri]
Expand Down Expand Up @@ -234,32 +234,5 @@ def examples_table_row(row)
@name_suffix = " (outline example : #{@row_name})"
end
end

class ResultBuilder
attr_reader :test_case_duration

def initialize(result)
@test_case_duration = 0
result.describe_to(self)
end

def passed(*) end

def failed(*) end

def undefined(*) end

def skipped(*) end

def pending(*) end

def exception(*) end

def duration(duration, *)
duration.tap { |dur| @test_case_duration = dur.nanoseconds / 10**9.0 }
end

def attach(*) end
end
end
end
1 change: 1 addition & 0 deletions lib/cucumber/formatter/progress.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def print_summary
CHARS = {
passed: '.',
failed: 'F',
ambiguous: 'A',
undefined: 'U',
pending: 'P',
skipped: '-'
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/step_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def initialize(error)
end

def activate(test_step)
test_step.with_action { raise @error }
test_step.with_unskippable_action { raise Core::Test::Result::Ambiguous, @error.message }
end
end
end
Loading