google-geo 1.0 → 2.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/CHANGELOG +5 -0
- data/README +12 -8
- data/lib/google/geo.rb +10 -6
- data/test/fixtures/invalid_map_key.xml +10 -0
- data/test/fixtures/missing_address.xml +10 -0
- data/test/fixtures/server_error.xml +10 -0
- data/test/fixtures/success.xml +36 -0
- data/test/fixtures/success_with_multiple_addresses.xml +62 -0
- data/test/fixtures/too_many_queries.xml +10 -0
- data/test/fixtures/unavailable_address.xml +10 -0
- data/test/fixtures/unknown_address.xml +10 -0
- data/test/geo_test.rb +19 -5
- data/vendor/mocha-0.4.0/COPYING +3 -0
- data/vendor/mocha-0.4.0/MIT-LICENSE +7 -0
- data/vendor/mocha-0.4.0/README +35 -0
- data/vendor/mocha-0.4.0/RELEASE +98 -0
- data/vendor/mocha-0.4.0/Rakefile +126 -0
- data/vendor/mocha-0.4.0/examples/misc.rb +36 -0
- data/vendor/mocha-0.4.0/examples/mocha.rb +26 -0
- data/vendor/mocha-0.4.0/examples/stubba.rb +65 -0
- data/vendor/mocha-0.4.0/lib/mocha.rb +19 -0
- data/vendor/mocha-0.4.0/lib/mocha/any_instance_method.rb +35 -0
- data/vendor/mocha-0.4.0/lib/mocha/auto_verify.rb +113 -0
- data/vendor/mocha-0.4.0/lib/mocha/central.rb +35 -0
- data/vendor/mocha-0.4.0/lib/mocha/class_method.rb +62 -0
- data/vendor/mocha-0.4.0/lib/mocha/expectation.rb +295 -0
- data/vendor/mocha-0.4.0/lib/mocha/expectation_error.rb +6 -0
- data/vendor/mocha-0.4.0/lib/mocha/infinite_range.rb +27 -0
- data/vendor/mocha-0.4.0/lib/mocha/inspect.rb +37 -0
- data/vendor/mocha-0.4.0/lib/mocha/instance_method.rb +8 -0
- data/vendor/mocha-0.4.0/lib/mocha/metaclass.rb +7 -0
- data/vendor/mocha-0.4.0/lib/mocha/mock.rb +20 -0
- data/vendor/mocha-0.4.0/lib/mocha/mock_methods.rb +122 -0
- data/vendor/mocha-0.4.0/lib/mocha/object.rb +100 -0
- data/vendor/mocha-0.4.0/lib/mocha/pretty_parameters.rb +28 -0
- data/vendor/mocha-0.4.0/lib/mocha/setup_and_teardown.rb +23 -0
- data/vendor/mocha-0.4.0/lib/mocha/standalone.rb +30 -0
- data/vendor/mocha-0.4.0/lib/mocha/test_case_adapter.rb +49 -0
- data/vendor/mocha-0.4.0/lib/mocha_standalone.rb +2 -0
- data/vendor/mocha-0.4.0/lib/stubba.rb +2 -0
- data/vendor/mocha-0.4.0/test/active_record_test_case.rb +36 -0
- data/vendor/mocha-0.4.0/test/all_tests.rb +75 -0
- data/vendor/mocha-0.4.0/test/execution_point.rb +34 -0
- data/vendor/mocha-0.4.0/test/method_definer.rb +18 -0
- data/vendor/mocha-0.4.0/test/mocha/any_instance_method_test.rb +124 -0
- data/vendor/mocha-0.4.0/test/mocha/auto_verify_test.rb +163 -0
- data/vendor/mocha-0.4.0/test/mocha/central_test.rb +124 -0
- data/vendor/mocha-0.4.0/test/mocha/class_method_test.rb +196 -0
- data/vendor/mocha-0.4.0/test/mocha/expectation_test.rb +357 -0
- data/vendor/mocha-0.4.0/test/mocha/infinite_range_test.rb +50 -0
- data/vendor/mocha-0.4.0/test/mocha/inspect_test.rb +90 -0
- data/vendor/mocha-0.4.0/test/mocha/metaclass_test.rb +22 -0
- data/vendor/mocha-0.4.0/test/mocha/mock_methods_test.rb +235 -0
- data/vendor/mocha-0.4.0/test/mocha/mock_test.rb +84 -0
- data/vendor/mocha-0.4.0/test/mocha/object_test.rb +165 -0
- data/vendor/mocha-0.4.0/test/mocha/pretty_parameters_test.rb +32 -0
- data/vendor/mocha-0.4.0/test/mocha/setup_and_teardown_test.rb +76 -0
- data/vendor/mocha-0.4.0/test/mocha_acceptance_test.rb +98 -0
- data/vendor/mocha-0.4.0/test/mocha_test_result_integration_test.rb +105 -0
- data/vendor/mocha-0.4.0/test/standalone_acceptance_test.rb +110 -0
- data/vendor/mocha-0.4.0/test/stubba_acceptance_test.rb +102 -0
- data/vendor/mocha-0.4.0/test/stubba_integration_test.rb +89 -0
- data/vendor/mocha-0.4.0/test/stubba_test_result_integration_test.rb +85 -0
- data/vendor/mocha-0.4.0/test/test_helper.rb +4 -0
- metadata +73 -3
@@ -0,0 +1,165 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/mock'
|
3
|
+
require 'method_definer'
|
4
|
+
|
5
|
+
require 'mocha/object'
|
6
|
+
|
7
|
+
class ObjectTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
include Mocha
|
10
|
+
|
11
|
+
def test_should_build_mocha
|
12
|
+
instance = Object.new
|
13
|
+
mocha = instance.mocha
|
14
|
+
assert_not_nil mocha
|
15
|
+
assert mocha.is_a?(Mock)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_reuse_existing_mocha
|
19
|
+
instance = Object.new
|
20
|
+
mocha_1 = instance.mocha
|
21
|
+
mocha_2 = instance.mocha
|
22
|
+
assert_equal mocha_1, mocha_2
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_should_reset_mocha
|
26
|
+
instance = Object.new
|
27
|
+
assert_nil instance.reset_mocha
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_stub_instance_method
|
31
|
+
instance = Object.new
|
32
|
+
$stubba = Mock.new
|
33
|
+
$stubba.expects(:stub).with(Mocha::InstanceMethod.new(instance, :method1))
|
34
|
+
instance.expects(:method1)
|
35
|
+
$stubba.verify
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_should_build_and_store_expectation
|
39
|
+
instance = Object.new
|
40
|
+
$stubba = Mock.new
|
41
|
+
$stubba.stubs(:stub)
|
42
|
+
expectation = instance.expects(:method1)
|
43
|
+
assert_equal [expectation], instance.mocha.expectations
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_should_verify_expectations
|
47
|
+
instance = Object.new
|
48
|
+
$stubba = Mock.new
|
49
|
+
$stubba.stubs(:stub)
|
50
|
+
instance.expects(:method1).with(:value1, :value2)
|
51
|
+
assert_raise(ExpectationError) { instance.verify }
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_pass_backtrace_into_expects
|
55
|
+
instance = Object.new
|
56
|
+
$stubba = Mock.new
|
57
|
+
$stubba.stubs(:stub)
|
58
|
+
mocha = Object.new
|
59
|
+
mocha.define_instance_accessor(:expects_parameters)
|
60
|
+
mocha.define_instance_method(:expects) { |*parameters| self.expects_parameters = parameters }
|
61
|
+
backtrace = Object.new
|
62
|
+
instance.define_instance_method(:mocha) { mocha }
|
63
|
+
instance.define_instance_method(:caller) { backtrace }
|
64
|
+
instance.expects(:method1)
|
65
|
+
assert_equal [:method1, backtrace], mocha.expects_parameters
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_should_pass_backtrace_into_stubs
|
69
|
+
instance = Object.new
|
70
|
+
$stubba = Mock.new
|
71
|
+
$stubba.stubs(:stub)
|
72
|
+
mocha = Object.new
|
73
|
+
mocha.define_instance_accessor(:stubs_parameters)
|
74
|
+
mocha.define_instance_method(:stubs) { |*parameters| self.stubs_parameters = parameters }
|
75
|
+
backtrace = Object.new
|
76
|
+
instance.define_instance_method(:mocha) { mocha }
|
77
|
+
instance.define_instance_method(:caller) { backtrace }
|
78
|
+
instance.stubs(:method1)
|
79
|
+
assert_equal [:method1, backtrace], mocha.stubs_parameters
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_should_build_any_instance_object
|
83
|
+
klass = Class.new
|
84
|
+
any_instance = klass.any_instance
|
85
|
+
assert_not_nil any_instance
|
86
|
+
assert any_instance.is_a?(Class::AnyInstance)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_should_return_same_any_instance_object
|
90
|
+
klass = Class.new
|
91
|
+
any_instance_1 = klass.any_instance
|
92
|
+
any_instance_2 = klass.any_instance
|
93
|
+
assert_equal any_instance_1, any_instance_2
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_should_stub_class_method
|
97
|
+
klass = Class.new
|
98
|
+
$stubba = Mock.new
|
99
|
+
$stubba.expects(:stub).with(Mocha::ClassMethod.new(klass, :method1))
|
100
|
+
klass.expects(:method1)
|
101
|
+
$stubba.verify
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_should_build_and_store_class_method_expectation
|
105
|
+
klass = Class.new
|
106
|
+
$stubba = Mock.new
|
107
|
+
$stubba.stubs(:stub)
|
108
|
+
expectation = klass.expects(:method1)
|
109
|
+
assert_equal [expectation], klass.mocha.expectations
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_should_stub_module_method
|
113
|
+
mod = Module.new
|
114
|
+
$stubba = Mock.new
|
115
|
+
$stubba.expects(:stub).with(Mocha::ClassMethod.new(mod, :method1))
|
116
|
+
mod.expects(:method1)
|
117
|
+
$stubba.verify
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_should_build_and_store_module_method_expectation
|
121
|
+
mod = Module.new
|
122
|
+
$stubba = Mock.new
|
123
|
+
$stubba.stubs(:stub)
|
124
|
+
expectation = mod.expects(:method1)
|
125
|
+
assert_equal [expectation], mod.mocha.expectations
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_should_use_stubba_instance_method_for_object
|
129
|
+
assert_equal Mocha::InstanceMethod, Object.new.stubba_method
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_should_use_stubba_class_method_for_module
|
133
|
+
assert_equal Mocha::ClassMethod, Module.new.stubba_method
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_should_use_stubba_class_method_for_class
|
137
|
+
assert_equal Mocha::ClassMethod, Class.new.stubba_method
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_should_use_stubba_class_method_for_any_instance
|
141
|
+
assert_equal Mocha::AnyInstanceMethod, Class::AnyInstance.new(nil).stubba_method
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_should_stub_self_for_object
|
145
|
+
object = Object.new
|
146
|
+
assert_equal object, object.stubba_object
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_should_stub_self_for_module
|
150
|
+
mod = Module.new
|
151
|
+
assert_equal mod, mod.stubba_object
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_should_stub_self_for_class
|
155
|
+
klass = Class.new
|
156
|
+
assert_equal klass, klass.stubba_object
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_should_stub_relevant_class_for_any_instance
|
160
|
+
klass = Class.new
|
161
|
+
any_instance = Class::AnyInstance.new(klass)
|
162
|
+
assert_equal klass, any_instance.stubba_object
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/pretty_parameters'
|
3
|
+
|
4
|
+
class PrettyParametersTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
include Mocha
|
7
|
+
|
8
|
+
def test_should_remove_outer_array_braces
|
9
|
+
params = [1, 2, [3, 4]]
|
10
|
+
parameters = PrettyParameters.new(params)
|
11
|
+
assert_equal '1, 2, [3, 4]', parameters.pretty
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_display_numeric_arguments_as_is
|
15
|
+
params = [1, 2, 3]
|
16
|
+
parameters = PrettyParameters.new(params)
|
17
|
+
assert_equal '1, 2, 3', parameters.pretty
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_remove_curly_braces_if_hash_is_only_argument
|
21
|
+
params = [{:a => 1, :z => 2}]
|
22
|
+
parameters = PrettyParameters.new(params)
|
23
|
+
assert_match /^:[az] => [12], :[az] => [12]$/, parameters.pretty
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_not_remove_curly_braces_if_hash_is_not_the_only_argument
|
27
|
+
params = [1, {:a => 1}]
|
28
|
+
parameters = PrettyParameters.new(params)
|
29
|
+
assert_equal '1, {:a => 1}', parameters.pretty
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/mock'
|
3
|
+
|
4
|
+
require 'mocha/setup_and_teardown'
|
5
|
+
|
6
|
+
class SetupAndTeardownTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include Mocha
|
9
|
+
|
10
|
+
def test_should_instantiate_new_stubba
|
11
|
+
test_case = stubbed_test_case_class.new
|
12
|
+
test_case.setup_stubs
|
13
|
+
|
14
|
+
assert $stubba
|
15
|
+
assert $stubba.is_a?(Mocha::Central)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_verify_all_expectations
|
19
|
+
test_case = stubbed_test_case_class.new
|
20
|
+
stubba = Mock.new
|
21
|
+
stubba.expects(:verify_all)
|
22
|
+
$stubba = stubba
|
23
|
+
|
24
|
+
test_case.verify_stubs
|
25
|
+
|
26
|
+
stubba.verify
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_yield_to_block_for_each_assertion
|
30
|
+
test_case = stubbed_test_case_class.new
|
31
|
+
$stubba = Mock.new
|
32
|
+
$stubba.stubs(:verify_all).yields
|
33
|
+
yielded = false
|
34
|
+
|
35
|
+
test_case.verify_stubs { yielded = true }
|
36
|
+
|
37
|
+
assert_equal true, yielded
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_should_unstub_all_stubbed_methods
|
41
|
+
test_case = stubbed_test_case_class.new
|
42
|
+
stubba = Mock.new
|
43
|
+
stubba.expects(:unstub_all)
|
44
|
+
$stubba = stubba
|
45
|
+
|
46
|
+
test_case.teardown_stubs
|
47
|
+
|
48
|
+
stubba.verify
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_should_set_stubba_to_nil
|
52
|
+
test_case = stubbed_test_case_class.new
|
53
|
+
$stubba = Mock.new
|
54
|
+
$stubba.stubs(:unstub_all)
|
55
|
+
|
56
|
+
test_case.teardown_stubs
|
57
|
+
|
58
|
+
assert_nil $stubba
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_should_not_raise_exception_if_no_stubba_central_available
|
62
|
+
test_case = stubbed_test_case_class.new
|
63
|
+
$stubba = nil
|
64
|
+
assert_nothing_raised { test_case.teardown_stubs }
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def stubbed_test_case_class
|
70
|
+
Class.new do
|
71
|
+
include Mocha::SetupAndTeardown
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'mocha'
|
3
|
+
|
4
|
+
class MochaAcceptanceTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class Rover
|
7
|
+
|
8
|
+
def initialize(left_track, right_track, steps_per_metre, steps_per_degree)
|
9
|
+
@left_track, @right_track, @steps_per_metre, @steps_per_degree = left_track, right_track, steps_per_metre, steps_per_degree
|
10
|
+
end
|
11
|
+
|
12
|
+
def forward(metres)
|
13
|
+
@left_track.step(metres * @steps_per_metre)
|
14
|
+
@right_track.step(metres * @steps_per_metre)
|
15
|
+
wait
|
16
|
+
end
|
17
|
+
|
18
|
+
def backward(metres)
|
19
|
+
forward(-metres)
|
20
|
+
end
|
21
|
+
|
22
|
+
def left(degrees)
|
23
|
+
@left_track.step(-degrees * @steps_per_degree)
|
24
|
+
@right_track.step(+degrees * @steps_per_degree)
|
25
|
+
wait
|
26
|
+
end
|
27
|
+
|
28
|
+
def right(degrees)
|
29
|
+
left(-degrees)
|
30
|
+
end
|
31
|
+
|
32
|
+
def wait
|
33
|
+
while (@left_track.moving? or @right_track.moving?); end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_should_step_both_tracks_forward_ten_steps
|
39
|
+
left_track = mock('left_track')
|
40
|
+
right_track = mock('right_track')
|
41
|
+
steps_per_metre = 5
|
42
|
+
rover = Rover.new(left_track, right_track, steps_per_metre, nil)
|
43
|
+
|
44
|
+
left_track.expects(:step).with(10)
|
45
|
+
right_track.expects(:step).with(10)
|
46
|
+
|
47
|
+
left_track.stubs(:moving?).returns(false)
|
48
|
+
right_track.stubs(:moving?).returns(false)
|
49
|
+
|
50
|
+
rover.forward(2)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_should_step_both_tracks_backward_ten_steps
|
54
|
+
left_track = mock('left_track')
|
55
|
+
right_track = mock('right_track')
|
56
|
+
steps_per_metre = 5
|
57
|
+
rover = Rover.new(left_track, right_track, steps_per_metre, nil)
|
58
|
+
|
59
|
+
left_track.expects(:step).with(-10)
|
60
|
+
right_track.expects(:step).with(-10)
|
61
|
+
|
62
|
+
left_track.stubs(:moving?).returns(false)
|
63
|
+
right_track.stubs(:moving?).returns(false)
|
64
|
+
|
65
|
+
rover.backward(2)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_should_step_left_track_forwards_five_steps_and_right_track_backwards_five_steps
|
69
|
+
left_track = mock('left_track')
|
70
|
+
right_track = mock('right_track')
|
71
|
+
steps_per_degree = 5.0 / 90.0
|
72
|
+
rover = Rover.new(left_track, right_track, nil, steps_per_degree)
|
73
|
+
|
74
|
+
left_track.expects(:step).with(+5)
|
75
|
+
right_track.expects(:step).with(-5)
|
76
|
+
|
77
|
+
left_track.stubs(:moving?).returns(false)
|
78
|
+
right_track.stubs(:moving?).returns(false)
|
79
|
+
|
80
|
+
rover.right(90)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_should_step_left_track_backwards_five_steps_and_right_track_forwards_five_steps
|
84
|
+
left_track = mock('left_track')
|
85
|
+
right_track = mock('right_track')
|
86
|
+
steps_per_degree = 5.0 / 90.0
|
87
|
+
rover = Rover.new(left_track, right_track, nil, steps_per_degree)
|
88
|
+
|
89
|
+
left_track.expects(:step).with(-5)
|
90
|
+
right_track.expects(:step).with(+5)
|
91
|
+
|
92
|
+
left_track.stubs(:moving?).returns(false)
|
93
|
+
right_track.stubs(:moving?).returns(false)
|
94
|
+
|
95
|
+
rover.left(90)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'mocha/standalone'
|
3
|
+
require 'mocha/test_case_adapter'
|
4
|
+
require 'execution_point'
|
5
|
+
|
6
|
+
class MochaTestResultIntegrationTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_should_include_expectation_verification_in_assertion_count
|
9
|
+
test_result = run_test do
|
10
|
+
object = mock()
|
11
|
+
object.expects(:message)
|
12
|
+
object.message
|
13
|
+
end
|
14
|
+
assert_equal 1, test_result.assertion_count
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_include_assertions_in_assertion_count
|
18
|
+
test_result = run_test do
|
19
|
+
assert true
|
20
|
+
end
|
21
|
+
assert_equal 1, test_result.assertion_count
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_not_include_stubbing_expectation_verification_in_assertion_count
|
25
|
+
test_result = run_test do
|
26
|
+
object = mock()
|
27
|
+
object.stubs(:message)
|
28
|
+
object.message
|
29
|
+
end
|
30
|
+
assert_equal 0, test_result.assertion_count
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_include_expectation_verification_failure_in_failure_count
|
34
|
+
test_result = run_test do
|
35
|
+
object = mock()
|
36
|
+
object.expects(:message)
|
37
|
+
end
|
38
|
+
assert_equal 1, test_result.failure_count
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_include_unexpected_verification_failure_in_failure_count
|
42
|
+
test_result = run_test do
|
43
|
+
object = mock()
|
44
|
+
object.message
|
45
|
+
end
|
46
|
+
assert_equal 1, test_result.failure_count
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_include_assertion_failure_in_failure_count
|
50
|
+
test_result = run_test do
|
51
|
+
flunk
|
52
|
+
end
|
53
|
+
assert_equal 1, test_result.failure_count
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_display_backtrace_indicating_line_number_where_expects_was_called
|
57
|
+
test_result = Test::Unit::TestResult.new
|
58
|
+
faults = []
|
59
|
+
test_result.add_listener(Test::Unit::TestResult::FAULT, &lambda { |fault| faults << fault })
|
60
|
+
execution_point = nil
|
61
|
+
run_test(test_result) do
|
62
|
+
object = mock()
|
63
|
+
execution_point = ExecutionPoint.current; object.expects(:message)
|
64
|
+
end
|
65
|
+
assert_equal 1, faults.size
|
66
|
+
assert_equal execution_point, ExecutionPoint.new(faults.first.location)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_should_display_backtrace_indicating_line_number_where_unexpected_method_was_called
|
70
|
+
test_result = Test::Unit::TestResult.new
|
71
|
+
faults = []
|
72
|
+
test_result.add_listener(Test::Unit::TestResult::FAULT, &lambda { |fault| faults << fault })
|
73
|
+
execution_point = nil
|
74
|
+
run_test(test_result) do
|
75
|
+
object = mock()
|
76
|
+
execution_point = ExecutionPoint.current; object.message
|
77
|
+
end
|
78
|
+
assert_equal 1, faults.size
|
79
|
+
assert_equal execution_point, ExecutionPoint.new(faults.first.location)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called
|
83
|
+
test_result = Test::Unit::TestResult.new
|
84
|
+
faults = []
|
85
|
+
test_result.add_listener(Test::Unit::TestResult::FAULT, &lambda { |fault| faults << fault })
|
86
|
+
execution_point = nil
|
87
|
+
run_test(test_result) do
|
88
|
+
execution_point = ExecutionPoint.current; flunk
|
89
|
+
end
|
90
|
+
assert_equal 1, faults.size
|
91
|
+
assert_equal execution_point, ExecutionPoint.new(faults.first.location)
|
92
|
+
end
|
93
|
+
|
94
|
+
def run_test(test_result = Test::Unit::TestResult.new, &block)
|
95
|
+
test_class = Class.new(Test::Unit::TestCase) do
|
96
|
+
include Mocha::Standalone
|
97
|
+
include Mocha::TestCaseAdapter
|
98
|
+
define_method(:test_me, &block)
|
99
|
+
end
|
100
|
+
test = test_class.new(:test_me)
|
101
|
+
test.run(test_result) {}
|
102
|
+
test_result
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|