rspec-expectations 3.8.1 → 3.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/Changelog.md +203 -4
  4. data/README.md +35 -20
  5. data/lib/rspec/expectations/configuration.rb +15 -0
  6. data/lib/rspec/expectations/expectation_target.rb +42 -6
  7. data/lib/rspec/expectations/failure_aggregator.rb +41 -6
  8. data/lib/rspec/expectations/handler.rb +20 -8
  9. data/lib/rspec/expectations/version.rb +1 -1
  10. data/lib/rspec/matchers/aliased_matcher.rb +3 -3
  11. data/lib/rspec/matchers/built_in/all.rb +1 -0
  12. data/lib/rspec/matchers/built_in/base_matcher.rb +5 -0
  13. data/lib/rspec/matchers/built_in/be.rb +10 -107
  14. data/lib/rspec/matchers/built_in/be_instance_of.rb +5 -1
  15. data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -1
  16. data/lib/rspec/matchers/built_in/be_within.rb +2 -2
  17. data/lib/rspec/matchers/built_in/change.rb +26 -2
  18. data/lib/rspec/matchers/built_in/compound.rb +20 -1
  19. data/lib/rspec/matchers/built_in/contain_exactly.rb +10 -2
  20. data/lib/rspec/matchers/built_in/count_expectation.rb +169 -0
  21. data/lib/rspec/matchers/built_in/exist.rb +1 -1
  22. data/lib/rspec/matchers/built_in/has.rb +88 -24
  23. data/lib/rspec/matchers/built_in/have_attributes.rb +1 -1
  24. data/lib/rspec/matchers/built_in/include.rb +82 -18
  25. data/lib/rspec/matchers/built_in/output.rb +7 -0
  26. data/lib/rspec/matchers/built_in/raise_error.rb +63 -22
  27. data/lib/rspec/matchers/built_in/respond_to.rb +53 -18
  28. data/lib/rspec/matchers/built_in/throw_symbol.rb +10 -4
  29. data/lib/rspec/matchers/built_in/yield.rb +26 -83
  30. data/lib/rspec/matchers/built_in.rb +2 -1
  31. data/lib/rspec/matchers/composable.rb +1 -1
  32. data/lib/rspec/matchers/dsl.rb +29 -11
  33. data/lib/rspec/matchers/english_phrasing.rb +1 -1
  34. data/lib/rspec/matchers/expecteds_for_multiple_diffs.rb +16 -7
  35. data/lib/rspec/matchers/matcher_protocol.rb +6 -0
  36. data/lib/rspec/matchers.rb +78 -68
  37. data.tar.gz.sig +0 -0
  38. metadata +29 -24
  39. metadata.gz.sig +0 -0
@@ -83,7 +83,7 @@ module RSpec
83
83
  RSpec::Support::ObjectFormatter.format(object)
84
84
  end
85
85
 
86
- # Transforms the given data structue (typically a hash or array)
86
+ # Transforms the given data structure (typically a hash or array)
87
87
  # into a new data structure that, when `#inspect` is called on it,
88
88
  # will provide descriptions of any contained matchers rather than
89
89
  # the normal `#inspect` output.
@@ -1,8 +1,10 @@
1
+ RSpec::Support.require_rspec_support "with_keywords_when_needed"
2
+
1
3
  module RSpec
2
4
  module Matchers
3
5
  # Defines the custom matcher DSL.
4
6
  module DSL
5
- # Defines a matcher alias. The returned matcher's `description` will be overriden
7
+ # Defines a matcher alias. The returned matcher's `description` will be overridden
6
8
  # to reflect the phrasing of the new name, which will be used in failure messages
7
9
  # when passed as an argument to another matcher in a composed matcher expression.
8
10
  #
@@ -23,7 +25,7 @@ module RSpec
23
25
  # @param old_name [Symbol] the original name for the matcher
24
26
  # @param options [Hash] options for the aliased matcher
25
27
  # @option options [Class] :klass the ruby class to use as the decorator. (Not normally used).
