mocha 2.1.0 → 2.7.1
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 +4 -4
- data/.rubocop.yml +6 -1
- data/.yardopts +1 -1
- data/Gemfile +6 -1
- data/README.md +13 -18
- data/RELEASE.md +199 -0
- data/Rakefile +9 -9
- data/lib/mocha/api.rb +25 -6
- data/lib/mocha/cardinality.rb +4 -0
- data/lib/mocha/configuration.rb +7 -0
- data/lib/mocha/detection/{mini_test.rb → minitest.rb} +5 -5
- data/lib/mocha/detection/test_unit.rb +2 -2
- data/lib/mocha/expectation.rb +38 -6
- data/lib/mocha/expectation_error_factory.rb +2 -2
- data/lib/mocha/expectation_list.rb +8 -6
- data/lib/mocha/hooks.rb +10 -4
- data/lib/mocha/inspect.rb +13 -2
- data/lib/mocha/integration/{mini_test → minitest}/adapter.rb +20 -5
- data/lib/mocha/integration/{mini_test → minitest}/exception_translation.rb +2 -2
- data/lib/mocha/integration/minitest.rb +28 -0
- data/lib/mocha/integration/test_unit/adapter.rb +5 -0
- data/lib/mocha/minitest.rb +3 -3
- data/lib/mocha/mock.rb +37 -14
- data/lib/mocha/mockery.rb +13 -9
- data/lib/mocha/object_methods.rb +2 -2
- data/lib/mocha/parameter_matchers/base.rb +4 -9
- data/lib/mocha/parameter_matchers/has_entries.rb +7 -2
- data/lib/mocha/parameter_matchers/includes.rb +3 -3
- data/lib/mocha/parameter_matchers/instance_methods.rb +9 -10
- data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +3 -1
- data/lib/mocha/parameter_matchers/responds_with.rb +32 -5
- data/lib/mocha/parameters_matcher.rb +8 -4
- data/lib/mocha/ruby_version.rb +1 -0
- data/lib/mocha/version.rb +1 -1
- data/mocha.gemspec +9 -1
- metadata +15 -9
- data/lib/mocha/integration/mini_test.rb +0 -28
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/.rubocop.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
|
2
2
|
|
|
3
3
|
AllCops:
|
|
4
|
-
TargetRubyVersion: 2.2 # closest to required_ruby_version of '>= 2.
|
|
4
|
+
TargetRubyVersion: 2.2 # closest to required_ruby_version of '>= 2.1'
|
|
5
5
|
|
|
6
6
|
# Even the reference in the documentation suggests that you should prefer
|
|
7
7
|
# `alias_method` vs `alias`, so I don't understand why that isn't the default.
|
|
@@ -36,6 +36,11 @@ Style/WhileUntilModifier:
|
|
|
36
36
|
Style/AccessModifierDeclarations:
|
|
37
37
|
Enabled: false
|
|
38
38
|
|
|
39
|
+
# `Module#===` is useful in presence of objects such as mocks
|
|
40
|
+
# that may have a `is_a?` implementation that lies.
|
|
41
|
+
Style/CaseEquality:
|
|
42
|
+
Enabled: false
|
|
43
|
+
|
|
39
44
|
# This is useful when using `ExecutionPoint.current` to make tests more robust
|
|
40
45
|
Style/Semicolon:
|
|
41
46
|
Enabled: false
|
data/.yardopts
CHANGED
|
@@ -16,7 +16,7 @@ lib/mocha/expectation_error.rb
|
|
|
16
16
|
lib/mocha/stubbing_error.rb
|
|
17
17
|
lib/mocha/unexpected_invocation.rb
|
|
18
18
|
lib/mocha/integration/test_unit/adapter.rb
|
|
19
|
-
lib/mocha/integration/
|
|
19
|
+
lib/mocha/integration/minitest/adapter.rb
|
|
20
20
|
-
|
|
21
21
|
RELEASE.md
|
|
22
22
|
COPYING.md
|
data/Gemfile
CHANGED
|
@@ -22,7 +22,12 @@ if RUBY_VERSION >= '2.2.0'
|
|
|
22
22
|
gem 'minitest'
|
|
23
23
|
end
|
|
24
24
|
if RUBY_VERSION >= '2.2.0'
|
|
25
|
-
gem '
|
|
25
|
+
gem 'jaro_winkler', '>= 1.5.5'
|
|
26
|
+
gem 'rubocop', '> 0.56', '<= 0.58.2'
|
|
27
|
+
end
|
|
28
|
+
if RUBY_ENGINE == 'jruby'
|
|
29
|
+
# Workaround for https://github.com/jruby/jruby/issues/8488
|
|
30
|
+
gem 'jar-dependencies', '~> 0.4.1'
|
|
26
31
|
end
|
|
27
32
|
if ENV['MOCHA_GENERATE_DOCS']
|
|
28
33
|
gem 'redcarpet'
|
data/README.md
CHANGED
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
* A Ruby library for [mocking](http://xunitpatterns.com/Mock%20Object.html) and [stubbing](http://xunitpatterns.com/Test%20Stub.html) - but deliberately not (yet) [faking](http://xunitpatterns.com/Fake%20Object.html) or [spying](http://xunitpatterns.com/Test%20Spy.html).
|
|
6
6
|
* A unified, simple and readable syntax for both full & partial mocking.
|
|
7
|
-
* Built-in support for
|
|
7
|
+
* Built-in support for Minitest and Test::Unit.
|
|
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
|
|
@@ -18,7 +19,7 @@ Install the latest version of the gem with the following command...
|
|
|
18
19
|
|
|
19
20
|
$ gem install mocha
|
|
20
21
|
|
|
21
|
-
Note: If you are intending to use Mocha with Test::Unit or
|
|
22
|
+
Note: If you are intending to use Mocha with Test::Unit or Minitest, you should only setup Mocha *after* loading the relevant test library...
|
|
22
23
|
|
|
23
24
|
##### Test::Unit
|
|
24
25
|
|
|
@@ -29,12 +30,12 @@ require 'test/unit'
|
|
|
29
30
|
require 'mocha/test_unit'
|
|
30
31
|
```
|
|
31
32
|
|
|
32
|
-
#####
|
|
33
|
+
##### Minitest
|
|
33
34
|
|
|
34
35
|
```ruby
|
|
35
36
|
require 'rubygems'
|
|
36
37
|
gem 'mocha'
|
|
37
|
-
require 'minitest/
|
|
38
|
+
require 'minitest/autorun'
|
|
38
39
|
require 'mocha/minitest'
|
|
39
40
|
```
|
|
40
41
|
|
|
@@ -53,14 +54,14 @@ require 'test/unit'
|
|
|
53
54
|
require 'mocha/test_unit'
|
|
54
55
|
```
|
|
55
56
|
|
|
56
|
-
#####
|
|
57
|
+
##### Minitest
|
|
57
58
|
|
|
58
59
|
```ruby
|
|
59
60
|
# Gemfile
|
|
60
61
|
gem 'mocha'
|
|
61
62
|
|
|
62
63
|
# Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'`
|
|
63
|
-
require 'minitest/
|
|
64
|
+
require 'minitest/autorun'
|
|
64
65
|
require 'mocha/minitest'
|
|
65
66
|
```
|
|
66
67
|
|
|
@@ -103,9 +104,9 @@ end
|
|
|
103
104
|
|
|
104
105
|
If you're loading Mocha using Bundler within a Rails application, you should setup Mocha manually e.g. at the bottom of your `test_helper.rb`.
|
|
105
106
|
|
|
106
|
-
#####
|
|
107
|
+
##### Minitest
|
|
107
108
|
|
|
108
|
-
Note that since Rails v4 (at least), `ActiveSupport::TestCase` has inherited from `Minitest::Test` or its earlier equivalents. Thus unless you are *explicitly* using Test::Unit, you are likely to be using
|
|
109
|
+
Note that since Rails v4 (at least), `ActiveSupport::TestCase` has inherited from `Minitest::Test` or its earlier equivalents. Thus unless you are *explicitly* using Test::Unit, you are likely to be using Minitest.
|
|
109
110
|
|
|
110
111
|
```ruby
|
|
111
112
|
# Gemfile in Rails app
|
|
@@ -121,13 +122,7 @@ Follow the instructions for the relevant test framework in the [Bundler](#bundle
|
|
|
121
122
|
|
|
122
123
|
#### Known Issues
|
|
123
124
|
|
|
124
|
-
*
|
|
125
|
-
* In Mocha v1.2.0 there is a scenario where stubbing a class method originally defined in a module hangs the Ruby interpreter due to [a bug in Ruby v2.3.1](https://bugs.ruby-lang.org/issues/12832). See #272. This was fixed in Mocha v1.2.1.
|
|
126
|
-
* Since v1.1.0 Mocha has used prepended modules internally for stubbing methods. There is [an obscure Ruby bug](https://bugs.ruby-lang.org/issues/12876) in many (but not all) versions of Ruby between v2.0 & v2.3 which under certain circumstances may cause your Ruby interpreter to hang. See the Ruby bug report for more details. The bug has been fixed in Ruby v2.3.3 & v2.4.0.
|
|
127
|
-
* Stubbing an aliased class method, where the original method is defined in a module that's used to `extend` the class doesn't work in Ruby 1.8.x. See stub_method_defined_on_module_and_aliased_test.rb for an example of this behaviour.
|
|
128
|
-
* 0.13.x versions cause a harmless, but annoying, deprecation warning when used with Rails 3.2.0-3.2.12, 3.1.0-3.1.10 & 3.0.0-3.0.19.
|
|
129
|
-
* 0.11.x versions don't work with Rails 3.2.13 (`TypeError: superclass mismatch for class ExpectationError`). See #115.
|
|
130
|
-
* Versions 0.10.2, 0.10.3 & 0.11.0 of the Mocha gem were broken. Please do not use these versions.
|
|
125
|
+
* Prior to v1.15.0 (when support for Ruby v1.8 was dropped), stubbing an aliased class method where the original method is defined in a module that's used to `extend` the class doesn't work in Ruby v1.8. See `test/acceptance/stub_method_defined_on_module_and_aliased_test.rb` for an example of this behaviour.
|
|
131
126
|
|
|
132
127
|
### Usage
|
|
133
128
|
|
|
@@ -151,7 +146,7 @@ class MiscExampleTest < Test::Unit::TestCase
|
|
|
151
146
|
end
|
|
152
147
|
|
|
153
148
|
def test_stubbing_instance_methods_on_real_objects
|
|
154
|
-
prices = [stub(:
|
|
149
|
+
prices = [stub(pence: 1000), stub(pence: 2000)]
|
|
155
150
|
product = Product.new
|
|
156
151
|
product.stubs(:prices).returns(prices)
|
|
157
152
|
assert_equal [1000, 2000], product.prices.collect {|p| p.pence}
|
|
@@ -170,7 +165,7 @@ class MiscExampleTest < Test::Unit::TestCase
|
|
|
170
165
|
end
|
|
171
166
|
|
|
172
167
|
def test_shortcuts
|
|
173
|
-
object = stub(:
|
|
168
|
+
object = stub(method1: :result1, method2: :result2)
|
|
174
169
|
assert_equal :result1, object.method1
|
|
175
170
|
assert_equal :result2, object.method2
|
|
176
171
|
end
|
|
@@ -282,7 +277,7 @@ Maybe, but probably not. Partial mocking changes the state of objects in the `Ob
|
|
|
282
277
|
|
|
283
278
|
Stubs and expectations are basically the same thing. A stub is just an expectation of zero or more invocations. The `Expectation#stubs` method is syntactic sugar to make the intent of the test more explicit.
|
|
284
279
|
|
|
285
|
-
When a method is invoked on a mock object, the mock object searches through its expectations from newest to oldest to find one that matches the invocation. After the invocation, the matching expectation might stop matching further invocations.
|
|
280
|
+
When a method is invoked on a mock object, the mock object searches through its expectations from newest to oldest to find one that matches the invocation. After the invocation, the matching expectation might stop matching further invocations. If the expectation that matches the invocation has a cardinality of "never", then an unexpected invocation error is reported.
|
|
286
281
|
|
|
287
282
|
See the [documentation](https://mocha.jamesmead.org/Mocha/Mock.html) for `Mocha::Mock` for further details.
|
|
288
283
|
|
data/RELEASE.md
CHANGED
|
@@ -1,5 +1,162 @@
|
|
|
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
|
+
|
|
11
|
+
## 2.7.0
|
|
12
|
+
|
|
13
|
+
### External changes
|
|
14
|
+
|
|
15
|
+
* Fail fast if invocation matches never expectation (#679, #678, #490, #131 & #44) - thanks to @ducmtran & @davidstosik for reporting
|
|
16
|
+
|
|
17
|
+
### Internal changes
|
|
18
|
+
|
|
19
|
+
* Workaround for JRuby jar-dependencies issue (#690)
|
|
20
|
+
* Ruby v3.4 stacktrace uses single-quote vs backtick (#688 & #689) - thanks to Vít Ondruch
|
|
21
|
+
|
|
22
|
+
**WARNING: This release fixes a very _old_ bug**
|
|
23
|
+
* The bug relates to the use of `Expectation#never` in combination with other expectations on the same method.
|
|
24
|
+
* Please ensure you fix the relevant deprecation warnings when running against v2.6.1 *before* upgrading to v2.7.0.
|
|
25
|
+
* Previously, the following test would have passed, but now it will fail with an unexpected invocation error on the `foo.bar` line.
|
|
26
|
+
|
|
27
|
+
foo = mock('foo')
|
|
28
|
+
foo.stubs(:bar)
|
|
29
|
+
foo.expects(:bar).never
|
|
30
|
+
foo.bar
|
|
31
|
+
|
|
32
|
+
## 2.6.1
|
|
33
|
+
|
|
34
|
+
### External changes
|
|
35
|
+
|
|
36
|
+
* Fix logic for displaying deprecation warning for expectation with never cardinality (#686) - thanks to @davidstosik for reporting
|
|
37
|
+
|
|
38
|
+
## 2.6.0
|
|
39
|
+
|
|
40
|
+
### External changes
|
|
41
|
+
|
|
42
|
+
* Expectation with never cardinality should display deprecation warning (#681) - thanks to @ducmtran for reporting and testing
|
|
43
|
+
|
|
44
|
+
**WARNING: This release results in some incorrect deprecation warnings:**
|
|
45
|
+
* The logic for displaying the deprecation warnings is fixed in v2.6.1 (#686).
|
|
46
|
+
|
|
47
|
+
### Internal changes
|
|
48
|
+
|
|
49
|
+
* Simplify backtrace related assertions (#680)
|
|
50
|
+
* Remove unused `ExpectationList#match_but_out_of_order` (f2fa9919)
|
|
51
|
+
|
|
52
|
+
## 2.5.0
|
|
53
|
+
|
|
54
|
+
### External changes
|
|
55
|
+
|
|
56
|
+
* Add metadata to gem specification, including `changelog_uri` (#608, eb1b8ea2) - thanks to @mattbrictson
|
|
57
|
+
* Fix warnings in Ruby v3.4 (#672, #669) - thanks to @radville for reporting
|
|
58
|
+
* Add warnings & notes about regressions, known issues, etc to release notes (#675, #676 & #677) - thanks to @davidstosik
|
|
59
|
+
|
|
60
|
+
### Internal changes
|
|
61
|
+
|
|
62
|
+
* Fix `jaro_winkler` compilation errors on MacOS (5c7d14cb)
|
|
63
|
+
* Fix typos in `IncludesTest` test names (6fb5a5a6)
|
|
64
|
+
* Fix `rubocop` version constraint for Ruby > v2.2.0 (d5c6b98a)
|
|
65
|
+
|
|
66
|
+
## 2.4.5
|
|
67
|
+
|
|
68
|
+
### External changes
|
|
69
|
+
|
|
70
|
+
* Fix regression when stubbed method expects `Hash` but receives `ActionController::Parameters` object (#662, #664) - thanks to @evgeni for reporting and testing
|
|
71
|
+
|
|
72
|
+
## 2.4.4
|
|
73
|
+
|
|
74
|
+
### External changes
|
|
75
|
+
|
|
76
|
+
* Fix regression when method expecting `Hash` parameter or keyword arguments is invoked with no arguments (#662, #663) - thanks to @vlad-pisanov for reporting
|
|
77
|
+
|
|
78
|
+
**WARNING: This release includes a regression:**
|
|
79
|
+
* A `NoMethodError` was raised when a stubbed method was expecting a `Hash`, but was invoked with an instance of `ActionController::Parameters`. See #662 for the report and #664 for the fix which was released in v2.4.5.
|
|
80
|
+
|
|
81
|
+
## 2.4.3
|
|
82
|
+
|
|
83
|
+
### External changes
|
|
84
|
+
|
|
85
|
+
* Fix regression when matching `Hash` parameter or keyword arguments (#657, #660) - thanks to @josesei for reporting and testing
|
|
86
|
+
|
|
87
|
+
**WARNING: This release inadvertently introduced a couple of regressions:**
|
|
88
|
+
* A `NoMethodError` was raised when a stubbed method was expecting a `Hash`, but was invoked with no arguments, e.g. with `C.expects(:foo).with(bar: 42)` and invoking `C.expects(:foo)`. See #662 for the report and #663 for the fix which was released in v2.4.4.
|
|
89
|
+
* A `NoMethodError` was raised when a stubbed method was expecting a `Hash`, but was invoked with an instance of `ActionController::Parameters`. See #662 for the report and #664 for the fix which was released in v2.4.5.
|
|
90
|
+
|
|
91
|
+
## 2.4.2
|
|
92
|
+
|
|
93
|
+
### External changes
|
|
94
|
+
|
|
95
|
+
* Don't trust `Object#is_a?` in presence of mock objects (#656) - thanks to @casperisfine
|
|
96
|
+
|
|
97
|
+
**WARNING: This release includes a regression:**
|
|
98
|
+
* Keyword argument and top-level `Hash` matching became more relaxed than intended, e.g. `mock.expects(:method).with(key: "value")` accepted `mock.method(key: "value", key2: "value")` when it should not have done. See #657 & #675 for the reports and #660 for the fix which was released in v2.4.3.
|
|
99
|
+
|
|
100
|
+
## 2.4.1
|
|
101
|
+
|
|
102
|
+
### External changes
|
|
103
|
+
|
|
104
|
+
* Fix regression in matchers when used with keyword arguments (#654 & #655) - thanks to @ElvinEfendi for reporting
|
|
105
|
+
|
|
106
|
+
### Internal changes
|
|
107
|
+
|
|
108
|
+
* Reduce duplication & consolidate `#to_matcher` method definitions (600ee2aa, e9de64e4, #655)
|
|
109
|
+
* Change `#to_matcher` method to use keyword arguments (3b60b7df, #655)
|
|
110
|
+
|
|
111
|
+
**WARNING: This release includes a regression:**
|
|
112
|
+
* Keyword argument and top-level `Hash` matching became more relaxed than intended, e.g. `mock.expects(:method).with(key: "value")` accepted `mock.method(key: "value", key2: "value")` when it should not have done. See #657 & #675 for the reports and #660 for the fix which was released in v2.4.3.
|
|
113
|
+
|
|
114
|
+
## 2.4.0
|
|
115
|
+
|
|
116
|
+
### External changes
|
|
117
|
+
|
|
118
|
+
* Improve rendering of keyword arguments (#652) - thanks to @casperisfine
|
|
119
|
+
|
|
120
|
+
### Internal changes
|
|
121
|
+
|
|
122
|
+
**WARNING: This release includes a couple of regressions:**
|
|
123
|
+
* Nested parameter matching for keyword arguments became more relaxed than intended, e.g. `mock.expects(:method).with(has_entry(:k1, k2: 'v2'))` accepted `mock.method(k1: { k2: 'v2', k3: 'v3' })` when it should not have done. See #654 for the report and #655 for the fix which was released in v2.4.1.
|
|
124
|
+
* Keyword argument and top-level `Hash` matching became more relaxed than intended, e.g. `mock.expects(:method).with(key: "value")` accepted `mock.method(key: "value", key2: "value")` when it should not have done. See #657 & #675 for the reports and #660 for the fix which was released in v2.4.3.
|
|
125
|
+
|
|
126
|
+
* Improvements to `#mocha_inspect` unit tests (#650)
|
|
127
|
+
|
|
128
|
+
## 2.3.0
|
|
129
|
+
|
|
130
|
+
### External changes
|
|
131
|
+
|
|
132
|
+
* Fix nested parameter matching for keyword arguments (f94e2504, #648) - thanks to @CodingAnarchy for reporting
|
|
133
|
+
|
|
134
|
+
**WARNING: This release inadvertently introduced a couple of regressions:**
|
|
135
|
+
* Nested parameter matching for keyword arguments became more relaxed than intended, e.g. `mock.expects(:method).with(has_entry(:k1, k2: 'v2'))` accepted `mock.method(k1: { k2: 'v2', k3: 'v3' })` when it should not have done. See #654 for the report and #655 for the fix which was released in v2.4.1.
|
|
136
|
+
* Keyword argument and top-level `Hash` matching became more relaxed than intended, e.g. `mock.expects(:method).with(key: "value")` accepted `mock.method(key: "value", key2: "value")` when it should not have done. See #657 & #675 for the reports and #660 for the fix which was released in v2.4.3.
|
|
137
|
+
|
|
138
|
+
## 2.2.0
|
|
139
|
+
|
|
140
|
+
### External changes
|
|
141
|
+
|
|
142
|
+
* Support multiple methods in `responds_with` matcher (f086b7e4, #578) - thanks to @vlad-pisanov for the suggestion
|
|
143
|
+
* Add block syntax for sequences (93fdffd, #61)
|
|
144
|
+
* Improve sequence failure message (0800c6ff, #60)
|
|
145
|
+
* Drop support for Ruby v2.0 (85848fb0, #642)
|
|
146
|
+
* Include the original test name in expired stub error messages (ca3ff8eb, #641, #642) - thanks to @casperisfine
|
|
147
|
+
|
|
148
|
+
* Avoid rubocop directive ending up in YARD docs (2a9ee81a)
|
|
149
|
+
* Update docs to fix those for `Mock#method_missing` (cee0bad6)
|
|
150
|
+
* Reinstate missing CNAME for GitHub Pages site (da67bb0d)
|
|
151
|
+
* Use Ruby v1.9 Hash syntax in docs (6de20726, #625)
|
|
152
|
+
* Add missing YARD tag for API#sequence name param (343c5979)
|
|
153
|
+
* Add missing YARD tag for API#states name param (f798df83)
|
|
154
|
+
|
|
155
|
+
### Internal changes
|
|
156
|
+
|
|
157
|
+
* Tidy up Minitest vs MiniTest references (#626, #614, #615) - thanks to @zenspider & @Maimer for their help
|
|
158
|
+
* Add Ruby v3.3 to CI build matrix (ce31b544)
|
|
159
|
+
|
|
3
160
|
## 2.1.0
|
|
4
161
|
|
|
5
162
|
### External changes
|
|
@@ -249,6 +406,9 @@ from the Ruby v1.8 standard library are no longer supported (#540,969f4845)
|
|
|
249
406
|
* Add documentation for Cucumber integration (13ab797b)
|
|
250
407
|
* Add documentation about an undocumented feature of `API#mock`, `API#stub` & `API#stub_everything` being changed (7ed2e4e7, d30c1717)
|
|
251
408
|
|
|
409
|
+
**WARNING: This release inadvertently changed some undocumented behaviour:**
|
|
410
|
+
* An undocumented feature of `API#mock`, `API#stub` & `API#stub_everything` was changed. Previously when these methods were passed a single symbol, they returned a mock object that responded to the method identified by the symbol. Now Passing a single symbol is equivalent to passing a single string, i.e. it now defines the 'name' of the mock object.
|
|
411
|
+
|
|
252
412
|
## 1.10.0.beta.1
|
|
253
413
|
|
|
254
414
|
* Hide `ClassMethods#method_visibility` & `#method_exists?` methods to avoid clash with Rails (#428)
|
|
@@ -392,6 +552,9 @@ from the Ruby v1.8 standard library are no longer supported (#540,969f4845)
|
|
|
392
552
|
* Fix typo in docs for equals - thanks to @alexcoco (#254)
|
|
393
553
|
* Add known issue for Ruby v1.8 to README - thanks to @chrisroos (2c642096)
|
|
394
554
|
|
|
555
|
+
**WARNING: This release inadvertently introduced the possibility of causing the Ruby interpreter to hang:**
|
|
556
|
+
* There is a scenario where stubbing a class method originally defined in a module hangs the Ruby interpreter due to [a bug in Ruby v2.3.1](https://bugs.ruby-lang.org/issues/12832). See #272. This was fixed in Mocha v1.2.1.
|
|
557
|
+
|
|
395
558
|
## 1.1.0
|
|
396
559
|
|
|
397
560
|
* Set visibility of any instance stub method.
|
|
@@ -400,6 +563,9 @@ from the Ruby v1.8 standard library are no longer supported (#540,969f4845)
|
|
|
400
563
|
* Use GitHub convention for instructions on contributing to Mocha.
|
|
401
564
|
* Fix typos in docs. Thanks to @10io
|
|
402
565
|
|
|
566
|
+
**WARNING: This release inadvertently introduced the possibility of causing the Ruby interpreter to hang:**
|
|
567
|
+
* From this release onwards, prepended modules have been used internally for stubbing methods. There is [an obscure Ruby bug](https://bugs.ruby-lang.org/issues/12876) in many (but not all) versions of Ruby between v2.0 & v2.3 which under certain circumstances may cause your Ruby interpreter to hang. See the Ruby bug report for more details. The bug has been fixed in Ruby v2.3.3 & v2.4.0.
|
|
568
|
+
|
|
403
569
|
## 1.0.0
|
|
404
570
|
|
|
405
571
|
### External changes
|
|
@@ -462,6 +628,9 @@ relevant patch version.
|
|
|
462
628
|
* Adapt Mocha acceptance tests to cope with changes in output from latest (v4.6.2) of MiniTest.
|
|
463
629
|
* Updates to README about Rails compatibility.
|
|
464
630
|
|
|
631
|
+
**NOTE: This release inadvertently caused deprecation warnings in some contexts:**
|
|
632
|
+
* When used with Rails v3.2.0-v3.2.12, v3.1.0-v3.1.10 & v3.0.0-v3.0.19.
|
|
633
|
+
|
|
465
634
|
## 0.13.2
|
|
466
635
|
* Stubbing of methods re-declared with different visibilty. Fixes #109.
|
|
467
636
|
* Add `Mock#responds_like_instance_of`. Fixes #119.
|
|
@@ -471,10 +640,16 @@ relevant patch version.
|
|
|
471
640
|
* Add a Gem Badge to provide a link to Mocha on Rubygems.
|
|
472
641
|
* Make documentation example consistent with other examples.
|
|
473
642
|
|
|
643
|
+
**NOTE: This release inadvertently caused deprecation warnings in some contexts:**
|
|
644
|
+
* When used with Rails v3.2.0-v3.2.12, v3.1.0-v3.1.10 & v3.0.0-v3.0.19.
|
|
645
|
+
|
|
474
646
|
## 0.13.1
|
|
475
647
|
* Fix #97 - `Mocha::ParameterMatchers#has_entry` does not work with an Array as the entry's value. Thanks to @ngokli.
|
|
476
648
|
* Allow deprecation `:debug` mode to be switched on from `MOCHA_OPTIONS` environment variable.
|
|
477
649
|
|
|
650
|
+
**NOTE: This release inadvertently caused deprecation warnings in some contexts:**
|
|
651
|
+
* When used with Rails v3.2.0-v3.2.12, v3.1.0-v3.1.10 & v3.0.0-v3.0.19.
|
|
652
|
+
|
|
478
653
|
## 0.13.0
|
|
479
654
|
* Major overhaul of MiniTest & Test::Unit integration. Mocha now integrates with later versions of the two test libraries using documented hooks rather than monkey-patching. This should mean that Mocha will integrate with new versions of either library without the need to release a new version of Mocha each time, which was clearly bad and unsustainable. Many thanks to @tenderlove, @zenspider & @kou for their help, suggestions & patience.
|
|
480
655
|
* Temporarily deprecated `require 'mocha'`. Use `require 'mocha/setup'` instead. The plan is that eventually `require 'mocha'` will *not* automatically integrate with either of the two test libraries as it does at the moment, and you'll need to explicitly & separately trigger the integration. I think this will provide a lot more flexibility and will hopefully do away with the need for the `require: false` option in the `Gemfile` which has always confused people.
|
|
@@ -487,6 +662,9 @@ relevant patch version.
|
|
|
487
662
|
* Various improvements to automated testing of integration with test libraries.
|
|
488
663
|
* Make deprecation warnings more prominent.
|
|
489
664
|
|
|
665
|
+
**NOTE: This release inadvertently caused deprecation warnings in some contexts:**
|
|
666
|
+
* When used with Rails v3.2.0-v3.2.12, v3.1.0-v3.1.10 & v3.0.0-v3.0.19.
|
|
667
|
+
|
|
490
668
|
## 0.12.7
|
|
491
669
|
* Officially support minitest v4.1.0 (still monkey-patching).
|
|
492
670
|
|
|
@@ -523,15 +701,27 @@ relevant patch version.
|
|
|
523
701
|
## 0.11.4
|
|
524
702
|
* Homepage has moved to http://gofreerange.com/mocha/docs.
|
|
525
703
|
|
|
704
|
+
**WARNING: This release inadvertently included a Rails compatibility issue:**
|
|
705
|
+
* `TypeError: superclass mismatch for class ExpectationError` raised when using Rails v3.2.13. See #115.
|
|
706
|
+
|
|
526
707
|
## 0.11.3
|
|
527
708
|
* Fix for #78 i.e. alias Object#method as Object#_method, not Object#__method__ which already exists as another Ruby method.
|
|
528
709
|
|
|
710
|
+
**WARNING: This release inadvertently included a Rails compatibility issue:**
|
|
711
|
+
* `TypeError: superclass mismatch for class ExpectationError` raised when using Rails v3.2.13. See #115.
|
|
712
|
+
|
|
529
713
|
## 0.11.2
|
|
530
714
|
* Rails has a Request class which defines its own #method method. This broke the new mechanism for stubbing a method. This release includes a slightly modified version of fix #77 provided by @sikachu. See https://github.com/rails/rails/pull/5907 for further info.
|
|
531
715
|
|
|
716
|
+
**WARNING: This release inadvertently included a Rails compatibility issue:**
|
|
717
|
+
* `TypeError: superclass mismatch for class ExpectationError` raised when using Rails v3.2.13. See #115.
|
|
718
|
+
|
|
532
719
|
## 0.11.1
|
|
533
720
|
* In Ruby 1.8.7 methods accepting a block parameter were incorrectly restored without the block parameter after being stubbed. Fix for #76.
|
|
534
721
|
|
|
722
|
+
**WARNING: This release inadvertently included a Rails compatibility issue:**
|
|
723
|
+
* `TypeError: superclass mismatch for class ExpectationError` raised when using Rails v3.2.13. See #115.
|
|
724
|
+
|
|
535
725
|
## 0.11.0
|
|
536
726
|
* Store original method when stubbing rather than using alias_method. This fixes #41, #47, #74 and all tests now pass on both Ruby 1.8.7 and 1.9.3.
|
|
537
727
|
* Attempting to stub a method on a frozen object should fail fast. See #68.
|
|
@@ -544,6 +734,11 @@ relevant patch version.
|
|
|
544
734
|
* Improve documentation for ObjectMethods.
|
|
545
735
|
* Provide a way to run multiple tests within a single acceptance test method.
|
|
546
736
|
|
|
737
|
+
**WARNING: This release inadvertently included a significant bug - please do not use it!**
|
|
738
|
+
|
|
739
|
+
**WARNING: This release inadvertently introduced a Rails compatibility issue:**
|
|
740
|
+
* `TypeError: superclass mismatch for class ExpectationError` raised when using Rails v3.2.13. See #115.
|
|
741
|
+
|
|
547
742
|
## 0.10.5
|
|
548
743
|
* Fix for issue #66 (hopefully without regressing on issue #63) - Mocha::Mock has Mocha::Mockery as a dependency. Stop trying to pretend otherwise. Thanks to @kennyj for reporting.
|
|
549
744
|
* Fix a bunch of warnings in Ruby 1.9. There are still the 6 test failures mentioned in issue #41 which I suspect are due to the introspection gem not being Ruby 1.9-compatible.
|
|
@@ -562,9 +757,13 @@ Hash with wrong number of entries.
|
|
|
562
757
|
## 0.10.3
|
|
563
758
|
* Fix for issue #57. Gem::Requirement#=~ was only added in rubygems v1.8.0, but Object#=~ means the result of various monkey-patching checks is always false/nil for earlier versions of rubygems. However, the method it aliases #satisfied_by? has existed since Gem::Dependency was extracted from Gem::Version in rubygems v0.9.4.4, so it's much safer to use that. Thanks to fguillen for reporting and helping with diagnosis.
|
|
564
759
|
|
|
760
|
+
**WARNING: This release inadvertently included a significant bug - please do not use it!**
|
|
761
|
+
|
|
565
762
|
## 0.10.2
|
|
566
763
|
* Merge pull request #53. Unstubbing a method should not remove expectations for other stubbed methods. Fixes #52. Thanks to saikat.
|
|
567
764
|
|
|
765
|
+
**WARNING: This release inadvertently included a significant bug - please do not use it!**
|
|
766
|
+
|
|
568
767
|
## 0.10.1
|
|
569
768
|
* Merge pull request #51. Use Gem::Requirement & Gem::Version for version comparison. Fixes issue #50. Thanks to meineerde.
|
|
570
769
|
* Fixed typo in rdoc for Mocha::ObjectMethods.
|
data/Rakefile
CHANGED
|
@@ -42,10 +42,10 @@ namespace 'test' do # rubocop:disable Metrics/BlockLength
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
namespace 'integration' do
|
|
45
|
-
desc 'Run
|
|
45
|
+
desc 'Run Minitest integration tests (intended to be run in its own process)'
|
|
46
46
|
Rake::TestTask.new('minitest') do |t|
|
|
47
47
|
t.libs << 'test'
|
|
48
|
-
t.test_files = FileList['test/integration/
|
|
48
|
+
t.test_files = FileList['test/integration/minitest_test.rb']
|
|
49
49
|
t.verbose = true
|
|
50
50
|
t.warning = true
|
|
51
51
|
end
|
|
@@ -93,18 +93,18 @@ end
|
|
|
93
93
|
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
94
94
|
def benchmark_test_case(klass, iterations)
|
|
95
95
|
require 'benchmark'
|
|
96
|
-
require 'mocha/detection/
|
|
96
|
+
require 'mocha/detection/minitest'
|
|
97
97
|
|
|
98
|
-
if defined?(
|
|
99
|
-
minitest_version = Gem::Version.new(Mocha::Detection::
|
|
98
|
+
if defined?(Minitest)
|
|
99
|
+
minitest_version = Gem::Version.new(Mocha::Detection::Minitest.version)
|
|
100
100
|
if Gem::Requirement.new('>= 5.0.0').satisfied_by?(minitest_version)
|
|
101
101
|
Minitest.seed = 1
|
|
102
|
-
result = Benchmark.realtime { iterations.times { |_i| klass.run(
|
|
103
|
-
|
|
102
|
+
result = Benchmark.realtime { iterations.times { |_i| klass.run(Minitest::CompositeReporter.new) } }
|
|
103
|
+
Minitest::Runnable.runnables.delete(klass)
|
|
104
104
|
result
|
|
105
105
|
else
|
|
106
|
-
|
|
107
|
-
Benchmark.realtime { iterations.times { |_i|
|
|
106
|
+
Minitest::Unit.output = StringIO.new
|
|
107
|
+
Benchmark.realtime { iterations.times { |_i| Minitest::Unit.new.run([klass]) } }
|
|
108
108
|
end
|
|
109
109
|
else
|
|
110
110
|
load 'test/unit/ui/console/testrunner.rb' unless defined?(Test::Unit::UI::Console::TestRunner)
|
data/lib/mocha/api.rb
CHANGED
|
@@ -7,7 +7,7 @@ require 'mocha/object_methods'
|
|
|
7
7
|
require 'mocha/class_methods'
|
|
8
8
|
|
|
9
9
|
module Mocha
|
|
10
|
-
# Methods added to +Test::Unit::TestCase+, +
|
|
10
|
+
# Methods added to +Test::Unit::TestCase+, +Minitest::Unit::TestCase+ or equivalent.
|
|
11
11
|
# The mock creation methods are {#mock}, {#stub} and {#stub_everything}, all of which return a #{Mock}
|
|
12
12
|
# which can be further modified by {Mock#responds_like} and {Mock#responds_like_instance_of} methods,
|
|
13
13
|
# both of which return a {Mock}, too, and can therefore, be chained to the original creation methods.
|
|
@@ -60,7 +60,7 @@ module Mocha
|
|
|
60
60
|
#
|
|
61
61
|
# @example Using expected_methods_vs_return_values Hash to setup expectations.
|
|
62
62
|
# def test_motor_starts_and_stops
|
|
63
|
-
# motor = mock('motor', :
|
|
63
|
+
# motor = mock('motor', start: true, stop: true)
|
|
64
64
|
# assert motor.start
|
|
65
65
|
# assert motor.stop
|
|
66
66
|
# # an error will be raised unless both Motor#start and Motor#stop have been called
|
|
@@ -88,7 +88,7 @@ module Mocha
|
|
|
88
88
|
#
|
|
89
89
|
# @example Using stubbed_methods_vs_return_values Hash to setup stubbed methods.
|
|
90
90
|
# def test_motor_starts_and_stops
|
|
91
|
-
# motor = stub('motor', :
|
|
91
|
+
# motor = stub('motor', start: true, stop: true)
|
|
92
92
|
# assert motor.start
|
|
93
93
|
# assert motor.stop
|
|
94
94
|
# # an error will not be raised even if either Motor#start or Motor#stop has not been called
|
|
@@ -115,7 +115,7 @@ module Mocha
|
|
|
115
115
|
#
|
|
116
116
|
# @example Ignore invocations of irrelevant methods.
|
|
117
117
|
# def test_motor_stops
|
|
118
|
-
# motor = stub_everything('motor', :
|
|
118
|
+
# motor = stub_everything('motor', stop: true)
|
|
119
119
|
# assert_nil motor.irrelevant_method_1 # => no error raised
|
|
120
120
|
# assert_nil motor.irrelevant_method_2 # => no error raised
|
|
121
121
|
# assert motor.stop
|
|
@@ -131,8 +131,11 @@ module Mocha
|
|
|
131
131
|
|
|
132
132
|
# Builds a new sequence which can be used to constrain the order in which expectations can occur.
|
|
133
133
|
#
|
|
134
|
-
# Specify that an expected invocation must occur within a named {Sequence} by
|
|
134
|
+
# Specify that an expected invocation must occur within a named {Sequence} by calling {Expectation#in_sequence}
|
|
135
|
+
# on each expectation or by passing a block within which all expectations should be constrained by the {Sequence}.
|
|
135
136
|
#
|
|
137
|
+
# @param [String] name name of sequence
|
|
138
|
+
# @yield optional block within which expectations should be constrained by the sequence
|
|
136
139
|
# @return [Sequence] a new sequence
|
|
137
140
|
#
|
|
138
141
|
# @see Expectation#in_sequence
|
|
@@ -156,8 +159,23 @@ module Mocha
|
|
|
156
159
|
#
|
|
157
160
|
# task_one.execute
|
|
158
161
|
# task_two.execute
|
|
162
|
+
#
|
|
163
|
+
# @example Ensure methods on egg are invoked in the correct order using a block.
|
|
164
|
+
# egg = mock('egg')
|
|
165
|
+
# sequence('breakfast') do
|
|
166
|
+
# egg.expects(:crack)
|
|
167
|
+
# egg.expects(:fry)
|
|
168
|
+
# egg.expects(:eat)
|
|
169
|
+
# end
|
|
159
170
|
def sequence(name)
|
|
160
|
-
Sequence.new(name)
|
|
171
|
+
Sequence.new(name).tap do |seq|
|
|
172
|
+
Mockery.instance.sequences.push(seq)
|
|
173
|
+
begin
|
|
174
|
+
yield if block_given?
|
|
175
|
+
ensure
|
|
176
|
+
Mockery.instance.sequences.pop
|
|
177
|
+
end
|
|
178
|
+
end
|
|
161
179
|
end
|
|
162
180
|
|
|
163
181
|
# Builds a new state machine which can be used to constrain the order in which expectations can occur.
|
|
@@ -170,6 +188,7 @@ module Mocha
|
|
|
170
188
|
#
|
|
171
189
|
# A test can contain multiple state machines.
|
|
172
190
|
#
|
|
191
|
+
# @param [String] name name of state machine
|
|
173
192
|
# @return [StateMachine] a new state machine
|
|
174
193
|
#
|
|
175
194
|
# @see Expectation#then
|
data/lib/mocha/cardinality.rb
CHANGED
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
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
module Mocha
|
|
2
2
|
module Detection
|
|
3
|
-
module
|
|
3
|
+
module Minitest
|
|
4
4
|
def self.testcase
|
|
5
5
|
if defined?(::Minitest::Test)
|
|
6
6
|
::Minitest::Test
|
|
7
|
-
elsif defined?(::
|
|
8
|
-
::
|
|
7
|
+
elsif defined?(::Minitest::Unit::TestCase)
|
|
8
|
+
::Minitest::Unit::TestCase
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def self.version
|
|
13
|
-
if defined?(::
|
|
14
|
-
::
|
|
13
|
+
if defined?(::Minitest::Unit::VERSION)
|
|
14
|
+
::Minitest::Unit::VERSION
|
|
15
15
|
elsif defined?(::Minitest::VERSION)
|
|
16
16
|
::Minitest::VERSION
|
|
17
17
|
else
|
|
@@ -3,8 +3,8 @@ module Mocha
|
|
|
3
3
|
module TestUnit
|
|
4
4
|
def self.testcase
|
|
5
5
|
if defined?(::Test::Unit::TestCase) &&
|
|
6
|
-
!(defined?(::
|
|
7
|
-
!(defined?(::
|
|
6
|
+
!(defined?(::Minitest::Unit::TestCase) && (::Test::Unit::TestCase < ::Minitest::Unit::TestCase)) &&
|
|
7
|
+
!(defined?(::Minitest::Spec) && (::Test::Unit::TestCase < ::Minitest::Spec))
|
|
8
8
|
::Test::Unit::TestCase
|
|
9
9
|
end
|
|
10
10
|
end
|