mocha 2.1.0 → 2.7.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 +4 -4
- data/.rubocop.yml +6 -1
- data/.yardopts +1 -1
- data/Gemfile +6 -1
- data/README.md +12 -18
- data/RELEASE.md +191 -0
- data/Rakefile +9 -9
- data/lib/mocha/api.rb +25 -6
- data/lib/mocha/cardinality.rb +4 -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 +13 -2
- 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 +1 -1
- 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: 36441d2fc56cc4d162b3f1e790c6add3c70eebac844ec6e6b275ef1b6e5f268c
|
|
4
|
+
data.tar.gz: b63504e88684874b3609b91096bcd90d18f31639b3d32ba95e36f48e8fc67ecf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 43c0128284d592878e833404f53f95a3c64bfeca18c85f7f94313b475566f98dc0993ed2b41a9d5118c1b4aabbb99e8848510d7aa3b4afa55804d67c0dd25658
|
|
7
|
+
data.tar.gz: d9b9785fbf25b80552a7f25e649a5e3ce08ef628c82a1dd36bccf260867156a4ac2c6cf1726e720c6ed8d836a8a1aa0e2441e29e869e65c244ac0c51f93c9423
|
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,7 +4,7 @@
|
|
|
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
|
|
@@ -18,7 +18,7 @@ Install the latest version of the gem with the following command...
|
|
|
18
18
|
|
|
19
19
|
$ gem install mocha
|
|
20
20
|
|
|
21
|
-
Note: If you are intending to use Mocha with Test::Unit or
|
|
21
|
+
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
22
|
|
|
23
23
|
##### Test::Unit
|
|
24
24
|
|
|
@@ -29,12 +29,12 @@ require 'test/unit'
|
|
|
29
29
|
require 'mocha/test_unit'
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
#####
|
|
32
|
+
##### Minitest
|
|
33
33
|
|
|
34
34
|
```ruby
|
|
35
35
|
require 'rubygems'
|
|
36
36
|
gem 'mocha'
|
|
37
|
-
require 'minitest/
|
|
37
|
+
require 'minitest/autorun'
|
|
38
38
|
require 'mocha/minitest'
|
|
39
39
|
```
|
|
40
40
|
|
|
@@ -53,14 +53,14 @@ require 'test/unit'
|
|
|
53
53
|
require 'mocha/test_unit'
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
#####
|
|
56
|
+
##### Minitest
|
|
57
57
|
|
|
58
58
|
```ruby
|
|
59
59
|
# Gemfile
|
|
60
60
|
gem 'mocha'
|
|
61
61
|
|
|
62
62
|
# Elsewhere after Bundler has loaded gems e.g. after `require 'bundler/setup'`
|
|
63
|
-
require 'minitest/
|
|
63
|
+
require 'minitest/autorun'
|
|
64
64
|
require 'mocha/minitest'
|
|
65
65
|
```
|
|
66
66
|
|
|
@@ -103,9 +103,9 @@ end
|
|
|
103
103
|
|
|
104
104
|
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
105
|
|
|
106
|
-
#####
|
|
106
|
+
##### Minitest
|
|
107
107
|
|
|
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
|
|
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 Minitest.
|
|
109
109
|
|
|
110
110
|
```ruby
|
|
111
111
|
# Gemfile in Rails app
|
|
@@ -121,13 +121,7 @@ Follow the instructions for the relevant test framework in the [Bundler](#bundle
|
|
|
121
121
|
|
|
122
122
|
#### Known Issues
|
|
123
123
|
|
|
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.
|
|
124
|
+
* 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
125
|
|
|
132
126
|
### Usage
|
|
133
127
|
|
|
@@ -151,7 +145,7 @@ class MiscExampleTest < Test::Unit::TestCase
|
|
|
151
145
|
end
|
|
152
146
|
|
|
153
147
|
def test_stubbing_instance_methods_on_real_objects
|
|
154
|
-
prices = [stub(:
|
|
148
|
+
prices = [stub(pence: 1000), stub(pence: 2000)]
|
|
155
149
|
product = Product.new
|
|
156
150
|
product.stubs(:prices).returns(prices)
|
|
157
151
|
assert_equal [1000, 2000], product.prices.collect {|p| p.pence}
|
|
@@ -170,7 +164,7 @@ class MiscExampleTest < Test::Unit::TestCase
|
|
|
170
164
|
end
|
|
171
165
|
|
|
172
166
|
def test_shortcuts
|
|
173
|
-
object = stub(:
|
|
167
|
+
object = stub(method1: :result1, method2: :result2)
|
|
174
168
|
assert_equal :result1, object.method1
|
|
175
169
|
assert_equal :result2, object.method2
|
|
176
170
|
end
|
|
@@ -282,7 +276,7 @@ Maybe, but probably not. Partial mocking changes the state of objects in the `Ob
|
|
|
282
276
|
|
|
283
277
|
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
278
|
|
|
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.
|
|
279
|
+
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
280
|
|
|
287
281
|
See the [documentation](https://mocha.jamesmead.org/Mocha/Mock.html) for `Mocha::Mock` for further details.
|
|
288
282
|
|
data/RELEASE.md
CHANGED
|
@@ -1,5 +1,154 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
+
## 2.7.0
|
|
4
|
+
|
|
5
|
+
### External changes
|
|
6
|
+
|
|
7
|
+
* Fail fast if invocation matches never expectation (#679, #678, #490, #131 & #44) - thanks to @ducmtran & @davidstosik for reporting
|
|
8
|
+
|
|
9
|
+
### Internal changes
|
|
10
|
+
|
|
11
|
+
* Workaround for JRuby jar-dependencies issue (#690)
|
|
12
|
+
* Ruby v3.4 stacktrace uses single-quote vs backtick (#688 & #689) - thanks to Vít Ondruch
|
|
13
|
+
|
|
14
|
+
**WARNING: This release fixes a very _old_ bug**
|
|
15
|
+
* The bug relates to the use of `Expectation#never` in combination with other expectations on the same method.
|
|
16
|
+
* Please ensure you fix the relevant deprecation warnings when running against v2.6.1 *before* upgrading to v2.7.0.
|
|
17
|
+
* Previously, the following test would have passed, but now it will fail with an unexpected invocation error on the `foo.bar` line.
|
|
18
|
+
|
|
19
|
+
foo = mock('foo')
|
|
20
|
+
foo.stubs(:bar)
|
|
21
|
+
foo.expects(:bar).never
|
|
22
|
+
foo.bar
|
|
23
|
+
|
|
24
|
+
## 2.6.1
|
|
25
|
+
|
|
26
|
+
### External changes
|
|
27
|
+
|
|
28
|
+
* Fix logic for displaying deprecation warning for expectation with never cardinality (#686) - thanks to @davidstosik for reporting
|
|
29
|
+
|
|
30
|
+
## 2.6.0
|
|
31
|
+
|
|
32
|
+
### External changes
|
|
33
|
+
|
|
34
|
+
* Expectation with never cardinality should display deprecation warning (#681) - thanks to @ducmtran for reporting and testing
|
|
35
|
+
|
|
36
|
+
**WARNING: This release results in some incorrect deprecation warnings:**
|
|
37
|
+
* The logic for displaying the deprecation warnings is fixed in v2.6.1 (#686).
|
|
38
|
+
|
|
39
|
+
### Internal changes
|
|
40
|
+
|
|
41
|
+
* Simplify backtrace related assertions (#680)
|
|
42
|
+
* Remove unused `ExpectationList#match_but_out_of_order` (f2fa9919)
|
|
43
|
+
|
|
44
|
+
## 2.5.0
|
|
45
|
+
|
|
46
|
+
### External changes
|
|
47
|
+
|
|
48
|
+
* Add metadata to gem specification, including `changelog_uri` (#608, eb1b8ea2) - thanks to @mattbrictson
|
|
49
|
+
* Fix warnings in Ruby v3.4 (#672, #669) - thanks to @radville for reporting
|
|
50
|
+
* Add warnings & notes about regressions, known issues, etc to release notes (#675, #676 & #677) - thanks to @davidstosik
|
|
51
|
+
|
|
52
|
+
### Internal changes
|
|
53
|
+
|
|
54
|
+
* Fix `jaro_winkler` compilation errors on MacOS (5c7d14cb)
|
|
55
|
+
* Fix typos in `IncludesTest` test names (6fb5a5a6)
|
|
56
|
+
* Fix `rubocop` version constraint for Ruby > v2.2.0 (d5c6b98a)
|
|
57
|
+
|
|
58
|
+
## 2.4.5
|
|
59
|
+
|
|
60
|
+
### External changes
|
|
61
|
+
|
|
62
|
+
* Fix regression when stubbed method expects `Hash` but receives `ActionController::Parameters` object (#662, #664) - thanks to @evgeni for reporting and testing
|
|
63
|
+
|
|
64
|
+
## 2.4.4
|
|
65
|
+
|
|
66
|
+
### External changes
|
|
67
|
+
|
|
68
|
+
* Fix regression when method expecting `Hash` parameter or keyword arguments is invoked with no arguments (#662, #663) - thanks to @vlad-pisanov for reporting
|
|
69
|
+
|
|
70
|
+
**WARNING: This release includes a regression:**
|
|
71
|
+
* 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.
|
|
72
|
+
|
|
73
|
+
## 2.4.3
|
|
74
|
+
|
|
75
|
+
### External changes
|
|
76
|
+
|
|
77
|
+
* Fix regression when matching `Hash` parameter or keyword arguments (#657, #660) - thanks to @josesei for reporting and testing
|
|
78
|
+
|
|
79
|
+
**WARNING: This release inadvertently introduced a couple of regressions:**
|
|
80
|
+
* 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.
|
|
81
|
+
* 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.
|
|
82
|
+
|
|
83
|
+
## 2.4.2
|
|
84
|
+
|
|
85
|
+
### External changes
|
|
86
|
+
|
|
87
|
+
* Don't trust `Object#is_a?` in presence of mock objects (#656) - thanks to @casperisfine
|
|
88
|
+
|
|
89
|
+
**WARNING: This release includes a regression:**
|
|
90
|
+
* 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.
|
|
91
|
+
|
|
92
|
+
## 2.4.1
|
|
93
|
+
|
|
94
|
+
### External changes
|
|
95
|
+
|
|
96
|
+
* Fix regression in matchers when used with keyword arguments (#654 & #655) - thanks to @ElvinEfendi for reporting
|
|
97
|
+
|
|
98
|
+
### Internal changes
|
|
99
|
+
|
|
100
|
+
* Reduce duplication & consolidate `#to_matcher` method definitions (600ee2aa, e9de64e4, #655)
|
|
101
|
+
* Change `#to_matcher` method to use keyword arguments (3b60b7df, #655)
|
|
102
|
+
|
|
103
|
+
**WARNING: This release includes a regression:**
|
|
104
|
+
* 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.
|
|
105
|
+
|
|
106
|
+
## 2.4.0
|
|
107
|
+
|
|
108
|
+
### External changes
|
|
109
|
+
|
|
110
|
+
* Improve rendering of keyword arguments (#652) - thanks to @casperisfine
|
|
111
|
+
|
|
112
|
+
### Internal changes
|
|
113
|
+
|
|
114
|
+
**WARNING: This release includes a couple of regressions:**
|
|
115
|
+
* 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.
|
|
116
|
+
* 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.
|
|
117
|
+
|
|
118
|
+
* Improvements to `#mocha_inspect` unit tests (#650)
|
|
119
|
+
|
|
120
|
+
## 2.3.0
|
|
121
|
+
|
|
122
|
+
### External changes
|
|
123
|
+
|
|
124
|
+
* Fix nested parameter matching for keyword arguments (f94e2504, #648) - thanks to @CodingAnarchy for reporting
|
|
125
|
+
|
|
126
|
+
**WARNING: This release inadvertently introduced a couple of regressions:**
|
|
127
|
+
* 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.
|
|
128
|
+
* 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.
|
|
129
|
+
|
|
130
|
+
## 2.2.0
|
|
131
|
+
|
|
132
|
+
### External changes
|
|
133
|
+
|
|
134
|
+
* Support multiple methods in `responds_with` matcher (f086b7e4, #578) - thanks to @vlad-pisanov for the suggestion
|
|
135
|
+
* Add block syntax for sequences (93fdffd, #61)
|
|
136
|
+
* Improve sequence failure message (0800c6ff, #60)
|
|
137
|
+
* Drop support for Ruby v2.0 (85848fb0, #642)
|
|
138
|
+
* Include the original test name in expired stub error messages (ca3ff8eb, #641, #642) - thanks to @casperisfine
|
|
139
|
+
|
|
140
|
+
* Avoid rubocop directive ending up in YARD docs (2a9ee81a)
|
|
141
|
+
* Update docs to fix those for `Mock#method_missing` (cee0bad6)
|
|
142
|
+
* Reinstate missing CNAME for GitHub Pages site (da67bb0d)
|
|
143
|
+
* Use Ruby v1.9 Hash syntax in docs (6de20726, #625)
|
|
144
|
+
* Add missing YARD tag for API#sequence name param (343c5979)
|
|
145
|
+
* Add missing YARD tag for API#states name param (f798df83)
|
|
146
|
+
|
|
147
|
+
### Internal changes
|
|
148
|
+
|
|
149
|
+
* Tidy up Minitest vs MiniTest references (#626, #614, #615) - thanks to @zenspider & @Maimer for their help
|
|
150
|
+
* Add Ruby v3.3 to CI build matrix (ce31b544)
|
|
151
|
+
|
|
3
152
|
## 2.1.0
|
|
4
153
|
|
|
5
154
|
### External changes
|
|
@@ -249,6 +398,9 @@ from the Ruby v1.8 standard library are no longer supported (#540,969f4845)
|
|
|
249
398
|
* Add documentation for Cucumber integration (13ab797b)
|
|
250
399
|
* Add documentation about an undocumented feature of `API#mock`, `API#stub` & `API#stub_everything` being changed (7ed2e4e7, d30c1717)
|
|
251
400
|
|
|
401
|
+
**WARNING: This release inadvertently changed some undocumented behaviour:**
|
|
402
|
+
* 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.
|
|
403
|
+
|
|
252
404
|
## 1.10.0.beta.1
|
|
253
405
|
|
|
254
406
|
* Hide `ClassMethods#method_visibility` & `#method_exists?` methods to avoid clash with Rails (#428)
|
|
@@ -392,6 +544,9 @@ from the Ruby v1.8 standard library are no longer supported (#540,969f4845)
|
|
|
392
544
|
* Fix typo in docs for equals - thanks to @alexcoco (#254)
|
|
393
545
|
* Add known issue for Ruby v1.8 to README - thanks to @chrisroos (2c642096)
|
|
394
546
|
|
|
547
|
+
**WARNING: This release inadvertently introduced the possibility of causing the Ruby interpreter to hang:**
|
|
548
|
+
* 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.
|
|
549
|
+
|
|
395
550
|
## 1.1.0
|
|
396
551
|
|
|
397
552
|
* Set visibility of any instance stub method.
|
|
@@ -400,6 +555,9 @@ from the Ruby v1.8 standard library are no longer supported (#540,969f4845)
|
|
|
400
555
|
* Use GitHub convention for instructions on contributing to Mocha.
|
|
401
556
|
* Fix typos in docs. Thanks to @10io
|
|
402
557
|
|
|
558
|
+
**WARNING: This release inadvertently introduced the possibility of causing the Ruby interpreter to hang:**
|
|
559
|
+
* 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.
|
|
560
|
+
|
|
403
561
|
## 1.0.0
|
|
404
562
|
|
|
405
563
|
### External changes
|
|
@@ -462,6 +620,9 @@ relevant patch version.
|
|
|
462
620
|
* Adapt Mocha acceptance tests to cope with changes in output from latest (v4.6.2) of MiniTest.
|
|
463
621
|
* Updates to README about Rails compatibility.
|
|
464
622
|
|
|
623
|
+
**NOTE: This release inadvertently caused deprecation warnings in some contexts:**
|
|
624
|
+
* When used with Rails v3.2.0-v3.2.12, v3.1.0-v3.1.10 & v3.0.0-v3.0.19.
|
|
625
|
+
|
|
465
626
|
## 0.13.2
|
|
466
627
|
* Stubbing of methods re-declared with different visibilty. Fixes #109.
|
|
467
628
|
* Add `Mock#responds_like_instance_of`. Fixes #119.
|
|
@@ -471,10 +632,16 @@ relevant patch version.
|
|
|
471
632
|
* Add a Gem Badge to provide a link to Mocha on Rubygems.
|
|
472
633
|
* Make documentation example consistent with other examples.
|
|
473
634
|
|
|
635
|
+
**NOTE: This release inadvertently caused deprecation warnings in some contexts:**
|
|
636
|
+
* When used with Rails v3.2.0-v3.2.12, v3.1.0-v3.1.10 & v3.0.0-v3.0.19.
|
|
637
|
+
|
|
474
638
|
## 0.13.1
|
|
475
639
|
* Fix #97 - `Mocha::ParameterMatchers#has_entry` does not work with an Array as the entry's value. Thanks to @ngokli.
|
|
476
640
|
* Allow deprecation `:debug` mode to be switched on from `MOCHA_OPTIONS` environment variable.
|
|
477
641
|
|
|
642
|
+
**NOTE: This release inadvertently caused deprecation warnings in some contexts:**
|
|
643
|
+
* When used with Rails v3.2.0-v3.2.12, v3.1.0-v3.1.10 & v3.0.0-v3.0.19.
|
|
644
|
+
|
|
478
645
|
## 0.13.0
|
|
479
646
|
* 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
647
|
* 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 +654,9 @@ relevant patch version.
|
|
|
487
654
|
* Various improvements to automated testing of integration with test libraries.
|
|
488
655
|
* Make deprecation warnings more prominent.
|
|
489
656
|
|
|
657
|
+
**NOTE: This release inadvertently caused deprecation warnings in some contexts:**
|
|
658
|
+
* When used with Rails v3.2.0-v3.2.12, v3.1.0-v3.1.10 & v3.0.0-v3.0.19.
|
|
659
|
+
|
|
490
660
|
## 0.12.7
|
|
491
661
|
* Officially support minitest v4.1.0 (still monkey-patching).
|
|
492
662
|
|
|
@@ -523,15 +693,27 @@ relevant patch version.
|
|
|
523
693
|
## 0.11.4
|
|
524
694
|
* Homepage has moved to http://gofreerange.com/mocha/docs.
|
|
525
695
|
|
|
696
|
+
**WARNING: This release inadvertently included a Rails compatibility issue:**
|
|
697
|
+
* `TypeError: superclass mismatch for class ExpectationError` raised when using Rails v3.2.13. See #115.
|
|
698
|
+
|
|
526
699
|
## 0.11.3
|
|
527
700
|
* Fix for #78 i.e. alias Object#method as Object#_method, not Object#__method__ which already exists as another Ruby method.
|
|
528
701
|
|
|
702
|
+
**WARNING: This release inadvertently included a Rails compatibility issue:**
|
|
703
|
+
* `TypeError: superclass mismatch for class ExpectationError` raised when using Rails v3.2.13. See #115.
|
|
704
|
+
|
|
529
705
|
## 0.11.2
|
|
530
706
|
* 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
707
|
|
|
708
|
+
**WARNING: This release inadvertently included a Rails compatibility issue:**
|
|
709
|
+
* `TypeError: superclass mismatch for class ExpectationError` raised when using Rails v3.2.13. See #115.
|
|
710
|
+
|
|
532
711
|
## 0.11.1
|
|
533
712
|
* In Ruby 1.8.7 methods accepting a block parameter were incorrectly restored without the block parameter after being stubbed. Fix for #76.
|
|
534
713
|
|
|
714
|
+
**WARNING: This release inadvertently included a Rails compatibility issue:**
|
|
715
|
+
* `TypeError: superclass mismatch for class ExpectationError` raised when using Rails v3.2.13. See #115.
|
|
716
|
+
|
|
535
717
|
## 0.11.0
|
|
536
718
|
* 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
719
|
* Attempting to stub a method on a frozen object should fail fast. See #68.
|
|
@@ -544,6 +726,11 @@ relevant patch version.
|
|
|
544
726
|
* Improve documentation for ObjectMethods.
|
|
545
727
|
* Provide a way to run multiple tests within a single acceptance test method.
|
|
546
728
|
|
|
729
|
+
**WARNING: This release inadvertently included a significant bug - please do not use it!**
|
|
730
|
+
|
|
731
|
+
**WARNING: This release inadvertently introduced a Rails compatibility issue:**
|
|
732
|
+
* `TypeError: superclass mismatch for class ExpectationError` raised when using Rails v3.2.13. See #115.
|
|
733
|
+
|
|
547
734
|
## 0.10.5
|
|
548
735
|
* 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
736
|
* 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 +749,13 @@ Hash with wrong number of entries.
|
|
|
562
749
|
## 0.10.3
|
|
563
750
|
* 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
751
|
|
|
752
|
+
**WARNING: This release inadvertently included a significant bug - please do not use it!**
|
|
753
|
+
|
|
565
754
|
## 0.10.2
|
|
566
755
|
* Merge pull request #53. Unstubbing a method should not remove expectations for other stubbed methods. Fixes #52. Thanks to saikat.
|
|
567
756
|
|
|
757
|
+
**WARNING: This release inadvertently included a significant bug - please do not use it!**
|
|
758
|
+
|
|
568
759
|
## 0.10.1
|
|
569
760
|
* Merge pull request #51. Use Gem::Requirement & Gem::Version for version comparison. Fixes issue #50. Thanks to meineerde.
|
|
570
761
|
* 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
|
@@ -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
|
data/lib/mocha/expectation.rb
CHANGED
|
@@ -632,14 +632,20 @@ module Mocha
|
|
|
632
632
|
@ordering_constraints.all?(&:allows_invocation_now?)
|
|
633
633
|
end
|
|
634
634
|
|
|
635
|
+
# @private
|
|
636
|
+
def ordering_constraints_not_allowing_invocation_now
|
|
637
|
+
@ordering_constraints.reject(&:allows_invocation_now?)
|
|
638
|
+
end
|
|
639
|
+
|
|
635
640
|
# @private
|
|
636
641
|
def matches_method?(method_name)
|
|
637
642
|
@method_matcher.match?(method_name)
|
|
638
643
|
end
|
|
639
644
|
|
|
640
645
|
# @private
|
|
641
|
-
def match?(invocation)
|
|
642
|
-
@method_matcher.match?(invocation.method_name) && @parameters_matcher.match?(invocation.arguments) && @block_matcher.match?(invocation.block)
|
|
646
|
+
def match?(invocation, ignoring_order: false)
|
|
647
|
+
order_independent_match = @method_matcher.match?(invocation.method_name) && @parameters_matcher.match?(invocation.arguments) && @block_matcher.match?(invocation.block)
|
|
648
|
+
ignoring_order ? order_independent_match : order_independent_match && in_correct_order?
|
|
643
649
|
end
|
|
644
650
|
|
|
645
651
|
# @private
|
|
@@ -647,6 +653,11 @@ module Mocha
|
|
|
647
653
|
@cardinality.invocations_allowed?
|
|
648
654
|
end
|
|
649
655
|
|
|
656
|
+
# @private
|
|
657
|
+
def invocations_never_allowed?
|
|
658
|
+
@cardinality.invocations_never_allowed?
|
|
659
|
+
end
|
|
660
|
+
|
|
650
661
|
# @private
|
|
651
662
|
def satisfied?
|
|
652
663
|
@cardinality.satisfied?
|
|
@@ -6,9 +6,9 @@ module Mocha
|
|
|
6
6
|
#
|
|
7
7
|
# This class should only be used by authors of test libraries and not by typical "users" of Mocha.
|
|
8
8
|
#
|
|
9
|
-
# For example, it is used by +Mocha::Integration::
|
|
9
|
+
# For example, it is used by +Mocha::Integration::Minitest::Adapter+ in order to have Mocha raise a +Minitest::Assertion+ which can then be sensibly handled by +Minitest::Unit::TestCase+.
|
|
10
10
|
#
|
|
11
|
-
# @see Mocha::Integration::
|
|
11
|
+
# @see Mocha::Integration::Minitest::Adapter
|
|
12
12
|
class ExpectationErrorFactory
|
|
13
13
|
class << self
|
|
14
14
|
# @!attribute exception_class
|