mocha 0.5.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/README +4 -4
  2. data/RELEASE +45 -0
  3. data/Rakefile +55 -33
  4. data/lib/mocha.rb +1 -0
  5. data/lib/mocha/any_instance_method.rb +24 -4
  6. data/lib/mocha/backtrace_filter.rb +17 -0
  7. data/lib/mocha/cardinality.rb +92 -0
  8. data/lib/mocha/central.rb +1 -9
  9. data/lib/mocha/change_state_side_effect.rb +19 -0
  10. data/lib/mocha/class_method.rb +25 -5
  11. data/lib/mocha/configuration.rb +60 -0
  12. data/lib/mocha/exception_raiser.rb +1 -1
  13. data/lib/mocha/expectation.rb +109 -48
  14. data/lib/mocha/expectation_error.rb +6 -6
  15. data/lib/mocha/expectation_list.rb +10 -14
  16. data/lib/mocha/in_state_ordering_constraint.rb +19 -0
  17. data/lib/mocha/instance_method.rb +9 -0
  18. data/lib/mocha/logger.rb +15 -0
  19. data/lib/mocha/mock.rb +19 -14
  20. data/lib/mocha/mockery.rb +166 -0
  21. data/lib/mocha/module_method.rb +17 -0
  22. data/lib/mocha/names.rb +53 -0
  23. data/lib/mocha/object.rb +26 -9
  24. data/lib/mocha/parameter_matchers.rb +2 -1
  25. data/lib/mocha/parameter_matchers/all_of.rb +3 -3
  26. data/lib/mocha/parameter_matchers/any_of.rb +3 -3
  27. data/lib/mocha/parameter_matchers/anything.rb +1 -1
  28. data/lib/mocha/parameter_matchers/has_entries.rb +4 -1
  29. data/lib/mocha/parameter_matchers/has_entry.rb +3 -2
  30. data/lib/mocha/parameter_matchers/has_key.rb +1 -1
  31. data/lib/mocha/parameter_matchers/has_value.rb +1 -1
  32. data/lib/mocha/parameter_matchers/not.rb +2 -2
  33. data/lib/mocha/parameter_matchers/object.rb +1 -1
  34. data/lib/mocha/parameter_matchers/optionally.rb +22 -0
  35. data/lib/mocha/parameter_matchers/regexp_matches.rb +2 -2
  36. data/lib/mocha/parameter_matchers/responds_with.rb +43 -0
  37. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +43 -0
  38. data/lib/mocha/single_return_value.rb +2 -9
  39. data/lib/mocha/standalone.rb +151 -17
  40. data/lib/mocha/state_machine.rb +91 -0
  41. data/lib/mocha/stubbing_error.rb +16 -0
  42. data/lib/mocha/test_case_adapter.rb +76 -22
  43. data/lib/stubba.rb +2 -1
  44. data/test/acceptance/acceptance_test_helper.rb +38 -0
  45. data/test/acceptance/bug_18914_test.rb +43 -0
  46. data/test/acceptance/{expected_invocation_count_acceptance_test.rb → expected_invocation_count_test.rb} +29 -20
  47. data/test/acceptance/failure_messages_test.rb +64 -0
  48. data/test/acceptance/{mocha_acceptance_test.rb → mocha_example_test.rb} +5 -5
  49. data/test/{integration/mocha_test_result_integration_test.rb → acceptance/mocha_test_result_test.rb} +19 -40
  50. data/test/acceptance/mock_test.rb +100 -0
  51. data/test/acceptance/{mock_with_initializer_block_acceptance_test.rb → mock_with_initializer_block_test.rb} +12 -5
  52. data/test/acceptance/{mocked_methods_dispatch_acceptance_test.rb → mocked_methods_dispatch_test.rb} +12 -5
  53. data/test/acceptance/{optional_parameters_acceptance_test.rb → optional_parameters_test.rb} +11 -4
  54. data/test/acceptance/{parameter_matcher_acceptance_test.rb → parameter_matcher_test.rb} +67 -5
  55. data/test/acceptance/{partial_mocks_acceptance_test.rb → partial_mocks_test.rb} +12 -5
  56. data/test/acceptance/return_value_test.rb +52 -0
  57. data/test/acceptance/{sequence_acceptance_test.rb → sequence_test.rb} +13 -6
  58. data/test/acceptance/{standalone_acceptance_test.rb → standalone_test.rb} +19 -11
  59. data/test/acceptance/states_test.rb +70 -0
  60. data/test/acceptance/stub_any_instance_method_test.rb +195 -0
  61. data/test/acceptance/stub_class_method_test.rb +203 -0
  62. data/test/acceptance/stub_everything_test.rb +56 -0
  63. data/test/acceptance/stub_instance_method_test.rb +165 -0
  64. data/test/acceptance/stub_module_method_test.rb +163 -0
  65. data/test/acceptance/stub_test.rb +52 -0
  66. data/test/acceptance/{stubba_acceptance_test.rb → stubba_example_test.rb} +1 -1
  67. data/test/{integration/stubba_test_result_integration_test.rb → acceptance/stubba_test_result_test.rb} +17 -36
  68. data/test/acceptance/stubbing_error_backtrace_test.rb +64 -0
  69. data/test/acceptance/stubbing_method_unnecessarily_test.rb +65 -0
  70. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +130 -0
  71. data/test/acceptance/stubbing_non_existent_class_method_test.rb +155 -0
  72. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +145 -0
  73. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +130 -0
  74. data/test/acceptance/stubbing_non_public_class_method_test.rb +161 -0
  75. data/test/acceptance/stubbing_non_public_instance_method_test.rb +141 -0
  76. data/test/acceptance/stubbing_on_non_mock_object_test.rb +64 -0
  77. data/test/execution_point.rb +3 -1
  78. data/test/simple_counter.rb +13 -0
  79. data/test/test_helper.rb +0 -1
  80. data/test/test_runner.rb +6 -4
  81. data/test/unit/any_instance_method_test.rb +1 -1
  82. data/test/unit/array_inspect_test.rb +1 -1
  83. data/test/unit/backtrace_filter_test.rb +19 -0
  84. data/test/unit/cardinality_test.rb +56 -0
  85. data/test/unit/central_test.rb +4 -63
  86. data/test/unit/change_state_side_effect_test.rb +41 -0
  87. data/test/unit/class_method_test.rb +38 -1
  88. data/test/unit/date_time_inspect_test.rb +1 -1
  89. data/test/unit/{expectation_raiser_test.rb → exception_raiser_test.rb} +14 -0
  90. data/test/unit/expectation_list_test.rb +4 -22
  91. data/test/unit/expectation_test.rb +70 -94
  92. data/test/unit/in_state_ordering_constraint_test.rb +43 -0
  93. data/test/unit/mock_test.rb +16 -37
  94. data/test/unit/mockery_test.rb +149 -0
  95. data/test/unit/{no_yield_test.rb → no_yields_test.rb} +0 -0
  96. data/test/unit/object_test.rb +6 -89
  97. data/test/unit/parameter_matchers/equals_test.rb +25 -0
  98. data/test/unit/parameter_matchers/has_entries_test.rb +22 -1
  99. data/test/unit/parameter_matchers/has_entry_test.rb +24 -2
  100. data/test/unit/parameter_matchers/has_key_test.rb +11 -0
  101. data/test/unit/parameter_matchers/has_value_test.rb +12 -0
  102. data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -1
  103. data/test/unit/parameter_matchers/responds_with_test.rb +25 -0
  104. data/test/unit/parameter_matchers/stub_matcher.rb +4 -0
  105. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +25 -0
  106. data/test/unit/single_return_value_test.rb +0 -19
  107. data/test/unit/state_machine_test.rb +98 -0
  108. metadata +108 -69
  109. data/lib/mocha/auto_verify.rb +0 -118
  110. data/lib/mocha/infinite_range.rb +0 -25
  111. data/lib/mocha/missing_expectation.rb +0 -17
  112. data/lib/mocha/setup_and_teardown.rb +0 -23
  113. data/lib/mocha/stub.rb +0 -18
  114. data/test/integration/stubba_integration_test.rb +0 -89
  115. data/test/unit/auto_verify_test.rb +0 -129
  116. data/test/unit/expectation_error_test.rb +0 -24
  117. data/test/unit/infinite_range_test.rb +0 -53
  118. data/test/unit/missing_expectation_test.rb +0 -42
  119. data/test/unit/setup_and_teardown_test.rb +0 -76
  120. data/test/unit/stub_test.rb +0 -24
