Skip to content

Commit

Permalink
Merge pull request #2621 from herwinw/regexp_last_match
Browse files Browse the repository at this point in the history
Clarify spec error for Regexp.last_match
  • Loading branch information
herwinw committed Feb 26, 2025
2 parents 7516e33 + c221db7 commit 30451cb
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions spec/core/regexp/last_match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@

it "raises an IndexError when given a missing name" do
/(?<test>[A-Z]+.*)/ =~ "TEST123"
NATFIXME "this error gets thrown, but when in a proc it doesn't get bubbled up properly", exception: SpecFailedException do
NATFIXME 'Regexp globals are not accessible from a block', exception: SpecFailedException do
-> { Regexp.last_match(:missing) }.should raise_error(IndexError)
end

# NATFIXME: Alternate implementation of the test
error = begin
-> {
/(?<test>[A-Z]+.*)/ =~ "TEST123"
Regexp.last_match(:missing)
nil
rescue IndexError => e
e
end
error.should be_kind_of(IndexError)
}.should raise_error(IndexError)
end
end

Expand All @@ -61,18 +58,15 @@
it "raises a TypeError when unable to coerce" do
obj = Object.new
/(?<test>[A-Z]+.*)/ =~ "TEST123"
NATFIXME "this error gets thrown, but when in a proc it doesn't get bubbled up properly", exception: SpecFailedException do
NATFIXME 'Regexp globals are not accessible from a block', exception: SpecFailedException do
-> { Regexp.last_match(obj) }.should raise_error(TypeError)
end

# NATFIXME: Alternate implementation of the test
error = begin
-> {
/(?<test>[A-Z]+.*)/ =~ "TEST123"
Regexp.last_match(obj)
nil
rescue TypeError => e
e
end
error.should be_kind_of(TypeError)
}.should raise_error(TypeError)
end
end
end

0 comments on commit 30451cb

Please sign in to comment.