rspec-expectations 3.9.3 → 3.10.2

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.
@@ -1,3 +1,5 @@
1
+ require 'rspec/matchers/built_in/count_expectation'
2
+
1
3
  RSpec::Support.require_rspec_support 'method_signature_verifier'
2
4
 
3
5
  module RSpec
@@ -97,64 +99,12 @@ module RSpec
97
99
  # Provides the implementation for `yield_control`.
98
100
  # Not intended to be instantiated directly.
99
101
  class YieldControl < BaseMatcher
100
- def initialize
101
- @expectation_type = @expected_yields_count = nil
102
- end
103
-
104
- # @api public
105
- # Specifies that the method is expected to yield once.
106
- def once
107
- exactly(1)
108
- self
109
- end
110
-
111
- # @api public
112
- # Specifies that the method is expected to yield twice.
113
- def twice
114
- exactly(2)
115
- self
116
- end
117
-
118
- # @api public
119
- # Specifies that the method is expected to yield thrice.
120
- def thrice
121
- exactly(3)
122
- self
123
- end
124
-
125
- # @api public
126
- # Specifies that the method is expected to yield the given number of times.
127
- def exactly(number)
128
- set_expected_yields_count(:==, number)
129
- self
130
- end
131
-
132
- # @api public
133
- # Specifies the maximum number of times the method is expected to yield
134
- def at_most(number)
135
- set_expected_yields_count(:<=, number)
136
- self
137
- end
138
-
139
- # @api public
140
- # Specifies the minimum number of times the method is expected to yield
141
- def at_least(number)
142
- set_expected_yields_count(:>=, number)
143
- self
144
- end
145
-
146
- # @api public
147
- # No-op. Provides syntactic sugar.
148
- def times
149
- self
150
- end
151
-
102
+ include CountExpectation
152
103
  # @private
153
104
  def matches?(block)
154
105
  @probe = YieldProbe.probe(block)
155
106
  return false unless @probe.has_block?
156
- return @probe.num_yields > 0 unless @expectation_type
157
- @probe.num_yields.__send__(@expectation_type, @expected_yields_count)
107
+ expected_count_matches?(@probe.num_yields)
158
108
  end
159
109
 
160
110
  # @private
@@ -181,46 +131,10 @@ module RSpec
181
131
 
182
132
  private
183
133
 
184
- def set_expected_yields_count(relativity, n)
185
- raise "Multiple count constraints are not supported" if @expectation_type
186
-
187
- @expectation_type = relativity
188
- @expected_yields_count = count_constraint_to_number(n)
189
- end
190
-
191
- def count_constraint_to_number(n)
192
- case n
193
- when Numeric then n
194
- when :once then 1
195
- when :twice then 2
196
- when :thrice then 3
197
- else
198
- raise ArgumentError, "Expected a number, :once, :twice or :thrice," \
199
- " but got #{n}"
200
- end
201
- end
202
-
203
134
  def failure_reason
204
135
  return ' but was not a block' unless @probe.has_block?
205
- "#{human_readable_expectation_type}#{human_readable_count(@expected_yields_count)}" \
206
- " but yielded#{human_readable_count(@probe.num_yields)}"
207
- end
208
-
209
- def human_readable_expectation_type
210
- case @expectation_type
211
- when :<= then ' at most'
212
- when :>= then ' at least'
213
- else ''
214
- end
215
- end
216
-
217
- def human_readable_count(count)
218
- case count
219
- when nil then ''
220
- when 1 then ' once'
221
- when 2 then ' twice'
222
- else " #{count} times"
223
- end
136
+ return "#{count_expectation_description} but did not yield" if @probe.num_yields == 0
137
+ count_failure_reason('yielded')
224
138
  end
225
139
  end
226
140
 
@@ -16,8 +16,9 @@ module RSpec
16
16
  autoload :Be, 'rspec/matchers/built_in/be'
17
17
  autoload :BeComparedTo, 'rspec/matchers/built_in/be'
18
18
  autoload :BeFalsey, 'rspec/matchers/built_in/be'
19
+ autoload :BeHelpers, 'rspec/matchers/built_in/be'
19
20
  autoload :BeNil, 'rspec/matchers/built_in/be'
20
- autoload :BePredicate, 'rspec/matchers/built_in/be'
21
+ autoload :BePredicate, 'rspec/matchers/built_in/has'
21
22
  autoload :BeTruthy, 'rspec/matchers/built_in/be'
22
23
  autoload :BeWithin, 'rspec/matchers/built_in/be_within'
23
24
  autoload :Change, 'rspec/matchers/built_in/change'
@@ -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,10 +697,10 @@ 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
@@ -761,20 +761,22 @@ module RSpec
761
761
  # expect { do_something_risky }.to raise_error
762
762
  # expect { do_something_risky }.to raise_error(PoorRiskDecisionError)
