mocha 0.9.12 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +3 -0
- data/Gemfile.minitest.1.3.0 +7 -0
- data/Gemfile.minitest.1.4.0 +7 -0
- data/Gemfile.minitest.1.4.1 +7 -0
- data/Gemfile.minitest.1.4.2 +7 -0
- data/Gemfile.minitest.2.0.0 +7 -0
- data/Gemfile.minitest.2.0.1 +7 -0
- data/Gemfile.minitest.2.3.0 +7 -0
- data/Gemfile.minitest.latest +7 -0
- data/Gemfile.test-unit.2.0.0 +8 -0
- data/Gemfile.test-unit.2.0.1 +7 -0
- data/Gemfile.test-unit.2.0.3 +7 -0
- data/Gemfile.test-unit.latest +7 -0
- data/README.rdoc +4 -0
- data/RELEASE.rdoc +22 -3
- data/Rakefile +17 -90
- data/init.rb +3 -0
- data/lib/mocha.rb +1 -1
- data/lib/mocha/central.rb +4 -4
- data/lib/mocha/class_method.rb +20 -20
- data/lib/mocha/expectation.rb +33 -6
- data/lib/mocha/instance_method.rb +17 -1
- data/lib/mocha/integration/mini_test.rb +17 -13
- data/lib/mocha/integration/mini_test/{version_201_to_202.rb → version_201_to_222.rb} +9 -9
- data/lib/mocha/integration/mini_test/version_230_to_251.rb +59 -0
- data/lib/mocha/integration/test_unit.rb +17 -13
- data/lib/mocha/integration/test_unit/{gem_version_203_to_209.rb → gem_version_203_to_220.rb} +8 -8
- data/lib/mocha/integration/test_unit/gem_version_230_to_233.rb +58 -0
- data/lib/mocha/mock.rb +14 -14
- data/lib/mocha/object.rb +1 -1
- data/lib/mocha/thrower.rb +15 -0
- data/lib/mocha/version.rb +3 -0
- data/mocha.gemspec +43 -0
- data/test/acceptance/acceptance_test_helper.rb +3 -0
- data/test/acceptance/expectations_on_multiple_methods_test.rb +55 -0
- data/test/acceptance/minitest_test.rb +12 -7
- data/test/acceptance/raise_exception_test.rb +39 -0
- data/test/acceptance/{stub_class_method_test.rb → stub_class_method_defined_on_active_record_association_proxy_test.rb} +3 -103
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +72 -0
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +75 -0
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +75 -0
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +93 -0
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +69 -0
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +66 -0
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +75 -0
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +75 -0
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +75 -0
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +70 -0
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +72 -0
- data/test/acceptance/throw_test.rb +45 -0
- data/test/method_definer.rb +3 -3
- data/test/test_helper.rb +0 -6
- data/test/unit/central_test.rb +7 -3
- data/test/unit/class_method_test.rb +10 -10
- data/test/unit/mockery_test.rb +1 -0
- data/test/unit/thrower_test.rb +20 -0
- metadata +110 -33
- data/lib/mocha/metaclass.rb +0 -13
- data/test/acceptance/stub_instance_method_test.rb +0 -206
- data/test/unit/metaclass_test.rb +0 -22
data/lib/mocha/metaclass.rb
DELETED
@@ -1,206 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
class StubInstanceMethodTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_leave_stubbed_public_method_unchanged_after_test
|
17
|
-
instance = Class.new do
|
18
|
-
def my_instance_method
|
19
|
-
:original_return_value
|
20
|
-
end
|
21
|
-
end.new
|
22
|
-
run_as_test do
|
23
|
-
instance.stubs(:my_instance_method).returns(:new_return_value)
|
24
|
-
end
|
25
|
-
assert instance.public_methods(false).any? { |m| m.to_s == 'my_instance_method' }
|
26
|
-
assert_equal :original_return_value, instance.my_instance_method
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_should_leave_stubbed_protected_method_unchanged_after_test
|
30
|
-
instance = Class.new do
|
31
|
-
def my_instance_method
|
32
|
-
:original_return_value
|
33
|
-
end
|
34
|
-
protected :my_instance_method
|
35
|
-
def my_unprotected_instance_method
|
36
|
-
my_instance_method
|
37
|
-
end
|
38
|
-
end.new
|
39
|
-
run_as_test do
|
40
|
-
instance.stubs(:my_instance_method).returns(:new_return_value)
|
41
|
-
end
|
42
|
-
assert instance.protected_methods(false).any? { |m| m.to_s == 'my_instance_method' }
|
43
|
-
assert_equal :original_return_value, instance.my_unprotected_instance_method
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_should_leave_stubbed_private_method_unchanged_after_test
|
47
|
-
instance = Class.new do
|
48
|
-
def my_instance_method
|
49
|
-
:original_return_value
|
50
|
-
end
|
51
|
-
private :my_instance_method
|
52
|
-
end.new
|
53
|
-
run_as_test do
|
54
|
-
instance.stubs(:my_instance_method).returns(:new_return_value)
|
55
|
-
end
|
56
|
-
assert instance.private_methods(false).any? { |m| m.to_s == 'my_instance_method' }
|
57
|
-
assert_equal :original_return_value, instance.send(:my_instance_method)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_reset_expectations_after_test
|
61
|
-
instance = Class.new do
|
62
|
-
def my_instance_method
|
63
|
-
:original_return_value
|
64
|
-
end
|
65
|
-
end.new
|
66
|
-
run_as_test do
|
67
|
-
instance.stubs(:my_instance_method).returns(:new_return_value)
|
68
|
-
end
|
69
|
-
assert_equal 0, instance.mocha.expectations.length
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_should_be_able_to_stub_a_superclass_method
|
73
|
-
superklass = Class.new do
|
74
|
-
def my_superclass_method
|
75
|
-
:original_return_value
|
76
|
-
end
|
77
|
-
end
|
78
|
-
klass = Class.new(superklass)
|
79
|
-
instance = klass.new
|
80
|
-
test_result = run_as_test do
|
81
|
-
instance.stubs(:my_superclass_method).returns(:new_return_value)
|
82
|
-
assert_equal :new_return_value, instance.my_superclass_method
|
83
|
-
end
|
84
|
-
assert_passed(test_result)
|
85
|
-
assert instance.public_methods(true).any? { |m| m.to_s == 'my_superclass_method' }
|
86
|
-
assert !instance.public_methods(false).any? { |m| m.to_s == 'my_superclass_method' }
|
87
|
-
assert_equal :original_return_value, instance.my_superclass_method
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy
|
91
|
-
ruby18_instance = Class.new do
|
92
|
-
def public_methods(include_superclass = true)
|
93
|
-
['my_instance_method']
|
94
|
-
end
|
95
|
-
end.new
|
96
|
-
test_result = run_as_test do
|
97
|
-
ruby18_instance.stubs(:my_instance_method).returns(:new_return_value)
|
98
|
-
assert_equal :new_return_value, ruby18_instance.my_instance_method
|
99
|
-
end
|
100
|
-
assert_passed(test_result)
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy
|
104
|
-
ruby19_instance = Class.new do
|
105
|
-
def public_methods(include_superclass = true)
|
106
|
-
[:my_instance_method]
|
107
|
-
end
|
108
|
-
end.new
|
109
|
-
test_result = run_as_test do
|
110
|
-
ruby19_instance.stubs(:my_instance_method).returns(:new_return_value)
|
111
|
-
assert_equal :new_return_value, ruby19_instance.my_instance_method
|
112
|
-
end
|
113
|
-
assert_passed(test_result)
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_should_be_able_to_stub_method_if_ruby18_protected_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy
|
117
|
-
ruby18_instance = Class.new do
|
118
|
-
def protected_methods(include_superclass = true)
|
119
|
-
['my_instance_method']
|
120
|
-
end
|
121
|
-
end.new
|
122
|
-
test_result = run_as_test do
|
123
|
-
ruby18_instance.stubs(:my_instance_method).returns(:new_return_value)
|
124
|
-
assert_equal :new_return_value, ruby18_instance.my_instance_method
|
125
|
-
end
|
126
|
-
assert_passed(test_result)
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy
|
130
|
-
ruby19_instance = Class.new do
|
131
|
-
def protected_methods(include_superclass = true)
|
132
|
-
[:my_instance_method]
|
133
|
-
end
|
134
|
-
end.new
|
135
|
-
test_result = run_as_test do
|
136
|
-
ruby19_instance.stubs(:my_instance_method).returns(:new_return_value)
|
137
|
-
assert_equal :new_return_value, ruby19_instance.my_instance_method
|
138
|
-
end
|
139
|
-
assert_passed(test_result)
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy
|
143
|
-
ruby18_instance = Class.new do
|
144
|
-
def private_methods(include_superclass = true)
|
145
|
-
['my_instance_method']
|
146
|
-
end
|
147
|
-
end.new
|
148
|
-
test_result = run_as_test do
|
149
|
-
ruby18_instance.stubs(:my_instance_method).returns(:new_return_value)
|
150
|
-
assert_equal :new_return_value, ruby18_instance.my_instance_method
|
151
|
-
end
|
152
|
-
assert_passed(test_result)
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_exist_like_active_record_association_proxy
|
156
|
-
ruby19_instance = Class.new do
|
157
|
-
def private_methods(include_superclass = true)
|
158
|
-
[:my_instance_method]
|
159
|
-
end
|
160
|
-
end.new
|
161
|
-
test_result = run_as_test do
|
162
|
-
ruby19_instance.stubs(:my_instance_method).returns(:new_return_value)
|
163
|
-
assert_equal :new_return_value, ruby19_instance.my_instance_method
|
164
|
-
end
|
165
|
-
assert_passed(test_result)
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_should_be_able_to_specify_expectations_on_multiple_methods_in_a_single_call_to_expects
|
169
|
-
instance = Class.new do
|
170
|
-
def my_instance_method_1
|
171
|
-
:original_return_value_1
|
172
|
-
end
|
173
|
-
def my_instance_method_2
|
174
|
-
:original_return_value_2
|
175
|
-
end
|
176
|
-
end.new
|
177
|
-
run_as_test do
|
178
|
-
instance.expects(
|
179
|
-
:my_instance_method_1 => :new_return_value_1,
|
180
|
-
:my_instance_method_2 => :new_return_value_2
|
181
|
-
)
|
182
|
-
assert_equal :new_return_value_1, instance.my_instance_method_1
|
183
|
-
assert_equal :new_return_value_2, instance.my_instance_method_2
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_should_be_able_to_specify_expectations_on_multiple_methods_in_a_single_call_to_stubs
|
188
|
-
instance = Class.new do
|
189
|
-
def my_instance_method_1
|
190
|
-
:original_return_value_1
|
191
|
-
end
|
192
|
-
def my_instance_method_2
|
193
|
-
:original_return_value_2
|
194
|
-
end
|
195
|
-
end.new
|
196
|
-
run_as_test do
|
197
|
-
instance.stubs(
|
198
|
-
:my_instance_method_1 => :new_return_value_1,
|
199
|
-
:my_instance_method_2 => :new_return_value_2
|
200
|
-
)
|
201
|
-
assert_equal :new_return_value_1, instance.my_instance_method_1
|
202
|
-
assert_equal :new_return_value_2, instance.my_instance_method_2
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
end
|
data/test/unit/metaclass_test.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/metaclass'
|
3
|
-
|
4
|
-
class MetaclassTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_should_return_objects_singleton_class
|
7
|
-
object = Object.new
|
8
|
-
assert_raises(NoMethodError) { object.success? }
|
9
|
-
|
10
|
-
object = Object.new
|
11
|
-
assert object.__metaclass__.ancestors.include?(Object)
|
12
|
-
assert object.__metaclass__.ancestors.include?(Kernel)
|
13
|
-
assert object.__metaclass__.is_a?(Class)
|
14
|
-
|
15
|
-
object.__metaclass__.class_eval { def success?; true; end }
|
16
|
-
assert object.success?
|
17
|
-
|
18
|
-
object = Object.new
|
19
|
-
assert_raises(NoMethodError) { object.success? }
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|