metadata CHANGED
@@ -1,52 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: mocha
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.5.6
7
- date: 2007-12-23 00:00:00 +00:00
8
- summary: Mocking and stubbing library
9
- require_paths:
10
- - lib
11
- email: mocha-developer@rubyforge.org
12
- homepage: http://mocha.rubyforge.org
13
- rubyforge_project: mocha
14
- description: Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
15
- autorequire: mocha
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.9.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - James Mead
8
+ autorequire: mocha
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-24 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
25
+ email: mocha-developer@rubyforge.org
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - COPYING
31
33
  files:
32
34
  - lib/mocha/any_instance_method.rb
33
- - lib/mocha/auto_verify.rb
35
+ - lib/mocha/backtrace_filter.rb
36
+ - lib/mocha/cardinality.rb
34
37
  - lib/mocha/central.rb
38
+ - lib/mocha/change_state_side_effect.rb
35
39
  - lib/mocha/class_method.rb
40
+ - lib/mocha/configuration.rb
36
41
  - lib/mocha/deprecation.rb
37
42
  - lib/mocha/exception_raiser.rb
38
43
  - lib/mocha/expectation.rb
39
44
  - lib/mocha/expectation_error.rb
40
45
  - lib/mocha/expectation_list.rb
41
- - lib/mocha/infinite_range.rb
46
+ - lib/mocha/in_state_ordering_constraint.rb
42
47
  - lib/mocha/inspect.rb
