From b4d053885f78ed78e5bac01c92afdb30a74b4eb8 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Thu, 5 Sep 2013 12:02:24 +0200 Subject: [PATCH] Display full backtrace when every line filtered. Restores previous behavior and adds a message to the backtrace explaining that we're showing the full backtrace because every line was filtered. --- lib/rspec/core/backtrace_formatter.rb | 11 ++++++++++- spec/rspec/core/backtrace_formatter_spec.rb | 22 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/rspec/core/backtrace_formatter.rb b/lib/rspec/core/backtrace_formatter.rb index c63df92055..8cc195f6f9 100644 --- a/lib/rspec/core/backtrace_formatter.rb +++ b/lib/rspec/core/backtrace_formatter.rb @@ -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 diff --git a/spec/rspec/core/backtrace_formatter_spec.rb b/spec/rspec/core/backtrace_formatter_spec.rb index 2f284fc528..1325ec3ce3 100644 --- a/spec/rspec/core/backtrace_formatter_spec.rb +++ b/spec/rspec/core/backtrace_formatter_spec.rb @@ -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