@@ -102,7 +102,7 @@ def self.validate_expected(expected, errors)
102102
103103 types = [ 'Matcher' , *valid_expected_types . map ( &:name ) ] . to_sentence ( conjunction : 'or' )
104104
105- errors << "expected `#{ key } :` to be a #{ types } , but was #{ expected . inspect } "
105+ errors << "expected `#{ key } :` to be a #{ types } , but it was #{ expected . inspect } "
106106 end
107107
108108 protected
@@ -189,6 +189,36 @@ def self.validate_expected(expected, errors)
189189 #
190190 private_class_method def self . literal_match? ( actual , expected ) = actual == expected
191191
192+ # Add to `failures` if actual value matches the normalized expected value
193+ #
194+ # This is called when expected is not an RSpec matcher.
195+ #
196+ # Option subclasses should override this method to provide custom matching
197+ # logic or custom failure messages.
198+ #
199+ # @param actual [Object] the actual value fetched from the file system
200+ #
201+ # @param expected [Object] the expected literal value to match against
202+ #
203+ # @param failures [Array<RSpec::PathMatchers::Failure>] the array to append
204+ # failure objects to (if any)
205+ #
206+ # @return [void]
207+ #
208+ # @api protected
209+ #
210+ private_class_method def self . match_literal ( actual , expected , failures )
211+ expected = normalize_expected_literal ( expected )
212+
213+ return if literal_match? ( actual , expected )
214+
215+ add_failure ( literal_failure_message ( actual , expected ) , failures )
216+ end
217+
218+ private_class_method def self . add_failure ( message , failures )
219+ failures << RSpec ::PathMatchers ::Failure . new ( '.' , message )
220+ end
221+
192222 # Generates a failure message for a literal match failure
193223 #
194224 # This is used when the actual value does not match the expected value.
@@ -201,9 +231,9 @@ def self.validate_expected(expected, errors)
201231 # @example generate a failure message for a literal match failure
202232 # def self.literal_failure_message(actual, expected)
203233 # if expected.is_a?(Regexp)
204- # "expected #{key} to match #{expected.inspect}, but was #{actual.inspect}"
234+ # "expected #{key} to match #{expected.inspect}, but it was #{actual.inspect}"
205235 # else
206- # "expected #{key} to be #{expected.inspect}, but was #{actual.inspect}"
236+ # "expected #{key} to be #{expected.inspect}, but it was #{actual.inspect}"
207237 # end
208238 # end
209239 #
@@ -216,19 +246,19 @@ def self.validate_expected(expected, errors)
216246 # @api protected
217247 #
218248 private_class_method def self . literal_failure_message ( actual , expected )
219- "expected #{ key } to be #{ expected . inspect } , but was #{ actual . inspect } "
249+ "expected #{ key } to be #{ expected . inspect } , but it was #{ actual . inspect } "
220250 end
221251
222252 # Add to `failures` if actual value matches the normalized expected value
223253 #
224- # This is called when expected is not an RSpec matcher.
254+ # This is called when expected is an RSpec matcher.
225255 #
226256 # Option subclasses should override this method to provide custom matching
227257 # logic or custom failure messages.
228258 #
229259 # @param actual [Object] the actual value fetched from the file system
230260 #
231- # @param expected [Object ] the expected literal value to match against
261+ # @param expected [RSpec::Matchers::Matcher ] the expected matcher to match against
232262 #
233263 # @param failures [Array<RSpec::PathMatchers::Failure>] the array to append
234264 # failure objects to (if any)
@@ -237,42 +267,31 @@ def self.validate_expected(expected, errors)
237267 #
238268 # @api protected
239269 #
240- private_class_method def self . match_literal ( actual , expected , failures )
241- expected = normalize_expected_literal ( expected )
242-
243- return if literal_match? ( actual , expected )
244-
245- message = literal_failure_message ( actual , expected )
246- add_failure ( message , failures )
247- end
270+ private_class_method def self . match_matcher ( actual , expected , failures )
271+ return if expected . matches? ( actual )
248272
249- private_class_method def self . add_failure ( message , failures )
250- failures << RSpec ::PathMatchers ::Failure . new ( '.' , message )
273+ add_failure ( matcher_failure_message ( actual , expected ) , failures )
251274 end
252275
253- # Add to `failures` if actual value matches the normalized expected value
276+ # Generates a failure message for a matcher match failure
254277 #
255- # This is called when expected is an RSpec matcher.
278+ # This is used when the actual value does not match the expected value.
279+ # It provides a clear message indicating what was expected and what was
280+ # actually found.
256281 #
257- # Option subclasses should override this method to provide custom matching
258- # logic or custom failure messages .
282+ # Option subclasses should override this method to provide custom failure
283+ # messages for specific types of options .
259284 #
260285 # @param actual [Object] the actual value fetched from the file system
261286 #
262- # @param expected [RSpec::Matchers::Matcher] the expected matcher to match against
263- #
264- # @param failures [Array<RSpec::PathMatchers::Failure>] the array to append
265- # failure objects to (if any)
287+ # @param expected [Object] the expected literal value to match against
266288 #
267- # @return [void]
289+ # @return [String] the failure message
268290 #
269291 # @api protected
270292 #
271- private_class_method def self . match_matcher ( actual , expected , failures )
272- return if expected . matches? ( actual )
273-
274- message = "expected #{ key } to #{ expected . description } , but was #{ actual . inspect } "
275- add_failure ( message , failures )
293+ private_class_method def self . matcher_failure_message ( actual , expected )
294+ "expected #{ key } to #{ expected . description } , but it was #{ actual . inspect } "
276295 end
277296
278297 # Warning message for unsupported expectations
0 commit comments