rspec-mocks 2.99.4 → 3.0.0.beta1
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 +14 -6
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +1 -0
- data/Changelog.md +89 -105
- data/License.txt +1 -0
- data/README.md +77 -57
- data/features/argument_matchers/explicit.feature +5 -5
- data/features/argument_matchers/general_matchers.feature +10 -10
- data/features/argument_matchers/type_matchers.feature +3 -3
- data/features/message_expectations/allow_any_instance_of.feature +1 -1
- data/features/message_expectations/any_instance.feature +27 -5
- data/features/message_expectations/call_original.feature +2 -2
- data/features/message_expectations/expect_message_using_expect.feature +2 -2
- data/features/message_expectations/expect_message_using_should_receive.feature +2 -2
- data/features/message_expectations/receive_counts.feature +7 -7
- data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +3 -3
- data/features/method_stubs/README.md +3 -0
- data/features/method_stubs/any_instance.feature +11 -11
- data/features/method_stubs/as_null_object.feature +4 -4
- data/features/method_stubs/simple_return_value_with_stub.feature +7 -7
- data/features/method_stubs/stub_chain.feature +3 -3
- data/features/method_stubs/stub_implementation.feature +2 -2
- data/features/method_stubs/to_ary.feature +2 -2
- data/features/mutating_constants/hiding_defined_constant.feature +2 -2
- data/features/mutating_constants/stub_defined_constant.feature +5 -5
- data/features/mutating_constants/stub_undefined_constant.feature +6 -6
- data/features/outside_rspec/configuration.feature +0 -2
- data/features/outside_rspec/standalone.feature +1 -1
- data/features/spies/spy_partial_mock_method.feature +2 -2
- data/features/spies/spy_pure_mock_method.feature +5 -5
- data/features/spies/spy_unstubbed_method.feature +1 -1
- data/features/support/env.rb +10 -1
- data/features/test_frameworks/test_unit.feature +1 -1
- data/features/verifying_doubles/class_doubles.feature +88 -0
- data/features/verifying_doubles/dynamic_classes.feature +72 -0
- data/features/verifying_doubles/introduction.feature +85 -0
- data/features/verifying_doubles/object_doubles.feature +65 -0
- data/features/verifying_doubles/partial_doubles.feature +34 -0
- data/lib/rspec/mocks.rb +8 -34
- data/lib/rspec/mocks/any_instance/chain.rb +4 -34
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +14 -4
- data/lib/rspec/mocks/any_instance/message_chains.rb +27 -12
- data/lib/rspec/mocks/any_instance/recorder.rb +23 -31
- data/lib/rspec/mocks/any_instance/stub_chain.rb +9 -4
- data/lib/rspec/mocks/argument_list_matcher.rb +8 -1
- data/lib/rspec/mocks/argument_matchers.rb +26 -12
- data/lib/rspec/mocks/arity_calculator.rb +66 -0
- data/lib/rspec/mocks/configuration.rb +42 -14
- data/lib/rspec/mocks/error_generator.rb +34 -10
- data/lib/rspec/mocks/example_methods.rb +64 -19
- data/lib/rspec/mocks/extensions/marshal.rb +0 -15
- data/lib/rspec/mocks/framework.rb +4 -4
- data/lib/rspec/mocks/instance_method_stasher.rb +80 -62
- data/lib/rspec/mocks/matchers/have_received.rb +18 -14
- data/lib/rspec/mocks/matchers/receive.rb +29 -7
- data/lib/rspec/mocks/matchers/receive_messages.rb +72 -0
- data/lib/rspec/mocks/message_expectation.rb +95 -148
- data/lib/rspec/mocks/method_double.rb +77 -139
- data/lib/rspec/mocks/method_reference.rb +95 -0
- data/lib/rspec/mocks/mock.rb +1 -1
- data/lib/rspec/mocks/mutate_const.rb +12 -9
- data/lib/rspec/mocks/object_reference.rb +90 -0
- data/lib/rspec/mocks/order_group.rb +49 -7
- data/lib/rspec/mocks/proxy.rb +72 -33
- data/lib/rspec/mocks/proxy_for_nil.rb +2 -2
- data/lib/rspec/mocks/space.rb +13 -18
- data/lib/rspec/mocks/stub_chain.rb +2 -2
- data/lib/rspec/mocks/syntax.rb +61 -36
- data/lib/rspec/mocks/targets.rb +40 -19
- data/lib/rspec/mocks/test_double.rb +12 -56
- data/lib/rspec/mocks/verifying_double.rb +77 -0
- data/lib/rspec/mocks/verifying_message_expecation.rb +60 -0
- data/lib/rspec/mocks/verifying_proxy.rb +151 -0
- data/lib/rspec/mocks/version.rb +1 -1
- data/spec/rspec/mocks/and_call_original_spec.rb +34 -30
- data/spec/rspec/mocks/and_yield_spec.rb +2 -2
- data/spec/rspec/mocks/any_instance/message_chains_spec.rb +1 -1
- data/spec/rspec/mocks/any_instance_spec.rb +53 -260
- data/spec/rspec/mocks/argument_expectation_spec.rb +4 -4
- data/spec/rspec/mocks/arity_calculator_spec.rb +95 -0
- data/spec/rspec/mocks/array_including_matcher_spec.rb +41 -0
- data/spec/rspec/mocks/at_least_spec.rb +4 -32
- data/spec/rspec/mocks/block_return_value_spec.rb +4 -135
- data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +10 -11
- data/spec/rspec/mocks/configuration_spec.rb +79 -0
- data/spec/rspec/mocks/double_spec.rb +10 -78
- data/spec/rspec/mocks/extensions/marshal_spec.rb +0 -8
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +49 -4
- data/spec/rspec/mocks/instance_method_stasher_spec.rb +20 -3
- data/spec/rspec/mocks/matchers/have_received_spec.rb +74 -0
- data/spec/rspec/mocks/matchers/receive_messages_spec.rb +140 -0
- data/spec/rspec/mocks/matchers/receive_spec.rb +82 -42
- data/spec/rspec/mocks/methods_spec.rb +1 -1
- data/spec/rspec/mocks/{bug_report_830_spec.rb → mock_expectation_error_spec.rb} +4 -3
- data/spec/rspec/mocks/mock_ordering_spec.rb +11 -0
- data/spec/rspec/mocks/mock_space_spec.rb +10 -1
- data/spec/rspec/mocks/mock_spec.rb +26 -82
- data/spec/rspec/mocks/multiple_return_value_spec.rb +1 -1
- data/spec/rspec/mocks/mutate_const_spec.rb +18 -5
- data/spec/rspec/mocks/null_object_mock_spec.rb +6 -4
- data/spec/rspec/mocks/options_hash_spec.rb +3 -3
- data/spec/rspec/mocks/order_group_spec.rb +27 -0
- data/spec/rspec/mocks/partial_mock_spec.rb +101 -1
- data/spec/rspec/mocks/passing_argument_matchers_spec.rb +3 -20
- data/spec/rspec/mocks/record_messages_spec.rb +4 -4
- data/spec/rspec/mocks/serialization_spec.rb +4 -6
- data/spec/rspec/mocks/space_spec.rb +3 -3
- data/spec/rspec/mocks/stub_chain_spec.rb +0 -12
- data/spec/rspec/mocks/stub_spec.rb +23 -44
- data/spec/rspec/mocks/test_double_spec.rb +3 -22
- data/spec/rspec/mocks/verifying_double_spec.rb +327 -0
- data/spec/rspec/mocks/verifying_message_expecation_spec.rb +68 -0
- data/spec/rspec/mocks_spec.rb +16 -39
- data/spec/spec_helper.rb +29 -18
- metadata +131 -86
- metadata.gz.sig +1 -0
- data/features/message_expectations/expect_any_instance_of.feature +0 -27
- data/lib/rspec/mocks/caller_filter.rb +0 -60
- data/lib/rspec/mocks/deprecation.rb +0 -26
- data/lib/rspec/mocks/extensions/instance_exec.rb +0 -34
- data/lib/rspec/mocks/extensions/proc.rb +0 -63
- data/lib/spec/mocks.rb +0 -4
- data/spec/rspec/mocks/and_return_spec.rb +0 -17
- data/spec/rspec/mocks/any_number_of_times_spec.rb +0 -36
- data/spec/rspec/mocks/before_all_spec.rb +0 -74
- data/spec/rspec/mocks/bug_report_10260_spec.rb +0 -8
- data/spec/rspec/mocks/bug_report_10263_spec.rb +0 -27
- data/spec/rspec/mocks/bug_report_11545_spec.rb +0 -32
- data/spec/rspec/mocks/bug_report_496_spec.rb +0 -17
- data/spec/rspec/mocks/bug_report_600_spec.rb +0 -22
- data/spec/rspec/mocks/bug_report_7611_spec.rb +0 -16
- data/spec/rspec/mocks/bug_report_8165_spec.rb +0 -31
- data/spec/rspec/mocks/bug_report_957_spec.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MWQyODY3ZjBkNmUxYWY1ZjFlZWNlM2Q0NjZlY2M1OTEwOTI3N2E1ZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzI0OGE3YzFmZDQ4MTc5ZmJlODExYjNjNDE5MzMyOGI4ZTE2ZDY2MQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTA4ZmE4NjJhNDhjYTFmMWU4MmM3OTkzMTk3OTQ3M2YyYTNmMzljYzQzNDFm
|
10
|
+
MjgwMzE0NDlmZDFmYzVkMzIwZWIzOGYxNjZlN2U1MDMwZDIwNGYxZDkzYWFj
|
11
|
+
MDAzM2NmMWEyNDA1NTg5OTBmMzViMzdhYjRlMTUyODNmMDJkMjU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjExYjNmYzZhMTAyZjQyN2RjNWY1NmNhMjRiNmU5NDhjOTY0NWNiYzMxOWUy
|
14
|
+
MGMzOGIzOTYzNDhmOWNlNzVkODQ5ZmYyN2RmN2MwZGM2ZThmMWIwY2U3NGIx
|
15
|
+
M2Q3ZTFhNTVkZjFjZmJhNmQ4M2NkNTJhMGRiN2IzMmY3ZThkNGQ=
|
checksums.yaml.gz.sig
ADDED
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
�旺]v�����h��(*�z(��������:�d-XH�?ibI�4L��0*�ʆ˫K��Y?D��u<��);�p��]8�ҥ��P��8�ۥ��v<�MZ�M@���3��ӑ۶�Y���Ͷ�D�ОP �Mɭ�(B�[�Vk�"8��)'�Hs�%�j�ldyg�����Ԅ�f��đ��)�ѻ�gb�L��K��;7r)գC�1�� �lN�vKϣ!���Qr$9�P�ZI� u�'�a��=[�6/e
|
data/Changelog.md
CHANGED
@@ -1,70 +1,71 @@
|
|
1
|
-
###
|
2
|
-
[
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
*
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
### 3.0.0.beta1 / 2013-11-07
|
2
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.99.0.beta1...v3.0.0.beta1)
|
3
|
+
|
4
|
+
Breaking Changes for 3.0.0:
|
5
|
+
|
6
|
+
* Raise an explicit error if `should_not_receive(...).and_return` is used. (Sam
|
7
|
+
Phippen)
|
8
|
+
* Remove 1.8.6 workarounds. (Jon Rowe)
|
9
|
+
* Remove `stub!` and `unstub!`. (Sam Phippen)
|
10
|
+
* Remove `mock(name, methods)` and `stub(name, methods)`, leaving
|
11
|
+
`double(name, methods)` for creating test doubles. (Sam Phippen, Michi Huber)
|
12
|
+
* Remove `any_number_of_times` since `should_receive(:msg).any_number_of_times`
|
13
|
+
is really a stub in a mock's clothing. (Sam Phippen)
|
14
|
+
* Remove support for re-using the same null-object test double in multiple
|
15
|
+
examples. Test doubles are designed to only live for one example.
|
16
|
+
(Myron Marston)
|
17
|
+
* Make `at_least(0)` raise an error. (Sam Phippen)
|
18
|
+
* Remove support for `require 'spec/mocks'` which had been kept
|
19
|
+
in place for backwards compatibility with RSpec 1. (Myron Marston)
|
20
|
+
* Blocks provided to `with` are always used as implementation. (Xavier Shay)
|
21
|
+
* The config option (added in 2.99) to yield the receiver to
|
22
|
+
`any_instance` implementation blocks now defaults to "on". (Sam Phippen)
|
17
23
|
|
18
24
|
Enhancements:
|
19
25
|
|
20
|
-
*
|
21
|
-
(
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
*
|
29
|
-
|
26
|
+
* Allow the `have_received` matcher to use a block to set further expectations
|
27
|
+
on arguments. (Tim Cowlishaw)
|
28
|
+
* Provide `instance_double` and `class_double` to create verifying doubles,
|
29
|
+
ported from `rspec-fire`. (Xavier Shay)
|
30
|
+
* `as_null_object` on a verifying double only responds to defined methods.
|
31
|
+
(Xavier Shay)
|
32
|
+
* Provide `object_double` to create verified doubles of specific object
|
33
|
+
instances. (Xavier Shay)
|
34
|
+
* Provide 'verify_partial_doubles` configuration that provides `object_double`
|
35
|
+
like verification behaviour on partial mocks. (Xavier Shay)
|
36
|
+
* Improved performance of double creation, particularly those with many
|
37
|
+
attributes. (Xavier Shay)
|
38
|
+
* Default value of `transfer_nested_constants` option for constant stubbing can
|
39
|
+
be configured. (Xavier Shay)
|
40
|
+
* Messages can be allowed or expected on in bulk via
|
41
|
+
`receive_messages(:message => :value)`. (Jon Rowe)
|
42
|
+
* `allow(Klass.any_instance)` and `expect(Klass.any_instance)` now print a
|
43
|
+
warning. This is usually a mistake, and users usually want
|
44
|
+
`allow_any_instance_of` or `expect_any_instance_of` instead. (Sam Phippen)
|
45
|
+
* `instance_double` and `class_double` raise `ArgumentError` if the underlying
|
46
|
+
module is loaded and the arity of the method being invoked does not match the
|
47
|
+
arity of the method as it is actually implemented. (Andy Lindeman)
|
48
|
+
* Spies can now check their invocation ordering is correct. (Jon Rowe)
|
30
49
|
|
31
50
|
Deprecations:
|
32
51
|
|
33
|
-
*
|
52
|
+
* Using the old `:should` syntax without explicitly configuring it
|
53
|
+
is disabled. It will continue to work but will emit a deprecation
|
54
|
+
warning in RSpec 3 if you do not explicitly enable it. (Sam Phippen)
|
34
55
|
|
35
|
-
|
36
|
-
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.99.0.rc1...v2.99.0)
|
37
|
-
|
38
|
-
No changes. Just taking it out of pre-release.
|
39
|
-
|
40
|
-
### 2.99.0.rc1 / 2014-05-18
|
41
|
-
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.99.0.beta2...v2.99.0.rc1)
|
42
|
-
|
43
|
-
Deprecations:
|
44
|
-
|
45
|
-
* Deprecate `RSpec::Mocks::TestDouble.extend_onto`. (Myron Marston)
|
46
|
-
* Deprecate `RSpec::Mocks::ConstantStubber`. (Jon Rowe)
|
47
|
-
* Deprecate `Marshal.dump` monkey-patch without opt-in. (Xavier Shay)
|
48
|
-
|
49
|
-
### 2.99.0.beta2 / 2014-02-17
|
50
|
-
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.99.0.beta1...v2.99.0.beta2)
|
51
|
-
|
52
|
-
Deprecations:
|
56
|
+
Bug Fixes:
|
53
57
|
|
54
|
-
*
|
55
|
-
(Myron Marston)
|
56
|
-
*
|
57
|
-
`
|
58
|
-
|
59
|
-
|
60
|
-
lifecycle (e.g. from a `before(:all)` hook). (Myron Marston)
|
61
|
-
* Deprecate re-using a test double in another example. (Myron Marston)
|
62
|
-
* Deprecate `and_return { value }` and `and_return` without arguments. (Yuji Nakayama)
|
58
|
+
* Fix `and_call_original` to handle a complex edge case involving
|
59
|
+
singleton class ancestors. (Marc-André Lafortune, Myron Marston)
|
60
|
+
* When generating an error message for unexpected arguments,
|
61
|
+
use `#inspect` rather than `#description` if `#description`
|
62
|
+
returns `nil` or `''` so that you still get a useful message.
|
63
|
+
(Nick DeLuca)
|
63
64
|
|
64
65
|
### 2.99.0.beta1 / 2013-11-07
|
65
|
-
[
|
66
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.4...v2.99.0.beta1)
|
66
67
|
|
67
|
-
Deprecations
|
68
|
+
Deprecations
|
68
69
|
|
69
70
|
* Expecting to use lambdas or other strong arity implementations for stub
|
70
71
|
methods with mis-matched arity is deprecated and support for them will be
|
@@ -86,26 +87,8 @@ Enhancements:
|
|
86
87
|
* Add a config option to yield the receiver to `any_instance` implementation
|
87
88
|
blocks. (Sam Phippen)
|
88
89
|
|
89
|
-
### 2.14.6 / 2014-02-20
|
90
|
-
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.5...v2.14.6)
|
91
|
-
|
92
|
-
Bug Fixes:
|
93
|
-
|
94
|
-
* Ensure `any_instance` method stubs and expectations are torn down regardless of
|
95
|
-
expectation failures. (Sam Phippen)
|
96
|
-
|
97
|
-
### 2.14.5 / 2014-02-01
|
98
|
-
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.4...v2.14.5)
|
99
|
-
|
100
|
-
Bug Fixes:
|
101
|
-
|
102
|
-
* Fix regression that caused block implementations to not receive all
|
103
|
-
args on 1.8.7 if the block also receives a block, due to Proc#arity
|
104
|
-
reporting `1` no matter how many args the block receives if it
|
105
|
-
receives a block, too. (Myron Marston)
|
106
|
-
|
107
90
|
### 2.14.4 / 2013-10-15
|
108
|
-
[
|
91
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.3...v2.14.4)
|
109
92
|
|
110
93
|
Bug Fixes:
|
111
94
|
|
@@ -115,7 +98,7 @@ Bug Fixes:
|
|
115
98
|
the usage of modifications (`and_return` etc) (Jon Rowe)
|
116
99
|
|
117
100
|
### 2.14.3 / 2013-08-08
|
118
|
-
[
|
101
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.2...v2.14.3)
|
119
102
|
|
120
103
|
Bug Fixes:
|
121
104
|
|
@@ -123,7 +106,7 @@ Bug Fixes:
|
|
123
106
|
a prepended Module (Bradley Schaefer)
|
124
107
|
|
125
108
|
### 2.14.2 / 2013-07-30
|
126
|
-
[
|
109
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.1...v2.14.2)
|
127
110
|
|
128
111
|
Bug Fixes:
|
129
112
|
|
@@ -133,7 +116,7 @@ Bug Fixes:
|
|
133
116
|
return a test double rather than stub a method (Myron Marston).
|
134
117
|
|
135
118
|
### 2.14.1 / 2013-07-07
|
136
|
-
[
|
119
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.0...v2.14.1)
|
137
120
|
|
138
121
|
Bug Fixes:
|
139
122
|
|
@@ -145,7 +128,7 @@ Bug Fixes:
|
|
145
128
|
in 3.0. (Myron Marston)
|
146
129
|
|
147
130
|
### 2.14.0 / 2013-07-06
|
148
|
-
[
|
131
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.0.rc1...v2.14.0)
|
149
132
|
|
150
133
|
Enhancements:
|
151
134
|
|
@@ -169,7 +152,7 @@ Bug Fixes:
|
|
169
152
|
similar preloading gems (Andy Lindeman).
|
170
153
|
|
171
154
|
### 2.14.0.rc1 / 2013-05-27
|
172
|
-
[
|
155
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.13.0...v2.14.0.rc1)
|
173
156
|
|
174
157
|
Enhancements:
|
175
158
|
|
@@ -207,6 +190,7 @@ Bug fixes
|
|
207
190
|
(Luke Imhoff, Jon Rowe)
|
208
191
|
* Fix isolation of `allow_message_expectations_on_nil` (Jon Rowe)
|
209
192
|
* Use inspect to format actual arguments on expectations in failure messages (#280, Ben Langfeld)
|
193
|
+
* Protect against improperly initialised test doubles (#293) (Joseph Shraibman and Jon Rowe)
|
210
194
|
|
211
195
|
Deprecations
|
212
196
|
|
@@ -218,7 +202,7 @@ Deprecations
|
|
218
202
|
* Deprecate `at_least(0).times` and `any_number_of_times` (Michi Huber).
|
219
203
|
|
220
204
|
### 2.13.1 / 2013-04-06
|
221
|
-
[
|
205
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.13.0...v2.13.1)
|
222
206
|
|
223
207
|
Bug fixes
|
224
208
|
|
@@ -226,7 +210,7 @@ Bug fixes
|
|
226
210
|
`and_yield`, `and_raise`, `and_return` or `and_throw` (Myron Marston).
|
227
211
|
|
228
212
|
### 2.13.0 / 2013-02-23
|
229
|
-
[
|
213
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.12.2...v2.13.0)
|
230
214
|
|
231
215
|
Bug fixes
|
232
216
|
|
@@ -256,7 +240,7 @@ Bug fixes
|
|
256
240
|
(Myron Marston).
|
257
241
|
|
258
242
|
### 2.12.2 / 2013-01-27
|
259
|
-
[
|
243
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.12.1...v.2.12.2)
|
260
244
|
|
261
245
|
Bug fixes
|
262
246
|
|
@@ -271,7 +255,7 @@ Bug fixes
|
|
271
255
|
versions (Andy Lindeman).
|
272
256
|
|
273
257
|
### 2.12.1 / 2012-12-21
|
274
|
-
[
|
258
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.12.0...v2.12.1)
|
275
259
|
|
276
260
|
Bug fixes
|
277
261
|
|
@@ -283,7 +267,7 @@ Bug fixes
|
|
283
267
|
work properly with constant strings that are prefixed with `::` (Myron Marston).
|
284
268
|
|
285
269
|
### 2.12.0 / 2012-11-12
|
286
|
-
[
|
270
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.11.3...v2.12.0)
|
287
271
|
|
288
272
|
Enhancements
|
289
273
|
|
@@ -299,7 +283,7 @@ Deprecations:
|
|
299
283
|
(Neha Kumari)
|
300
284
|
|
301
285
|
### 2.11.3 / 2012-09-19
|
302
|
-
[
|
286
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.11.2...v2.11.3)
|
303
287
|
|
304
288
|
Bug fixes
|
305
289
|
|
@@ -313,7 +297,7 @@ Bug fixes
|
|
313
297
|
extra time with the wrong arguments (Myron Marston).
|
314
298
|
|
315
299
|
### 2.11.2 / 2012-08-11
|
316
|
-
[
|
300
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.11.1...v2.11.2)
|
317
301
|
|
318
302
|
Bug fixes
|
319
303
|
|
@@ -325,7 +309,7 @@ Bug fixes
|
|
325
309
|
Marston)
|
326
310
|
|
327
311
|
### 2.11.1 / 2012-07-09
|
328
|
-
[
|
312
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.11.0...v2.11.1)
|
329
313
|
|
330
314
|
Bug fixes
|
331
315
|
|
@@ -335,7 +319,7 @@ Bug fixes
|
|
335
319
|
overriden with the null object implementation--`return self`). (Myron Marston)
|
336
320
|
|
337
321
|
### 2.11.0 / 2012-07-07
|
338
|
-
[
|
322
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.10.1...v2.11.0)
|
339
323
|
|
340
324
|
Enhancements
|
341
325
|
|
@@ -360,7 +344,7 @@ Bug fixes
|
|
360
344
|
`Exception` by default, just like ruby does. (Andrew Marshall)
|
361
345
|
|
362
346
|
### 2.10.1 / 2012-05-05
|
363
|
-
[
|
347
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.10.0...v2.10.1)
|
364
348
|
|
365
349
|
Bug fixes
|
366
350
|
|
@@ -370,14 +354,14 @@ Bug fixes
|
|
370
354
|
* fixed failure of `object.should_not_receive(:message).and_return value`
|
371
355
|
|
372
356
|
### 2.10.0 / 2012-05-03
|
373
|
-
[
|
357
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.9.0...v2.10.0)
|
374
358
|
|
375
359
|
Bug fixes
|
376
360
|
|
377
361
|
* fail fast when an `exactly` or `at_most` expectation is exceeded
|
378
362
|
|
379
363
|
### 2.9.0 / 2012-03-17
|
380
|
-
[
|
364
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.8.0...v2.9.0)
|
381
365
|
|
382
366
|
Enhancements
|
383
367
|
|
@@ -392,19 +376,19 @@ Bug fixes
|
|
392
376
|
|
393
377
|
### 2.8.0 / 2012-01-04
|
394
378
|
|
395
|
-
[
|
379
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.8.0.rc2...v2.8.0)
|
396
380
|
|
397
381
|
No changes for this release. Just releasing with the other rspec gems.
|
398
382
|
|
399
383
|
### 2.8.0.rc2 / 2011-12-19
|
400
384
|
|
401
|
-
[
|
385
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.8.0.rc1...v2.8.0.rc2)
|
402
386
|
|
403
387
|
No changes for this release. Just releasing with the other rspec gems.
|
404
388
|
|
405
389
|
### 2.8.0.rc1 / 2011-11-06
|
406
390
|
|
407
|
-
[
|
391
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.7.0...v2.8.0.rc1)
|
408
392
|
|
409
393
|
Enhancements
|
410
394
|
|
@@ -412,7 +396,7 @@ Enhancements
|
|
412
396
|
|
413
397
|
### 2.7.0 / 2011-10-16
|
414
398
|
|
415
|
-
[
|
399
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.6.0...v2.7.0)
|
416
400
|
|
417
401
|
Enhancements
|
418
402
|
|
@@ -435,7 +419,7 @@ Bug fixes
|
|
435
419
|
|
436
420
|
### 2.6.0 / 2011-05-12
|
437
421
|
|
438
|
-
[
|
422
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.5.0...v2.6.0)
|
439
423
|
|
440
424
|
Enhancements
|
441
425
|
|
@@ -449,7 +433,7 @@ Bug fixes
|
|
449
433
|
|
450
434
|
### 2.5.0 / 2011-02-05
|
451
435
|
|
452
|
-
[
|
436
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.4.0...v2.5.0)
|
453
437
|
|
454
438
|
Bug fixes
|
455
439
|
|
@@ -460,14 +444,14 @@ Bug fixes
|
|
460
444
|
|
461
445
|
### 2.4.0 / 2011-01-02
|
462
446
|
|
463
|
-
[
|
447
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.3.0...v2.4.0)
|
464
448
|
|
465
449
|
No functional changes in this release, which was made to align with the
|
466
450
|
rspec-core-2.4.0 release.
|
467
451
|
|
468
452
|
### 2.3.0 / 2010-12-12
|
469
453
|
|
470
|
-
[
|
454
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.2.0...v2.3.0)
|
471
455
|
|
472
456
|
Bug fixes
|
473
457
|
|
@@ -476,7 +460,7 @@ Bug fixes
|
|
476
460
|
|
477
461
|
### 2.2.0 / 2010-11-28
|
478
462
|
|
479
|
-
[
|
463
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.1.0...v2.2.0)
|
480
464
|
|
481
465
|
Enhancements
|
482
466
|
|
@@ -490,7 +474,7 @@ Bug fix
|
|
490
474
|
|
491
475
|
### 2.1.0 / 2010-11-07
|
492
476
|
|
493
|
-
[
|
477
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.1...v2.1.0)
|
494
478
|
|
495
479
|
Bug fixes
|
496
480
|
|
@@ -498,11 +482,11 @@ Bug fixes
|
|
498
482
|
|
499
483
|
### 2.0.0 / 2010-10-10
|
500
484
|
|
501
|
-
[
|
485
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.22...v2.0.0)
|
502
486
|
|
503
487
|
### 2.0.0.rc / 2010-10-05
|
504
488
|
|
505
|
-
[
|
489
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.22...v2.0.0.rc)
|
506
490
|
|
507
491
|
Enhancements
|
508
492
|
|
@@ -516,7 +500,7 @@ Bug fixes
|
|
516
500
|
|
517
501
|
### 2.0.0.beta.22 / 2010-09-12
|
518
502
|
|
519
|
-
[
|
503
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.20...v2.0.0.beta.22)
|
520
504
|
|
521
505
|
Bug fixes
|
522
506
|
|
data/License.txt
CHANGED
data/README.md
CHANGED
@@ -26,9 +26,8 @@ stubs can be declared on test doubles or real objects using the same syntax.
|
|
26
26
|
rspec-mocks supports 3 forms for declaring method stubs:
|
27
27
|
|
28
28
|
```ruby
|
29
|
-
book.
|
30
|
-
book.
|
31
|
-
book.stub(:title).and_return("The RSpec Book")
|
29
|
+
allow(book).to receive(:title) { "The RSpec Book" }
|
30
|
+
allow(book).to receive(:title).and_return("The RSpec Book")
|
32
31
|
```
|
33
32
|
|
34
33
|
You can also use this shortcut, which creates a test double and declares a
|
@@ -60,7 +59,7 @@ arguments to `and_return`. The invocations cycle through the list. The last
|
|
60
59
|
value is returned for any subsequent invocations:
|
61
60
|
|
62
61
|
```ruby
|
63
|
-
die.
|
62
|
+
allow(die).to receive(:roll).and_return(1,2,3)
|
64
63
|
die.roll # => 1
|
65
64
|
die.roll # => 2
|
66
65
|
die.roll # => 3
|
@@ -71,7 +70,7 @@ die.roll # => 3
|
|
71
70
|
To return an array in a single invocation, declare an array:
|
72
71
|
|
73
72
|
```ruby
|
74
|
-
team.
|
73
|
+
allow(team).to receive(:players).and_return([double(:name => "David")])
|
75
74
|
```
|
76
75
|
|
77
76
|
## Message Expectations
|
@@ -82,11 +81,33 @@ expectation is satisfied. If not, the example fails.
|
|
82
81
|
|
83
82
|
```ruby
|
84
83
|
validator = double("validator")
|
85
|
-
validator.
|
84
|
+
expect(validator).to receive(:validate) { "02134" }
|
86
85
|
zipcode = Zipcode.new("02134", validator)
|
87
86
|
zipcode.valid?
|
88
87
|
```
|
89
88
|
|
89
|
+
## Test Spies
|
90
|
+
|
91
|
+
Verifies the given object received the expected message during the course of the
|
92
|
+
test. The method must have previously been stubbed in order for messages to be
|
93
|
+
verified.
|
94
|
+
|
95
|
+
Stubbing and verifying messages received in this way implements the Test Spy
|
96
|
+
pattern.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
invitation = double('invitation', :accept => true)
|
100
|
+
|
101
|
+
user.accept_invitation(invitation)
|
102
|
+
|
103
|
+
expect(invitation).to have_received(:accept)
|
104
|
+
|
105
|
+
# You can also use other common message expectations. For example:
|
106
|
+
expect(invitation).to have_received(:accept).with(mailer)
|
107
|
+
expect(invitation).to have_received(:accept).twice
|
108
|
+
expect(invitation).to_not have_received(:accept).with(mailer)
|
109
|
+
```
|
110
|
+
|
90
111
|
## Nomenclature
|
91
112
|
|
92
113
|
### Mock Objects and Test Stubs
|
@@ -112,7 +133,7 @@ For example, in Rails:
|
|
112
133
|
|
113
134
|
```ruby
|
114
135
|
person = double("person")
|
115
|
-
Person.
|
136
|
+
allow(Person).to receive(:find) { person }
|
116
137
|
```
|
117
138
|
|
118
139
|
In this case we're instrumenting Person to return the person object we've
|
@@ -121,27 +142,25 @@ expectation so that the example fails if `find` is not called:
|
|
121
142
|
|
122
143
|
```ruby
|
123
144
|
person = double("person")
|
124
|
-
Person.
|
145
|
+
expect(Person).to receive(:find) { person }
|
125
146
|
```
|
126
147
|
|
127
|
-
|
128
|
-
and `should_receive` methods to every object, including class objects. When we
|
129
|
-
use either, RSpec replaces the method we're stubbing or mocking with its own
|
148
|
+
RSpec replaces the method we're stubbing or mocking with its own
|
130
149
|
test-double-like method. At the end of the example, RSpec verifies any message
|
131
150
|
expectations, and then restores the original methods.
|
132
151
|
|
133
152
|
## Expecting Arguments
|
134
153
|
|
135
154
|
```ruby
|
136
|
-
double.
|
137
|
-
double.
|
155
|
+
expect(double).to receive(:msg).with(*args)
|
156
|
+
expect(double).to_not receive(:msg).with(*args)
|
138
157
|
```
|
139
158
|
|
140
159
|
You can set multiple expectations for the same message if you need to:
|
141
160
|
|
142
161
|
```ruby
|
143
|
-
double.
|
144
|
-
double.
|
162
|
+
expect(double).to receive(:msg).with("A", 1, 3)
|
163
|
+
expect(double).to receive(:msg).with("B", 2, 4)
|
145
164
|
```
|
146
165
|
|
147
166
|
## Argument Matchers
|
@@ -157,81 +176,81 @@ rspec-mocks also adds some keyword Symbols that you can use to
|
|
157
176
|
specify certain kinds of arguments:
|
158
177
|
|
159
178
|
```ruby
|
160
|
-
double.
|
161
|
-
double.
|
162
|
-
double.
|
163
|
-
double.
|
164
|
-
double.
|
165
|
-
double.
|
166
|
-
double.
|
179
|
+
expect(double).to receive(:msg).with(no_args())
|
180
|
+
expect(double).to receive(:msg).with(any_args())
|
181
|
+
expect(double).to receive(:msg).with(1, kind_of(Numeric), "b") #2nd argument can be any kind of Numeric
|
182
|
+
expect(double).to receive(:msg).with(1, boolean(), "b") #2nd argument can be true or false
|
183
|
+
expect(double).to receive(:msg).with(1, /abc/, "b") #2nd argument can be any String matching the submitted Regexp
|
184
|
+
expect(double).to receive(:msg).with(1, anything(), "b") #2nd argument can be anything at all
|
185
|
+
expect(double).to receive(:msg).with(1, duck_type(:abs, :div), "b")
|
167
186
|
#2nd argument can be object that responds to #abs and #div
|
168
187
|
```
|
169
188
|
|
170
189
|
## Receive Counts
|
171
190
|
|
172
191
|
```ruby
|
173
|
-
double.
|
174
|
-
double.
|
175
|
-
double.
|
176
|
-
double.
|
177
|
-
double.
|
178
|
-
double.
|
179
|
-
double.
|
180
|
-
double.
|
181
|
-
double.
|
182
|
-
double.
|
192
|
+
expect(double).to receive(:msg).once
|
193
|
+
expect(double).to receive(:msg).twice
|
194
|
+
expect(double).to receive(:msg).exactly(n).times
|
195
|
+
expect(double).to receive(:msg).at_least(:once)
|
196
|
+
expect(double).to receive(:msg).at_least(:twice)
|
197
|
+
expect(double).to receive(:msg).at_least(n).times
|
198
|
+
expect(double).to receive(:msg).at_most(:once)
|
199
|
+
expect(double).to receive(:msg).at_most(:twice)
|
200
|
+
expect(double).to receive(:msg).at_most(n).times
|
201
|
+
expect(double).to receive(:msg).any_number_of_times
|
183
202
|
```
|
184
203
|
|
185
204
|
## Ordering
|
186
205
|
|
187
206
|
```ruby
|
188
|
-
double.
|
189
|
-
double.
|
207
|
+
expect(double).to receive(:msg).ordered
|
208
|
+
expect(double).to receive(:other_msg).ordered
|
190
209
|
#This will fail if the messages are received out of order
|
191
210
|
```
|
192
211
|
|
193
212
|
This can include the same message with different arguments:
|
194
213
|
|
195
214
|
```ruby
|
196
|
-
double.
|
197
|
-
double.
|
215
|
+
expect(double).to receive(:msg).with("A", 1, 3).ordered
|
216
|
+
expect(double).to receive(:msg).with("B", 2, 4).ordered
|
198
217
|
```
|
199
218
|
|
200
219
|
## Setting Responses
|
201
220
|
|
202
221
|
Whether you are setting a message expectation or a method stub, you can
|
203
222
|
tell the object precisely how to respond. The most generic way is to pass
|
204
|
-
a block to `
|
223
|
+
a block to `receive`:
|
205
224
|
|
206
225
|
```ruby
|
207
|
-
double.
|
226
|
+
expect(double).to receive(:msg) { value }
|
208
227
|
```
|
209
228
|
|
210
229
|
When the double receives the `msg` message, it evaluates the block and returns
|
211
230
|
the result.
|
212
231
|
|
213
232
|
```ruby
|
214
|
-
double.
|
215
|
-
double.
|
233
|
+
expect(double).to receive(:msg).and_return(value)
|
234
|
+
expect(double).to receive(:msg).exactly(3).times.and_return(value1, value2, value3)
|
216
235
|
# returns value1 the first time, value2 the second, etc
|
217
|
-
double.
|
236
|
+
expect(double).to receive(:msg).and_raise(error)
|
218
237
|
#error can be an instantiated object or a class
|
219
238
|
#if it is a class, it must be instantiable with no args
|
220
|
-
double.
|
221
|
-
double.
|
222
|
-
double.
|
239
|
+
expect(double).to receive(:msg).and_throw(:msg)
|
240
|
+
expect(double).to receive(:msg).and_yield(values,to,yield)
|
241
|
+
expect(double).to receive(:msg).and_yield(values,to,yield).and_yield(some,other,values,this,time)
|
223
242
|
# for methods that yield to a block multiple times
|
224
243
|
```
|
225
244
|
|
226
245
|
Any of these responses can be applied to a stub as well
|
227
246
|
|
228
247
|
```ruby
|
229
|
-
double.
|
230
|
-
double.
|
231
|
-
double.
|
232
|
-
double.
|
233
|
-
double.
|
234
|
-
double.
|
248
|
+
allow(double).to receive(:msg).and_return(value)
|
249
|
+
allow(double).to receive(:msg).and_return(value1, value2, value3)
|
250
|
+
allow(double).to receive(:msg).and_raise(error)
|
251
|
+
allow(double).to receive(:msg).and_throw(:msg)
|
252
|
+
allow(double).to receive(:msg).and_yield(values,to,yield)
|
253
|
+
allow(double).to receive(:msg).and_yield(values,to,yield).and_yield(some,other,values,this,time)
|
235
254
|
```
|
236
255
|
|
237
256
|
## Arbitrary Handling
|
@@ -242,8 +261,8 @@ to come with an Array argument that has a specific length, but you don't care
|
|
242
261
|
what is in it. You could do this:
|
243
262
|
|
244
263
|
```ruby
|
245
|
-
double.
|
246
|
-
arg.size.
|
264
|
+
expect(double).to receive(:msg) do |arg|
|
265
|
+
expect(arg.size).to eq 7
|
247
266
|
end
|
248
267
|
```
|
249
268
|
|
@@ -251,7 +270,7 @@ If the method being stubbed itself takes a block, and you need to yield to it
|
|
251
270
|
in some special way, you can use this:
|
252
271
|
|
253
272
|
```ruby
|
254
|
-
double.
|
273
|
+
expect(double).to receive(:msg) do |&arg|
|
255
274
|
begin
|
256
275
|
arg.call
|
257
276
|
ensure
|
@@ -268,7 +287,7 @@ the object responds to the message. You can use `and_call_original`
|
|
268
287
|
to achieve this:
|
269
288
|
|
270
289
|
```ruby
|
271
|
-
Person.
|
290
|
+
expect(Person).to receive(:find).and_call_original
|
272
291
|
Person.find # => executes the original find method and returns the result
|
273
292
|
```
|
274
293
|
|
@@ -278,7 +297,7 @@ Combining the message name with specific arguments, receive counts and responses
|
|
278
297
|
you can get quite a bit of detail in your expectations:
|
279
298
|
|
280
299
|
```ruby
|
281
|
-
double.
|
300
|
+
expect(double).to receive(:<<).with("illegal value").once.and_raise(ArgumentError)
|
282
301
|
```
|
283
302
|
|
284
303
|
While this is a good thing when you really need it, you probably don't really
|
@@ -303,8 +322,9 @@ There are many different viewpoints about the meaning of mocks and stubs. If
|
|
303
322
|
you are interested in learning more, here is some recommended reading:
|
304
323
|
|
305
324
|
* Mock Objects: http://www.mockobjects.com/
|
306
|
-
* Endo-Testing: http://
|
307
|
-
* Mock Roles, Not Objects: http://
|
325
|
+
* Endo-Testing: http://stalatest.googlecode.com/svn/trunk/Literatur/mockobjects.pdf
|
326
|
+
* Mock Roles, Not Objects: http://jmock.org/oopsla2004.pdf
|
327
|
+
* Test Double: http://www.martinfowler.com/bliki/TestDouble.html
|
308
328
|
* Test Double Patterns: http://xunitpatterns.com/Test%20Double%20Patterns.html
|
309
329
|
* Mocks aren't stubs: http://www.martinfowler.com/articles/mocksArentStubs.html
|
310
330
|
|