mocha-macruby 0.9.8.20100129120100 → 0.9.9.20101102121900
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.rdoc +3 -0
- data/{MIT-LICENSE → MIT-LICENSE.rdoc} +0 -0
- data/{README → README.rdoc} +7 -7
- data/{RELEASE → RELEASE.rdoc} +18 -0
- data/Rakefile +44 -28
- data/lib/mocha.rb +1 -0
- data/lib/mocha/class_method.rb +1 -3
- data/lib/mocha/expectation.rb +37 -34
- data/lib/mocha/integration/mini_test.rb +32 -4
- data/lib/mocha/integration/mini_test/exception_translation.rb +20 -0
- data/lib/mocha/integration/mini_test/{version_131_and_above.rb → version_13.rb} +7 -13
- data/lib/mocha/integration/mini_test/version_140.rb +52 -0
- data/lib/mocha/integration/mini_test/version_141.rb +56 -0
- data/lib/mocha/integration/mini_test/version_142_and_above.rb +47 -0
- data/lib/mocha/integration/test_unit.rb +23 -8
- data/lib/mocha/integration/test_unit/gem_version_200.rb +3 -0
- data/lib/mocha/integration/test_unit/{gem_version_201_and_above.rb → gem_version_201_to_202.rb} +4 -1
- data/lib/mocha/integration/test_unit/gem_version_203_to_209.rb +52 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +3 -0
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +3 -0
- data/lib/mocha/mock.rb +33 -18
- data/lib/mocha/module_method.rb +1 -1
- data/lib/mocha/object.rb +144 -160
- data/lib/mocha/options.rb +1 -0
- data/lib/mocha/parameter_matchers/base.rb +50 -2
- data/test/acceptance/acceptance_test_helper.rb +1 -1
- data/test/acceptance/api_test.rb +1 -1
- 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/expected_invocation_count_test.rb +1 -1
- data/test/acceptance/failure_messages_test.rb +1 -1
- data/test/acceptance/minitest_test.rb +128 -124
- 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/optional_parameters_test.rb +1 -1
- data/test/acceptance/parameter_matcher_test.rb +38 -1
- data/test/acceptance/partial_mocks_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 +5 -2
- data/test/acceptance/stub_class_method_test.rb +5 -2
- data/test/acceptance/stub_everything_test.rb +1 -1
- data/test/acceptance/stub_instance_method_test.rb +5 -2
- data/test/acceptance/stub_module_method_test.rb +3 -3
- data/test/acceptance/stub_test.rb +1 -1
- data/test/acceptance/stubba_example_test.rb +1 -1
- data/test/acceptance/stubba_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_method_unnecessarily_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +5 -5
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +5 -5
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +5 -5
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +9 -9
- data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
- data/test/mini_test_result.rb +74 -0
- data/test/test_helper.rb +3 -1
- data/test/test_runner.rb +25 -11
- data/test/unit/any_instance_method_test.rb +1 -1
- data/test/unit/array_inspect_test.rb +1 -1
- data/test/unit/backtrace_filter_test.rb +1 -1
- data/test/unit/cardinality_test.rb +1 -1
- data/test/unit/central_test.rb +1 -1
- data/test/unit/change_state_side_effect_test.rb +1 -1
- data/test/unit/class_method_test.rb +2 -2
- data/test/unit/configuration_test.rb +1 -1
- data/test/unit/date_time_inspect_test.rb +1 -1
- data/test/unit/exception_raiser_test.rb +1 -1
- data/test/unit/expectation_list_test.rb +1 -1
- data/test/unit/expectation_test.rb +1 -1
- data/test/unit/hash_inspect_test.rb +1 -1
- data/test/unit/in_state_ordering_constraint_test.rb +1 -1
- data/test/unit/metaclass_test.rb +1 -1
- data/test/unit/method_matcher_test.rb +1 -1
- data/test/unit/mock_test.rb +16 -14
- data/test/unit/mockery_test.rb +1 -1
- data/test/unit/multiple_yields_test.rb +1 -1
- data/test/unit/no_yields_test.rb +1 -1
- data/test/unit/object_inspect_test.rb +10 -9
- data/test/unit/object_test.rb +11 -10
- data/test/unit/parameter_matchers/all_of_test.rb +1 -1
- data/test/unit/parameter_matchers/any_of_test.rb +1 -1
- data/test/unit/parameter_matchers/anything_test.rb +1 -1
- data/test/unit/parameter_matchers/equals_test.rb +1 -1
- data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
- data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
- data/test/unit/parameter_matchers/has_key_test.rb +1 -1
- data/test/unit/parameter_matchers/has_value_test.rb +1 -1
- data/test/unit/parameter_matchers/includes_test.rb +5 -5
- data/test/unit/parameter_matchers/instance_of_test.rb +2 -2
- data/test/unit/parameter_matchers/is_a_test.rb +1 -1
- data/test/unit/parameter_matchers/kind_of_test.rb +1 -1
- data/test/unit/parameter_matchers/not_test.rb +1 -1
- data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -1
- data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +1 -1
- data/test/unit/parameters_matcher_test.rb +1 -1
- data/test/unit/return_values_test.rb +1 -1
- data/test/unit/sequence_test.rb +1 -1
- data/test/unit/single_return_value_test.rb +1 -1
- data/test/unit/single_yield_test.rb +1 -1
- data/test/unit/state_machine_test.rb +1 -1
- data/test/unit/string_inspect_test.rb +1 -1
- data/test/unit/yield_parameters_test.rb +1 -1
- metadata +43 -19
- data/COPYING +0 -3
@@ -1,153 +1,157 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
if defined?(MiniTest)
|
4
|
+
$stderr.puts "TODO: Running suite with MiniTest, running the MiniTestAdapterTest results in an error so skipping it for now."
|
5
|
+
else
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'minitest'
|
9
|
+
rescue Gem::LoadError
|
10
|
+
# MiniTest gem not available
|
11
|
+
end
|
9
12
|
|
10
|
-
begin
|
11
|
-
|
12
|
-
rescue LoadError
|
13
|
-
|
14
|
-
end
|
13
|
+
begin
|
14
|
+
require 'minitest/unit'
|
15
|
+
rescue LoadError
|
16
|
+
# MiniTest not available
|
17
|
+
end
|
15
18
|
|
16
|
-
if defined?(MiniTest)
|
19
|
+
if defined?(MiniTest)
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
# monkey-patch MiniTest now that it has hopefully been loaded
|
22
|
+
require 'mocha/integration/mini_test'
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
24
|
+
class MiniTestSampleTest < MiniTest::Unit::TestCase
|
25
|
+
|
26
|
+
def test_mocha_with_fulfilled_expectation
|
27
|
+
mockee = mock()
|
28
|
+
mockee.expects(:blah)
|
29
|
+
mockee.blah
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_mocha_with_unfulfilled_expectation
|
33
|
+
mockee = mock()
|
34
|
+
mockee.expects(:blah)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_mocha_with_unexpected_invocation
|
38
|
+
mockee = mock()
|
39
|
+
mockee.blah
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_stubba_with_fulfilled_expectation
|
43
|
+
stubbee = Class.new { define_method(:blah) {} }.new
|
44
|
+
stubbee.expects(:blah)
|
45
|
+
stubbee.blah
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_stubba_with_unfulfilled_expectation
|
49
|
+
stubbee = Class.new { define_method(:blah) {} }.new
|
50
|
+
stubbee.expects(:blah)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_mocha_with_matching_parameter
|
54
|
+
mockee = mock()
|
55
|
+
mockee.expects(:blah).with(has_key(:wibble))
|
56
|
+
mockee.blah(:wibble => 1)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_mocha_with_non_matching_parameter
|
60
|
+
mockee = mock()
|
61
|
+
mockee.expects(:blah).with(has_key(:wibble))
|
62
|
+
mockee.blah(:wobble => 2)
|
63
|
+
end
|
33
64
|
|
34
|
-
def test_mocha_with_unexpected_invocation
|
35
|
-
mockee = mock()
|
36
|
-
mockee.blah
|
37
65
|
end
|
38
|
-
|
39
|
-
def test_stubba_with_fulfilled_expectation
|
40
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
41
|
-
stubbee.expects(:blah)
|
42
|
-
stubbee.blah
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_stubba_with_unfulfilled_expectation
|
46
|
-
stubbee = Class.new { define_method(:blah) {} }.new
|
47
|
-
stubbee.expects(:blah)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_mocha_with_matching_parameter
|
51
|
-
mockee = mock()
|
52
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
53
|
-
mockee.blah(:wibble => 1)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_mocha_with_non_matching_parameter
|
57
|
-
mockee = mock()
|
58
|
-
mockee.expects(:blah).with(has_key(:wibble))
|
59
|
-
mockee.blah(:wobble => 2)
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
66
|
|
64
|
-
|
67
|
+
class MiniTestTest < Test::Unit::TestCase
|
65
68
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
def setup
|
70
|
+
@output = StringIO.new
|
71
|
+
MiniTest::Unit.output = @output
|
72
|
+
@runner = MiniTest::Unit.new
|
73
|
+
end
|
71
74
|
|
72
|
-
|
75
|
+
attr_reader :runner
|
73
76
|
|
74
|
-
|
75
|
-
|
77
|
+
def test_should_pass_mocha_test
|
78
|
+
runner.run(%w(-n test_mocha_with_fulfilled_expectation))
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
assert_equal 0, runner.failures
|
81
|
+
assert_equal 0, runner.errors
|
82
|
+
assert_equal 1, runner.assertion_count
|
83
|
+
end
|
81
84
|
|
82
|
-
|
83
|
-
|
85
|
+
def test_should_fail_mocha_test_due_to_unfulfilled_expectation
|
86
|
+
runner.run(%w(-n test_mocha_with_unfulfilled_expectation))
|
84
87
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
assert_equal 1, runner.failures
|
89
|
+
assert_equal 0, runner.errors
|
90
|
+
assert_equal 1, runner.assertion_count
|
91
|
+
assert_not_all_expectation_were_satisfied
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_should_fail_mocha_test_due_to_unexpected_invocation
|
95
|
+
runner.run(%w(-n test_mocha_with_unexpected_invocation))
|
93
96
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
97
|
+
assert_equal 1, runner.failures
|
98
|
+
assert_equal 0, runner.errors
|
99
|
+
assert_equal 0, runner.assertion_count
|
100
|
+
assert_unexpected_invocation
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_should_pass_stubba_test
|
104
|
+
runner.run(%w(-n test_stubba_with_fulfilled_expectation))
|
102
105
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
106
|
+
assert_equal 0, runner.failures
|
107
|
+
assert_equal 0, runner.errors
|
108
|
+
assert_equal 1, runner.assertion_count
|
109
|
+
end
|
107
110
|
|
108
|
-
|
109
|
-
|
111
|
+
def test_should_fail_stubba_test_due_to_unfulfilled_expectation
|
112
|
+
runner.run(%w(-n test_stubba_with_unfulfilled_expectation))
|
110
113
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
114
|
+
assert_equal 1, runner.failures
|
115
|
+
assert_equal 0, runner.errors
|
116
|
+
assert_equal 1, runner.assertion_count
|
117
|
+
assert_not_all_expectation_were_satisfied
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_should_pass_mocha_test_with_matching_parameter
|
121
|
+
runner.run(%w(-n test_mocha_with_matching_parameter))
|
119
122
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
123
|
+
assert_equal 0, runner.failures
|
124
|
+
assert_equal 0, runner.errors
|
125
|
+
assert_equal 1, runner.assertion_count
|
126
|
+
end
|
124
127
|
|
125
|
-
|
126
|
-
|
128
|
+
def test_should_fail_mocha_test_with_non_matching_parameter
|
129
|
+
runner.run(%w(-n test_mocha_with_non_matching_parameter))
|
127
130
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
131
|
+
assert_equal 1, runner.failures
|
132
|
+
assert_equal 0, runner.errors
|
133
|
+
assert_equal 0, runner.assertion_count # unexpected invocation occurs before expectation is verified
|
134
|
+
assert_unexpected_invocation
|
135
|
+
end
|
133
136
|
|
134
|
-
|
137
|
+
private
|
135
138
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
139
|
+
def output
|
140
|
+
@output.rewind
|
141
|
+
@output.read
|
142
|
+
end
|
140
143
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
+
def assert_unexpected_invocation
|
145
|
+
assert_match Regexp.new('unexpected invocation'), output, "MiniTest output:\n#{output}"
|
146
|
+
end
|
147
|
+
|
148
|
+
def assert_not_all_expectation_were_satisfied
|
149
|
+
assert_match Regexp.new('not all expectations were satisfied'), output, "MiniTest output:\n#{output}"
|
150
|
+
end
|
144
151
|
|
145
|
-
def assert_not_all_expectation_were_satisfied
|
146
|
-
assert_match Regexp.new('not all expectations were satisfied'), output, "MiniTest output:\n#{output}"
|
147
152
|
end
|
148
153
|
|
154
|
+
else
|
155
|
+
$stderr.puts "MiniTest is not available, so MiniTestAdapterTest has not been run."
|
149
156
|
end
|
150
|
-
|
151
|
-
else
|
152
|
-
warn "MiniTest is not available, so MiniTestAdapterTest has not been run."
|
153
157
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class ParameterMatcherTest < Test::Unit::TestCase
|
@@ -157,6 +157,25 @@ class ParameterMatcherTest < Test::Unit::TestCase
|
|
157
157
|
end
|
158
158
|
assert_failed(test_result)
|
159
159
|
end
|
160
|
+
|
161
|
+
def test_should_match_parameter_that_matches_any_of_the_given_matchers
|
162
|
+
test_result = run_as_test do
|
163
|
+
mock = mock()
|
164
|
+
mock.expects(:method).with(has_key(:foo) | has_key(:bar)).times(2)
|
165
|
+
mock.method(:foo => 'fooval')
|
166
|
+
mock.method(:bar => 'barval')
|
167
|
+
end
|
168
|
+
assert_passed(test_result)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_should_not_match_parameter_that_does_not_match_any_of_the_given_matchers
|
172
|
+
test_result = run_as_test do
|
173
|
+
mock = mock()
|
174
|
+
mock.expects(:method).with(has_key(:foo) | has_key(:bar))
|
175
|
+
mock.method(:baz => 'bazval')
|
176
|
+
end
|
177
|
+
assert_failed(test_result)
|
178
|
+
end
|
160
179
|
|
161
180
|
def test_should_match_parameter_that_matches_all_values
|
162
181
|
test_result = run_as_test do
|
@@ -175,6 +194,24 @@ class ParameterMatcherTest < Test::Unit::TestCase
|
|
175
194
|
end
|
176
195
|
assert_failed(test_result)
|
177
196
|
end
|
197
|
+
|
198
|
+
def test_should_match_parameter_that_matches_all_matchers
|
199
|
+
test_result = run_as_test do
|
200
|
+
mock = mock()
|
201
|
+
mock.expects(:method).with(has_key(:foo) & has_key(:bar))
|
202
|
+
mock.method(:foo => 'fooval', :bar => 'barval')
|
203
|
+
end
|
204
|
+
assert_passed(test_result)
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_should_not_match_parameter_that_does_not_match_all_matchers
|
208
|
+
test_result = run_as_test do
|
209
|
+
mock = mock()
|
210
|
+
mock.expects(:method).with(has_key(:foo) & has_key(:bar))
|
211
|
+
mock.method(:foo => 'fooval', :baz => 'bazval')
|
212
|
+
end
|
213
|
+
assert_failed(test_result)
|
214
|
+
end
|
178
215
|
|
179
216
|
def test_should_match_parameter_that_responds_with_specified_value
|
180
217
|
klass = Class.new do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class StubAnyInstanceMethodTest < Test::Unit::TestCase
|
@@ -47,13 +47,16 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
|
|
47
47
|
:original_return_value
|
48
48
|
end
|
49
49
|
protected :my_instance_method
|
50
|
+
def my_unprotected_instance_method
|
51
|
+
my_instance_method
|
52
|
+
end
|
50
53
|
end
|
51
54
|
instance = klass.new
|
52
55
|
run_as_test do
|
53
56
|
klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
|
54
57
|
end
|
55
58
|
assert instance.protected_methods(false).any? { |m| m.to_s == 'my_instance_method' }
|
56
|
-
assert_equal :original_return_value, instance.
|
59
|
+
assert_equal :original_return_value, instance.my_unprotected_instance_method
|
57
60
|
end
|
58
61
|
|
59
62
|
def test_should_leave_stubbed_private_method_unchanged_after_test
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
2
|
require 'mocha'
|
3
3
|
|
4
4
|
class StubClassMethodTest < Test::Unit::TestCase
|
@@ -50,13 +50,16 @@ class StubClassMethodTest < Test::Unit::TestCase
|
|
50
50
|
:original_return_value
|
51
51
|
end
|
52
52
|
protected :my_class_method
|
53
|
+
def my_unprotected_class_method
|
54
|
+
my_class_method
|
55
|
+
end
|
53
56
|
end
|
54
57
|
end
|
55
58
|
run_as_test do
|
56
59
|
klass.stubs(:my_class_method).returns(:new_return_value)
|
57
60
|
end
|
58
61
|
assert klass.protected_methods(false).any? { |m| m.to_s == 'my_class_method' }
|
59
|
-
assert_equal :original_return_value, klass.
|
62
|
+
assert_equal :original_return_value, klass.my_unprotected_class_method
|
60
63
|
end
|
61
64
|
|
62
65
|
def test_should_leave_stubbed_private_method_unchanged_after_test
|