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 Drieam#75
  • Loading branch information
StefSchenkelaars committed Sep 16, 2024
1 parent 075c231 commit 27e2b38
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/rspec/github/notification_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ def initialize(notification)
end

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

def annotation
require 'pry'; binding.pry

"#{example.full_description}\n\n#{message}"
.gsub(Regexp.union(ESCAPE_MAP.keys), ESCAPE_MAP)
end

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 +44,12 @@ def message
end
end

def raw_path
example.location.split(':')[0]
def location
if @notification.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 27e2b38

Please sign in to comment.