Skip to content

Commit

Permalink
Fixed lengthy stacktrace when running cucumber -f stepdefs when ste…
Browse files Browse the repository at this point in the history
…ps aren't defined (#1286)
  • Loading branch information
xtrasimplicity authored Mar 31, 2018
1 parent 0f7d951 commit 130949b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
22 changes: 22 additions & 0 deletions features/docs/formatters/usage_formatter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
28 changes: 16 additions & 12 deletions lib/cucumber/formatter/usage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 130949b

Please sign in to comment.