Skip to content

Commit

Permalink
Apply the backtrace filter in the Json formatter.
Browse files Browse the repository at this point in the history
When using the formatter callback functions the backtrace filter is
applied to the result objects before they are passed to the formatter
callback functions. When using events the formatters need to apply the
backtrace filter themselves.
  • Loading branch information
brasmusson committed Mar 30, 2016
1 parent a47f78a commit 84a498f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 2 additions & 6 deletions features/docs/formatters/json_formatter.feature
Expand Up @@ -286,7 +286,6 @@ Feature: JSON output formatter
"""

@spawn
Scenario: DocString
Given a file named "features/doc_string.feature" with:
"""
Expand Down Expand Up @@ -349,9 +348,8 @@ Feature: JSON output formatter
]
"""

@spawn
Scenario: embedding screenshot
When I run `cucumber -b --format json features/embed.feature`
When I run `cucumber --format json features/embed.feature`
Then it should pass with JSON:
"""
[
Expand Down Expand Up @@ -630,9 +628,8 @@ Feature: JSON output formatter
"""

@spawn
Scenario: embedding data directly
When I run `cucumber -b --format json -x features/embed_data_directly.feature`
When I run `cucumber --format json -x features/embed_data_directly.feature`
Then it should pass with JSON:
"""
[
Expand Down Expand Up @@ -733,7 +730,6 @@ Feature: JSON output formatter
]
"""
@spawn
Scenario: handle output from hooks
Given a file named "features/step_definitions/output_steps.rb" with:
"""
Expand Down
5 changes: 3 additions & 2 deletions lib/cucumber/formatter/json.rb
@@ -1,5 +1,6 @@
require 'multi_json'
require 'base64'
require 'cucumber/formatter/backtrace_filter'
require 'cucumber/formatter/io'
require 'cucumber/formatter/hook_query_visitor'

Expand Down Expand Up @@ -57,14 +58,14 @@ def on_before_test_step(event)

def on_after_test_step(event)
test_step = event.test_step
result = event.result
result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
return if internal_hook?(test_step)
add_match_and_result(test_step, result)
@any_step_failed = true if result.failed?
end

def on_after_test_case(event)
result = event.result
result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
add_failed_around_hook(result) if result.failed? && !@any_step_failed
end

Expand Down

0 comments on commit 84a498f

Please sign in to comment.