43
48
  - lib/mocha/instance_method.rb
44
49
  - lib/mocha/is_a.rb
50
+ - lib/mocha/logger.rb
45
51
  - lib/mocha/metaclass.rb
46
52
  - lib/mocha/method_matcher.rb
47
- - lib/mocha/missing_expectation.rb
48
53
  - lib/mocha/mock.rb
54
+ - lib/mocha/mockery.rb
55
+ - lib/mocha/module_method.rb
49
56
  - lib/mocha/multiple_yields.rb
57
+ - lib/mocha/names.rb
50
58
  - lib/mocha/no_yields.rb
51
59
  - lib/mocha/object.rb
52
60
  - lib/mocha/parameter_matchers/all_of.rb
@@ -67,63 +75,88 @@ files:
67
75
  - lib/mocha/parameter_matchers/object.rb
68
76
  - lib/mocha/parameter_matchers/optionally.rb
69
77
  - lib/mocha/parameter_matchers/regexp_matches.rb
78
+ - lib/mocha/parameter_matchers/responds_with.rb
79
+ - lib/mocha/parameter_matchers/yaml_equivalent.rb
70
80
  - lib/mocha/parameter_matchers.rb
71
81
  - lib/mocha/parameters_matcher.rb
72
82
  - lib/mocha/pretty_parameters.rb
73
83
  - lib/mocha/return_values.rb
74
84
  - lib/mocha/sequence.rb
75
- - lib/mocha/setup_and_teardown.rb
76
85
  - lib/mocha/single_return_value.rb
77
86
  - lib/mocha/single_yield.rb
78
87
  - lib/mocha/standalone.rb
79
- - lib/mocha/stub.rb
88
+ - lib/mocha/state_machine.rb
89
+ - lib/mocha/stubbing_error.rb
80
90
  - lib/mocha/test_case_adapter.rb
81
91
  - lib/mocha/yield_parameters.rb
82
92
  - lib/mocha.rb
83
93
  - lib/mocha_standalone.rb
84
94
  - lib/stubba.rb
