Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
Add a pending_failure_output configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed May 3, 2022
1 parent bc9bb2d commit c669cbc
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 1 deletion.
58 changes: 58 additions & 0 deletions features/configuration/pending_failure_output.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Feature: Pending failure output

Configure the format of pending examples output with an option (defaults to `:full`):

```ruby
RSpec.configure do |c|
c.pending_failure_output = :no_backtrace
end
```

Allowed options are `:full`, `:no_backtrace` and `:skip`.

Background:
Given a file named "spec/example_spec.rb" with:
"""ruby
require "spec_helper"
RSpec.describe "something" do
pending "will never happen again" do
expect(Time.now.year).to eq(2021)
end
end
"""

Scenario: By default outputs backtrace and details
Given a file named "spec/spec_helper.rb" with:
"""ruby
"""
When I run `rspec spec`
Then the examples should all pass
And the output should contain "Pending: (Failures listed here are expected and do not affect your suite's status)"
And the output should contain "1) something will never happen again"
And the output should contain "expected: 2021"
And the output should contain "./spec/example_spec.rb:5"

Scenario: Setting `pending_failure_output` to `:no_backtrace` hides the backtrace
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure { |c| c.pending_failure_output = :no_backtrace }
"""
When I run `rspec spec`
Then the examples should all pass
And the output should contain "Pending: (Failures listed here are expected and do not affect your suite's status)"
And the output should contain "1) something will never happen again"
And the output should contain "expected: 2021"
And the output should not contain "./spec/example_spec.rb:5"

Scenario: Setting `pending_failure_output` to `:skip` hides the backtrace
Given a file named "spec/spec_helper.rb" with:
"""ruby
RSpec.configure { |c| c.pending_failure_output = :skip }
"""
When I run `rspec spec`
Then the examples should all pass
And the output should not contain "Pending: (Failures listed here are expected and do not affect your suite's status)"
And the output should not contain "1) something will never happen again"
And the output should not contain "expected: 2021"
And the output should not contain "./spec/example_spec.rb:5"
15 changes: 15 additions & 0 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,20 @@ def shared_context_metadata_behavior=(value)
# return [Integer]
add_setting :max_displayed_failure_line_count

# @macro add_setting
# Format the output for pending examples. Can be set to:
# - :full (default) - pending examples appear similarly to failures
# - :no_backtrace - same as above, but with no backtrace
# - :skip - do not show the section at all
# return [Symbol]
add_read_only_setting :pending_failure_output
def pending_failure_output=(mode)
raise ArgumentError,
"`pending_failure_output` can be set to :full, :no_backtrace, " \
"or :skip" unless [:full, :no_backtrace, :skip].include?(mode)
@pending_failure_output = mode
end

# Determines which bisect runner implementation gets used to run subsets
# of the suite during a bisection. Your choices are:
#
Expand Down Expand Up @@ -559,6 +573,7 @@ def initialize
@max_displayed_failure_line_count = 10
@world = World::Null
@shared_context_metadata_behavior = :trigger_inclusion
@pending_failure_output = :full

define_built_in_hooks
end
Expand Down
6 changes: 5 additions & 1 deletion lib/rspec/core/formatters/exception_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,14 @@ def pending_options
]
}
elsif @execution_result.status == :pending
{
options = {
:message_color => RSpec.configuration.pending_color,
:detail_formatter => PENDING_DETAIL_FORMATTER
}
if RSpec.configuration.pending_failure_output == :no_backtrace
options[:backtrace_formatter] = EmptyBacktraceFormatter
end
options
end
end

Expand Down
2 changes: 2 additions & 0 deletions lib/rspec/core/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def fully_formatted_failed_examples(colorizer=::RSpec::Core::Formatters::Console
# @return [String] The list of pending examples, fully formatted in the
# way that RSpec's built-in formatters emit.
def fully_formatted_pending_examples(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
return if RSpec.configuration.pending_failure_output == :skip

formatted = "\nPending: (Failures listed here are expected and do not affect your suite's status)\n".dup

pending_notifications.each_with_index do |notification, index|
Expand Down
30 changes: 30 additions & 0 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,36 @@ def emulate_not_configured_expectation_framework
end
end

describe '#pending_failure_output' do
it 'defaults to :full' do
expect(config.pending_failure_output).to eq :full
end

it 'can be set to :full' do
config.pending_failure_output = :full
expect(config.pending_failure_output).to eq :full
end

it 'can be set to :no_backtrace' do
config.pending_failure_output = :no_backtrace
expect(config.pending_failure_output).to eq :no_backtrace
end

it 'can be set to :skip' do
config.pending_failure_output = :skip
expect(config.pending_failure_output).to eq :skip
end

it 'cannot be set to any other values' do
expect {
config.pending_failure_output = :another_value
}.to raise_error(
ArgumentError,
'`pending_failure_output` can be set to :full, :no_backtrace, or :skip'
)
end
end

# assigns files_or_directories_to_run and triggers post-processing
# via `files_to_run`.
def assign_files_or_directories_to_run(*value)
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def handle_current_dir_change
end

RSpec.configure do |c|
c.pending_failure_output = :no_backtrace
c.example_status_persistence_file_path = "./spec/examples.txt"
c.around(:example, :isolated_directory) do |ex|
handle_current_dir_change(&ex)
Expand Down

0 comments on commit c669cbc

Please sign in to comment.