google-geo 1.0 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,50 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/infinite_range'
|
3
|
+
|
4
|
+
class InfiniteRangeTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_should_include_values_at_or_above_minimum
|
7
|
+
range = Range.at_least(10)
|
8
|
+
assert(range === 10)
|
9
|
+
assert(range === 11)
|
10
|
+
assert(range === 1000000)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_not_include_values_below_minimum
|
14
|
+
range = Range.at_least(10)
|
15
|
+
assert_false(range === 0)
|
16
|
+
assert_false(range === 9)
|
17
|
+
assert_false(range === -11)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_be_human_readable_description_for_at_least
|
21
|
+
assert_equal "at least 10", Range.at_least(10).to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_include_values_at_or_below_maximum
|
25
|
+
range = Range.at_most(10)
|
26
|
+
assert(range === 10)
|
27
|
+
assert(range === 0)
|
28
|
+
assert(range === -1000000)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_not_include_values_above_maximum
|
32
|
+
range = Range.at_most(10)
|
33
|
+
assert_false(range === 11)
|
34
|
+
assert_false(range === 1000000)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_be_human_readable_description_for_at_most
|
38
|
+
assert_equal "at most 10", Range.at_most(10).to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_not_break_original_description
|
42
|
+
assert_equal "1..10", (1..10).to_s
|
43
|
+
assert_equal "1...10", (1...10).to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
def assert_false(condition)
|
47
|
+
assert(!condition)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/inspect'
|
3
|
+
require 'method_definer'
|
4
|
+
|
5
|
+
class InspectTest
|
6
|
+
def self.suite
|
7
|
+
suite = Test::Unit::TestSuite.new('MochaInspectTests')
|
8
|
+
suite << ObjectInspectTest.suite
|
9
|
+
suite << TimeDateInspectTest.suite
|
10
|
+
suite << StringInspectTest.suite
|
11
|
+
suite << ArrayInstanceTest.suite
|
12
|
+
suite << HashInspectTest.suite
|
13
|
+
suite
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class ObjectInspectTest < Test::Unit::TestCase
|
18
|
+
|
19
|
+
def test_should_provide_custom_representation_of_object
|
20
|
+
object = Object.new
|
21
|
+
assert_equal "#<#{object.class}:#{"0x%x" % object.__id__}>", object.mocha_inspect
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_be_stubbed
|
25
|
+
object = Object.new
|
26
|
+
object.define_instance_accessor(:called)
|
27
|
+
object.called = false
|
28
|
+
object.replace_instance_method(:object_id) { self.called = true; 1 }
|
29
|
+
object.replace_instance_method(:id) { self.called = true; 1 }
|
30
|
+
object.mocha_inspect
|
31
|
+
assert_equal false, object.called
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
class TimeDateInspectTest < Test::Unit::TestCase
|
37
|
+
|
38
|
+
def test_should_use_include_date_in_seconds
|
39
|
+
time = Time.now
|
40
|
+
assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_use_to_s_for_date
|
44
|
+
date = Date.new(2006, 1, 1)
|
45
|
+
assert_equal date.to_s, date.mocha_inspect
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_use_to_s_for_datetime
|
49
|
+
datetime = DateTime.new(2006, 1, 1)
|
50
|
+
assert_equal datetime.to_s, datetime.mocha_inspect
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
class StringInspectTest < Test::Unit::TestCase
|
56
|
+
|
57
|
+
def test_should_replace_escaped_quotes_with_single_quote
|
58
|
+
string = "my_string"
|
59
|
+
assert_equal "'my_string'", string.mocha_inspect
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
class ArrayInstanceTest < Test::Unit::TestCase
|
65
|
+
|
66
|
+
def test_should_use_inspect
|
67
|
+
array = [1, 2]
|
68
|
+
assert_equal array.inspect, array.mocha_inspect
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_should_use_mocha_inspect_on_each_item
|
72
|
+
array = [1, 2, "chris"]
|
73
|
+
assert_equal "[1, 2, 'chris']", array.mocha_inspect
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
class HashInspectTest < Test::Unit::TestCase
|
79
|
+
|
80
|
+
def test_should_keep_spacing_between_key_value
|
81
|
+
hash = {:a => true}
|
82
|
+
assert_equal '{:a => true}', hash.mocha_inspect
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_should_use_mocha_inspect_on_each_item
|
86
|
+
hash = {:a => 'mocha'}
|
87
|
+
assert_equal "{:a => 'mocha'}", hash.mocha_inspect
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
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
|
@@ -0,0 +1,235 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/mock_methods'
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
class MockMethodsTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Mocha
|
8
|
+
|
9
|
+
def test_should_create_and_add_expectations
|
10
|
+
mock = Object.new
|
11
|
+
mock.extend(MockMethods)
|
12
|
+
|
13
|
+
expectation1 = mock.expects(:method1)
|
14
|
+
expectation2 = mock.expects(:method2)
|
15
|
+
|
16
|
+
assert_equal [expectation1, expectation2].to_set, mock.expectations.to_set
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_pass_backtrace_into_expectation
|
20
|
+
mock = Object.new
|
21
|
+
mock.extend(MockMethods)
|
22
|
+
backtrace = Object.new
|
23
|
+
expectation = mock.expects(:method1, backtrace)
|
24
|
+
assert_equal backtrace, expectation.backtrace
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_pass_backtrace_into_stub
|
28
|
+
mock = Object.new
|
29
|
+
mock.extend(MockMethods)
|
30
|
+
backtrace = Object.new
|
31
|
+
stub = mock.stubs(:method1, backtrace)
|
32
|
+
assert_equal backtrace, stub.backtrace
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_create_and_add_stubs
|
36
|
+
mock = Object.new
|
37
|
+
mock.extend(MockMethods)
|
38
|
+
|
39
|
+
stub1 = mock.stubs(:method1)
|
40
|
+
stub2 = mock.stubs(:method2)
|
41
|
+
|
42
|
+
assert_equal [stub1, stub2].to_set, mock.expectations.to_set
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_find_matching_expectation
|
46
|
+
mock = Object.new
|
47
|
+
mock.extend(MockMethods)
|
48
|
+
|
49
|
+
expectation1 = mock.expects(:my_method).with(:argument1, :argument2)
|
50
|
+
expectation2 = mock.expects(:my_method).with(:argument3, :argument4)
|
51
|
+
|
52
|
+
assert_same expectation2, mock.matching_expectation(:my_method, :argument3, :argument4)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_should_find_most_recent_matching_expectation
|
56
|
+
mock = Object.new
|
57
|
+
mock.extend(MockMethods)
|
58
|
+
|
59
|
+
expectation1 = mock.expects(:my_method).with(:argument1, :argument2)
|
60
|
+
expectation2 = mock.expects(:my_method).with(:argument1, :argument2)
|
61
|
+
|
62
|
+
assert_same expectation2, mock.matching_expectation(:my_method, :argument1, :argument2)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_should_invoke_expectation_and_return_result
|
66
|
+
mock = Object.new
|
67
|
+
mock.extend(MockMethods)
|
68
|
+
mock.expects(:my_method).returns(:result)
|
69
|
+
|
70
|
+
result = mock.my_method
|
71
|
+
|
72
|
+
assert_equal :result, result
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_should_not_raise_error_if_stubbing_everything
|
76
|
+
mock = Class.new { def initialize; @stub_everything = true; end }.new
|
77
|
+
mock.extend(MockMethods)
|
78
|
+
|
79
|
+
result = nil
|
80
|
+
assert_nothing_raised(ExpectationError) do
|
81
|
+
result = mock.unexpected_method
|
82
|
+
end
|
83
|
+
assert_nil result
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_should_raise_no_method_error
|
87
|
+
mock = Object.new
|
88
|
+
mock.extend(MockMethods)
|
89
|
+
assert_raise(NoMethodError) do
|
90
|
+
mock.super_method_missing(nil)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_should_raise_assertion_error_for_unexpected_method_call
|
95
|
+
mock = Object.new
|
96
|
+
mock.extend(MockMethods)
|
97
|
+
error = assert_raise(ExpectationError) do
|
98
|
+
mock.unexpected_method_called(:my_method, :argument1, :argument2)
|
99
|
+
end
|
100
|
+
assert_match /my_method/, error.message
|
101
|
+
assert_match /argument1/, error.message
|
102
|
+
assert_match /argument2/, error.message
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_should_indicate_unexpected_method_called
|
106
|
+
mock = Object.new
|
107
|
+
mock.extend(MockMethods)
|
108
|
+
class << mock
|
109
|
+
attr_accessor :symbol, :arguments
|
110
|
+
def unexpected_method_called(symbol, *arguments)
|
111
|
+
self.symbol, self.arguments = symbol, arguments
|
112
|
+
end
|
113
|
+
end
|
114
|
+
mock.my_method(:argument1, :argument2)
|
115
|
+
|
116
|
+
assert_equal :my_method, mock.symbol
|
117
|
+
assert_equal [:argument1, :argument2], mock.arguments
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_should_call_method_missing_for_parent
|
121
|
+
mock = Object.new
|
122
|
+
mock.extend(MockMethods)
|
123
|
+
class << mock
|
124
|
+
attr_accessor :symbol, :arguments
|
125
|
+
def super_method_missing(symbol, *arguments, &block)
|
126
|
+
self.symbol, self.arguments = symbol, arguments
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
mock.my_method(:argument1, :argument2)
|
131
|
+
|
132
|
+
assert_equal :my_method, mock.symbol
|
133
|
+
assert_equal [:argument1, :argument2], mock.arguments
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_should_verify_that_all_expectations_have_been_fulfilled
|
137
|
+
mock = Object.new
|
138
|
+
mock.extend(MockMethods)
|
139
|
+
mock.expects(:method1)
|
140
|
+
mock.expects(:method2)
|
141
|
+
mock.method1
|
142
|
+
assert_raise(ExpectationError) do
|
143
|
+
mock.verify
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_should_report_possible_expectations
|
148
|
+
mock = Object.new.extend(MockMethods)
|
149
|
+
mock.expects(:expected_method).with(1)
|
150
|
+
exception = assert_raise(ExpectationError) { mock.expected_method(2) }
|
151
|
+
assert_equal "#{mock.mocha_inspect}.expected_method(2) - expected calls: 0, actual calls: 1\nSimilar expectations:\nexpected_method(1)", exception.message
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_should_pass_block_through_to_expectations_verify_method
|
155
|
+
mock = Object.new
|
156
|
+
mock.extend(MockMethods)
|
157
|
+
expected_expectation = mock.expects(:method1)
|
158
|
+
mock.method1
|
159
|
+
expectations = []
|
160
|
+
mock.verify() { |expectation| expectations << expectation }
|
161
|
+
assert_equal [expected_expectation], expectations
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_should_yield_supplied_parameters_to_block
|
165
|
+
mock = Object.new
|
166
|
+
mock.extend(MockMethods)
|
167
|
+
parameters_for_yield = [1, 2, 3]
|
168
|
+
mock.expects(:method1).yields(*parameters_for_yield)
|
169
|
+
yielded_parameters = nil
|
170
|
+
mock.method1() { |*parameters| yielded_parameters = parameters }
|
171
|
+
assert_equal parameters_for_yield, yielded_parameters
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_should_respond_to_expected_method
|
175
|
+
mock = Object.new
|
176
|
+
mock.extend(MockMethods)
|
177
|
+
mock.expects(:method1)
|
178
|
+
assert_equal true, mock.respond_to?(:method1)
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_should_not_respond_to_unexpected_method
|
182
|
+
mock = Object.new
|
183
|
+
mock.extend(MockMethods)
|
184
|
+
assert_equal false, mock.respond_to?(:method1)
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_should_set_up_multiple_expectations_with_return_values
|
188
|
+
mock = Object.new
|
189
|
+
mock.extend(MockMethods)
|
190
|
+
mock.expects(:method1 => :result1, :method2 => :result2)
|
191
|
+
assert_equal :result1, mock.method1
|
192
|
+
assert_equal :result2, mock.method2
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_should_set_up_multiple_stubs_with_return_values
|
196
|
+
mock = Object.new
|
197
|
+
mock.extend(MockMethods)
|
198
|
+
mock.stubs(:method1 => :result1, :method2 => :result2)
|
199
|
+
assert_equal :result1, mock.method1
|
200
|
+
assert_equal :result2, mock.method2
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_should_match_most_recent_call_to_expects
|
204
|
+
mock = Object.new
|
205
|
+
mock.extend(MockMethods)
|
206
|
+
mock.expects(:method1).returns(0)
|
207
|
+
mock.expects(:method1).returns(1)
|
208
|
+
assert_equal 1, mock.method1
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_should_match_most_recent_call_to_stubs
|
212
|
+
mock = Object.new
|
213
|
+
mock.extend(MockMethods)
|
214
|
+
mock.stubs(:method1).returns(0)
|
215
|
+
mock.stubs(:method1).returns(1)
|
216
|
+
assert_equal 1, mock.method1
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_should_match_call_to_expects_with_previous_call_to_stubs
|
220
|
+
mock = Object.new
|
221
|
+
mock.extend(MockMethods)
|
222
|
+
mock.stubs(:method1).returns(0)
|
223
|
+
mock.expects(:method1).returns(1)
|
224
|
+
assert_equal 1, mock.method1
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_should_match_call_to_stubs_with_previous_call_to_expects
|
228
|
+
mock = Object.new
|
229
|
+
mock.extend(MockMethods)
|
230
|
+
mock.expects(:method1).returns(0)
|
231
|
+
mock.stubs(:method1).returns(1)
|
232
|
+
assert_equal 1, mock.method1
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
require 'mocha/mock'
|
3
|
+
require 'mocha/expectation_error'
|
4
|
+
|
5
|
+
class MockTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
include Mocha
|
8
|
+
|
9
|
+
def test_should_include_mocha_methods
|
10
|
+
assert Mock.included_modules.include?(MockMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_set_single_expectation
|
14
|
+
mock = Mock.new
|
15
|
+
mock.expects(:method1).returns(1)
|
16
|
+
assert_nothing_raised(ExpectationError) do
|
17
|
+
assert_equal 1, mock.method1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_build_and_store_expectations
|
22
|
+
mock = Mock.new
|
23
|
+
expectation = mock.expects(:method1)
|
24
|
+
assert_not_nil expectation
|
25
|
+
assert_equal [expectation], mock.expectations
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_should_not_stub_everything_by_default
|
29
|
+
mock = Mock.new
|
30
|
+
assert_equal false, mock.stub_everything
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_stub_everything
|
34
|
+
mock = Mock.new(stub_everything = true)
|
35
|
+
assert_equal true, mock.stub_everything
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_should_display_object_id_for_inspect_if_mock_has_no_name
|
39
|
+
mock = Mock.new
|
40
|
+
assert_match Regexp.new("#<Mock:0x[0-9A-Fa-f]{6}>"), mock.mocha_inspect
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_display_name_for_inspect_if_mock_has_name
|
44
|
+
mock = Mock.new(false, 'named_mock')
|
45
|
+
assert_equal "#<Mock:named_mock>", mock.mocha_inspect
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_give_name_in_inspect_message
|
49
|
+
mock = Mock.new(false, 'named_mock')
|
50
|
+
assert_equal "#<Mock:named_mock>", mock.mocha_inspect
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_should_be_able_to_extend_mock_object_with_module
|
54
|
+
mock = Mock.new
|
55
|
+
assert_nothing_raised(ExpectationError) { mock.extend(Module.new) }
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_should_be_equal
|
59
|
+
mock = Mock.new
|
60
|
+
assert_equal true, mock.eql?(mock)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_should_be_able_to_mock_standard_object_methods
|
64
|
+
mock = Mock.new
|
65
|
+
object_methods = Object.public_instance_methods.reject { |m| m =~ /^__.*__$/ }.sort
|
66
|
+
object_methods.each { |method| mock.__expects__(method.to_sym).returns(method) }
|
67
|
+
object_methods.each { |method| assert_equal method, mock.__send__(method.to_sym) }
|
68
|
+
assert_nothing_raised(ExpectationError) { mock.verify }
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_should_be_able_to_stub_standard_object_methods
|
72
|
+
mock = Mock.new
|
73
|
+
object_methods = Object.public_instance_methods.reject { |m| m =~ /^__.*__$/ }.sort
|
74
|
+
object_methods.each { |method| mock.__stubs__(method.to_sym).returns(method) }
|
75
|
+
object_methods.each { |method| assert_equal method, mock.__send__(method.to_sym) }
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_should_respond_to_expected_methods
|
79
|
+
mock = Mock.new
|
80
|
+
mock.expects(:method1)
|
81
|
+
assert_equal true, mock.respond_to?(:method1)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|