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