26
- # @yield [String] optional block that, when given, is used to define the overriden
28
+ # @yield [String] optional block that, when given, is used to define the overridden
27
29
  # logic. The yielded arg is the original description or failure message. If no
28
30
  # block is provided, a default override is used based on the old and new names.
29
31
  # @see RSpec::Matchers
@@ -38,10 +40,11 @@ module RSpec
38
40
  matcher.matcher_name = new_name if matcher.respond_to?(:matcher_name=)
39
41
  klass.new(matcher, description_override)
40
42
  end
43
+ ruby2_keywords new_name if respond_to?(:ruby2_keywords, true)
41
44
  end
42
45
 
43
46
  # Defines a negated matcher. The returned matcher's `description` and `failure_message`
44
- # will be overriden to reflect the phrasing of the new name, and the match logic will
47
+ # will be overridden to reflect the phrasing of the new name, and the match logic will
45
48
  # be based on the original matcher but negated.
46
49
  #
47
50
  # @example
@@ -51,7 +54,7 @@ module RSpec
51
54
  #
52
55
  # @param negated_name [Symbol] the name for the negated matcher
53
56
  # @param base_name [Symbol] the name of the original matcher that will be negated
54
- # @yield [String] optional block that, when given, is used to define the overriden
57
+ # @yield [String] optional block that, when given, is used to define the overridden
55
58
  # logic. The yielded arg is the original description or failure message. If no
56
59
  # block is provided, a default override is used based on the old and new names.
57
60
  # @see RSpec::Matchers
@@ -120,7 +123,7 @@ module RSpec
120
123
  #
121
124
  # By default the match block will swallow expectation errors (e.g.
122
125
  # caused by using an expectation such as `expect(1).to eq 2`), if you
123
- # with to allow these to bubble up, pass in the option
126
+ # wish to allow these to bubble up, pass in the option
124
127
  # `:notify_expectation_failures => true`.
125
128
  #
126
129
  # @param [Hash] options for defining the behavior of the match block.
@@ -147,8 +150,14 @@ module RSpec
147
150
  # is rarely necessary, but can be helpful, for example, when specifying
148
151
  # asynchronous processes that require different timeouts.
149
152
  #
153
+ # By default the match block will swallow expectation errors (e.g.
154
+ # caused by using an expectation such as `expect(1).to eq 2`), if you
155
+ # wish to allow these to bubble up, pass in the option
156
+ # `:notify_expectation_failures => true`.
157
+ #
158
+ # @param [Hash] options for defining the behavior of the match block.
150
159
  # @yield [Object] actual the actual value (i.e. the value wrapped by `expect`)
151
- def match_when_negated(&match_block)
160
+ def match_when_negated(options={}, &match_block)
152
161
  define_user_override(:does_not_match?, match_block) do |actual|
153
162
  begin
154
163
  @actual = actual
@@ -156,6 +165,7 @@ module RSpec
156
165
  super(*actual_arg_for(match_block))
157
166
  end
158
167
  rescue RSpec::Expectations::ExpectationNotMetError
168
+ raise if options[:notify_expectation_failures]
159
169
  false
160
170
  end
161
171
  end
@@ -188,7 +198,7 @@ module RSpec
188
198
  end
189
199
  end
190
200
 
191
- # Customizes the failure messsage to use when this matcher is
201
+ # Customizes the failure message to use when this matcher is
192
202
  # asked to positively match. Only use this when the message
193
203
  # generated by default doesn't suit your needs.
194
204
  #
@@ -207,7 +217,7 @@ module RSpec
207
217
  define_user_override(__method__, definition)
208
218
  end
209
219
 
210
- # Customize the failure messsage to use when this matcher is asked
220
+ # Customize the failure message to use when this matcher is asked
211
221
  # to negatively match. Only use this when the message generated by
212
222
  # default doesn't suit your needs.
213
223
  #
@@ -321,7 +331,7 @@ module RSpec
321
331
  # - Defines the named method using a user-provided block
322
332
  # in @user_method_defs, which is included as an ancestor
