From 3ae521612214207bc1b8982565cd7d429c0b3997 Mon Sep 17 00:00:00 2001 From: Andrey Subbota Date: Wed, 22 Jan 2020 11:38:51 +0200 Subject: [PATCH] Initialize failure line groups as array. Issue #56 --- lib/super_diff/rspec/monkey_patches.rb | 10 +++++---- .../rspec/unhandled_errors_spec.rb | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/super_diff/rspec/monkey_patches.rb b/lib/super_diff/rspec/monkey_patches.rb index a718a057..7487b2c6 100644 --- a/lib/super_diff/rspec/monkey_patches.rb +++ b/lib/super_diff/rspec/monkey_patches.rb @@ -91,10 +91,12 @@ def initialize(exception, example, options={}) @skip_shared_group_trace = options.fetch(:skip_shared_group_trace, false) # Patch to convert options[:failure_lines] to groups if options.include?(:failure_lines) - @failure_line_groups = { - lines: options[:failure_lines], - already_colorized: false - } + @failure_line_groups = [ + { + lines: options[:failure_lines], + already_colorized: false + } + ] end end diff --git a/spec/integration/rspec/unhandled_errors_spec.rb b/spec/integration/rspec/unhandled_errors_spec.rb index c3319ec8..5a97ec38 100644 --- a/spec/integration/rspec/unhandled_errors_spec.rb +++ b/spec/integration/rspec/unhandled_errors_spec.rb @@ -66,4 +66,25 @@ end end end + + context "when multiple exception occur" do + it "highlights the first line in red, and then leaves the rest of the message alone" do + as_both_colored_and_uncolored do |color_enabled| + program = <<~PROGRAM.strip + #{set_up_with("super_diff/rspec", color_enabled: color_enabled)} + RSpec.describe "test" do + after(:each) do + raise "Some kind of after error or whatever\\n\\nThis is another line" + end + it "passes" do + raise "Some kind of error or whatever\\n\\nThis is another line" + end + end + PROGRAM + + expect(program). + to produce_output_when_run('Some kind of after error or whatever') + end + end + end end