Skip to content

Commit

Permalink
Display full backtrace when every line filtered.
Browse files Browse the repository at this point in the history
Restores previous behavior and adds a message to the backtrace
explaining that we're showing the full backtrace because every line was
filtered.
  • Loading branch information
dchelimsky committed Sep 23, 2013
1 parent 3b138ae commit b4d0538
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/rspec/core/backtrace_formatter.rb
Expand Up @@ -37,7 +37,16 @@ def format_backtrace(backtrace, options = {})
backtrace.
take_while {|l| l != RSpec::Core::Runner::AT_EXIT_HOOK_BACKTRACE_LINE}.
map {|l| backtrace_line(l)}.
compact
compact.
tap do |filtered|
if filtered.empty?
filtered.concat backtrace
filtered << ""
filtered << " Showing full backtrace because every line was filtered out."
filtered << " See docs for RSpec::Configuration#backtrace_exclusion_patterns and"
filtered << " RSpec::Configuration#backtrace_inclusion_patterns for more information."
end
end
end

# @api private
Expand Down
22 changes: 22 additions & 0 deletions spec/rspec/core/backtrace_formatter_spec.rb
Expand Up @@ -61,6 +61,28 @@ def make_backtrace_formatter(exclusion_patterns=nil, inclusion_patterns=nil)
]
expect(BacktraceFormatter.new.format_backtrace(backtrace)).to eq(["./spec/my_spec.rb:7", "./spec/my_spec.rb:5"])
end

context "when every line is filtered out" do
it "includes full backtrace" do
backtrace = [
"/path/to/rspec-expectations/lib/rspec/expectations/foo.rb:37",
"/path/to/rspec-expectations/lib/rspec/matchers/foo.rb:37",
"/path/to/rspec-mocks/lib/rspec/mocks/foo.rb:37",
"/path/to/rspec-core/lib/rspec/core/foo.rb:37"
]
expect(BacktraceFormatter.new.format_backtrace(backtrace).take(4)).to eq backtrace
end

it "adds a message explaining everything was filtered" do
backtrace = [
"/path/to/rspec-expectations/lib/rspec/expectations/foo.rb:37",
"/path/to/rspec-expectations/lib/rspec/matchers/foo.rb:37",
"/path/to/rspec-mocks/lib/rspec/mocks/foo.rb:37",
"/path/to/rspec-core/lib/rspec/core/foo.rb:37"
]
expect(BacktraceFormatter.new.format_backtrace(backtrace).drop(4).join).to match(/Showing full backtrace/)
end
end
end

describe "#full_backtrace=true" do
Expand Down

0 comments on commit b4d0538

Please sign in to comment.