diff --git a/features/docs/formatters/usage_formatter.feature b/features/docs/formatters/usage_formatter.feature index 4a030ec08f..6cbd6b693f 100644 --- a/features/docs/formatters/usage_formatter.feature +++ b/features/docs/formatters/usage_formatter.feature @@ -99,3 +99,25 @@ Feature: Usage formatter 11 steps (11 skipped) """ + + Scenario: Run with --format stepdefs when some steps are undefined + Given a file named "features/calculator.feature" with: + """ + Feature: Calculator + Scenario: Adding numbers + When I add 4 and 5 + Then I should get 9 + """ + When I run `cucumber -f stepdefs features/calculator.feature` + Then it should pass with: + """ + You can implement step definitions for undefined steps with these snippets: + + When("I add {int} and {int}") do |int, int2| + pending # Write code here that turns the phrase above into concrete actions + end + + Then("I should get {int}") do |int| + pending # Write code here that turns the phrase above into concrete actions + end + """ \ No newline at end of file diff --git a/lib/cucumber/formatter/usage.rb b/lib/cucumber/formatter/usage.rb index afcca9bad4..b4b2bb8ec4 100644 --- a/lib/cucumber/formatter/usage.rb +++ b/lib/cucumber/formatter/usage.rb @@ -38,19 +38,23 @@ def on_test_step_finished(event) test_step = event.test_step result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter) step_match = @matches[test_step.source] - step_definition = step_match.step_definition - stepdef_key = StepDefKey.new(step_definition.expression.to_s, step_definition.location) - unless @stepdef_to_match[stepdef_key].map { |key| key[:location] }.include? test_step.location - duration = DurationExtractor.new(result).result_duration - - @stepdef_to_match[stepdef_key] << { - keyword: test_step.source.last.keyword, - step_match: step_match, - status: result.to_sym, - location: test_step.location, - duration: duration - } + + unless step_match.nil? + step_definition = step_match.step_definition + stepdef_key = StepDefKey.new(step_definition.expression.to_s, step_definition.location) + unless @stepdef_to_match[stepdef_key].map { |key| key[:location] }.include? test_step.location + duration = DurationExtractor.new(result).result_duration + + @stepdef_to_match[stepdef_key] << { + keyword: test_step.source.last.keyword, + step_match: step_match, + status: result.to_sym, + location: test_step.location, + duration: duration + } + end end + super end