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.
Files changed (133) hide show
  1. checksums.yaml +14 -6
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +1 -0
  4. data/Changelog.md +89 -105
  5. data/License.txt +1 -0
  6. data/README.md +77 -57
  7. data/features/argument_matchers/explicit.feature +5 -5
  8. data/features/argument_matchers/general_matchers.feature +10 -10
  9. data/features/argument_matchers/type_matchers.feature +3 -3
  10. data/features/message_expectations/allow_any_instance_of.feature +1 -1
  11. data/features/message_expectations/any_instance.feature +27 -5
  12. data/features/message_expectations/call_original.feature +2 -2
  13. data/features/message_expectations/expect_message_using_expect.feature +2 -2
  14. data/features/message_expectations/expect_message_using_should_receive.feature +2 -2
  15. data/features/message_expectations/receive_counts.feature +7 -7
  16. data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +3 -3
  17. data/features/method_stubs/README.md +3 -0
  18. data/features/method_stubs/any_instance.feature +11 -11
  19. data/features/method_stubs/as_null_object.feature +4 -4
  20. data/features/method_stubs/simple_return_value_with_stub.feature +7 -7
  21. data/features/method_stubs/stub_chain.feature +3 -3
  22. data/features/method_stubs/stub_implementation.feature +2 -2
  23. data/features/method_stubs/to_ary.feature +2 -2
  24. data/features/mutating_constants/hiding_defined_constant.feature +2 -2
  25. data/features/mutating_constants/stub_defined_constant.feature +5 -5
  26. data/features/mutating_constants/stub_undefined_constant.feature +6 -6
  27. data/features/outside_rspec/configuration.feature +0 -2
  28. data/features/outside_rspec/standalone.feature +1 -1
  29. data/features/spies/spy_partial_mock_method.feature +2 -2
  30. data/features/spies/spy_pure_mock_method.feature +5 -5
  31. data/features/spies/spy_unstubbed_method.feature +1 -1
  32. data/features/support/env.rb +10 -1
  33. data/features/test_frameworks/test_unit.feature +1 -1
  34. data/features/verifying_doubles/class_doubles.feature +88 -0
  35. data/features/verifying_doubles/dynamic_classes.feature +72 -0
  36. data/features/verifying_doubles/introduction.feature +85 -0
  37. data/features/verifying_doubles/object_doubles.feature +65 -0
  38. data/features/verifying_doubles/partial_doubles.feature +34 -0
  39. data/lib/rspec/mocks.rb +8 -34
  40. data/lib/rspec/mocks/any_instance/chain.rb +4 -34
  41. data/lib/rspec/mocks/any_instance/expectation_chain.rb +14 -4
  42. data/lib/rspec/mocks/any_instance/message_chains.rb +27 -12
  43. data/lib/rspec/mocks/any_instance/recorder.rb +23 -31
  44. data/lib/rspec/mocks/any_instance/stub_chain.rb +9 -4
  45. data/lib/rspec/mocks/argument_list_matcher.rb +8 -1
  46. data/lib/rspec/mocks/argument_matchers.rb +26 -12
  47. data/lib/rspec/mocks/arity_calculator.rb +66 -0
  48. data/lib/rspec/mocks/configuration.rb +42 -14
  49. data/lib/rspec/mocks/error_generator.rb +34 -10
  50. data/lib/rspec/mocks/example_methods.rb +64 -19
  51. data/lib/rspec/mocks/extensions/marshal.rb +0 -15
  52. data/lib/rspec/mocks/framework.rb +4 -4
  53. data/lib/rspec/mocks/instance_method_stasher.rb +80 -62
  54. data/lib/rspec/mocks/matchers/have_received.rb +18 -14
  55. data/lib/rspec/mocks/matchers/receive.rb +29 -7
  56. data/lib/rspec/mocks/matchers/receive_messages.rb +72 -0
  57. data/lib/rspec/mocks/message_expectation.rb +95 -148
  58. data/lib/rspec/mocks/method_double.rb +77 -139
  59. data/lib/rspec/mocks/method_reference.rb +95 -0
  60. data/lib/rspec/mocks/mock.rb +1 -1
  61. data/lib/rspec/mocks/mutate_const.rb +12 -9
  62. data/lib/rspec/mocks/object_reference.rb +90 -0
  63. data/lib/rspec/mocks/order_group.rb +49 -7
  64. data/lib/rspec/mocks/proxy.rb +72 -33
  65. data/lib/rspec/mocks/proxy_for_nil.rb +2 -2
  66. data/lib/rspec/mocks/space.rb +13 -18
  67. data/lib/rspec/mocks/stub_chain.rb +2 -2
  68. data/lib/rspec/mocks/syntax.rb +61 -36
  69. data/lib/rspec/mocks/targets.rb +40 -19
  70. data/lib/rspec/mocks/test_double.rb +12 -56
  71. data/lib/rspec/mocks/verifying_double.rb +77 -0
  72. data/lib/rspec/mocks/verifying_message_expecation.rb +60 -0
  73. data/lib/rspec/mocks/verifying_proxy.rb +151 -0
  74. data/lib/rspec/mocks/version.rb +1 -1
  75. data/spec/rspec/mocks/and_call_original_spec.rb +34 -30
  76. data/spec/rspec/mocks/and_yield_spec.rb +2 -2
  77. data/spec/rspec/mocks/any_instance/message_chains_spec.rb +1 -1
  78. data/spec/rspec/mocks/any_instance_spec.rb +53 -260
  79. data/spec/rspec/mocks/argument_expectation_spec.rb +4 -4
  80. data/spec/rspec/mocks/arity_calculator_spec.rb +95 -0
  81. data/spec/rspec/mocks/array_including_matcher_spec.rb +41 -0
  82. data/spec/rspec/mocks/at_least_spec.rb +4 -32
  83. data/spec/rspec/mocks/block_return_value_spec.rb +4 -135
  84. data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +10 -11
  85. data/spec/rspec/mocks/configuration_spec.rb +79 -0
  86. data/spec/rspec/mocks/double_spec.rb +10 -78
  87. data/spec/rspec/mocks/extensions/marshal_spec.rb +0 -8
  88. data/spec/rspec/mocks/failing_argument_matchers_spec.rb +49 -4
  89. data/spec/rspec/mocks/instance_method_stasher_spec.rb +20 -3
  90. data/spec/rspec/mocks/matchers/have_received_spec.rb +74 -0
  91. data/spec/rspec/mocks/matchers/receive_messages_spec.rb +140 -0
  92. data/spec/rspec/mocks/matchers/receive_spec.rb +82 -42
  93. data/spec/rspec/mocks/methods_spec.rb +1 -1
  94. data/spec/rspec/mocks/{bug_report_830_spec.rb → mock_expectation_error_spec.rb} +4 -3
  95. data/spec/rspec/mocks/mock_ordering_spec.rb +11 -0
  96. data/spec/rspec/mocks/mock_space_spec.rb +10 -1
  97. data/spec/rspec/mocks/mock_spec.rb +26 -82
  98. data/spec/rspec/mocks/multiple_return_value_spec.rb +1 -1
  99. data/spec/rspec/mocks/mutate_const_spec.rb +18 -5
  100. data/spec/rspec/mocks/null_object_mock_spec.rb +6 -4
  101. data/spec/rspec/mocks/options_hash_spec.rb +3 -3
  102. data/spec/rspec/mocks/order_group_spec.rb +27 -0
  103. data/spec/rspec/mocks/partial_mock_spec.rb +101 -1
  104. data/spec/rspec/mocks/passing_argument_matchers_spec.rb +3 -20
  105. data/spec/rspec/mocks/record_messages_spec.rb +4 -4
  106. data/spec/rspec/mocks/serialization_spec.rb +4 -6
  107. data/spec/rspec/mocks/space_spec.rb +3 -3
  108. data/spec/rspec/mocks/stub_chain_spec.rb +0 -12
  109. data/spec/rspec/mocks/stub_spec.rb +23 -44
  110. data/spec/rspec/mocks/test_double_spec.rb +3 -22
  111. data/spec/rspec/mocks/verifying_double_spec.rb +327 -0
  112. data/spec/rspec/mocks/verifying_message_expecation_spec.rb +68 -0
  113. data/spec/rspec/mocks_spec.rb +16 -39
  114. data/spec/spec_helper.rb +29 -18
  115. metadata +131 -86
  116. metadata.gz.sig +1 -0
  117. data/features/message_expectations/expect_any_instance_of.feature +0 -27
  118. data/lib/rspec/mocks/caller_filter.rb +0 -60
  119. data/lib/rspec/mocks/deprecation.rb +0 -26
  120. data/lib/rspec/mocks/extensions/instance_exec.rb +0 -34
  121. data/lib/rspec/mocks/extensions/proc.rb +0 -63
  122. data/lib/spec/mocks.rb +0 -4
  123. data/spec/rspec/mocks/and_return_spec.rb +0 -17
  124. data/spec/rspec/mocks/any_number_of_times_spec.rb +0 -36
  125. data/spec/rspec/mocks/before_all_spec.rb +0 -74
  126. data/spec/rspec/mocks/bug_report_10260_spec.rb +0 -8
  127. data/spec/rspec/mocks/bug_report_10263_spec.rb +0 -27
  128. data/spec/rspec/mocks/bug_report_11545_spec.rb +0 -32
  129. data/spec/rspec/mocks/bug_report_496_spec.rb +0 -17
  130. data/spec/rspec/mocks/bug_report_600_spec.rb +0 -22
  131. data/spec/rspec/mocks/bug_report_7611_spec.rb +0 -16
  132. data/spec/rspec/mocks/bug_report_8165_spec.rb +0 -31
  133. data/spec/rspec/mocks/bug_report_957_spec.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 471207f568702e87294befee6dcfc4516e1fa21f