323
333
  # in the singleton class in which we eval the `define` block.
324
- # - Defines an overriden definition for the same method
334
+ # - Defines an overridden definition for the same method
325
335
  # usign the provided `our_def` block.
326
336
  # - Provides a default `our_def` block for the common case
327
337
  # of needing to call the user's definition with `@actual`
@@ -394,6 +404,10 @@ module RSpec
394
404
  false
395
405
  end
396
406
 
407
+ def supports_value_expectations?
408
+ true
409
+ end
410
+
397
411
  # Most matchers do not expect call stack jumps.
398
412
  def expects_call_stack_jump?
399
413
  false
@@ -453,11 +467,12 @@ module RSpec
453
467
  @chained_method_clauses = []
454
468
  @block_arg = block_arg
455
469
 
456
- class << self
470
+ klass = class << self
457
471
  # See `Macros#define_user_override` above, for an explanation.
458
472
  include(@user_method_defs = Module.new)
459
473
  self
460
- end.class_exec(*expected, &declarations)
474
+ end
475
+ RSpec::Support::WithKeywordsWhenNeeded.class_exec(klass, *expected, &declarations)
461
476
  end
462
477
 
463
478
  # Provides the expected value. This will return an array if
@@ -521,6 +536,9 @@ module RSpec
521
536
  super(method, *args, &block)
522
537
  end
523
538
  end
539
+ # The method_missing method should be refactored to pass kw args in RSpec 4
540
+ # then this can be removed
541
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
524
542
  end
525
543
  end
526
544
  end
@@ -24,7 +24,7 @@ module RSpec
24
24
  # list([]) #=> ""
25
25
  #
26
26
  def self.list(obj)
27
- return " #{RSpec::Support::ObjectFormatter.format(obj)}" if !obj || Struct === obj
27
+ return " #{RSpec::Support::ObjectFormatter.format(obj)}" if !obj || Struct === obj || Hash === obj
28
28
  items = Array(obj).map { |w| RSpec::Support::ObjectFormatter.format(w) }
29
29
  case items.length
30
30
  when 0
@@ -52,20 +52,29 @@ module RSpec
52
52
 
53
53
  private
54
54
 
55
- def self.diff_label_for(matcher)
56
- "Diff for (#{truncated(RSpec::Support::ObjectFormatter.format(matcher))}):"
57
- end
55
+ class << self
56
+ private
57
+
58
+ def diff_label_for(matcher)
59
+ "Diff for (#{truncated(RSpec::Support::ObjectFormatter.format(matcher))}):"
60
+ end
58
61
 
59
- def self.truncated(description)
60
- return description if description.length <= DESCRIPTION_MAX_LENGTH
61
- description[0...DESCRIPTION_MAX_LENGTH - 3] << "..."
62
+ def truncated(description)
63
+ return description if description.length <= DESCRIPTION_MAX_LENGTH
64
+ description[0...DESCRIPTION_MAX_LENGTH - 3] << "..."
65
+ end
62
66
  end
63
67
 
64
68
  def diffs(differ, actual)
65
69
  @expected_list.map do |(expected, diff_label)|
66
70
  diff = differ.diff(actual, expected)
67
71
  next if diff.strip.empty?
68
- "#{diff_label}#{diff}"
72
+ if diff == "\e[0m\n\e[0m"
73
+ "#{diff_label}\n" \
74
+ " <The diff is empty, are your objects producing identical `#inspect` output?>"
75
+ else
76
+ "#{diff_label}#{diff}"
77
+ end
69
78
  end.compact.join("\n")
70
79
  end
71
80
  end
@@ -60,6 +60,12 @@ module RSpec
60
60
  # @return [Boolean] true if this matcher can be used in block expressions.
61
61
  # @note If not defined, RSpec assumes a value of `false` for this method.
62
62
 
63
+ # @!method supports_value_expectations?
64
+ # Indicates that this matcher can be used in a value expectation expression,
65
+ # such as `expect(foo).to eq(bar)`.
66
+ # @return [Boolean] true if this matcher can be used in value expressions.
67
+ # @note If not defined, RSpec assumes a value of `true` for this method.
68
+
63
69
  # @!method expects_call_stack_jump?
