Skip to content

Commit

Permalink
Annotate exception location instead of spec
Browse files Browse the repository at this point in the history
This is just a test commit as the final version should be configurable.
Instead this can be used for early testing.

Closes #75
  • Loading branch information
StefSchenkelaars committed Sep 16, 2024
1 parent 075c231 commit bb04a07
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/rspec/github/notification_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(notification)
end

def line
example.location.split(':')[1]
location[1]
end

def annotation
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/integration/crashing_spec.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions spec/integration/test_class.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class TestClass
def self.crash
raise 'Ay!'
end
end

0 comments on commit bb04a07

Please sign in to comment.