4
- data.tar.gz: a6049d633e700b93394acdd366bf7b563224d312
5
- SHA512:
6
- metadata.gz: a2c42ecb51e479ba57358c837a3a7d5befe5e3880ac6ece6b948b7f5a6955f2473b745cb19e4cbe0b2e31d8bd2a8f3b01ce9e9aaa95004d2b861fb780f704f10
7
- data.tar.gz: 214851eb67b0ac4a03bf1db3433c1ee94d13130eed03f583f834d32183a15d99313c478c2178c683345e60d24bb2fa54a68abf0387e6c498856b3b309b6fb64e
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=
@@ -0,0 +1,2 @@
1
+ }��{ �ͨ�k}���{Z�E ����@;P�?�t���.�+��D.�d�����p3x|�Vv��hhv�p@�i�R8���E(���¸D~�����~�3�jC1Of+Wm7*��k�
2
+ �3�
@@ -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
@@ -1,70 +1,71 @@
1
- ### 2.99.4 / 2015-06-19
2
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.99.3...v2.99.4)
3
-
4
- Bug Fixes:
5
-
6
- * Add missing deprecation for using `with` with no arguments e.g. `with()`. (Yousuke, #970)
7
-
8
- ### 2.99.3 / 2015-01-09
9
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.99.2...v2.99.3)
10
-
11
- Bug Fixes:
12
-
13
- * Fix regression that caused an error when a test double was deserialized from YAML. (Yuji Nakayama, #777)
14
-
15
- ### 2.99.2 / 2014-07-21
16
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.99.1...v2.99.2)
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
- * Warn about upcoming change to `#===` matching and `DateTime#===` behaviour.
21
- (Jon Rowe, #735)
22
-
23
- ### 2.99.1 / 2014-06-12
24
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.99.0...v2.99.1)
25
-
26
- Bug Fixes:
27
-
28
- * Fix bug that caused errors at the end of each example
29
- when a `double.as_null_object` had been frozen. (Yuji Nakayama, #698)
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
- * Deprecate freezing a test double. (Yuji Nakayama, #698)
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
- ### 2.99.0 / 2014-06-01
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
- * Deprecate `RSpec::Mocks::Mock` in favor of `RSpec::Mocks::Double`.
55
- (Myron Marston)
56
- * Deprecate the `host` argument of `RSpec::Mocks.setup`. Instead
57
- `RSpec::Mocks::ExampleMethods` should be included directly in the scope where
58
- RSpec's mocking capabilities are used. (Sam Phippen)
59
- * Deprecate using any of rspec-mocks' features outside the per-test
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.4...v2.99.0.beta1)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.3...v2.14.4)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.2...v2.14.3)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.1...v2.14.2)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.0...v2.14.1)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.0.rc1...v2.14.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.13.0...v2.14.0.rc1)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.13.0...v2.13.1)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.12.2...v2.13.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.12.1...v.2.12.2)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.12.0...v2.12.1)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.11.3...v2.12.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.11.2...v2.11.3)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.11.1...v2.11.2)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.11.0...v2.11.1)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.10.1...v2.11.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.10.0...v2.10.1)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.9.0...v2.10.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.8.0...v2.9.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.8.0.rc2...v2.8.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.8.0.rc1...v2.8.0.rc2)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.7.0...v2.8.0.rc1)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.6.0...v2.7.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.5.0...v2.6.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.4.0...v2.5.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.3.0...v2.4.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.2.0...v2.3.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.1.0...v2.2.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.1...v2.1.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.22...v2.0.0)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.22...v2.0.0.rc)
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
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.20...v2.0.0.beta.22)
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
 