64
70
  # Indicates that when this matcher is used in a block expectation
65
71
  # expression, it expects the block to use a ruby construct that causes
@@ -36,7 +36,7 @@ module RSpec
36
36
  # expect([]).to be_empty # => [].empty?() | passes
37
37
  # expect([]).not_to be_empty # => [].empty?() | fails
38
38
  #
39
- # In addtion to prefixing the predicate matchers with "be_", you can also use "be_a_"
39
+ # In addition to prefixing the predicate matchers with "be_", you can also use "be_a_"
40
40
  # and "be_an_", making your specs read much more naturally:
41
41
  #
42
42
  # expect("a string").to be_an_instance_of(String) # =>"a string".instance_of?(String) # passes
@@ -238,7 +238,7 @@ module RSpec
238
238
  # best to find a more positive name for the negated form, such as
239
239
  # `avoid_changing` rather than `not_change`.
240
240
  #
241
- module Matchers
241
+ module Matchers # rubocop:disable Metrics/ModuleLength
242
242
  extend ::RSpec::Matchers::DSL
243
243
 
244
244
  # @!macro [attach] alias_matcher
@@ -266,9 +266,9 @@ module RSpec
266
266
  # @example
267
267
  # expect(actual).to eq(expected)
268
268
  # expect(actual).not_to eq(expected)
269
- # @return [ExpectationTarget]
270
- # @see ExpectationTarget#to
271
- # @see ExpectationTarget#not_to
269
+ # @return [Expectations::ExpectationTarget]
270
+ # @see Expectations::ExpectationTarget#to
271
+ # @see Expectations::ExpectationTarget#not_to
272
272
 
273
273
  # Allows multiple expectations in the provided block to fail, and then
274
274
  # aggregates them into a single exception, rather than aborting on the
@@ -316,9 +316,9 @@ module RSpec
316
316
  def be_falsey
317
317
  BuiltIn::BeFalsey.new
318
318
  end
319
- alias_matcher :be_falsy, :be_falsey
319
+ alias_matcher :be_falsy, :be_falsey
320
320
  alias_matcher :a_falsey_value, :be_falsey
321
- alias_matcher :a_falsy_value, :be_falsey
321
+ alias_matcher :a_falsy_value, :be_falsey
322
322
 
323
323
  # Passes if actual is nil
324
324
  def be_nil
@@ -379,7 +379,7 @@ module RSpec
379
379
  BuiltIn::BeAKindOf.new(expected)
380
380
  end
381
381
  alias_method :be_kind_of, :be_a_kind_of
382
- alias_matcher :a_kind_of, :be_a_kind_of
382
+ alias_matcher :a_kind_of, :be_a_kind_of
383
383
 
384
384
  # Passes if actual.between?(min, max). Works with any Comparable object,
385
385
  # including String, Symbol, Time, or Numeric (Fixnum, Bignum, Integer,
@@ -406,7 +406,7 @@ module RSpec
406
406
  BuiltIn::BeWithin.new(delta)
407
407
  end
408
408
  alias_matcher :a_value_within, :be_within
409
- alias_matcher :within, :be_within
409
+ alias_matcher :within, :be_within
410
410
 
411
411
  # Applied to a proc, specifies that its execution will cause some value to
412
412
  # change.
@@ -492,8 +492,8 @@ module RSpec
492
492
  def change(receiver=nil, message=nil, &block)
493
493
  BuiltIn::Change.new(receiver, message, &block)
494
494
  end
495
- alias_matcher :a_block_changing, :change
496
- alias_matcher :changing, :change
495
+ alias_matcher :a_block_changing, :change
496
+ alias_matcher :changing, :change
497
497
 
498
498
  # Passes if actual contains all of the expected regardless of order.
499
499
  # This works for collections. Pass in multiple args and it will only
