mocha 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +28 -10
- data/examples/stubba.rb +1 -1
- data/lib/mocha/auto_verify.rb +6 -6
- data/lib/mocha/deprecation.rb +22 -0
- data/lib/mocha/exception_raiser.rb +17 -0
- data/lib/mocha/expectation.rb +167 -84
- data/lib/mocha/infinite_range.rb +4 -6
- data/lib/mocha/inspect.rb +3 -1
- data/lib/mocha/is_a.rb +9 -0
- data/lib/mocha/missing_expectation.rb +27 -0
- data/lib/mocha/mock.rb +191 -5
- data/lib/mocha/multiple_yields.rb +20 -0
- data/lib/mocha/no_yields.rb +11 -0
- data/lib/mocha/object.rb +11 -1
- data/lib/mocha/parameter_matchers.rb +9 -0
- data/lib/mocha/parameter_matchers/all_of.rb +39 -0
- data/lib/mocha/parameter_matchers/any_of.rb +44 -0
- data/lib/mocha/parameter_matchers/anything.rb +30 -0
- data/lib/mocha/parameter_matchers/has_entry.rb +39 -0
- data/lib/mocha/parameter_matchers/has_key.rb +39 -0
- data/lib/mocha/parameter_matchers/has_value.rb +39 -0
- data/lib/mocha/parameter_matchers/includes.rb +37 -0
- data/lib/mocha/return_values.rb +31 -0
- data/lib/mocha/single_return_value.rb +24 -0
- data/lib/mocha/single_yield.rb +18 -0
- data/lib/mocha/standalone.rb +2 -0
- data/lib/mocha/stub.rb +18 -0
- data/lib/mocha/yield_parameters.rb +31 -0
- data/test/{mocha_acceptance_test.rb → acceptance/mocha_acceptance_test.rb} +1 -1
- data/test/acceptance/mocked_methods_dispatch_acceptance_test.rb +72 -0
- data/test/acceptance/parameter_matcher_acceptance_test.rb +63 -0
- data/test/{standalone_acceptance_test.rb → acceptance/standalone_acceptance_test.rb} +22 -1
- data/test/{stubba_acceptance_test.rb → acceptance/stubba_acceptance_test.rb} +1 -1
- data/test/deprecation_disabler.rb +15 -0
- data/test/{mocha_test_result_integration_test.rb → integration/mocha_test_result_integration_test.rb} +1 -1
- data/test/{stubba_integration_test.rb → integration/stubba_integration_test.rb} +1 -1
- data/test/{stubba_test_result_integration_test.rb → integration/stubba_test_result_integration_test.rb} +1 -1
- data/test/test_helper.rb +8 -0
- data/test/test_runner.rb +31 -0
- data/test/{mocha → unit}/any_instance_method_test.rb +0 -0
- data/test/unit/array_inspect_test.rb +16 -0
- data/test/{mocha → unit}/auto_verify_test.rb +0 -0
- data/test/{mocha → unit}/central_test.rb +0 -0
- data/test/{mocha → unit}/class_method_test.rb +0 -0
- data/test/unit/date_time_inspect_test.rb +21 -0
- data/test/unit/expectation_raiser_test.rb +28 -0
- data/test/{mocha → unit}/expectation_test.rb +105 -63
- data/test/unit/hash_inspect_test.rb +16 -0
- data/test/{mocha → unit}/infinite_range_test.rb +8 -5
- data/test/{mocha → unit}/metaclass_test.rb +0 -0
- data/test/unit/missing_expectation_test.rb +51 -0
- data/test/unit/mock_test.rb +351 -0
- data/test/unit/multiple_yields_test.rb +18 -0
- data/test/unit/no_yield_test.rb +18 -0
- data/test/unit/object_inspect_test.rb +35 -0
- data/test/{mocha → unit}/object_test.rb +0 -0
- data/test/unit/parameter_matchers/all_of_test.rb +26 -0
- data/test/unit/parameter_matchers/any_of_test.rb +26 -0
- data/test/unit/parameter_matchers/anything_test.rb +21 -0
- data/test/unit/parameter_matchers/has_entry_test.rb +25 -0
- data/test/unit/parameter_matchers/has_key_test.rb +25 -0
- data/test/unit/parameter_matchers/has_value_test.rb +25 -0
- data/test/unit/parameter_matchers/includes_test.rb +25 -0
- data/test/unit/parameter_matchers/stub_matcher.rb +22 -0
- data/test/{mocha → unit}/pretty_parameters_test.rb +0 -0
- data/test/unit/return_values_test.rb +63 -0
- data/test/{mocha → unit}/setup_and_teardown_test.rb +0 -0
- data/test/unit/single_return_value_test.rb +33 -0
- data/test/unit/single_yield_test.rb +18 -0
- data/test/unit/string_inspect_test.rb +11 -0
- data/test/unit/stub_test.rb +24 -0
- data/test/unit/yield_parameters_test.rb +93 -0
- metadata +117 -73
- data/lib/mocha/mock_methods.rb +0 -122
- data/test/all_tests.rb +0 -75
- data/test/mocha/inspect_test.rb +0 -90
- data/test/mocha/mock_methods_test.rb +0 -235
- data/test/mocha/mock_test.rb +0 -84
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
2
|
require 'mocha_standalone'
|
3
3
|
|
4
4
|
class NotATestUnitAssertionFailedError < StandardError
|
@@ -70,6 +70,18 @@ class SampleTest < NotATestUnitTestCase
|
|
70
70
|
stubbee.expects(:blah)
|
71
71
|
end
|
72
72
|
|
73
|
+
def mocha_with_matching_parameter
|
74
|
+
mockee = mock()
|
75
|
+
mockee.expects(:blah).with(has_key(:wibble))
|
76
|
+
mockee.blah(:wibble => 1)
|
77
|
+
end
|
78
|
+
|
79
|
+
def mocha_with_non_matching_parameter
|
80
|
+
mockee = mock()
|
81
|
+
mockee.expects(:blah).with(has_key(:wibble))
|
82
|
+
mockee.blah(:wobble => 2)
|
83
|
+
end
|
84
|
+
|
73
85
|
end
|
74
86
|
|
75
87
|
require 'test/unit'
|
@@ -107,4 +119,13 @@ class StandaloneAcceptanceTest < Test::Unit::TestCase
|
|
107
119
|
assert_equal 1, sample_test.assertion_count
|
108
120
|
end
|
109
121
|
|
122
|
+
def test_should_pass_mocha_test_with_matching_parameter
|
123
|
+
assert_nothing_raised { sample_test.run(:mocha_with_matching_parameter) }
|
124
|
+
assert_equal 1, sample_test.assertion_count
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_should_fail_mocha_test_with_non_matching_parameter
|
128
|
+
assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_non_matching_parameter) }
|
129
|
+
end
|
130
|
+
|
110
131
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'mocha/deprecation'
|
2
|
+
|
3
|
+
module DeprecationDisabler
|
4
|
+
|
5
|
+
def disable_deprecations
|
6
|
+
original_mode = Mocha::Deprecation.mode
|
7
|
+
Mocha::Deprecation.mode = :disabled
|
8
|
+
begin
|
9
|
+
yield
|
10
|
+
ensure
|
11
|
+
Mocha::Deprecation.mode = original_mode
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
+
unless defined?(STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS)
|
2
|
+
STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS = Object.public_instance_methods
|
3
|
+
end
|
4
|
+
|
1
5
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
2
6
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
|
7
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit'))
|
8
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers'))
|
9
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'integration'))
|
10
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance'))
|
3
11
|
|
4
12
|
require 'test/unit'
|
data/test/test_runner.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test/unit/testresult'
|
2
|
+
require 'test/unit/testcase'
|
3
|
+
require 'mocha/standalone'
|
4
|
+
require 'mocha/test_case_adapter'
|
5
|
+
|
6
|
+
module TestRunner
|
7
|
+
|
8
|
+
def run_test(test_result = Test::Unit::TestResult.new, &block)
|
9
|
+
test_class = Class.new(Test::Unit::TestCase) do
|
10
|
+
include Mocha::Standalone
|
11
|
+
include Mocha::TestCaseAdapter
|
12
|
+
define_method(:test_me, &block)
|
13
|
+
end
|
14
|
+
test = test_class.new(:test_me)
|
15
|
+
test.run(test_result) {}
|
16
|
+
class << test_result
|
17
|
+
attr_reader :failures, :errors
|
18
|
+
end
|
19
|
+
test_result
|
20
|
+
end
|
21
|
+
|
22
|
+
def assert_passed(test_result)
|
23
|
+
flunk "Test failed unexpectedly with message: #{test_result.failures.first.message}" if test_result.failure_count > 0
|
24
|
+
flunk "Test failed unexpectedly with message: #{test_result.errors.first.message}" if test_result.error_count > 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def assert_failed(test_result)
|
28
|
+
flunk "Test passed unexpectedly" if test_result.passed?
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/inspect'
|
3
|
+
|
4
|
+
class ArrayInstanceTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_should_use_inspect
|
7
|
+
array = [1, 2]
|
8
|
+
assert_equal array.inspect, array.mocha_inspect
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_use_mocha_inspect_on_each_item
|
12
|
+
array = [1, 2, "chris"]
|
13
|
+
assert_equal "[1, 2, 'chris']", array.mocha_inspect
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/inspect'
|
3
|
+
|
4
|
+
class TimeDateInspectTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_should_use_include_date_in_seconds
|
7
|
+
time = Time.now
|
8
|
+
assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_use_to_s_for_date
|
12
|
+
date = Date.new(2006, 1, 1)
|
13
|
+
assert_equal date.to_s, date.mocha_inspect
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_use_to_s_for_datetime
|
17
|
+
datetime = DateTime.new(2006, 1, 1)
|
18
|
+
assert_equal datetime.to_s, datetime.mocha_inspect
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
|
3
|
+
require 'mocha/exception_raiser'
|
4
|
+
|
5
|
+
class ExceptionRaiserTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Mocha
|
8
|
+
|
9
|
+
def test_should_raise_exception_with_specified_class_and_default_message
|
10
|
+
exception_class = Class.new(StandardError)
|
11
|
+
raiser = ExceptionRaiser.new(exception_class, nil)
|
12
|
+
exception = assert_raises(exception_class) { raiser.evaluate }
|
13
|
+
assert_equal exception_class.to_s, exception.message
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_should_raise_exception_with_specified_class_and_message
|
17
|
+
exception_class = Class.new(StandardError)
|
18
|
+
raiser = ExceptionRaiser.new(exception_class, 'message')
|
19
|
+
exception = assert_raises(exception_class) { raiser.evaluate }
|
20
|
+
assert_equal 'message', exception.message
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
|
24
|
+
raiser = ExceptionRaiser.new(Interrupt, nil)
|
25
|
+
assert_raises(Interrupt) { raiser.evaluate }
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -2,10 +2,12 @@ require File.join(File.dirname(__FILE__), "..", "test_helper")
|
|
2
2
|
require 'method_definer'
|
3
3
|
require 'mocha/expectation'
|
4
4
|
require 'execution_point'
|
5
|
+
require 'deprecation_disabler'
|
5
6
|
|
6
7
|
class ExpectationTest < Test::Unit::TestCase
|
7
8
|
|
8
9
|
include Mocha
|
10
|
+
include DeprecationDisabler
|
9
11
|
|
10
12
|
def new_expectation
|
11
13
|
Expectation.new(nil, :expected_method)
|
@@ -35,6 +37,11 @@ class ExpectationTest < Test::Unit::TestCase
|
|
35
37
|
assert expectation.match?(:expected_method, 1, 2, 3)
|
36
38
|
end
|
37
39
|
|
40
|
+
def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected
|
41
|
+
expectation = new_expectation.with() {|x, y, z| x + y == z}
|
42
|
+
assert !expectation.match?(:different_method, 1, 2, 3)
|
43
|
+
end
|
44
|
+
|
38
45
|
def test_should_not_match_calls_to_different_methods_with_no_parameters
|
39
46
|
assert !new_expectation.match?(:unexpected_method)
|
40
47
|
end
|
@@ -59,6 +66,33 @@ class ExpectationTest < Test::Unit::TestCase
|
|
59
66
|
assert !expectation.match?(:expected_method, 1, 0, 3)
|
60
67
|
end
|
61
68
|
|
69
|
+
def test_should_match_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two
|
70
|
+
expectation = new_expectation.times(1)
|
71
|
+
assert expectation.match?(:expected_method)
|
72
|
+
expectation.invoke
|
73
|
+
assert !expectation.match?(:expected_method)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_should_match_until_expected_invocation_count_is_two_and_actual_invocation_count_would_be_three
|
77
|
+
expectation = new_expectation.times(2)
|
78
|
+
assert expectation.match?(:expected_method)
|
79
|
+
expectation.invoke
|
80
|
+
assert expectation.match?(:expected_method)
|
81
|
+
expectation.invoke
|
82
|
+
assert !expectation.match?(:expected_method)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_should_match_until_expected_invocation_count_is_a_range_from_two_to_three_and_actual_invocation_count_would_be_four
|
86
|
+
expectation = new_expectation.times(2..3)
|
87
|
+
assert expectation.match?(:expected_method)
|
88
|
+
expectation.invoke
|
89
|
+
assert expectation.match?(:expected_method)
|
90
|
+
expectation.invoke
|
91
|
+
assert expectation.match?(:expected_method)
|
92
|
+
expectation.invoke
|
93
|
+
assert !expectation.match?(:expected_method)
|
94
|
+
end
|
95
|
+
|
62
96
|
def test_should_store_provided_backtrace
|
63
97
|
backtrace = Object.new
|
64
98
|
expectation = Expectation.new(nil, :expected_method, backtrace)
|
@@ -77,18 +111,40 @@ class ExpectationTest < Test::Unit::TestCase
|
|
77
111
|
end
|
78
112
|
|
79
113
|
def test_should_yield_no_parameters
|
80
|
-
expectation = new_expectation.yields
|
114
|
+
expectation = new_expectation().yields()
|
81
115
|
yielded_parameters = nil
|
82
|
-
expectation.invoke() { |*parameters| yielded_parameters
|
116
|
+
expectation.invoke() { |*parameters| yielded_parameters = parameters }
|
83
117
|
assert_equal Array.new, yielded_parameters
|
84
118
|
end
|
85
119
|
|
86
120
|
def test_should_yield_with_specified_parameters
|
87
|
-
|
88
|
-
expectation = new_expectation.yields(*parameters_for_yield)
|
121
|
+
expectation = new_expectation().yields(1, 2, 3)
|
89
122
|
yielded_parameters = nil
|
90
|
-
expectation.invoke() { |*parameters| yielded_parameters
|
91
|
-
assert_equal
|
123
|
+
expectation.invoke() { |*parameters| yielded_parameters = parameters }
|
124
|
+
assert_equal [1, 2, 3], yielded_parameters
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_should_yield_different_parameters_on_consecutive_invocations
|
128
|
+
expectation = new_expectation().yields(1, 2, 3).yields(4, 5)
|
129
|
+
yielded_parameters = []
|
130
|
+
expectation.invoke() { |*parameters| yielded_parameters << parameters }
|
131
|
+
expectation.invoke() { |*parameters| yielded_parameters << parameters }
|
132
|
+
assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_should_yield_multiple_times_for_single_invocation
|
136
|
+
expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5])
|
137
|
+
yielded_parameters = []
|
138
|
+
expectation.invoke() { |*parameters| yielded_parameters << parameters }
|
139
|
+
assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_should_yield_multiple_times_for_first_invocation_and_once_for_second_invocation
|
143
|
+
expectation = new_expectation().multiple_yields([1, 2, 3], [4, 5]).then.yields(6, 7)
|
144
|
+
yielded_parameters = []
|
145
|
+
expectation.invoke() { |*parameters| yielded_parameters << parameters }
|
146
|
+
expectation.invoke() { |*parameters| yielded_parameters << parameters }
|
147
|
+
assert_equal [[1, 2, 3], [4, 5], [6, 7]], yielded_parameters
|
92
148
|
end
|
93
149
|
|
94
150
|
def test_should_return_specified_value
|
@@ -130,7 +186,9 @@ class ExpectationTest < Test::Unit::TestCase
|
|
130
186
|
def test_should_return_evaluated_proc
|
131
187
|
proc = lambda { 99 }
|
132
188
|
expectation = new_expectation.returns(proc)
|
133
|
-
|
189
|
+
result = nil
|
190
|
+
disable_deprecations { result = expectation.invoke }
|
191
|
+
assert_equal 99, result
|
134
192
|
end
|
135
193
|
|
136
194
|
def test_should_return_evaluated_proc_without_using_is_a_method
|
@@ -139,7 +197,7 @@ class ExpectationTest < Test::Unit::TestCase
|
|
139
197
|
proc.called = false
|
140
198
|
proc.replace_instance_method(:is_a?) { self.called = true; true}
|
141
199
|
expectation = new_expectation.returns(proc)
|
142
|
-
expectation.invoke
|
200
|
+
disable_deprecations { expectation.invoke }
|
143
201
|
assert_equal false, proc.called
|
144
202
|
end
|
145
203
|
|
@@ -175,6 +233,20 @@ class ExpectationTest < Test::Unit::TestCase
|
|
175
233
|
assert_equal exception_msg, exception.message
|
176
234
|
end
|
177
235
|
|
236
|
+
def test_should_return_values_then_raise_exception
|
237
|
+
expectation = new_expectation.returns(1, 2).then.raises()
|
238
|
+
assert_equal 1, expectation.invoke
|
239
|
+
assert_equal 2, expectation.invoke
|
240
|
+
assert_raise(RuntimeError) { expectation.invoke }
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_should_raise_exception_then_return_values
|
244
|
+
expectation = new_expectation.raises().then.returns(1, 2)
|
245
|
+
assert_raise(RuntimeError) { expectation.invoke }
|
246
|
+
assert_equal 1, expectation.invoke
|
247
|
+
assert_equal 2, expectation.invoke
|
248
|
+
end
|
249
|
+
|
178
250
|
def test_should_not_raise_error_on_verify_if_expected_call_was_made
|
179
251
|
expectation = new_expectation
|
180
252
|
expectation.invoke
|
@@ -183,6 +255,30 @@ class ExpectationTest < Test::Unit::TestCase
|
|
183
255
|
}
|
184
256
|
end
|
185
257
|
|
258
|
+
def test_should_raise_error_on_verify_if_call_expected_once_but_invoked_twice
|
259
|
+
expectation = new_expectation.once
|
260
|
+
expectation.invoke
|
261
|
+
expectation.invoke
|
262
|
+
assert_raises(ExpectationError) {
|
263
|
+
expectation.verify
|
264
|
+
}
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_should_raise_error_on_verify_if_call_expected_once_but_not_invoked
|
268
|
+
expectation = new_expectation.once
|
269
|
+
assert_raises(ExpectationError) {
|
270
|
+
expectation.verify
|
271
|
+
}
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_should_not_raise_error_on_verify_if_call_expected_once_and_invoked_once
|
275
|
+
expectation = new_expectation.once
|
276
|
+
expectation.invoke
|
277
|
+
assert_nothing_raised(ExpectationError) {
|
278
|
+
expectation.verify
|
279
|
+
}
|
280
|
+
end
|
281
|
+
|
186
282
|
def test_should_not_raise_error_on_verify_if_expected_call_was_made_at_least_once
|
187
283
|
expectation = new_expectation.at_least_once
|
188
284
|
3.times {expectation.invoke}
|
@@ -280,13 +376,6 @@ class ExpectationTest < Test::Unit::TestCase
|
|
280
376
|
assert_equal "expected_method", new_expectation.method_signature
|
281
377
|
end
|
282
378
|
|
283
|
-
def test_should_always_verify_successfully
|
284
|
-
stub = Stub.new(nil, :expected_method)
|
285
|
-
assert stub.verify
|
286
|
-
stub.invoke
|
287
|
-
assert stub.verify
|
288
|
-
end
|
289
|
-
|
290
379
|
def test_should_raise_error_with_message_indicating_which_method_was_expected_to_be_called_on_which_mock_object
|
291
380
|
mock = Class.new { def mocha_inspect; 'mock'; end }.new
|
292
381
|
expectation = Expectation.new(mock, :expected_method)
|
@@ -294,53 +383,6 @@ class ExpectationTest < Test::Unit::TestCase
|
|
294
383
|
assert_match "mock.expected_method", e.message
|
295
384
|
end
|
296
385
|
|
297
|
-
end
|
298
|
-
|
299
|
-
class ExpectationSimilarExpectationsTest < Test::Unit::TestCase
|
300
|
-
|
301
|
-
include Mocha
|
302
|
-
|
303
|
-
def new_expectation
|
304
|
-
Expectation.new(nil, :expected_method)
|
305
|
-
end
|
306
|
-
|
307
|
-
def test_should_find_expectations_to_the_same_method
|
308
|
-
expectation = new_expectation.with(1)
|
309
|
-
mock = Object.new
|
310
|
-
mock.define_instance_method(:expectations) { [expectation] }
|
311
|
-
failed_expectation = MissingExpectation.new(mock, :expected_method).with(2)
|
312
|
-
assert_equal [expectation], failed_expectation.similar_expectations
|
313
|
-
end
|
314
|
-
|
315
|
-
def test_should_report_similar_expectations
|
316
|
-
mock = Object.new
|
317
|
-
expectation_1 = new_expectation.with(1)
|
318
|
-
expectation_2 = new_expectation.with(2)
|
319
|
-
mock = Object.new
|
320
|
-
mock.define_instance_method(:expectations) { [expectation_1, expectation_2] }
|
321
|
-
missing_expectation = MissingExpectation.new(mock, :expected_method).with(3)
|
322
|
-
exception = assert_raise(ExpectationError) { missing_expectation.verify }
|
323
|
-
assert_equal "#{mock.mocha_inspect}.expected_method(3) - expected calls: 0, actual calls: 1\nSimilar expectations:\nexpected_method(1)\nexpected_method(2)", exception.message
|
324
|
-
end
|
325
|
-
|
326
|
-
def test_should_ignore_expectations_to_different_methods
|
327
|
-
expectation = new_expectation.with(1)
|
328
|
-
mock = Object.new
|
329
|
-
mock.define_instance_method(:expectations) { [expectation] }
|
330
|
-
failed_expectation = MissingExpectation.new(mock, :other_method).with(1)
|
331
|
-
assert failed_expectation.similar_expectations.empty?
|
332
|
-
end
|
333
|
-
|
334
|
-
def test_should_not_report_similar_expectations
|
335
|
-
expectation = new_expectation.with(1)
|
336
|
-
mock = Object.new
|
337
|
-
mock.define_instance_method(:expectations) { [expectation] }
|
338
|
-
mock.define_instance_method(:mocha_inspect) { 'mocha_inspect' }
|
339
|
-
missing_expectation = MissingExpectation.new(mock, :unexpected_method).with(1)
|
340
|
-
exception = assert_raise(ExpectationError) { missing_expectation.verify }
|
341
|
-
assert_equal "mocha_inspect.unexpected_method(1) - expected calls: 0, actual calls: 1", exception.message
|
342
|
-
end
|
343
|
-
|
344
386
|
def test_should_exclude_mocha_locations_from_backtrace
|
345
387
|
mocha_lib = "/username/workspace/mocha_wibble/lib/"
|
346
388
|
backtrace = [ mocha_lib + 'exclude/me/1', mocha_lib + 'exclude/me/2', '/keep/me', mocha_lib + 'exclude/me/3']
|
@@ -354,4 +396,4 @@ class ExpectationSimilarExpectationsTest < Test::Unit::TestCase
|
|
354
396
|
assert_match Regexp.new("/lib/$"), expectation.mocha_lib_directory
|
355
397
|
end
|
356
398
|
|
357
|
-
end
|
399
|
+
end
|