From bb04a076ec778b2fef17b9b350f940285b68bebf Mon Sep 17 00:00:00 2001 From: Stef Schenkelaars Date: Mon, 16 Sep 2024 09:34:22 +0000 Subject: [PATCH] Annotate exception location instead of spec This is just a test commit as the final version should be configurable. Instead this can be used for early testing. Closes #75 --- lib/rspec/github/notification_decorator.rb | 12 ++++++++---- spec/integration/crashing_spec.rb | 9 +++++++++ spec/integration/test_class.rb | 5 +++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 spec/integration/crashing_spec.rb create mode 100644 spec/integration/test_class.rb diff --git a/lib/rspec/github/notification_decorator.rb b/lib/rspec/github/notification_decorator.rb index f260308..703dd4d 100644 --- a/lib/rspec/github/notification_decorator.rb +++ b/lib/rspec/github/notification_decorator.rb @@ -15,7 +15,7 @@ def initialize(notification) end def line - example.location.split(':')[1] + location[1] end def annotation @@ -25,7 +25,7 @@ def annotation def path # TODO: use `delete_prefix` when dropping ruby 2.4 support - File.realpath(raw_path).sub(/\A#{workspace}#{File::SEPARATOR}/, '') + File.realpath(location[0]).sub(/\A#{workspace}#{File::SEPARATOR}/, '') end private @@ -42,8 +42,12 @@ def message end end - def raw_path - example.location.split(':')[0] + def location + if @notification.respond_to?(:exception) + @notification.exception.backtrace.first.split(':') + else + example.location.split(':') + end end def workspace diff --git a/spec/integration/crashing_spec.rb b/spec/integration/crashing_spec.rb new file mode 100644 index 0000000..b270374 --- /dev/null +++ b/spec/integration/crashing_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require_relative './test_class.rb' + +RSpec.describe RSpec::Github::Formatter do + it 'creates an error annotation for crashing specs' do + expect(TestClass.crash).to eq true + end +end diff --git a/spec/integration/test_class.rb b/spec/integration/test_class.rb new file mode 100644 index 0000000..6ebf660 --- /dev/null +++ b/spec/integration/test_class.rb @@ -0,0 +1,5 @@ +class TestClass + def self.crash + raise 'Ay!' + end +end \ No newline at end of file