@@ -511,7 +511,7 @@ module RSpec
511
511
  BuiltIn::ContainExactly.new(items)
512
512
  end
513
513
  alias_matcher :a_collection_containing_exactly, :contain_exactly
514
- alias_matcher :containing_exactly, :contain_exactly
514
+ alias_matcher :containing_exactly, :contain_exactly
515
515
 
516
516
  # Passes if actual covers expected. This works for
517
517
  # Ranges. You can also pass in multiple args
@@ -529,7 +529,7 @@ module RSpec
529
529
  BuiltIn::Cover.new(*values)
530
530
  end
531
531
  alias_matcher :a_range_covering, :cover
532
- alias_matcher :covering, :cover
532
+ alias_matcher :covering, :cover
533
533
 
534
534
  # Matches if the actual value ends with the expected value(s). In the case
535
535
  # of a string, matches against the last `expected.length` characters of the
@@ -544,8 +544,8 @@ module RSpec
544
544
  BuiltIn::EndWith.new(*expected)
545
545
  end
546
546
  alias_matcher :a_collection_ending_with, :end_with
547
- alias_matcher :a_string_ending_with, :end_with
548
- alias_matcher :ending_with, :end_with
547
+ alias_matcher :a_string_ending_with, :end_with
548
+ alias_matcher :ending_with, :end_with
549
549
 
550
550
  # Passes if <tt>actual == expected</tt>.
551
551
  #
@@ -559,7 +559,7 @@ module RSpec
559
559
  BuiltIn::Eq.new(expected)
560
560
  end
561
561
  alias_matcher :an_object_eq_to, :eq
562
- alias_matcher :eq_to, :eq
562
+ alias_matcher :eq_to, :eq
563
563
 
564
564
  # Passes if `actual.eql?(expected)`
565
565
  #
@@ -573,7 +573,7 @@ module RSpec
573
573
  BuiltIn::Eql.new(expected)
574
574
  end
575
575
  alias_matcher :an_object_eql_to, :eql
576
- alias_matcher :eql_to, :eql
576
+ alias_matcher :eql_to, :eql
577
577
 
578
578
  # Passes if <tt>actual.equal?(expected)</tt> (object identity).
579
579
  #
@@ -587,7 +587,7 @@ module RSpec
587
587
  BuiltIn::Equal.new(expected)
588
588
  end
589
589
  alias_matcher :an_object_equal_to, :equal
590
- alias_matcher :equal_to, :equal
590
+ alias_matcher :equal_to, :equal
591
591
 
592
592
  # Passes if `actual.exist?` or `actual.exists?`
593
593
  #
@@ -597,7 +597,7 @@ module RSpec
597
597
  BuiltIn::Exist.new(*args)
598
598
  end
599
599
  alias_matcher :an_object_existing, :exist
600
- alias_matcher :existing, :exist
600
+ alias_matcher :existing, :exist
601
601
 
602
602
  # Passes if actual's attribute values match the expected attributes hash.
603
603
  # This works no matter how you define your attribute readers.
@@ -617,7 +617,7 @@ module RSpec
617
617
  BuiltIn::HaveAttributes.new(expected)
618
618
  end
619
619
  alias_matcher :an_object_having_attributes, :have_attributes
620
- alias_matcher :having_attributes, :have_attributes
620
+ alias_matcher :having_attributes, :have_attributes
621
621
 
622
622
  # Passes if actual includes expected. This works for
623
623
  # collections and Strings. You can also pass in multiple args
@@ -640,9 +640,9 @@ module RSpec
640
640
  BuiltIn::Include.new(*expected)
641
641
  end
642
642
  alias_matcher :a_collection_including, :include
643
- alias_matcher :a_string_including, :include
644
- alias_matcher :a_hash_including, :include
645
- alias_matcher :including, :include
643
+ alias_matcher :a_string_including, :include
644
+ alias_matcher :a_hash_including, :include
645
+ alias_matcher :including, :include
646
646
 
647
647
  # Passes if the provided matcher passes when checked against all
648
648
  # elements of the collection.
