Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed lengthy stacktrace when running cucumber -f stepdefs when steps aren't defined #1286

Merged
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
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