85
- - test/acceptance/expected_invocation_count_acceptance_test.rb
86
- - test/acceptance/mocha_acceptance_test.rb
87
- - test/acceptance/mock_with_initializer_block_acceptance_test.rb
88
- - test/acceptance/mocked_methods_dispatch_acceptance_test.rb
89
- - test/acceptance/optional_parameters_acceptance_test.rb
90
- - test/acceptance/parameter_matcher_acceptance_test.rb
91
- - test/acceptance/partial_mocks_acceptance_test.rb
92
- - test/acceptance/sequence_acceptance_test.rb
93
- - test/acceptance/standalone_acceptance_test.rb
94
- - test/acceptance/stubba_acceptance_test.rb
95
+ - test/acceptance/acceptance_test_helper.rb
96
+ - test/acceptance/bug_18914_test.rb
97
+ - test/acceptance/expected_invocation_count_test.rb
98
+ - test/acceptance/failure_messages_test.rb
99
+ - test/acceptance/mocha_example_test.rb
100
+ - test/acceptance/mocha_test_result_test.rb
101
+ - test/acceptance/mock_test.rb
102
+ - test/acceptance/mock_with_initializer_block_test.rb
103
+ - test/acceptance/mocked_methods_dispatch_test.rb
104
+ - test/acceptance/optional_parameters_test.rb
105
+ - test/acceptance/parameter_matcher_test.rb
106
+ - test/acceptance/partial_mocks_test.rb
107
+ - test/acceptance/return_value_test.rb
108
+ - test/acceptance/sequence_test.rb
109
+ - test/acceptance/standalone_test.rb
110
+ - test/acceptance/states_test.rb
111
+ - test/acceptance/stub_any_instance_method_test.rb
112
+ - test/acceptance/stub_class_method_test.rb
113
+ - test/acceptance/stub_everything_test.rb
114
+ - test/acceptance/stub_instance_method_test.rb
115
+ - test/acceptance/stub_module_method_test.rb
116
+ - test/acceptance/stub_test.rb
117
+ - test/acceptance/stubba_example_test.rb
118
+ - test/acceptance/stubba_test_result_test.rb
119
+ - test/acceptance/stubbing_error_backtrace_test.rb
120
+ - test/acceptance/stubbing_method_unnecessarily_test.rb
121
+ - test/acceptance/stubbing_non_existent_any_instance_method_test.rb
122
+ - test/acceptance/stubbing_non_existent_class_method_test.rb
123
+ - test/acceptance/stubbing_non_existent_instance_method_test.rb
124
+ - test/acceptance/stubbing_non_public_any_instance_method_test.rb
125
+ - test/acceptance/stubbing_non_public_class_method_test.rb
126
+ - test/acceptance/stubbing_non_public_instance_method_test.rb
127
+ - test/acceptance/stubbing_on_non_mock_object_test.rb
95
128
  - test/active_record_test_case.rb
96
129
  - test/deprecation_disabler.rb
97
130
  - test/execution_point.rb
98
- - test/integration/mocha_test_result_integration_test.rb
99
- - test/integration/stubba_integration_test.rb
100
- - test/integration/stubba_test_result_integration_test.rb
101
131
  - test/method_definer.rb
132
+ - test/simple_counter.rb
102
133
  - test/test_helper.rb
103
134
  - test/test_runner.rb
104
135
  - test/unit/any_instance_method_test.rb
105
136
  - test/unit/array_inspect_test.rb
106
- - test/unit/auto_verify_test.rb
137
+ - test/unit/backtrace_filter_test.rb
138
+ - test/unit/cardinality_test.rb
107
139
  - test/unit/central_test.rb
140
+ - test/unit/change_state_side_effect_test.rb
108
141
  - test/unit/class_method_test.rb
109
142
  - test/unit/date_time_inspect_test.rb
110
- - test/unit/expectation_error_test.rb
143
+ - test/unit/exception_raiser_test.rb
111
144
  - test/unit/expectation_list_test.rb
112
- - test/unit/expectation_raiser_test.rb
113
145
  - test/unit/expectation_test.rb
114
146
  - test/unit/hash_inspect_test.rb
115
- - test/unit/infinite_range_test.rb
147
+ - test/unit/in_state_ordering_constraint_test.rb
116
148
  - test/unit/metaclass_test.rb
117
149
  - test/unit/method_matcher_test.rb
118
- - test/unit/missing_expectation_test.rb
119
150
  - test/unit/mock_test.rb
151
+ - test/unit/mockery_test.rb
120
152
  - test/unit/multiple_yields_test.rb
121
- - test/unit/no_yield_test.rb
153
+ - test/unit/no_yields_test.rb
122
154
  - test/unit/object_inspect_test.rb
123
155
  - test/unit/object_test.rb
124
156
  - test/unit/parameter_matchers/all_of_test.rb
125
157
  - test/unit/parameter_matchers/any_of_test.rb
126
158
  - test/unit/parameter_matchers/anything_test.rb
159
+ - test/unit/parameter_matchers/equals_test.rb
127
160
  - test/unit/parameter_matchers/has_entries_test.rb
128
161
  - test/unit/parameter_matchers/has_entry_test.rb
129
162
  - test/unit/parameter_matchers/has_key_test.rb
@@ -134,15 +167,16 @@ files:
134
167
  - test/unit/parameter_matchers/kind_of_test.rb