@@ -697,14 +697,14 @@ module RSpec
697
697
  def match(expected)
698
698
  BuiltIn::Match.new(expected)
699
699
  end
700
- alias_matcher :match_regex, :match
700
+ alias_matcher :match_regex, :match
701
701
  alias_matcher :an_object_matching, :match
702
- alias_matcher :a_string_matching, :match
703
- alias_matcher :matching, :match
702
+ alias_matcher :a_string_matching, :match
703
+ alias_matcher :matching, :match
704
704
 
705
705
  # An alternate form of `contain_exactly` that accepts
706
706
  # the expected contents as a single array arg rather
707
- # that splatted out as individual items.
707
+ # than splatted out as individual items.
708
708
  #
709
709
  # @example
710
710
  # expect(results).to contain_exactly(1, 2)
@@ -715,6 +715,9 @@ module RSpec
715
715
  def match_array(items)
716
716
  contain_exactly(*items)
717
717
  end
718
+ alias_matcher :an_array_matching, :match_array do |desc|
719
+ desc.sub("contain exactly", "an array containing exactly")
720
+ end
718
721
 
719
722
  # With no arg, passes if the block outputs `to_stdout` or `to_stderr`.
720
723
  # With a string, passes if the block outputs that specific string `to_stdout` or `to_stderr`.
@@ -753,28 +756,30 @@ module RSpec
753
756
 
754
757
  # With no args, matches if any error is raised.
755
758
  # With a named error, matches only if that specific error is raised.
756
- # With a named error and messsage specified as a String, matches only if both match.
757
- # With a named error and messsage specified as a Regexp, matches only if both match.
759
+ # With a named error and message specified as a String, matches only if both match.
760
+ # With a named error and message specified as a Regexp, matches only if both match.
758
761
  # Pass an optional block to perform extra verifications on the exception matched
759
762
  #
760
763
  # @example
761
764
  # expect { do_something_risky }.to raise_error
762
765
  # expect { do_something_risky }.to raise_error(PoorRiskDecisionError)
763
766
  # expect { do_something_risky }.to raise_error(PoorRiskDecisionError) { |error| expect(error.data).to eq 42 }
767
+ # expect { do_something_risky }.to raise_error { |error| expect(error.data).to eq 42 }
764
768
  # expect { do_something_risky }.to raise_error(PoorRiskDecisionError, "that was too risky")
765
769
  # expect { do_something_risky }.to raise_error(PoorRiskDecisionError, /oo ri/)
770
+ # expect { do_something_risky }.to raise_error("that was too risky")
766
771
  #
767
772
  # expect { do_something_risky }.not_to raise_error
768
- def raise_error(error=nil, message=nil, &block)
773
+ def raise_error(error=BuiltIn::RaiseError::UndefinedValue, message=nil, &block)
769
774
  BuiltIn::RaiseError.new(error, message, &block)
770
775
  end
771
- alias_method :raise_exception, :raise_error
776
+ alias_method :raise_exception, :raise_error
772
777
 
773
- alias_matcher :a_block_raising, :raise_error do |desc|
778
+ alias_matcher :a_block_raising, :raise_error do |desc|
774
779
  desc.sub("raise", "a block raising")
775
780
  end
776
781
 
777
- alias_matcher :raising, :raise_error do |desc|
782
+ alias_matcher :raising, :raise_error do |desc|
778
783
  desc.sub("raise", "raising")
779
784
  end
780
785
 
@@ -788,7 +793,7 @@ module RSpec
788
793
  BuiltIn::RespondTo.new(*names)
789
794
  end
790
795
  alias_matcher :an_object_responding_to, :respond_to
791
- alias_matcher :responding_to, :respond_to
796
+ alias_matcher :responding_to, :respond_to
792
797
 
793
798
  # Passes if the submitted block returns true. Yields target to the
794
799
  # block.
@@ -809,7 +814,7 @@ module RSpec
809
814
  BuiltIn::Satisfy.new(description, &block)
810
815
  end
811
816
  alias_matcher :an_object_satisfying, :satisfy