@@ -1,5 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
+ Copyright (c) 2012 David Chelimsky, Myron Marston
3
4
  Copyright (c) 2006 David Chelimsky, The RSpec Development Team
4
5
  Copyright (c) 2005 Steven Baker
5
6
 
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.stub(:title) { "The RSpec Book" }
30
- book.stub(:title => "The RSpec 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.stub(:roll).and_return(1,2,3)
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.stub(:players).and_return([stub(:name => "David")])
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.should_receive(:validate).with("02134")
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.stub(:find) { 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.should_receive(:find) { person }
145
+ expect(Person).to receive(:find) { person }
125
146
  ```
126
147
 
127
- We can do this with any object in a system because rspec-mocks adds the `stub`
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.should_receive(:msg).with(*args)
137
- double.should_not_receive(:msg).with(*args)
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.should_receive(:msg).with("A", 1, 3)
144
- double.should_receive(:msg).with("B", 2, 4)
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.should_receive(:msg).with(no_args())
161
- double.should_receive(:msg).with(any_args())
162
- double.should_receive(:msg).with(1, kind_of(Numeric), "b") #2nd argument can be any kind of Numeric
163
- double.should_receive(:msg).with(1, boolean(), "b") #2nd argument can be true or false
164
- double.should_receive(:msg).with(1, /abc/, "b") #2nd argument can be any String matching the submitted Regexp
165
- double.should_receive(:msg).with(1, anything(), "b") #2nd argument can be anything at all
166
- double.should_receive(:msg).with(1, duck_type(:abs, :div), "b")
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.should_receive(:msg).once
174
- double.should_receive(:msg).twice
175
- double.should_receive(:msg).exactly(n).times
176
- double.should_receive(:msg).at_least(:once)
177
- double.should_receive(:msg).at_least(:twice)
178
- double.should_receive(:msg).at_least(n).times
179
- double.should_receive(:msg).at_most(:once)
180
- double.should_receive(:msg).at_most(:twice)
181
- double.should_receive(:msg).at_most(n).times
182
- double.should_receive(:msg).any_number_of_times
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.should_receive(:msg).ordered
189
- double.should_receive(:other_msg).ordered
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.should_receive(:msg).with("A", 1, 3).ordered
197
- double.should_receive(:msg).with("B", 2, 4).ordered
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 `stub` or `should_receive`:
223
+ a block to `receive`:
205
224
 
206
225
  ```ruby
207
- double.should_receive(:msg) { value }
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.should_receive(:msg).and_return(value)
215
- double.should_receive(:msg).exactly(3).times.and_return(value1, value2, value3)
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.should_receive(:msg).and_raise(error)
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.should_receive(:msg).and_throw(:msg)
221
- double.should_receive(:msg).and_yield(values,to,yield)
222
- double.should_receive(:msg).and_yield(values,to,yield).and_yield(some,other,values,this,time)
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.stub(:msg).and_return(value)
230
- double.stub(:msg).and_return(value1, value2, value3)
231
- double.stub(:msg).and_raise(error)
232
- double.stub(:msg).and_throw(:msg)
233
- double.stub(:msg).and_yield(values,to,yield)
234
- double.stub(:msg).and_yield(values,to,yield).and_yield(some,other,values,this,time)
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.should_receive(:msg) do |arg|
246
- arg.size.should eq(7)
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.should_receive(:msg) do |&arg|
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.should_receive(:find).and_call_original
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.should_receive(:<<).with("illegal value").once.and_raise(ArgumentError)
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://www.mockobjects.com/files/endotesting.pdf
307
- * Mock Roles, Not Objects: http://www.mockobjects.com/files/mockrolesnotobjects.pdf
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