rspec-expectations 3.8.6 → 3.9.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1f0c43e7a6933605f4b96eb0a5545bd5e1b03a2b2de4471edada5000f3c5c37
4
- data.tar.gz: 62b85e7625d066114174dfaa586dbb2cb419aa0bc470b68918c2524b841f8762
3
+ metadata.gz: d8cb915ab51f5b587fcbaa864e697cc291ff3c1f49afd8d829837c1a9c4c4f6b
4
+ data.tar.gz: 6aa770883cacbfcf2921074a98506a0a789b4557ee6a7ea79738f008107e582d
5
5
  SHA512:
6
- metadata.gz: 5ba237ec4317b7af0780f5e929e10da26b501f76a23cb807684498a21118ef0f72598c1ded7ee0436a8a29f97ea16a0d4f887c7b345b22302f5b8ef50c660beb
7
- data.tar.gz: 4138b8b208b668216660d55f5634440e8240c4a36f15489fc3e1e6093d4a8530fc419d9f958ea4526ac63e7e9e2d589c7716a21832d257adac823486d5dfae77
6
+ metadata.gz: fc2669ca822767874cc62c9e7cef32040f90da7cd0d4c13b1bd97fde68230f7f7019a8b717e2ebfcd223da5b9e25aaa60270c0797ba4d304def5e4ae3bb63f03
7
+ data.tar.gz: e9d7a9e1b186c1eee547c315f177181992f5be9e35c61a16a041d97901537d054943a779e0d6bd7f2502e51a1fcbf95f0f6a10eab46fcdd85bebd8be1170a369
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,17 @@
1
+ ### 3.9.0 / 2019-10-02
2
+ [Full Changelog](http://github.com/rspec/rspec-expectations/compare/v3.8.5...v3.9.0)
3
+
4
+ Enhancements:
5
+
6
+ * The `respond_to` matcher now uses the signature from `initialize` to validate checks
7
+ for `new` (unless `new` is non standard). (Jon Rowe, #1072)
8
+ * Generated descriptions for matchers now use `is expected to` rather than `should` in
9
+ line with our preferred DSL. (Pete Johns, #1080, rspec/rspec-core#2572)
10
+ * Add the ability to re-raise expectation errors when matching
11
+ with `match_when_negated` blocks. (Jon Rowe, #1130)
12
+ * Add a warning when an empty diff is produce due to identical inspect output.
13
+ (Benoit Tigeot, #1126)
14
+
1
15
  ### 3.8.6 / 2019-10-07
2
16
 
3
17
  Bug Fixes:
data/README.md CHANGED
@@ -175,30 +175,45 @@ expect(1..10).to cover(3)
175
175
  ### Collection membership
176
176
 
177
177
  ```ruby
178
- expect(actual).to include(expected)
178
+ # exact order, entire collection
179
+ expect(actual).to eq(expected)
180
+
181
+ # exact order, partial collection (based on an exact position)
179
182
  expect(actual).to start_with(expected)
180
183
  expect(actual).to end_with(expected)
181
184
 
182
- expect(actual).to contain_exactly(individual, items)
183
- # ...which is the same as:
184
- expect(actual).to match_array(expected_array)
185
+ # any order, entire collection
186
+ expect(actual).to match_array(expected)
187
+
188
+ # You can also express this by passing the expected elements
189
+ # as individual arguments
190
+ expect(actual).to contain_exactly(expected_element1, expected_element2)
191
+
192
+ # any order, partial collection
193
+ expect(actual).to include(expected)
185
194
  ```
186
195
 
187
196
  #### Examples
188
197
 
189
198
  ```ruby
190
- expect([1, 2, 3]).to include(1)
191
- expect([1, 2, 3]).to include(1, 2)
192
- expect([1, 2, 3]).to start_with(1)
193
- expect([1, 2, 3]).to start_with(1, 2)
194
- expect([1, 2, 3]).to end_with(3)
195
- expect([1, 2, 3]).to end_with(2, 3)
196
- expect({:a => 'b'}).to include(:a => 'b')
197
- expect("this string").to include("is str")
198
- expect("this string").to start_with("this")
199
- expect("this string").to end_with("ring")
200
- expect([1, 2, 3]).to contain_exactly(2, 3, 1)
201
- expect([1, 2, 3]).to match_array([3, 2, 1])
199
+ expect([1, 2, 3]).to eq([1, 2, 3]) # Order dependent equality check
200
+ expect([1, 2, 3]).to include(1) # Exact ordering, partial collection matches
201
+ expect([1, 2, 3]).to include(2, 3) #
202
+ expect([1, 2, 3]).to start_with(1) # As above, but from the start of the collection
203
+ expect([1, 2, 3]).to start_with(1, 2) #
204
+ expect([1, 2, 3]).to end_with(3) # As above but from the end of the collection
205
+ expect([1, 2, 3]).to end_with(2, 3) #
206
+ expect({:a => 'b'}).to include(:a => 'b') # Matching within hashes
207
+ expect("this string").to include("is str") # Matching within strings
208
+ expect("this string").to start_with("this") #
209
+ expect("this string").to end_with("ring") #
210
+ expect([1, 2, 3]).to contain_exactly(2, 3, 1) # Order independent matches
211
+ expect([1, 2, 3]).to match_array([3, 2, 1]) #
212
+
213
+ # Order dependent compound matchers
214
+ expect(
215
+ [{:a => 'hash'},{:a => 'another'}]
216
+ ).to match([a_hash_including(:a => 'hash'), a_hash_including(:a => 'another')])
202
217
  ```
203
218
 
204
219
  ## `should` syntax
@@ -52,7 +52,7 @@ module RSpec
52
52
  end
53
53
 
54
54
  def self.verb
55
- "should"
55
+ 'is expected to'
56
56
  end
57
57
 
58
58
  def self.should_method
@@ -82,7 +82,7 @@ module RSpec
82
82
  end
83
83
 
84
84
  def self.verb
85
- "should not"
85
+ 'is expected not to'
86
86
  end
87
87
 
88
88
  def self.should_method
@@ -2,7 +2,7 @@ module RSpec
2
2
  module Expectations
3
3
  # @private
4
4
  module Version
5
- STRING = '3.8.6'
5
+ STRING = '3.9.0'
6
6
  end
7
7
  end
8
8
  end
@@ -1003,31 +1003,35 @@ module RSpec
1003
1003
  is_a_matcher?(obj) && obj.respond_to?(:description)
1004
1004
  end
1005
1005
 
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.
1006
+ class << self
1007
+ private
1014
1008
 
1015
- subclasses = ObjectSpace.each_object(Class).select { |c| c < mod && c < self }
1016
- return super unless subclasses.any?
1009
+ if RSpec::Support::Ruby.mri? && RUBY_VERSION[0, 3] == '1.9'
1010
+ # Note that `included` doesn't work for this because it is triggered
1011
+ # _after_ `RSpec::Matchers` is an ancestor of the inclusion host, rather
1012
+ # than _before_, like `append_features`. It's important we check this before
1013
+ # in order to find the cases where it was already previously included.
1014
+ # @api private
1015
+ def append_features(mod)
1016
+ return super if mod < self # `mod < self` indicates a re-inclusion.
1017
1017
 
1018
- subclasses.reject! { |s| subclasses.any? { |s2| s < s2 } } # Filter to the root ancestor.
1019
- subclasses = subclasses.map { |s| "`#{s}`" }.join(", ")
1018
+ subclasses = ObjectSpace.each_object(Class).select { |c| c < mod && c < self }
1019
+ return super unless subclasses.any?
1020
1020
 
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"
1021
+ subclasses.reject! { |s| subclasses.any? { |s2| s < s2 } } # Filter to the root ancestor.
1022
+ subclasses = subclasses.map { |s| "`#{s}`" }.join(", ")
1029
1023
 
1030
- super
1024
+ RSpec.warning "`#{self}` has been included in a superclass (`#{mod}`) " \
1025
+ "after previously being included in subclasses (#{subclasses}), " \
1026
+ "which can trigger infinite recursion from `super` due to an MRI 1.9 bug " \
1027
+ "(https://redmine.ruby-lang.org/issues/3351). To work around this, " \
1028
+ "either upgrade to MRI 2.0+, include a dup of the module (e.g. " \
1029
+ "`include #{self}.dup`), or find a way to include `#{self}` in `#{mod}` " \
1030
+ "before it is included in subclasses (#{subclasses}). See " \
1031
+ "https://github.com/rspec/rspec-expectations/issues/814 for more info"
1032
+
1033
+ super
1034
+ end
1031
1035
  end
1032
1036
  end
1033
1037
  end
@@ -154,7 +154,12 @@ module RSpec
154
154
  end
155
155
 
156
156
  def matcher_matches?(matcher)
157
- @match_results.fetch(matcher)
157
+ @match_results.fetch(matcher) do
158
+ raise ArgumentError, "Your #{matcher.description} has no match " \
159
+ "results, this can occur when an unexpected call stack or " \
160
+ "local jump occurs. Prehaps one of your matchers needs to " \
161
+ "declare `expects_call_stack_jump?` as `true`?"
162
+ end
158
163
  end
159
164
 
160
165
  private
@@ -125,9 +125,18 @@ module RSpec
125
125
 
126
126
  return true if expectation.empty?
127
127
 
128
- signature = Support::MethodSignature.new(Support.method_handle_for(actual, name))
128
+ Support::StrictSignatureVerifier.new(method_signature_for(actual, name)).
129
+ with_expectation(expectation).valid?
130
+ end
131
+
132
+ def method_signature_for(actual, name)
133
+ method_handle = Support.method_handle_for(actual, name)
129
134
 
130
- Support::StrictSignatureVerifier.new(signature).with_expectation(expectation).valid?
135
+ if name == :new && method_handle.owner === ::Class && ::Class === actual
136
+ Support::MethodSignature.new(actual.instance_method(:initialize))
137
+ else
138
+ Support::MethodSignature.new(method_handle)
139
+ end
131
140
  end
132
141
 
133
142
  def with_arity
@@ -147,8 +147,14 @@ module RSpec
147
147
  # is rarely necessary, but can be helpful, for example, when specifying
148
148
  # asynchronous processes that require different timeouts.
149
149
  #
150
+ # By default the match block will swallow expectation errors (e.g.
151
+ # caused by using an expectation such as `expect(1).to eq 2`), if you
152
+ # with to allow these to bubble up, pass in the option
153
+ # `:notify_expectation_failures => true`.
154
+ #
155
+ # @param [Hash] options for defining the behavior of the match block.
150
156
  # @yield [Object] actual the actual value (i.e. the value wrapped by `expect`)
151
- def match_when_negated(&match_block)
157
+ def match_when_negated(options={}, &match_block)
152
158
  define_user_override(:does_not_match?, match_block) do |actual|
153
159
  begin
154
160
  @actual = actual
@@ -156,6 +162,7 @@ module RSpec
156
162
  super(*actual_arg_for(match_block))
157
163
  end
158
164
  rescue RSpec::Expectations::ExpectationNotMetError
165
+ raise if options[:notify_expectation_failures]
159
166
  false
160
167
  end
161
168
  end
@@ -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
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.8.6
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
@@ -53,14 +53,14 @@ dependencies:
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 3.8.0
56
+ version: 3.9.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.8.0
63
+ version: 3.9.0
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: diff-lcs
66
66
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +123,20 @@ dependencies:
123
123
  - - "~>"
124
124
  - !ruby/object:Gem::Version
125
125
  version: '5.2'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rake
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 10.0.0
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 10.0.0
126
140
  description: rspec-expectations provides a simple, readable API to express expected
127
141
  outcomes of a code example.
128
142
  email: rspec@googlegroups.com
@@ -188,7 +202,7 @@ licenses:
188
202
  - MIT
189
203
  metadata:
190
204
  bug_tracker_uri: https://github.com/rspec/rspec-expectations/issues
191
- changelog_uri: https://github.com/rspec/rspec-expectations/blob/v3.8.6/Changelog.md
205
+ changelog_uri: https://github.com/rspec/rspec-expectations/blob/v3.9.0/Changelog.md
192
206
  documentation_uri: https://rspec.info/documentation/
193
207
  mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
194
208
  source_code_uri: https://github.com/rspec/rspec-expectations
@@ -211,5 +225,5 @@ requirements: []
211
225
  rubygems_version: 3.0.6
212
226
  signing_key:
213
227
  specification_version: 4
214
- summary: rspec-expectations-3.8.6
228
+ summary: rspec-expectations-3.9.0
215
229
  test_files: []
metadata.gz.sig CHANGED
Binary file