Skip to content

Commit

Permalink
Correctly detect location when shared example is used (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrcuns authored Mar 18, 2024
1 parent 52569f0 commit 47a5f00
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 2 additions & 2 deletions allure-rspec/lib/allure_rspec/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def test_result(example)

Allure::TestResult.new(
name: example.description,
description: "Location - #{strip_relative(example.location)}",
description_html: "Location - #{strip_relative(example.location)}",
description: "Location - #{strip_relative(parser.location)}",
description_html: "Location - #{strip_relative(parser.location)}",
history_id: example.id,
full_name: example.full_description,
labels: parser.labels,
Expand Down
17 changes: 16 additions & 1 deletion allure-rspec/lib/allure_rspec/metadata_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RspecMetadataParser
# Metadata parser instance
#
# @param [RSpec::Core::Example] example
# @param [AllureRspec::RspecConfig] config <description>
# @param [AllureRspec::RspecConfig] config
def initialize(example, config)
@example = example
@config = config
Expand Down Expand Up @@ -67,6 +67,21 @@ def status_details
)
end

# Example location
#
# @return [String]
def location
file = example
.metadata
.fetch(:shared_group_inclusion_backtrace)
.last
&.formatted_inclusion_location

return example.location unless file

file
end

private

# @return [RSpec::Core::Example]
Expand Down
22 changes: 22 additions & 0 deletions allure-rspec/spec/unit/formatter_example_started_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@
end
end
end

context "with shared example" do
it "correctly detects spec location" do
run_rspec(<<~SPEC)
shared_examples "shared" do
it "#{spec}" do |e|
e.step(name: "test body")
end
end
describe "#{suite}" do
it_behaves_like "shared"
end
SPEC

expect(lifecycle).to have_received(:start_test_case).once do |arg|
aggregate_failures "Should have correct args" do
expect(arg.description).to eq("Location - #{test_tmp_dir}/spec/test_spec.rb:8")
end
end
end
end
end

context "allure environment" do
Expand Down

0 comments on commit 47a5f00

Please sign in to comment.