51 lines
2.4 KiB
Diff
51 lines
2.4 KiB
Diff
From 1c20fa80772ca7a1ed0512056ce7cd6a94f8e68d Mon Sep 17 00:00:00 2001
|
|
From: Jon Rowe <hello@jonrowe.co.uk>
|
|
Date: Fri, 28 Nov 2025 10:59:10 +0000
|
|
Subject: [PATCH] Cope with the changes to block source_location in Ruby 4
|
|
|
|
---
|
|
rspec-core/lib/rspec/core/hooks.rb | 2 +-
|
|
rspec-core/lib/rspec/core/metadata.rb | 2 +-
|
|
rspec-core/lib/rspec/core/shared_example_group.rb | 2 +-
|
|
.../lib/rspec/expectations/block_snippet_extractor.rb | 2 +-
|
|
4 files changed, 4 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/rspec-core/lib/rspec/core/hooks.rb b/rspec-core/lib/rspec/core/hooks.rb
|
|
index f97962ce9..77eecc776 100644
|
|
--- a/rspec-core/lib/rspec/core/hooks.rb
|
|
+++ b/rspec-core/lib/rspec/core/hooks.rb
|
|
@@ -395,7 +395,7 @@ def execute_with(example, procsy)
|
|
|
|
if Proc.method_defined?(:source_location)
|
|
def hook_description
|
|
- "around hook at #{Metadata.relative_path(block.source_location.join(':'))}"
|
|
+ "around hook at #{Metadata.relative_path(block.source_location.take(2).join(':'))}"
|
|
end
|
|
else # for 1.8.7
|
|
# :nocov:
|
|
diff --git a/rspec-core/lib/rspec/core/metadata.rb b/rspec-core/lib/rspec/core/metadata.rb
|
|
index e887cb1c5..ed47bc07b 100644
|
|
--- a/rspec-core/lib/rspec/core/metadata.rb
|
|
+++ b/rspec-core/lib/rspec/core/metadata.rb
|
|
@@ -146,7 +146,7 @@ def populate_location_attributes
|
|
file_path, line_number = if backtrace
|
|
file_path_and_line_number_from(backtrace)
|
|
elsif block.respond_to?(:source_location)
|
|
- block.source_location
|
|
+ block.source_location.take(2)
|
|
else
|
|
file_path_and_line_number_from(caller)
|
|
end
|
|
diff --git a/rspec-core/lib/rspec/core/shared_example_group.rb b/rspec-core/lib/rspec/core/shared_example_group.rb
|
|
index b4a5dc317..1f2b9d623 100644
|
|
--- a/rspec-core/lib/rspec/core/shared_example_group.rb
|
|
+++ b/rspec-core/lib/rspec/core/shared_example_group.rb
|
|
@@ -243,7 +243,7 @@ def warn_if_key_taken(context, key, new_block)
|
|
|
|
if RUBY_VERSION.to_f >= 1.9
|
|
def formatted_location(block)
|
|
- block.source_location.join(":")
|
|
+ block.source_location.take(2).join(":")
|
|
end
|
|
else # 1.8.7
|
|
# :nocov:
|