763
763
  # expect { do_something_risky }.to raise_error(PoorRiskDecisionError) { |error| expect(error.data).to eq 42 }
764
+ # expect { do_something_risky }.to raise_error { |error| expect(error.data).to eq 42 }
764
765
  # expect { do_something_risky }.to raise_error(PoorRiskDecisionError, "that was too risky")
765
766
  # expect { do_something_risky }.to raise_error(PoorRiskDecisionError, /oo ri/)
767
+ # expect { do_something_risky }.to raise_error("that was too risky")
766
768
  #
767
769
  # expect { do_something_risky }.not_to raise_error
768
- def raise_error(error=nil, message=nil, &block)
770
+ def raise_error(error=BuiltIn::RaiseError::UndefinedValue, message=nil, &block)
769
771
  BuiltIn::RaiseError.new(error, message, &block)
770
772
  end
771
- alias_method :raise_exception, :raise_error
773
+ alias_method :raise_exception, :raise_error
772
774
 
773
- alias_matcher :a_block_raising, :raise_error do |desc|
775
+ alias_matcher :a_block_raising, :raise_error do |desc|
774
776
  desc.sub("raise", "a block raising")
775
777
  end
776
778
 
777
- alias_matcher :raising, :raise_error do |desc|
779
+ alias_matcher :raising, :raise_error do |desc|
778
780
  desc.sub("raise", "raising")
779
781
  end
780
782
 
@@ -788,7 +790,7 @@ module RSpec
788
790
  BuiltIn::RespondTo.new(*names)
789
791
  end
790
792
  alias_matcher :an_object_responding_to, :respond_to
791
- alias_matcher :responding_to, :respond_to
793
+ alias_matcher :responding_to, :respond_to
792
794
 
793
795
  # Passes if the submitted block returns true. Yields target to the
794
796
  # block.
@@ -809,7 +811,7 @@ module RSpec
809
811
  BuiltIn::Satisfy.new(description, &block)
810
812
  end
811
813
  alias_matcher :an_object_satisfying, :satisfy
812
- alias_matcher :satisfying, :satisfy
814
+ alias_matcher :satisfying, :satisfy
813
815
 
814
816
  # Matches if the actual value starts with the expected value(s). In the
815
817
  # case of a string, matches against the first `expected.length` characters
@@ -824,8 +826,8 @@ module RSpec
824
826
  BuiltIn::StartWith.new(*expected)
825
827
  end
826
828
  alias_matcher :a_collection_starting_with, :start_with
827
- alias_matcher :a_string_starting_with, :start_with
828
- alias_matcher :starting_with, :start_with
829
+ alias_matcher :a_string_starting_with, :start_with
830
+ alias_matcher :starting_with, :start_with
829
831
 
830
832
  # Given no argument, matches if a proc throws any Symbol.
831
833
  #
@@ -850,7 +852,7 @@ module RSpec
850
852
  desc.sub("throw", "a block throwing")
851
853
  end
852
854
 
853
- alias_matcher :throwing, :throw_symbol do |desc|
855
+ alias_matcher :throwing, :throw_symbol do |desc|
854
856
  desc.sub("throw", "throwing")
855
857
  end
856
858
 
@@ -866,8 +868,8 @@ module RSpec
866
868
  def yield_control
867
869
  BuiltIn::YieldControl.new
868
870
  end
869
- alias_matcher :a_block_yielding_control, :yield_control
870
- alias_matcher :yielding_control, :yield_control
871
+ alias_matcher :a_block_yielding_control, :yield_control
872
+ alias_matcher :yielding_control, :yield_control
871
873
 
872
874
  # Passes if the method called in the expect block yields with
873
875
  # no arguments. Fails if it does not yield, or yields with arguments.
@@ -884,8 +886,8 @@ module RSpec
884
886
  def yield_with_no_args
885
887
  BuiltIn::YieldWithNoArgs.new
886
888
  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
889
+ alias_matcher :a_block_yielding_with_no_args, :yield_with_no_args
890
+ alias_matcher :yielding_with_no_args, :yield_with_no_args
889
891
 
890
892
  # Given no arguments, matches if the method called in the expect
891
893
  # block yields with arguments (regardless of what they are or how
@@ -914,8 +916,8 @@ module RSpec
914
916
  def yield_with_args(*args)
915
917
  BuiltIn::YieldWithArgs.new(*args)
916
918
  end
917
- alias_matcher :a_block_yielding_with_args, :yield_with_args
918
- alias_matcher :yielding_with_args, :yield_with_args
919
+ alias_matcher :a_block_yielding_with_args, :yield_with_args
920
+ alias_matcher :yielding_with_args, :yield_with_args
919
921
 
920
922
  # Designed for use with methods that repeatedly yield (such as
921
923
  # iterators). Passes if the method called in the expect block yields
@@ -935,8 +937,8 @@ module RSpec
935
937
  def yield_successive_args(*args)
