Skip to content

Commit bb04a07

Browse files
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
1 parent 075c231 commit bb04a07

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

lib/rspec/github/notification_decorator.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def initialize(notification)
1515
end
1616

1717
def line
18-
example.location.split(':')[1]
18+
location[1]
1919
end
2020

2121
def annotation
@@ -25,7 +25,7 @@ def annotation
2525

2626
def path
2727
# TODO: use `delete_prefix` when dropping ruby 2.4 support
28-
File.realpath(raw_path).sub(/\A#{workspace}#{File::SEPARATOR}/, '')
28+
File.realpath(location[0]).sub(/\A#{workspace}#{File::SEPARATOR}/, '')
2929
end
3030

3131
private
@@ -42,8 +42,12 @@ def message
4242
end
4343
end
4444

45-
def raw_path
46-
example.location.split(':')[0]
45+
def location
46+
if @notification.respond_to?(:exception)
47+
@notification.exception.backtrace.first.split(':')
48+
else
49+
example.location.split(':')
50+
end
4751
end
4852

4953
def workspace

spec/integration/crashing_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
require_relative './test_class.rb'
4+
5+
RSpec.describe RSpec::Github::Formatter do
6+
it 'creates an error annotation for crashing specs' do
7+
expect(TestClass.crash).to eq true
8+
end
9+
end

spec/integration/test_class.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class TestClass
2+
def self.crash
3+
raise 'Ay!'
4+
end
5+
end

0 commit comments

Comments
 (0)