812
- alias_matcher :satisfying, :satisfy
817
+ alias_matcher :satisfying, :satisfy
813
818
 
814
819
  # Matches if the actual value starts with the expected value(s). In the
815
820
  # case of a string, matches against the first `expected.length` characters
@@ -824,8 +829,8 @@ module RSpec
824
829
  BuiltIn::StartWith.new(*expected)
825
830
  end
826
831
  alias_matcher :a_collection_starting_with, :start_with
827
- alias_matcher :a_string_starting_with, :start_with
828
- alias_matcher :starting_with, :start_with
832
+ alias_matcher :a_string_starting_with, :start_with
833
+ alias_matcher :starting_with, :start_with
829
834
 
830
835
  # Given no argument, matches if a proc throws any Symbol.
831
836
  #
@@ -850,7 +855,7 @@ module RSpec
850
855
  desc.sub("throw", "a block throwing")
851
856
  end
852
857
 
853
- alias_matcher :throwing, :throw_symbol do |desc|
858
+ alias_matcher :throwing, :throw_symbol do |desc|
854
859
  desc.sub("throw", "throwing")
855
860
  end
856
861
 
@@ -866,8 +871,8 @@ module RSpec
866
871
  def yield_control
867
872
  BuiltIn::YieldControl.new
868
873
  end
869
- alias_matcher :a_block_yielding_control, :yield_control
870
- alias_matcher :yielding_control, :yield_control
874
+ alias_matcher :a_block_yielding_control, :yield_control
875
+ alias_matcher :yielding_control, :yield_control
871
876
 
872
877
  # Passes if the method called in the expect block yields with
873
878
  # no arguments. Fails if it does not yield, or yields with arguments.
@@ -884,8 +889,8 @@ module RSpec
884
889
  def yield_with_no_args
885
890
  BuiltIn::YieldWithNoArgs.new
886
891
  end
887
- alias_matcher :a_block_yielding_with_no_args, :yield_with_no_args
888
- alias_matcher :yielding_with_no_args, :yield_with_no_args
892
+ alias_matcher :a_block_yielding_with_no_args, :yield_with_no_args
893
+ alias_matcher :yielding_with_no_args, :yield_with_no_args
889
894
 
890
895
  # Given no arguments, matches if the method called in the expect
891
896
  # block yields with arguments (regardless of what they are or how
@@ -914,8 +919,8 @@ module RSpec
914
919
  def yield_with_args(*args)
915
920
  BuiltIn::YieldWithArgs.new(*args)
916
921
  end
917
- alias_matcher :a_block_yielding_with_args, :yield_with_args
918
- alias_matcher :yielding_with_args, :yield_with_args
922
+ alias_matcher :a_block_yielding_with_args, :yield_with_args
923
+ alias_matcher :yielding_with_args, :yield_with_args
919
924
 
920
925
  # Designed for use with methods that repeatedly yield (such as
921
926
  # iterators). Passes if the method called in the expect block yields
@@ -935,8 +940,8 @@ module RSpec
935
940
  def yield_successive_args(*args)
936
941
  BuiltIn::YieldSuccessiveArgs.new(*args)
937
942
  end
938
- alias_matcher :a_block_yielding_successive_args, :yield_successive_args
939
- alias_matcher :yielding_successive_args, :yield_successive_args
943
+ alias_matcher :a_block_yielding_successive_args, :yield_successive_args
944
+ alias_matcher :yielding_successive_args, :yield_successive_args
940
945
 
941
946
  # Delegates to {RSpec::Expectations.configuration}.
942
947
  # This is here because rspec-core's `expect_with` option
@@ -949,7 +954,7 @@ module RSpec
949
954
 
950
955
  private
951
956
 
952
- BE_PREDICATE_REGEX = /^(be_(?:an?_)?)(.*)/
957
+ BE_PREDICATE_REGEX = /^(?:be_(?:an?_)?)(.*)/
953
958
  HAS_REGEX = /^(?:have_)(.*)/
