@@ -303,20 +303,6 @@ def expected_action_for_matcher_text
303303 end )
304304 end
305305
306- class BeTruthy
307- prepend SuperDiff ::RSpec ::AugmentedMatcher
308-
309- prepend ( Module . new do
310- def expected_action_for_matcher_text
311- "be"
312- end
313-
314- def expected_for_matcher_text
315- "truthy"
316- end
317- end )
318- end
319-
320306 class BeFalsey
321307 prepend SuperDiff ::RSpec ::AugmentedMatcher
322308
@@ -375,12 +361,18 @@ def matcher_text_builder_args
375361 end )
376362 end
377363
378- class Eq
364+ class BeTruthy
379365 prepend SuperDiff ::RSpec ::AugmentedMatcher
380- end
381366
382- class Equal
383- prepend SuperDiff ::RSpec ::AugmentedMatcher
367+ prepend ( Module . new do
368+ def expected_action_for_matcher_text
369+ "be"
370+ end
371+
372+ def expected_for_matcher_text
373+ "truthy"
374+ end
375+ end )
384376 end
385377
386378 class ContainExactly
@@ -405,82 +397,12 @@ def matcher_text_builder_class
405397 end )
406398 end
407399
408- class MatchArray < ContainExactly
409- def expected_for_diff
410- matchers . an_array_matching ( expected )
411- end
412-
413- def expected_action_for_matcher_text
414- "match array with"
415- end
416- end
417-
418- class Include
400+ class Eq
419401 prepend SuperDiff ::RSpec ::AugmentedMatcher
420-
421- prepend ( Module . new do
422- # Override this method so that the differ knows that this is a partial
423- # array or hash
424- def expected_for_diff
425- if expecteds . all? { |item | item . is_a? ( Hash ) }
426- matchers . a_collection_including ( expecteds . first )
427- else
428- matchers . a_collection_including ( *expecteds )
429- end
430- end
431-
432- private
433-
434- # Override to capitalize message and add period at end
435- def build_failure_message ( negated :)
436- message = super
437-
438- if actual . respond_to? ( :include? )
439- message
440- elsif message . end_with? ( "." )
441- message . sub ( "\. $" , ", " ) + "but it does not respond to `include?`."
442- else
443- message + "\n \n But it does not respond to `include?`."
444- end
445- end
446-
447- # Override to use readable_list_of
448- def expected_for_description
449- readable_list_of ( expecteds ) . lstrip
450- end
451-
452- # Override to use readable_list_of
453- def expected_for_failure_message
454- # TODO: Switch to using @divergent_items and handle this in the text
455- # builder
456- readable_list_of ( @divergent_items ) . lstrip
457- end
458-
459- # Update to use (...) as delimiter instead of {...}
460- def readable_list_of ( items )
461- if items && items . all? { |item | item . is_a? ( Hash ) }
462- description_of ( items . inject ( :merge ) ) .
463- sub ( /^\{ / , '(' ) .
464- sub ( / \} $/ , ')' )
465- else
466- super
467- end
468- end
469- end )
470402 end
471403
472- class Match
404+ class Equal
473405 prepend SuperDiff ::RSpec ::AugmentedMatcher
474-
475- prepend ( Module . new do
476- def matcher_text_builder_class
477- SuperDiff ::RSpec ::MatcherTextBuilders ::Match
478- end
479-
480- def matcher_text_builder_args
481- super . merge ( expected_captures : @expected_captures )
482- end
483- end )
484406 end
485407
486408 class HaveAttributes
@@ -560,33 +482,84 @@ def respond_to_failure_message_or
560482 end
561483 end
562484
563- class RespondTo
485+ class Include
564486 prepend SuperDiff ::RSpec ::AugmentedMatcher
565487
566488 prepend ( Module . new do
567- def matcher_text_builder_class
568- SuperDiff ::RSpec ::MatcherTextBuilders ::RespondTo
489+ # Override this method so that the differ knows that this is a partial
490+ # array or hash
491+ def expected_for_diff
492+ if expecteds . all? { |item | item . is_a? ( Hash ) }
493+ matchers . a_collection_including ( expecteds . first )
494+ else
495+ matchers . a_collection_including ( *expecteds )
496+ end
569497 end
570498
571- def matcher_text_builder_args
572- super . merge (
573- expected_arity : @expected_arity ,
574- arbitrary_keywords : @arbitrary_keywords ,
575- expected_keywords : @expected_keywords ,
576- unlimited_arguments : @unlimited_arguments
577- )
499+ private
500+
501+ # Override to capitalize message and add period at end
502+ def build_failure_message ( negated :)
503+ message = super
504+
505+ if actual . respond_to? ( :include? )
506+ message
507+ elsif message . end_with? ( "." )
508+ message . sub ( "\. $" , ", " ) + "but it does not respond to `include?`."
509+ else
510+ message + "\n \n But it does not respond to `include?`."
511+ end
578512 end
579513
514+ # Override to use readable_list_of
580515 def expected_for_description
581- @names
516+ readable_list_of ( expecteds ) . lstrip
582517 end
583518
519+ # Override to use readable_list_of
584520 def expected_for_failure_message
585- @failing_method_names
521+ # TODO: Switch to using @divergent_items and handle this in the text
522+ # builder
523+ readable_list_of ( @divergent_items ) . lstrip
524+ end
525+
526+ # Update to use (...) as delimiter instead of {...}
527+ def readable_list_of ( items )
528+ if items && items . all? { |item | item . is_a? ( Hash ) }
529+ description_of ( items . inject ( :merge ) ) .
530+ sub ( /^\{ / , '(' ) .
531+ sub ( / \} $/ , ')' )
532+ else
533+ super
534+ end
586535 end
587536 end )
588537 end
589538
539+ class Match
540+ prepend SuperDiff ::RSpec ::AugmentedMatcher
541+
542+ prepend ( Module . new do
543+ def matcher_text_builder_class
544+ SuperDiff ::RSpec ::MatcherTextBuilders ::Match
545+ end
546+
547+ def matcher_text_builder_args
548+ super . merge ( expected_captures : @expected_captures )
549+ end
550+ end )
551+ end
552+
553+ class MatchArray < ContainExactly
554+ def expected_for_diff
555+ matchers . an_array_matching ( expected )
556+ end
557+
558+ def expected_action_for_matcher_text
559+ "match array with"
560+ end
561+ end
562+
590563 class RaiseError
591564 prepend SuperDiff ::RSpec ::AugmentedMatcher
592565
@@ -630,6 +603,33 @@ def self.matcher_name
630603 'raise error'
631604 end
632605 end
606+
607+ class RespondTo
608+ prepend SuperDiff ::RSpec ::AugmentedMatcher
609+
610+ prepend ( Module . new do
611+ def matcher_text_builder_class
612+ SuperDiff ::RSpec ::MatcherTextBuilders ::RespondTo
613+ end
614+
615+ def matcher_text_builder_args
616+ super . merge (
617+ expected_arity : @expected_arity ,
618+ arbitrary_keywords : @arbitrary_keywords ,
619+ expected_keywords : @expected_keywords ,
620+ unlimited_arguments : @unlimited_arguments
621+ )
622+ end
623+
624+ def expected_for_description
625+ @names
626+ end
627+
628+ def expected_for_failure_message
629+ @failing_method_names
630+ end
631+ end )
632+ end
633633 end
634634
635635 def match_array ( items )
0 commit comments