135
168
  - test/unit/parameter_matchers/not_test.rb
136
169
  - test/unit/parameter_matchers/regexp_matches_test.rb
170
+ - test/unit/parameter_matchers/responds_with_test.rb
137
171
  - test/unit/parameter_matchers/stub_matcher.rb
172
+ - test/unit/parameter_matchers/yaml_equivalent_test.rb
138
173
  - test/unit/parameters_matcher_test.rb
139
174
  - test/unit/return_values_test.rb
140
175
  - test/unit/sequence_test.rb
141
- - test/unit/setup_and_teardown_test.rb
142
176
  - test/unit/single_return_value_test.rb
143
177
  - test/unit/single_yield_test.rb
178
+ - test/unit/state_machine_test.rb
144
179
  - test/unit/string_inspect_test.rb
145
- - test/unit/stub_test.rb
146
180
  - test/unit/yield_parameters_test.rb
147
181
  - examples/misc.rb
148
182
  - examples/mocha.rb
@@ -152,30 +186,35 @@ files:
152
186
  - Rakefile
153
187
  - README
154
188
  - RELEASE
155
- test_files: []
156
-
189
+ has_rdoc: true
190
+ homepage: http://mocha.rubyforge.org
191
+ post_install_message:
157
192
  rdoc_options:
158
193
  - --title
159
194
  - Mocha
160
195
  - --main
161
196
  - README
162
197
  - --line-numbers
163
- extra_rdoc_files:
164
- - README
165
- - COPYING
166
- executables: []
167
-
168
- extensions: []
169
-
198
+ require_paths:
199
+ - lib
200
+ required_ruby_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: "0"
205
+ version:
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: "0"
211
+ version:
170
212
  requirements: []
171
213
 
