Skip to content

Commit 4ea4bf7

Browse files
committed
Add raise_consistent_error matcher in MSpec
* To deal with https://bugs.ruby-lang.org/issues/21864
1 parent 880bcb9 commit 4ea4bf7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/mspec/matchers/raise_error.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,15 @@ module MSpecMatchers
9090
private def raise_error(exception = Exception, message = nil, &block)
9191
RaiseErrorMatcher.new(exception, message, &block)
9292
end
93+
94+
# CRuby < 4.1 has inconsistent coercion errors:
95+
# https://bugs.ruby-lang.org/issues/21864
96+
# This matcher ignores the message on CRuby < 4.1
97+
# and checks the message for all other cases, including other Rubies
98+
private def raise_consistent_error(exception = Exception, message = nil, &block)
99+
if RUBY_ENGINE == "ruby" and ruby_version_is ""..."4.1"
100+
message = nil
101+
end
102+
RaiseErrorMatcher.new(exception, message, &block)
103+
end
93104
end

0 commit comments

Comments
 (0)