936
938
  BuiltIn::YieldSuccessiveArgs.new(*args)
937
939
  end
938
- alias_matcher :a_block_yielding_successive_args, :yield_successive_args
939
- alias_matcher :yielding_successive_args, :yield_successive_args
940
+ alias_matcher :a_block_yielding_successive_args, :yield_successive_args
941
+ alias_matcher :yielding_successive_args, :yield_successive_args
940
942
 
941
943
  # Delegates to {RSpec::Expectations.configuration}.
942
944
  # This is here because rspec-core's `expect_with` option
@@ -949,35 +951,21 @@ module RSpec
949
951
 
950
952
  private
951
953
 
952
- BE_PREDICATE_REGEX = /^(be_(?:an?_)?)(.*)/
954
+ BE_PREDICATE_REGEX = /^(?:be_(?:an?_)?)(.*)/
953
955
  HAS_REGEX = /^(?:have_)(.*)/
954
956
  DYNAMIC_MATCHER_REGEX = Regexp.union(BE_PREDICATE_REGEX, HAS_REGEX)
955
957
 
956
- if RSpec::Support::RubyFeatures.kw_args_supported?
957
- binding.eval(<<-CODE, __FILE__, __LINE__)
958
- def method_missing(method, *args, **kwargs, &block)
959
- case method.to_s
960
- when BE_PREDICATE_REGEX
961
- BuiltIn::BePredicate.new(method, *args, **kwargs, &block)
962
- when HAS_REGEX
963
- BuiltIn::Has.new(method, *args, **kwargs, &block)
964
- else
965
- super
966
- end
967
- end
968
- CODE
969
- else
970
- def method_missing(method, *args, &block)
971
- case method.to_s
972
- when BE_PREDICATE_REGEX
973
- BuiltIn::BePredicate.new(method, *args, &block)
974
- when HAS_REGEX
975
- BuiltIn::Has.new(method, *args, &block)
976
- else
977
- super
978
- end
958
+ def method_missing(method, *args, &block)
959
+ case method.to_s
960
+ when BE_PREDICATE_REGEX
961
+ BuiltIn::BePredicate.new(method, *args, &block)
962
+ when HAS_REGEX
963
+ BuiltIn::Has.new(method, *args, &block)
964
+ else
965
+ super
979
966
  end
980
967
  end
968
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
981
969
 
982
970
  if RUBY_VERSION.to_f >= 1.9
983
971
  def respond_to_missing?(method, *)
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.3
4
+ version: 3.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
@@ -45,7 +45,7 @@ cert_chain:
45
45
  ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
46
46
  F3MdtaDehhjC
47
47
  -----END CERTIFICATE-----
48
- date: 2020-10-23 00:00:00.000000000 Z
48
+ date: 2022-01-14 00:00:00.000000000 Z
49
49
  dependencies:
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rspec-support
@@ -53,14 +53,14 @@ dependencies:
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 3.9.0
56
+ version: 3.10.0
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: 3.9.0
63
+ version: 3.10.0
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: diff-lcs
66
66
  requirement: !ruby/object:Gem::Requirement
@@ -99,14 +99,14 @@ dependencies:
99
99
  name: cucumber
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - "~>"
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: '1.3'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - "~>"
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '1.3'
112
112
  - !ruby/object:Gem::Dependency
@@ -172,6 +172,7 @@ files:
172
172
  - lib/rspec/matchers/built_in/change.rb
173
173
  - lib/rspec/matchers/built_in/compound.rb
174
174
  - lib/rspec/matchers/built_in/contain_exactly.rb
175
+ - lib/rspec/matchers/built_in/count_expectation.rb
175
176
  - lib/rspec/matchers/built_in/cover.rb
176
177
  - lib/rspec/matchers/built_in/eq.rb
177
178
  - lib/rspec/matchers/built_in/eql.rb
@@ -202,7 +203,7 @@ licenses:
202
203
  - MIT
203
204
  metadata:
204
205
  bug_tracker_uri: https://github.com/rspec/rspec-expectations/issues
205
- changelog_uri: https://github.com/rspec/rspec-expectations/blob/v3.9.3/Changelog.md
206
+ changelog_uri: https://github.com/rspec/rspec-expectations/blob/v3.10.2/Changelog.md
206
207
  documentation_uri: https://rspec.info/documentation/
207
208
  mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
208
209
  source_code_uri: https://github.com/rspec/rspec-expectations
@@ -222,8 +223,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  - !ruby/object:Gem::Version
223
224
  version: '0'
224
225
  requirements: []
225
- rubygems_version: 3.1.3
226
+ rubygems_version: 3.3.3
226
227
  signing_key:
227
228
  specification_version: 4
228
- summary: rspec-expectations-3.9.3
229
+ summary: rspec-expectations-3.10.2
229
230
  test_files: []
metadata.gz.sig CHANGED
Binary file