172
- dependencies:
173
- - !ruby/object:Gem::Dependency
174
- name: rake
175
- version_requirement:
176
- version_requirements: !ruby/object:Gem::Version::Requirement
177
- requirements:
178
- - - ">"
179
- - !ruby/object:Gem::Version
180
- version: 0.0.0
181
- version:
214
+ rubyforge_project: mocha
215
+ rubygems_version: 1.1.1
216
+ signing_key:
217
+ specification_version: 2
218
+ summary: Mocking and stubbing library
219
+ test_files: []
220
+
@@ -1,118 +0,0 @@
1
- require 'mocha/mock'
2
- require 'mocha/sequence'
3
-
4
- module Mocha # :nodoc:
5
-
6
- # Methods added to TestCase allowing creation of traditional mock objects.
7
- #
8
- # Mocks created this way will have their expectations automatically verified at the end of the test.
9
- #
10
- # See Mock for methods on mock objects.
11
- module AutoVerify
12
-
13
- def mocks # :nodoc:
14
- @mocks ||= []
15
- end
16
-
17
- def reset_mocks # :nodoc:
18
- @mocks = nil
19
- end
20
-
21
- # :call-seq: mock(name, &block) -> mock object
22
- # mock(expected_methods = {}, &block) -> mock object
23
- # mock(name, expected_methods = {}, &block) -> mock object
24
- #
25
- # Creates a mock object.
26
- #
27
- # +name+ is a +String+ identifier for the mock object.
28
- #
29
- # +expected_methods+ is a +Hash+ with expected method name symbols as keys and corresponding return values as values.
30
- #
31
- # +block+ is a block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs.
32
- #
33
- # Note that (contrary to expectations set up by #stub) these expectations <b>must</b> be fulfilled during the test.
34
- # def test_product
35
- # product = mock('ipod_product', :manufacturer => 'ipod', :price => 100)
36
- # assert_equal 'ipod', product.manufacturer
37
- # assert_equal 100, product.price
38
- # # an error will be raised unless both Product#manufacturer and Product#price have been called
39
- # end
40
- def mock(*arguments, &block)
41
- name = arguments.shift if arguments.first.is_a?(String)
42
- expectations = arguments.shift || {}
43
- mock = Mock.new(name, &block)
44
- mock.expects(expectations)
45
- mocks << mock
46
- mock
47
- end
48
-
49
- # :call-seq: stub(name, &block) -> mock object
50
- # stub(stubbed_methods = {}, &block) -> mock object
51
- # stub(name, stubbed_methods = {}, &block) -> mock object
52
- #
53
- # Creates a mock object.
54
- #
55
- # +name+ is a +String+ identifier for the mock object.
56
- #
57
- # +stubbed_methods+ is a +Hash+ with stubbed method name symbols as keys and corresponding return values as values.
58
- #
59
- # +block+ is a block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs.
60
- #
61
- # Note that (contrary to expectations set up by #mock) these expectations <b>need not</b> be fulfilled during the test.
62
- # def test_product
63
- # product = stub('ipod_product', :manufacturer => 'ipod', :price => 100)
64
- # assert_equal 'ipod', product.manufacturer
65
- # assert_equal 100, product.price
66
- # # an error will not be raised even if Product#manufacturer and Product#price have not been called
67
- # end
68
- def stub(*arguments, &block)
69
- name = arguments.shift if arguments.first.is_a?(String)
70
- expectations = arguments.shift || {}
71
- stub = Mock.new(name, &block)
72
- stub.stubs(expectations)
73
- mocks << stub
74
- stub
75
- end
76
-
77
- # :call-seq: stub_everything(name, &block) -> mock object
78
- # stub_everything(stubbed_methods = {}, &block) -> mock object
79
- # stub_everything(name, stubbed_methods = {}, &block) -> mock object
80
- #
81
- # Creates a mock object that accepts calls to any method.
82
- #
83
- # By default it will return +nil+ for any method call.
84
- #
85
- # +block+ is a block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs.
86
- #
87
- # +name+ and +stubbed_methods+ work in the same way as for #stub.
88
- # def test_product
89
- # product = stub_everything('ipod_product', :price => 100)
90
- # assert_nil product.manufacturer
91
- # assert_nil product.any_old_method
92
- # assert_equal 100, product.price
93
- # end
94
- def stub_everything(*arguments, &block)
95
- name = arguments.shift if arguments.first.is_a?(String)
96
- expectations = arguments.shift || {}
97
- stub = Mock.new(name, &block)
98
- stub.stub_everything
99
- stub.stubs(expectations)
100
- mocks << stub
101
- stub
102
- end
103
-
104
- def verify_mocks # :nodoc:
105
- mocks.each { |mock| mock.verify { yield if block_given? } }
106
- end
107
-
108
- def teardown_mocks # :nodoc:
109
- reset_mocks
110
- end
111
-
112
- def sequence(name) # :nodoc:
113
- Sequence.new(name)
114
- end
115
-
116
- end
117
-
118
- end
@@ -1,25 +0,0 @@
1
- class Range
2
-
3
- def self.at_least(minimum_value)
4
- Range.new(minimum_value, infinite)
5
- end
6
-
7
- def self.at_most(maximum_value)
8
- Range.new(-infinite, maximum_value, false)
9
- end
10
-
11
- def self.infinite
12
- 1/0.0
13
- end
14
-
15
- def mocha_inspect
16
- if first.respond_to?(:to_f) and first.to_f.infinite? then
17
- return "at most #{last}"
18
- elsif last.respond_to?(:to_f) and last.to_f.infinite? then
19
- return "at least #{first}"
20
- else
21
- to_s
22
- end
23
- end
24
-
25
- end
@@ -1,17 +0,0 @@
1
- require 'mocha/expectation'
2
-
3
- module Mocha # :nodoc:
4
-
5
- class MissingExpectation < Expectation # :nodoc:
6
-
7
- def verify
8
- message = error_message(0, 1)
9
- similar_expectations = @mock.expectations.similar(@method_matcher.expected_method_name)
10
- method_signatures = similar_expectations.map { |expectation| expectation.method_signature }
11
- message << "\nSimilar expectations:\n#{method_signatures.join("\n")}" unless method_signatures.empty?
12
- raise ExpectationError.new(message, backtrace)
13
- end
14
-
15
- end
16
-
17
- end
@@ -1,23 +0,0 @@
1
- require 'mocha/central'
2
-
3
- module Mocha
4
-
5
- module SetupAndTeardown
6
-
7
- def setup_stubs
8
- $stubba = Mocha::Central.new
9
- end
10
-
11
- def verify_stubs
12
- $stubba.verify_all { yield if block_given? } if $stubba
13
- end
14
-
15
- def teardown_stubs
16
- if $stubba then
17
- $stubba.unstub_all
18
- $stubba = nil
19
- end
20
- end
21
-
22
- end
23
- end