mocha 2.7.0 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/RELEASE.md +8 -0
- data/lib/mocha/configuration.rb +7 -0
- data/lib/mocha/expectation.rb +25 -4
- data/lib/mocha/parameters_matcher.rb +7 -3
- data/lib/mocha/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61f3a7bc2e73c16b715a31472883ed85fc55726d28e43d051b5d62da21362b52
|
4
|
+
data.tar.gz: 8e2b6b411543932dfb02f9d97cbe0eb35ed48e983e9079a426c7963f075416da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd352ea7b0ef64b7e56880a90faecd452b67891765a23441013f73405546da1746314025bb4c556b1322ea621a7d28d940efc77272a52b63716993bc27ebe94f
|
7
|
+
data.tar.gz: e229f55ddd4d53350941bef0af9d3b1026a76f904b666d187ebd6d808feb284101677c66e47005ea3889767626e1cd556330e222d80752f57be89665d4fafd3a
|
data/README.md
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
* Supported by many other test frameworks.
|
9
9
|
|
10
10
|
### Intended Usage
|
11
|
+
|
11
12
|
Mocha is intended to be used in unit tests for the [Mock Object](http://xunitpatterns.com/Mock%20Object.html) or [Test Stub](http://xunitpatterns.com/Test%20Stub.html) types of [Test Double](http://xunitpatterns.com/Test%20Double.html), not the [Fake Object](http://xunitpatterns.com/Fake%20Object.html) or [Test Spy](http://xunitpatterns.com/Test%20Spy.html) types. Although it would be possible to extend Mocha to allow the implementation of fakes and spies, we have chosen to keep it focused on mocks and stubs.
|
12
13
|
|
13
14
|
### Installation
|
data/RELEASE.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Release Notes
|
2
2
|
|
3
|
+
## 2.7.1
|
4
|
+
|
5
|
+
### External changes
|
6
|
+
|
7
|
+
* Deprecate `Configuration#stubbing_method_on_nil=` (#694)
|
8
|
+
* Indicate when parameter matcher logic is defined by block passed to `Expectation#with` (#698, b30e4434)
|
9
|
+
* Improve documentation for `Expectation#with`, especially when it is passed a block (#698, #682, #606 & #681)
|
10
|
+
|
3
11
|
## 2.7.0
|
4
12
|
|
5
13
|
### External changes
|
data/lib/mocha/configuration.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'mocha/ruby_version'
|
2
|
+
require 'mocha/deprecation'
|
2
3
|
|
3
4
|
module Mocha
|
4
5
|
# Allows setting of configuration options. See {Configuration} for the available options.
|
@@ -206,8 +207,14 @@ module Mocha
|
|
206
207
|
# When +value+ is +:prevent+, raise a {StubbingError}. This is the default.
|
207
208
|
#
|
208
209
|
# @param [Symbol] value one of +:allow+, +:warn+, +:prevent+.
|
210
|
+
# @deprecated This method is deprecated and will be removed in a future release. +nil+ is frozen in Ruby >= v2.2 and Mocha will be dropping support for Ruby v2.1. At that point it won't be possible to stub methods on +nil+ any more.
|
209
211
|
#
|
210
212
|
def stubbing_method_on_nil=(value)
|
213
|
+
Deprecation.warning([
|
214
|
+
'`Mocha::Configuration#stubbing_method_on_nil=` is deprecated and will be removed in a future release.',
|
215
|
+
'`nil` is frozen in Ruby >= v2.2 and Mocha will be dropping support for Ruby v2.1.',
|
216
|
+
"At that point it won't be possible to stub methods on `nil` any more."
|
217
|
+
].join(' '))
|
211
218
|
@options[:stubbing_method_on_nil] = value
|
212
219
|
end
|
213
220
|
|
data/lib/mocha/expectation.rb
CHANGED
@@ -193,6 +193,11 @@ module Mocha
|
|
193
193
|
#
|
194
194
|
# May be used with Ruby literals or variables for exact matching or with parameter matchers for less-specific matching, e.g. {ParameterMatchers#includes}, {ParameterMatchers#has_key}, etc. See {ParameterMatchers} for a list of all available parameter matchers.
|
195
195
|
#
|
196
|
+
# Alternatively a block argument can be passed to {#with} to implement custom parameter matching. The block receives the +*actual_parameters+ as its arguments and should return +true+ if they are acceptable or +false+ otherwise. See the example below where a method is expected to be called with a value divisible by 4.
|
197
|
+
# The block argument takes precedence over +expected_parameters_or_matchers+. The block may be called multiple times per invocation of the expected method and so it should be idempotent.
|
198
|
+
#
|
199
|
+
# Note that if {#with} is called multiple times on the same expectation, the last call takes precedence; other calls are ignored.
|
200
|
+
#
|
196
201
|
# Positional arguments were separated from keyword arguments in Ruby v3 (see {https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0 this article}). In relation to this a new configuration option ({Configuration#strict_keyword_argument_matching=}) is available in Ruby >= 2.7.
|
197
202
|
#
|
198
203
|
# When {Configuration#strict_keyword_argument_matching=} is set to +false+ (which is currently the default), a positional +Hash+ and a set of keyword arguments passed to {#with} are treated the same for the purposes of parameter matching. However, a deprecation warning will be displayed if a positional +Hash+ matches a set of keyword arguments or vice versa. This is because {Configuration#strict_keyword_argument_matching=} will default to +true+ in the future.
|
@@ -202,10 +207,10 @@ module Mocha
|
|
202
207
|
# @see ParameterMatchers
|
203
208
|
# @see Configuration#strict_keyword_argument_matching=
|
204
209
|
#
|
205
|
-
# @param [
|
210
|
+
# @param [Array<Object,ParameterMatchers::Base>] expected_parameters_or_matchers expected parameter values or parameter matchers.
|
206
211
|
# @yield optional block specifying custom matching.
|
207
|
-
# @yieldparam [
|
208
|
-
# @yieldreturn [Boolean] +true+ if +actual_parameters+ are acceptable.
|
212
|
+
# @yieldparam [Array<Object>] actual_parameters parameters with which expected method was invoked.
|
213
|
+
# @yieldreturn [Boolean] +true+ if +actual_parameters+ are acceptable; +false+ otherwise.
|
209
214
|
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
|
210
215
|
#
|
211
216
|
# @example Expected method must be called with exact parameter values.
|
@@ -256,7 +261,7 @@ module Mocha
|
|
256
261
|
# example.foo('a', { bar: 'b' })
|
257
262
|
# # This now fails as expected
|
258
263
|
#
|
259
|
-
# @example
|
264
|
+
# @example Using a block argument to expect the method to be called with a value divisible by 4.
|
260
265
|
# object = mock()
|
261
266
|
# object.expects(:expected_method).with() { |value| value % 4 == 0 }
|
262
267
|
# object.expected_method(16)
|
@@ -266,6 +271,22 @@ module Mocha
|
|
266
271
|
# object.expects(:expected_method).with() { |value| value % 4 == 0 }
|
267
272
|
# object.expected_method(17)
|
268
273
|
# # => verify fails
|
274
|
+
#
|
275
|
+
# @example Extracting a custom matcher into an instance method on the test class.
|
276
|
+
# class MyTest < Minitest::Test
|
277
|
+
# def test_expected_method_is_called_with_a_value_divisible_by_4
|
278
|
+
# object = mock()
|
279
|
+
# object.expects(:expected_method).with(&method(:divisible_by_4))
|
280
|
+
# object.expected_method(16)
|
281
|
+
# # => verify succeeds
|
282
|
+
# end
|
283
|
+
#
|
284
|
+
# private
|
285
|
+
#
|
286
|
+
# def divisible_by_4(value)
|
287
|
+
# value % 4 == 0
|
288
|
+
# end
|
289
|
+
# end
|
269
290
|
def with(*expected_parameters_or_matchers, &matching_block)
|
270
291
|
@parameters_matcher = ParametersMatcher.new(expected_parameters_or_matchers, self, &matching_block)
|
271
292
|
self
|
@@ -22,9 +22,13 @@ module Mocha
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def mocha_inspect
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
if @matching_block
|
26
|
+
'(arguments_accepted_by_custom_matching_block)'
|
27
|
+
else
|
28
|
+
signature = matchers.mocha_inspect
|
29
|
+
signature = signature.gsub(/^\[|\]$/, '')
|
30
|
+
"(#{signature})"
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
def matchers
|
data/lib/mocha/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mocha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Mead
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby2_keywords
|