954
959
  DYNAMIC_MATCHER_REGEX = Regexp.union(BE_PREDICATE_REGEX, HAS_REGEX)
955
960
 
@@ -963,6 +968,7 @@ module RSpec
963
968
  super
964
969
  end
965
970
  end
971
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
966
972
 
967
973
  if RUBY_VERSION.to_f >= 1.9
968
974
  def respond_to_missing?(method, *)
@@ -1003,31 +1009,35 @@ module RSpec
1003
1009
  is_a_matcher?(obj) && obj.respond_to?(:description)
1004
1010
  end
1005
1011
 
1006
- if RSpec::Support::Ruby.mri? && RUBY_VERSION[0, 3] == '1.9'
1007
- # @api private
1008
- # Note that `included` doesn't work for this because it is triggered
1009
- # _after_ `RSpec::Matchers` is an ancestor of the inclusion host, rather
1010
- # than _before_, like `append_features`. It's important we check this before
1011
- # in order to find the cases where it was already previously included.
1012
- def self.append_features(mod)
1013
- return super if mod < self # `mod < self` indicates a re-inclusion.
1012
+ class << self
1013
+ private
1014
1014
 
1015
- subclasses = ObjectSpace.each_object(Class).select { |c| c < mod && c < self }
1016
- return super unless subclasses.any?
1015
+ if RSpec::Support::Ruby.mri? && RUBY_VERSION[0, 3] == '1.9'
1016
+ # Note that `included` doesn't work for this because it is triggered
1017
+ # _after_ `RSpec::Matchers` is an ancestor of the inclusion host, rather
1018
+ # than _before_, like `append_features`. It's important we check this before
1019
+ # in order to find the cases where it was already previously included.
1020
+ # @api private
1021
+ def append_features(mod)
1022
+ return super if mod < self # `mod < self` indicates a re-inclusion.
1017
1023
 
1018
- subclasses.reject! { |s| subclasses.any? { |s2| s < s2 } } # Filter to the root ancestor.
1019
- subclasses = subclasses.map { |s| "`#{s}`" }.join(", ")
1024
+ subclasses = ObjectSpace.each_object(Class).select { |c| c < mod && c < self }
1025
+ return super unless subclasses.any?
1020
1026
 
1021
- RSpec.warning "`#{self}` has been included in a superclass (`#{mod}`) " \
1022
- "after previously being included in subclasses (#{subclasses}), " \
1023
- "which can trigger infinite recursion from `super` due to an MRI 1.9 bug " \
1024
- "(https://redmine.ruby-lang.org/issues/3351). To work around this, " \
1025
- "either upgrade to MRI 2.0+, include a dup of the module (e.g. " \
1026
- "`include #{self}.dup`), or find a way to include `#{self}` in `#{mod}` " \
1027
- "before it is included in subclasses (#{subclasses}). See " \
1028
- "https://github.com/rspec/rspec-expectations/issues/814 for more info"
1027
+ subclasses.reject! { |s| subclasses.any? { |s2| s < s2 } } # Filter to the root ancestor.
1028
+ subclasses = subclasses.map { |s| "`#{s}`" }.join(", ")
1029
1029
 
1030
- super
1030
+ RSpec.warning "`#{self}` has been included in a superclass (`#{mod}`) " \
1031
+ "after previously being included in subclasses (#{subclasses}), " \
1032
+ "which can trigger infinite recursion from `super` due to an MRI 1.9 bug " \
1033
+ "(https://redmine.ruby-lang.org/issues/3351). To work around this, " \
1034
+ "either upgrade to MRI 2.0+, include a dup of the module (e.g. " \
1035
+ "`include #{self}.dup`), or find a way to include `#{self}` in `#{mod}` " \
1036
+ "before it is included in subclasses (#{subclasses}). See " \
1037
+ "https://github.com/rspec/rspec-expectations/issues/814 for more info"
1038
+
1039
+ super
1040
+ end
1031
1041
  end
1032
1042
  end
1033
1043
  end
data.tar.gz.sig CHANGED
Binary file