mocha 0.12.10 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +22 -0
- data/COPYING.md +3 -0
- data/{MIT-LICENSE.rdoc → MIT-LICENSE.md} +0 -0
- data/README.md +230 -0
- data/{RELEASE.rdoc → RELEASE.md} +61 -56
- data/Rakefile +45 -37
- data/build-matrix.rb +16 -4
- data/lib/mocha.rb +6 -2
- data/lib/mocha/api.rb +13 -16
- data/lib/mocha/class_method.rb +7 -3
- data/lib/mocha/class_methods.rb +63 -0
- data/lib/mocha/debug.rb +11 -0
- data/lib/mocha/deprecation.rb +1 -1
- data/lib/mocha/exception_raiser.rb +1 -1
- data/lib/mocha/expectation_error.rb +5 -0
- data/lib/mocha/expectation_error_factory.rb +19 -0
- data/lib/mocha/hooks.rb +43 -0
- data/lib/mocha/integration.rb +6 -38
- data/lib/mocha/integration/assertion_counter.rb +13 -0
- data/lib/mocha/integration/mini_test.rb +42 -60
- data/lib/mocha/integration/mini_test/adapter.rb +54 -0
- data/lib/mocha/integration/mini_test/exception_translation.rb +0 -6
- data/lib/mocha/integration/mini_test/nothing.rb +19 -0
- data/lib/mocha/integration/mini_test/version_13.rb +32 -25
- data/lib/mocha/integration/mini_test/version_140.rb +32 -26
- data/lib/mocha/integration/mini_test/version_141.rb +40 -34
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +40 -34
- data/lib/mocha/integration/mini_test/version_200.rb +41 -35
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +41 -35
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +49 -43
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +53 -47
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +43 -37
- data/lib/mocha/integration/monkey_patcher.rb +18 -0
- data/lib/mocha/integration/test_unit.rb +38 -45
- data/lib/mocha/integration/test_unit/adapter.rb +51 -0
- data/lib/mocha/integration/test_unit/gem_version_200.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +65 -0
- data/lib/mocha/integration/test_unit/nothing.rb +19 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +36 -29
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +37 -30
- data/lib/mocha/method_matcher.rb +1 -1
- data/lib/mocha/module_methods.rb +14 -0
- data/lib/mocha/{object.rb → object_methods.rb} +0 -83
- data/lib/mocha/setup.rb +10 -0
- data/lib/mocha/standalone.rb +3 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha_standalone.rb +3 -1
- data/mocha.gemspec +16 -9
- data/test/acceptance/bug_18914_test.rb +1 -1
- data/test/acceptance/bug_21465_test.rb +1 -1
- data/test/acceptance/bug_21563_test.rb +1 -1
- data/test/acceptance/exception_rescue_test.rb +1 -1
- data/test/acceptance/expectations_on_multiple_methods_test.rb +1 -1
- data/test/acceptance/expected_invocation_count_test.rb +1 -1
- data/test/acceptance/failure_messages_test.rb +1 -1
- data/test/acceptance/issue_65_test.rb +1 -1
- data/test/acceptance/issue_70_test.rb +1 -1
- data/test/acceptance/mocha_example_test.rb +1 -1
- data/test/acceptance/mocha_test_result_test.rb +1 -1
- data/test/acceptance/mock_test.rb +1 -1
- data/test/acceptance/mock_with_initializer_block_test.rb +1 -1
- data/test/acceptance/mocked_methods_dispatch_test.rb +1 -1
- data/test/acceptance/multiple_expectations_failure_message_test.rb +1 -1
- data/test/acceptance/optional_parameters_test.rb +1 -1
- data/test/acceptance/parameter_matcher_test.rb +1 -1
- data/test/acceptance/partial_mocks_test.rb +1 -1
- data/test/acceptance/raise_exception_test.rb +1 -1
- data/test/acceptance/return_value_test.rb +1 -1
- data/test/acceptance/sequence_test.rb +1 -1
- data/test/acceptance/states_test.rb +1 -1
- data/test/acceptance/stub_any_instance_method_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +1 -1
- data/test/acceptance/stub_everything_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +1 -1
- data/test/acceptance/stub_module_method_test.rb +1 -1
- data/test/acceptance/stub_test.rb +1 -1
- data/test/acceptance/stubba_example_test.rb +1 -1
- data/test/acceptance/stubba_test_result_test.rb +1 -1
- data/test/acceptance/stubbing_error_backtrace_test.rb +1 -1
- data/test/acceptance/stubbing_frozen_object_test.rb +1 -1
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +1 -1
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +1 -1
- data/test/acceptance/stubbing_nil_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_class_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +1 -1
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +3 -3
- data/test/acceptance/throw_test.rb +1 -1
- data/test/acceptance/unstubbing_test.rb +1 -1
- data/test/integration/mini_test_test.rb +9 -0
- data/test/integration/shared_tests.rb +174 -0
- data/test/integration/test_unit_test.rb +9 -0
- data/test/mini_test_result.rb +0 -1
- data/test/test_runner.rb +14 -14
- data/test/unit/class_methods_test.rb +40 -0
- data/test/unit/method_matcher_test.rb +5 -0
- data/test/unit/mock_test.rb +6 -0
- data/test/unit/module_methods_test.rb +19 -0
- data/test/unit/object_methods_test.rb +45 -0
- metadata +45 -74
- data/COPYING.rdoc +0 -3
- data/README.rdoc +0 -56
- data/examples/misc.rb +0 -43
- data/examples/mocha.rb +0 -25
- data/examples/stubba.rb +0 -64
- data/gemfiles/Gemfile.minitest.3.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.4.2.0 +0 -7
- data/lib/mocha/integration/mini_test/assertion_counter.rb +0 -23
- data/lib/mocha/integration/mini_test/version_330_to_410.rb +0 -65
- data/lib/mocha/integration/mini_test/version_420_to_433.rb +0 -70
- data/lib/mocha/integration/mini_test/version_440.rb +0 -70
- data/lib/mocha/integration/mini_test/version_450_to_461.rb +0 -72
- data/lib/mocha/integration/test_unit/assertion_counter.rb +0 -23
- data/lib/mocha/integration/test_unit/gem_version_230_to_254.rb +0 -58
- data/lib/mocha/options.rb +0 -1
- data/test/acceptance/api_test.rb +0 -139
- data/test/acceptance/minitest_test.rb +0 -162
- data/test/unit/object_test.rb +0 -92
@@ -0,0 +1,174 @@
|
|
1
|
+
require 'test_runner'
|
2
|
+
require 'execution_point'
|
3
|
+
|
4
|
+
module SharedTests
|
5
|
+
include TestRunner
|
6
|
+
|
7
|
+
def test_assertion_satisfied
|
8
|
+
test_result = run_as_test do
|
9
|
+
assert true
|
10
|
+
end
|
11
|
+
assert_passed(test_result)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_assertion_unsatisfied
|
15
|
+
execution_point = nil
|
16
|
+
test_result = run_as_test do
|
17
|
+
execution_point = ExecutionPoint.current; flunk
|
18
|
+
end
|
19
|
+
assert_failed(test_result)
|
20
|
+
failure = test_result.failures.first
|
21
|
+
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_mock_object_unexpected_invocation
|
25
|
+
execution_point = nil
|
26
|
+
test_result = run_as_test do
|
27
|
+
mock = mock("not expecting invocation")
|
28
|
+
execution_point = ExecutionPoint.current; mock.unexpected
|
29
|
+
end
|
30
|
+
assert_failed(test_result)
|
31
|
+
failure = test_result.failures.first
|
32
|
+
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
33
|
+
assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_mock_object_explicitly_unexpected_invocation
|
37
|
+
execution_point = nil
|
38
|
+
test_result = run_as_test do
|
39
|
+
mock = mock("not expecting invocation")
|
40
|
+
mock.expects(:unexpected).never
|
41
|
+
execution_point = ExecutionPoint.current; mock.unexpected
|
42
|
+
end
|
43
|
+
assert_failed(test_result)
|
44
|
+
failure = test_result.failures.first
|
45
|
+
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
46
|
+
assert_equal [
|
47
|
+
"unexpected invocation: #<Mock:not expecting invocation>.unexpected()",
|
48
|
+
"unsatisfied expectations:",
|
49
|
+
"- expected never, invoked once: #<Mock:not expecting invocation>.unexpected(any_parameters)"
|
50
|
+
], test_result.failure_message_lines
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_mock_object_unsatisfied_expectation
|
54
|
+
execution_point = nil
|
55
|
+
test_result = run_as_test do
|
56
|
+
mock = mock("expecting invocation")
|
57
|
+
execution_point = ExecutionPoint.current; mock.expects(:expected)
|
58
|
+
end
|
59
|
+
assert_failed(test_result)
|
60
|
+
failure = test_result.failures.first
|
61
|
+
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
62
|
+
assert_equal [
|
63
|
+
"not all expectations were satisfied",
|
64
|
+
"unsatisfied expectations:",
|
65
|
+
"- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)"
|
66
|
+
], test_result.failure_message_lines
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_mock_object_unexpected_invocation_in_setup
|
70
|
+
execution_point = nil
|
71
|
+
test_result = run_as_tests(
|
72
|
+
:setup => lambda {
|
73
|
+
mock = mock("not expecting invocation")
|
74
|
+
execution_point = ExecutionPoint.current; mock.unexpected
|
75
|
+
},
|
76
|
+
:test_me => lambda {
|
77
|
+
assert true
|
78
|
+
}
|
79
|
+
)
|
80
|
+
assert_failed(test_result)
|
81
|
+
failure = test_result.failures.first
|
82
|
+
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
83
|
+
assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_mock_object_unsatisfied_expectation_in_setup
|
87
|
+
execution_point = nil
|
88
|
+
test_result = run_as_tests(
|
89
|
+
:setup => lambda {
|
90
|
+
mock = mock("expecting invocation")
|
91
|
+
execution_point = ExecutionPoint.current; mock.expects(:expected)
|
92
|
+
},
|
93
|
+
:test_me => lambda {
|
94
|
+
assert true
|
95
|
+
}
|
96
|
+
)
|
97
|
+
assert_failed(test_result)
|
98
|
+
failure = test_result.failures.first
|
99
|
+
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
100
|
+
assert_equal [
|
101
|
+
"not all expectations were satisfied",
|
102
|
+
"unsatisfied expectations:",
|
103
|
+
"- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)"
|
104
|
+
], test_result.failure_message_lines
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_mock_object_unexpected_invocation_in_teardown
|
108
|
+
execution_point = nil
|
109
|
+
test_result = run_as_tests(
|
110
|
+
:test_me => lambda {
|
111
|
+
assert true
|
112
|
+
},
|
113
|
+
:teardown => lambda {
|
114
|
+
mock = mock("not expecting invocation")
|
115
|
+
execution_point = ExecutionPoint.current; mock.unexpected
|
116
|
+
}
|
117
|
+
)
|
118
|
+
assert_failed(test_result)
|
119
|
+
failure = test_result.failures.first
|
120
|
+
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
121
|
+
assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_real_object_explicitly_unexpected_invocation
|
125
|
+
execution_point = nil
|
126
|
+
object = Object.new
|
127
|
+
test_result = run_as_test do
|
128
|
+
object.expects(:unexpected).never
|
129
|
+
execution_point = ExecutionPoint.current; object.unexpected
|
130
|
+
end
|
131
|
+
assert_failed(test_result)
|
132
|
+
failure = test_result.failures.first
|
133
|
+
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
134
|
+
assert_equal [
|
135
|
+
"unexpected invocation: #{object.mocha_inspect}.unexpected()",
|
136
|
+
"unsatisfied expectations:",
|
137
|
+
"- expected never, invoked once: #{object.mocha_inspect}.unexpected(any_parameters)"
|
138
|
+
], test_result.failure_message_lines
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_real_object_unsatisfied_expectation
|
142
|
+
execution_point = nil
|
143
|
+
object = Object.new
|
144
|
+
test_result = run_as_test do
|
145
|
+
execution_point = ExecutionPoint.current; object.expects(:expected)
|
146
|
+
end
|
147
|
+
assert_failed(test_result)
|
148
|
+
failure = test_result.failures.first
|
149
|
+
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
150
|
+
assert_equal [
|
151
|
+
"not all expectations were satisfied",
|
152
|
+
"unsatisfied expectations:",
|
153
|
+
"- expected exactly once, not yet invoked: #{object.mocha_inspect}.expected(any_parameters)"
|
154
|
+
], test_result.failure_message_lines
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_real_object_expectation_does_not_leak_into_subsequent_test
|
158
|
+
execution_point = nil
|
159
|
+
klass = Class.new
|
160
|
+
test_result = run_as_tests(
|
161
|
+
:test_1 => lambda {
|
162
|
+
klass.expects(:foo)
|
163
|
+
klass.foo
|
164
|
+
},
|
165
|
+
:test_2 => lambda {
|
166
|
+
execution_point = ExecutionPoint.current; klass.foo
|
167
|
+
}
|
168
|
+
)
|
169
|
+
assert_failed(test_result)
|
170
|
+
exception = test_result.errors.first.exception
|
171
|
+
assert_equal execution_point, ExecutionPoint.new(exception.backtrace)
|
172
|
+
assert_match %r{undefined method `foo'}, exception.message
|
173
|
+
end
|
174
|
+
end
|
data/test/mini_test_result.rb
CHANGED
data/test/test_runner.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'test/unit/testcase'
|
2
2
|
|
3
3
|
if defined?(MiniTest)
|
4
|
-
require 'mocha/integration/mini_test'
|
5
4
|
require File.expand_path('../mini_test_result', __FILE__)
|
6
5
|
else
|
7
6
|
require File.expand_path('../test_unit_result', __FILE__)
|
@@ -9,28 +8,29 @@ end
|
|
9
8
|
|
10
9
|
module TestRunner
|
11
10
|
def run_as_test(&block)
|
12
|
-
run_as_tests(block)
|
11
|
+
run_as_tests(:test_me => block)
|
13
12
|
end
|
14
13
|
|
15
|
-
def run_as_tests(
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
def run_as_tests(methods = {})
|
15
|
+
base_class = defined?(MiniTest) ? MiniTest::Unit::TestCase : Test::Unit::TestCase
|
16
|
+
test_class = Class.new(base_class) do
|
17
|
+
methods.each do |(method_name, proc)|
|
18
|
+
define_method(method_name, proc)
|
19
19
|
end
|
20
|
-
test_class.new(:test_me)
|
21
20
|
end
|
21
|
+
tests = methods.keys.select { |m| m.to_s[/^test/] }.map { |m| test_class.new(m) }
|
22
22
|
|
23
|
-
if defined?(
|
24
|
-
test_result = TestUnitResult.build_test_result
|
25
|
-
tests.each do |test|
|
26
|
-
test.run(test_result) {}
|
27
|
-
end
|
28
|
-
else
|
23
|
+
if defined?(MiniTest)
|
29
24
|
runner = MiniTest::Unit.new
|
30
25
|
tests.each do |test|
|
31
26
|
test.run(runner)
|
32
27
|
end
|
33
28
|
test_result = MiniTestResult.new(runner, tests)
|
29
|
+
else
|
30
|
+
test_result = TestUnitResult.build_test_result
|
31
|
+
tests.each do |test|
|
32
|
+
test.run(test_result) {}
|
33
|
+
end
|
34
34
|
end
|
35
35
|
|
36
36
|
test_result
|
@@ -42,7 +42,7 @@ module TestRunner
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def assert_failed(test_result)
|
45
|
-
flunk "Test passed unexpectedly"
|
45
|
+
flunk "Test passed unexpectedly" unless test_result.failure_count + test_result.error_count > 0
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
require 'mocha/class_methods'
|
3
|
+
require 'mocha/object_methods'
|
4
|
+
|
5
|
+
class ClassMethodsTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@klass = Class.new.extend(Mocha::ClassMethods, Mocha::ObjectMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_build_any_instance_object
|
12
|
+
any_instance = @klass.any_instance
|
13
|
+
assert_not_nil any_instance
|
14
|
+
assert any_instance.is_a?(Mocha::ClassMethods::AnyInstance)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_return_same_any_instance_object
|
18
|
+
any_instance_1 = @klass.any_instance
|
19
|
+
any_instance_2 = @klass.any_instance
|
20
|
+
assert_equal any_instance_1, any_instance_2
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_should_use_stubba_class_method_for_class
|
24
|
+
assert_equal Mocha::ClassMethod, @klass.stubba_method
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_use_stubba_class_method_for_any_instance
|
28
|
+
assert_equal Mocha::AnyInstanceMethod, @klass.any_instance.stubba_method
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_stub_self_for_class
|
32
|
+
assert_equal @klass, @klass.stubba_object
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_stub_relevant_class_for_any_instance
|
36
|
+
any_instance = @klass.any_instance
|
37
|
+
assert_equal @klass, any_instance.stubba_object
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -10,6 +10,11 @@ class MethodMatcherTest < Test::Unit::TestCase
|
|
10
10
|
assert method_matcher.match?(:method_name)
|
11
11
|
end
|
12
12
|
|
13
|
+
def test_should_match_if_actual_method_name_is_expected_method_name_as_string
|
14
|
+
method_matcher = MethodMatcher.new(:method_name)
|
15
|
+
assert method_matcher.match?('method_name')
|
16
|
+
end
|
17
|
+
|
13
18
|
def test_should_not_match_if_actual_method_name_is_not_same_as_expected_method_name
|
14
19
|
method_matcher = MethodMatcher.new(:method_name)
|
15
20
|
assert !method_matcher.match?(:different_method_name)
|
data/test/unit/mock_test.rb
CHANGED
@@ -214,6 +214,12 @@ class MockTest < Test::Unit::TestCase
|
|
214
214
|
assert_equal true, mock.respond_to?(:method1)
|
215
215
|
end
|
216
216
|
|
217
|
+
def test_should_respond_to_expected_method_as_string
|
218
|
+
mock = build_mock
|
219
|
+
mock.expects(:method1)
|
220
|
+
assert_equal true, mock.respond_to?('method1')
|
221
|
+
end
|
222
|
+
|
217
223
|
def test_should_not_respond_to_unexpected_method
|
218
224
|
mock = build_mock
|
219
225
|
assert_equal false, mock.respond_to?(:method1)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
require 'mocha/module_methods'
|
3
|
+
require 'mocha/object_methods'
|
4
|
+
|
5
|
+
class ModuleMethodsTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@module = Module.new.extend(Mocha::ModuleMethods, Mocha::ObjectMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_use_stubba_module_method_for_module
|
12
|
+
assert_equal Mocha::ModuleMethod, @module.stubba_method
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_stub_self_for_module
|
16
|
+
assert_equal @module, @module.stubba_object
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
require 'mocha/object_methods'
|
3
|
+
require 'mocha/mock'
|
4
|
+
|
5
|
+
class ObjectMethodsTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@object = Object.new.extend(Mocha::ObjectMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_build_mocha_referring_to_self
|
12
|
+
mocha = @object.mocha
|
13
|
+
assert_not_nil mocha
|
14
|
+
assert mocha.is_a?(Mocha::Mock)
|
15
|
+
assert_equal @object.mocha_inspect, mocha.mocha_inspect
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_reuse_existing_mocha
|
19
|
+
mocha_1 = @object.mocha
|
20
|
+
mocha_2 = @object.mocha
|
21
|
+
assert_equal mocha_1, mocha_2
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_reset_mocha
|
25
|
+
assert_nil @object.reset_mocha
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_use_stubba_instance_method_for_object
|
29
|
+
assert_equal Mocha::InstanceMethod, Object.new.stubba_method
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_stub_self_for_object
|
33
|
+
assert_equal @object, @object.stubba_object
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_nobody_expects_the_spanish_inquisition
|
37
|
+
assert_raise(Mocha::ExpectationError) { @object.expects(:the_spanish_inquisition) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_alias_object_method
|
41
|
+
klass = Class.new { def self.method_x; end }
|
42
|
+
assert_equal klass._method(:method_x), klass.method(:method_x)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
metadata
CHANGED
@@ -1,116 +1,87 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mocha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.13.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.12.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Mead
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: metaclass
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70267336106140 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 0.0.1
|
22
22
|
type: :runtime
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
|
-
requirements:
|
26
|
-
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
version: 0.0.1
|
29
23
|
prerelease: false
|
24
|
+
version_requirements: *70267336106140
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: rake
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70267336104820 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ! '>='
|
36
31
|
- !ruby/object:Gem::Version
|
37
32
|
version: '0'
|
38
33
|
type: :development
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
|
-
requirements:
|
42
|
-
- - ! '>='
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: '0'
|
45
34
|
prerelease: false
|
35
|
+
version_requirements: *70267336104820
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: introspection
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &70267336104360 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
40
|
requirements:
|
51
41
|
- - ~>
|
52
42
|
- !ruby/object:Gem::Version
|
53
43
|
version: 0.0.1
|
54
44
|
type: :development
|
55
|
-
version_requirements: !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
|
-
requirements:
|
58
|
-
- - ~>
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 0.0.1
|
61
45
|
prerelease: false
|
46
|
+
version_requirements: *70267336104360
|
62
47
|
- !ruby/object:Gem::Dependency
|
63
48
|
name: yard
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirement: &70267336103960 !ruby/object:Gem::Requirement
|
65
50
|
none: false
|
66
51
|
requirements:
|
67
52
|
- - ! '>='
|
68
53
|
- !ruby/object:Gem::Version
|
69
54
|
version: '0'
|
70
55
|
type: :development
|
71
|
-
version_requirements: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
|
-
requirements:
|
74
|
-
- - ! '>='
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
77
56
|
prerelease: false
|
57
|
+
version_requirements: *70267336103960
|
78
58
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
+
name: redcarpet
|
60
|
+
requirement: &70267336103420 !ruby/object:Gem::Requirement
|
81
61
|
none: false
|
82
62
|
requirements:
|
83
|
-
- -
|
63
|
+
- - ~>
|
84
64
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
65
|
+
version: '1'
|
86
66
|
type: :development
|
87
|
-
version_requirements: !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
|
-
requirements:
|
90
|
-
- - ! '>='
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: '0'
|
93
67
|
prerelease: false
|
68
|
+
version_requirements: *70267336103420
|
94
69
|
description: Mocking and stubbing library with JMock/SchMock syntax, which allows
|
95
70
|
mocking and stubbing of methods on real (non-mock) classes.
|
96
71
|
email: mocha-developer@googlegroups.com
|
97
72
|
executables: []
|
98
73
|
extensions: []
|
99
|
-
extra_rdoc_files:
|
100
|
-
- README.rdoc
|
101
|
-
- COPYING.rdoc
|
74
|
+
extra_rdoc_files: []
|
102
75
|
files:
|
103
76
|
- .gemtest
|
104
|
-
-
|
77
|
+
- .yardopts
|
78
|
+
- COPYING.md
|
105
79
|
- Gemfile
|
106
|
-
- MIT-LICENSE.
|
107
|
-
- README.
|
108
|
-
- RELEASE.
|
80
|
+
- MIT-LICENSE.md
|
81
|
+
- README.md
|
82
|
+
- RELEASE.md
|
109
83
|
- Rakefile
|
110
84
|
- build-matrix.rb
|
111
|
-
- examples/misc.rb
|
112
|
-
- examples/mocha.rb
|
113
|
-
- examples/stubba.rb
|
114
85
|
- gemfiles/Gemfile.minitest.1.3.0
|
115
86
|
- gemfiles/Gemfile.minitest.1.4.0
|
116
87
|
- gemfiles/Gemfile.minitest.1.4.1
|
@@ -120,8 +91,6 @@ files:
|
|
120
91
|
- gemfiles/Gemfile.minitest.2.11.0
|
121
92
|
- gemfiles/Gemfile.minitest.2.11.2
|
122
93
|
- gemfiles/Gemfile.minitest.2.3.0
|
123
|
-
- gemfiles/Gemfile.minitest.3.3.0
|
124
|
-
- gemfiles/Gemfile.minitest.4.2.0
|
125
94
|
- gemfiles/Gemfile.minitest.latest
|
126
95
|
- gemfiles/Gemfile.test-unit.2.0.0
|
127
96
|
- gemfiles/Gemfile.test-unit.2.0.1
|
@@ -137,20 +106,25 @@ files:
|
|
137
106
|
- lib/mocha/central.rb
|
138
107
|
- lib/mocha/change_state_side_effect.rb
|
139
108
|
- lib/mocha/class_method.rb
|
109
|
+
- lib/mocha/class_methods.rb
|
140
110
|
- lib/mocha/configuration.rb
|
111
|
+
- lib/mocha/debug.rb
|
141
112
|
- lib/mocha/deprecation.rb
|
142
113
|
- lib/mocha/exception_raiser.rb
|
143
114
|
- lib/mocha/expectation.rb
|
144
115
|
- lib/mocha/expectation_error.rb
|
145
116
|
- lib/mocha/expectation_error_factory.rb
|
146
117
|
- lib/mocha/expectation_list.rb
|
118
|
+
- lib/mocha/hooks.rb
|
147
119
|
- lib/mocha/in_state_ordering_constraint.rb
|
148
120
|
- lib/mocha/inspect.rb
|
149
121
|
- lib/mocha/instance_method.rb
|
150
122
|
- lib/mocha/integration.rb
|
123
|
+
- lib/mocha/integration/assertion_counter.rb
|
151
124
|
- lib/mocha/integration/mini_test.rb
|
152
|
-
- lib/mocha/integration/mini_test/
|
125
|
+
- lib/mocha/integration/mini_test/adapter.rb
|
153
126
|
- lib/mocha/integration/mini_test/exception_translation.rb
|
127
|
+
- lib/mocha/integration/mini_test/nothing.rb
|
154
128
|
- lib/mocha/integration/mini_test/version_13.rb
|
155
129
|
- lib/mocha/integration/mini_test/version_140.rb
|
156
130
|
- lib/mocha/integration/mini_test/version_141.rb
|
@@ -160,16 +134,14 @@ files:
|
|
160
134
|
- lib/mocha/integration/mini_test/version_2110_to_2111.rb
|
161
135
|
- lib/mocha/integration/mini_test/version_2112_to_320.rb
|
162
136
|
- lib/mocha/integration/mini_test/version_230_to_2101.rb
|
163
|
-
- lib/mocha/integration/
|
164
|
-
- lib/mocha/integration/mini_test/version_420_to_433.rb
|
165
|
-
- lib/mocha/integration/mini_test/version_440.rb
|
166
|
-
- lib/mocha/integration/mini_test/version_450_to_461.rb
|
137
|
+
- lib/mocha/integration/monkey_patcher.rb
|
167
138
|
- lib/mocha/integration/test_unit.rb
|
168
|
-
- lib/mocha/integration/test_unit/
|
139
|
+
- lib/mocha/integration/test_unit/adapter.rb
|
169
140
|
- lib/mocha/integration/test_unit/gem_version_200.rb
|
170
141
|
- lib/mocha/integration/test_unit/gem_version_201_to_202.rb
|
171
142
|
- lib/mocha/integration/test_unit/gem_version_203_to_220.rb
|
172
|
-
- lib/mocha/integration/test_unit/
|
143
|
+
- lib/mocha/integration/test_unit/gem_version_230_to_250.rb
|
144
|
+
- lib/mocha/integration/test_unit/nothing.rb
|
173
145
|
- lib/mocha/integration/test_unit/ruby_version_185_and_below.rb
|
174
146
|
- lib/mocha/integration/test_unit/ruby_version_186_and_above.rb
|
175
147
|
- lib/mocha/is_a.rb
|
@@ -178,11 +150,11 @@ files:
|
|
178
150
|
- lib/mocha/mock.rb
|
179
151
|
- lib/mocha/mockery.rb
|
180
152
|
- lib/mocha/module_method.rb
|
153
|
+
- lib/mocha/module_methods.rb
|
181
154
|
- lib/mocha/multiple_yields.rb
|
182
155
|
- lib/mocha/names.rb
|
183
156
|
- lib/mocha/no_yields.rb
|
184
|
-
- lib/mocha/
|
185
|
-
- lib/mocha/options.rb
|
157
|
+
- lib/mocha/object_methods.rb
|
186
158
|
- lib/mocha/parameter_matchers.rb
|
187
159
|
- lib/mocha/parameter_matchers/all_of.rb
|
188
160
|
- lib/mocha/parameter_matchers/any_of.rb
|
@@ -209,6 +181,7 @@ files:
|
|
209
181
|
- lib/mocha/pretty_parameters.rb
|
210
182
|
- lib/mocha/return_values.rb
|
211
183
|
- lib/mocha/sequence.rb
|
184
|
+
- lib/mocha/setup.rb
|
212
185
|
- lib/mocha/single_return_value.rb
|
213
186
|
- lib/mocha/single_yield.rb
|
214
187
|
- lib/mocha/standalone.rb
|
@@ -221,7 +194,6 @@ files:
|
|
221
194
|
- lib/mocha_standalone.rb
|
222
195
|
- mocha.gemspec
|
223
196
|
- test/acceptance/acceptance_test_helper.rb
|
224
|
-
- test/acceptance/api_test.rb
|
225
197
|
- test/acceptance/bug_18914_test.rb
|
226
198
|
- test/acceptance/bug_21465_test.rb
|
227
199
|
- test/acceptance/bug_21563_test.rb
|
@@ -231,7 +203,6 @@ files:
|
|
231
203
|
- test/acceptance/failure_messages_test.rb
|
232
204
|
- test/acceptance/issue_65_test.rb
|
233
205
|
- test/acceptance/issue_70_test.rb
|
234
|
-
- test/acceptance/minitest_test.rb
|
235
206
|
- test/acceptance/mocha_example_test.rb
|
236
207
|
- test/acceptance/mocha_test_result_test.rb
|
237
208
|
- test/acceptance/mock_test.rb
|
@@ -280,6 +251,9 @@ files:
|
|
280
251
|
- test/acceptance/unstubbing_test.rb
|
281
252
|
- test/deprecation_disabler.rb
|
282
253
|
- test/execution_point.rb
|
254
|
+
- test/integration/mini_test_test.rb
|
255
|
+
- test/integration/shared_tests.rb
|
256
|
+
- test/integration/test_unit_test.rb
|
283
257
|
- test/method_definer.rb
|
284
258
|
- test/mini_test_result.rb
|
285
259
|
- test/simple_counter.rb
|
@@ -293,6 +267,7 @@ files:
|
|
293
267
|
- test/unit/central_test.rb
|
294
268
|
- test/unit/change_state_side_effect_test.rb
|
295
269
|
- test/unit/class_method_test.rb
|
270
|
+
- test/unit/class_methods_test.rb
|
296
271
|
- test/unit/configuration_test.rb
|
297
272
|
- test/unit/date_time_inspect_test.rb
|
298
273
|
- test/unit/exception_raiser_test.rb
|
@@ -303,10 +278,11 @@ files:
|
|
303
278
|
- test/unit/method_matcher_test.rb
|
304
279
|
- test/unit/mock_test.rb
|
305
280
|
- test/unit/mockery_test.rb
|
281
|
+
- test/unit/module_methods_test.rb
|
306
282
|
- test/unit/multiple_yields_test.rb
|
307
283
|
- test/unit/no_yields_test.rb
|
308
284
|
- test/unit/object_inspect_test.rb
|
309
|
-
- test/unit/
|
285
|
+
- test/unit/object_methods_test.rb
|
310
286
|
- test/unit/parameter_matchers/all_of_test.rb
|
311
287
|
- test/unit/parameter_matchers/any_of_test.rb
|
312
288
|
- test/unit/parameter_matchers/anything_test.rb
|
@@ -336,12 +312,7 @@ files:
|
|
336
312
|
homepage: http://gofreerange.com/mocha/docs
|
337
313
|
licenses: []
|
338
314
|
post_install_message:
|
339
|
-
rdoc_options:
|
340
|
-
- --title
|
341
|
-
- Mocha
|
342
|
-
- --main
|
343
|
-
- README.rdoc
|
344
|
-
- --line-numbers
|
315
|
+
rdoc_options: []
|
345
316
|
require_paths:
|
346
317
|
- lib
|
347
318
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -349,10 +320,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
349
320
|
requirements:
|
350
321
|
- - ! '>='
|
351
322
|
- !ruby/object:Gem::Version
|
323
|
+
version: '0'
|
352
324
|
segments:
|
353
325
|
- 0
|
354
|
-
hash: -
|
355
|
-
version: '0'
|
326
|
+
hash: -4192078905680069090
|
356
327
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
357
328
|
none: false
|
358
329
|
requirements:
|
@@ -361,9 +332,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
361
332
|
version: '0'
|
362
333
|
requirements: []
|
363
334
|
rubyforge_project: mocha
|
364
|
-
rubygems_version: 1.8.
|
335
|
+
rubygems_version: 1.8.11
|
365
336
|
signing_key:
|
366
337
|
specification_version: 3
|
367
338
|
summary: Mocking and stubbing library
|
368
339
|
test_files: []
|
369
|
-
has_rdoc:
|
340
|
+
has_rdoc: yard
|