google-geo 1.0 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/CHANGELOG +5 -0
  2. data/README +12 -8
  3. data/lib/google/geo.rb +10 -6
  4. data/test/fixtures/invalid_map_key.xml +10 -0
  5. data/test/fixtures/missing_address.xml +10 -0
  6. data/test/fixtures/server_error.xml +10 -0
  7. data/test/fixtures/success.xml +36 -0
  8. data/test/fixtures/success_with_multiple_addresses.xml +62 -0
  9. data/test/fixtures/too_many_queries.xml +10 -0
  10. data/test/fixtures/unavailable_address.xml +10 -0
  11. data/test/fixtures/unknown_address.xml +10 -0
  12. data/test/geo_test.rb +19 -5
  13. data/vendor/mocha-0.4.0/COPYING +3 -0
  14. data/vendor/mocha-0.4.0/MIT-LICENSE +7 -0
  15. data/vendor/mocha-0.4.0/README +35 -0
  16. data/vendor/mocha-0.4.0/RELEASE +98 -0
  17. data/vendor/mocha-0.4.0/Rakefile +126 -0
  18. data/vendor/mocha-0.4.0/examples/misc.rb +36 -0
  19. data/vendor/mocha-0.4.0/examples/mocha.rb +26 -0
  20. data/vendor/mocha-0.4.0/examples/stubba.rb +65 -0
  21. data/vendor/mocha-0.4.0/lib/mocha.rb +19 -0
  22. data/vendor/mocha-0.4.0/lib/mocha/any_instance_method.rb +35 -0
  23. data/vendor/mocha-0.4.0/lib/mocha/auto_verify.rb +113 -0
  24. data/vendor/mocha-0.4.0/lib/mocha/central.rb +35 -0
  25. data/vendor/mocha-0.4.0/lib/mocha/class_method.rb +62 -0
  26. data/vendor/mocha-0.4.0/lib/mocha/expectation.rb +295 -0
  27. data/vendor/mocha-0.4.0/lib/mocha/expectation_error.rb +6 -0
  28. data/vendor/mocha-0.4.0/lib/mocha/infinite_range.rb +27 -0
  29. data/vendor/mocha-0.4.0/lib/mocha/inspect.rb +37 -0
  30. data/vendor/mocha-0.4.0/lib/mocha/instance_method.rb +8 -0
  31. data/vendor/mocha-0.4.0/lib/mocha/metaclass.rb +7 -0
  32. data/vendor/mocha-0.4.0/lib/mocha/mock.rb +20 -0
  33. data/vendor/mocha-0.4.0/lib/mocha/mock_methods.rb +122 -0
  34. data/vendor/mocha-0.4.0/lib/mocha/object.rb +100 -0
  35. data/vendor/mocha-0.4.0/lib/mocha/pretty_parameters.rb +28 -0
  36. data/vendor/mocha-0.4.0/lib/mocha/setup_and_teardown.rb +23 -0
  37. data/vendor/mocha-0.4.0/lib/mocha/standalone.rb +30 -0
  38. data/vendor/mocha-0.4.0/lib/mocha/test_case_adapter.rb +49 -0
  39. data/vendor/mocha-0.4.0/lib/mocha_standalone.rb +2 -0
  40. data/vendor/mocha-0.4.0/lib/stubba.rb +2 -0
  41. data/vendor/mocha-0.4.0/test/active_record_test_case.rb +36 -0
  42. data/vendor/mocha-0.4.0/test/all_tests.rb +75 -0
  43. data/vendor/mocha-0.4.0/test/execution_point.rb +34 -0
  44. data/vendor/mocha-0.4.0/test/method_definer.rb +18 -0
  45. data/vendor/mocha-0.4.0/test/mocha/any_instance_method_test.rb +124 -0
  46. data/vendor/mocha-0.4.0/test/mocha/auto_verify_test.rb +163 -0
  47. data/vendor/mocha-0.4.0/test/mocha/central_test.rb +124 -0
  48. data/vendor/mocha-0.4.0/test/mocha/class_method_test.rb +196 -0
  49. data/vendor/mocha-0.4.0/test/mocha/expectation_test.rb +357 -0
  50. data/vendor/mocha-0.4.0/test/mocha/infinite_range_test.rb +50 -0
  51. data/vendor/mocha-0.4.0/test/mocha/inspect_test.rb +90 -0
  52. data/vendor/mocha-0.4.0/test/mocha/metaclass_test.rb +22 -0
  53. data/vendor/mocha-0.4.0/test/mocha/mock_methods_test.rb +235 -0
  54. data/vendor/mocha-0.4.0/test/mocha/mock_test.rb +84 -0
  55. data/vendor/mocha-0.4.0/test/mocha/object_test.rb +165 -0
  56. data/vendor/mocha-0.4.0/test/mocha/pretty_parameters_test.rb +32 -0
  57. data/vendor/mocha-0.4.0/test/mocha/setup_and_teardown_test.rb +76 -0
  58. data/vendor/mocha-0.4.0/test/mocha_acceptance_test.rb +98 -0
  59. data/vendor/mocha-0.4.0/test/mocha_test_result_integration_test.rb +105 -0
  60. data/vendor/mocha-0.4.0/test/standalone_acceptance_test.rb +110 -0
  61. data/vendor/mocha-0.4.0/test/stubba_acceptance_test.rb +102 -0
  62. data/vendor/mocha-0.4.0/test/stubba_integration_test.rb +89 -0
  63. data/vendor/mocha-0.4.0/test/stubba_test_result_integration_test.rb +85 -0
  64. data/vendor/mocha-0.4.0/test/test_helper.rb +4 -0
  65. metadata +73 -3
@@ -0,0 +1,62 @@
1
+ require 'mocha/metaclass'
2
+
3
+ module Mocha
4
+
5
+ class ClassMethod
6
+
7
+ attr_reader :stubbee, :method
8
+
9
+ def initialize(stubbee, method)
10
+ @stubbee, @method = stubbee, method
11
+ end
12
+
13
+ def stub
14
+ hide_original_method
15
+ define_new_method
16
+ end
17
+
18
+ def unstub
19
+ remove_new_method
20
+ restore_original_method
21
+ stubbee.reset_mocha
22
+ end
23
+
24
+ def mock
25
+ stubbee.mocha
26
+ end
27
+
28
+ def hide_original_method
29
+ stubbee.__metaclass__.class_eval "alias_method :#{hidden_method}, :#{method}" if stubbee.__metaclass__.method_defined?(method)
30
+ end
31
+
32
+ def define_new_method
33
+ stubbee.__metaclass__.class_eval "def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end"
34
+ end
35
+
36
+ def remove_new_method
37
+ stubbee.__metaclass__.class_eval "remove_method :#{method}"
38
+ end
39
+
40
+ def restore_original_method
41
+ stubbee.__metaclass__.class_eval "alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}" if stubbee.__metaclass__.method_defined?(hidden_method)
42
+ end
43
+
44
+ def hidden_method
45
+ method_name = method.to_s.gsub(/\W/) {|s| "_substituted_character_#{s[0]}_" }
46
+ "__stubba__#{method_name}__stubba__"
47
+ end
48
+
49
+ def eql?(other)
50
+ return false unless (other.class == self.class)
51
+ (stubbee == other.stubbee) and (method == other.method)
52
+ end
53
+
54
+ alias_method :==, :eql?
55
+
56
+ def to_s
57
+ "#{stubbee}.#{method}"
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,295 @@
1
+ require 'mocha/infinite_range'
2
+ require 'mocha/pretty_parameters'
3
+ require 'mocha/expectation_error'
4
+
5
+ class Object
6
+
7
+ alias_method :__is_a__, :is_a?
8
+
9
+ end
10
+
11
+ module Mocha
12
+ # Methods on expectations returned from Mocha::MockMethods#expects and Mocha::MockMethods#stubs
13
+ class Expectation
14
+
15
+ # :stopdoc:
16
+
17
+ class InvalidExpectation < Exception; end
18
+
19
+ class AlwaysEqual
20
+ def ==(other)
21
+ true
22
+ end
23
+ end
24
+
25
+ attr_reader :method_name, :backtrace
26
+
27
+ def initialize(mock, method_name, backtrace = nil)
28
+ @mock, @method_name = mock, method_name
29
+ @count = 1
30
+ @parameters, @parameter_block = AlwaysEqual.new, nil
31
+ @invoked, @return_value = 0, nil
32
+ @backtrace = backtrace || caller
33
+ @yield = nil
34
+ end
35
+
36
+ def yield?
37
+ @yield
38
+ end
39
+
40
+ def match?(method_name, *arguments)
41
+ if @parameter_block then
42
+ @parameter_block.call(*arguments)
43
+ else
44
+ (@method_name == method_name) and (@parameters == arguments)
45
+ end
46
+ end
47
+
48
+ # :startdoc:
49
+
50
+ # :call-seq: times(range) -> expectation
51
+ #
52
+ # Modifies expectation so that the number of calls to the expected method must be within a specific +range+.
53
+ #
54
+ # +range+ can be specified as an exact integer or as a range of integers
55
+ # object = mock()
56
+ # object.expects(:expected_method).times(3)
57
+ # 3.times { object.expected_method } # => verify succeeds
58
+ #
59
+ # object = mock()
60
+ # object.expects(:expected_method).times(3)
61
+ # 2.times { object.expected_method } # => verify fails
62
+ #
63
+ # object = mock()
64
+ # object.expects(:expected_method).times(2..4)
65
+ # 3.times { object.expected_method } # => verify succeeds
66
+ #
67
+ # object = mock()
68
+ # object.expects(:expected_method).times(2..4)
69
+ # object.expected_method # => verify fails
70
+ def times(range)
71
+ @count = range
72
+ self
73
+ end
74
+
75
+ # :call-seq: never -> expectation
76
+ #
77
+ # Modifies expectation so that the expected method must never be called.
78
+ # object = mock()
79
+ # object.expects(:expected_method).never
80
+ # object.expected_method # => verify fails
81
+ #
82
+ # object = mock()
83
+ # object.expects(:expected_method).never
84
+ # object.expected_method # => verify succeeds
85
+ def never
86
+ times(0)
87
+ self
88
+ end
89
+
90
+ # :call-seq: at_least(minimum_number_of_times) -> expectation
91
+ #
92
+ # Modifies expectation so that the expected method must be called at least a +minimum_number_of_times+.
93
+ # object = mock()
94
+ # object.expects(:expected_method).at_least(2)
95
+ # 3.times { object.expected_method } # => verify succeeds
96
+ #
97
+ # object = mock()
98
+ # object.expects(:expected_method).at_least(2)
99
+ # object.expected_method # => verify fails
100
+ def at_least(minimum_number_of_times)
101
+ times(Range.at_least(minimum_number_of_times))
102
+ self
103
+ end
104
+
105
+ # :call-seq: at_least_once() -> expectation
106
+ #
107
+ # Modifies expectation so that the expected method must be called at least once.
108
+ # object = mock()
109
+ # object.expects(:expected_method).at_least_once
110
+ # object.expected_method # => verify succeeds
111
+ #
112
+ # object = mock()
113
+ # object.expects(:expected_method).at_least_once
114
+ # # => verify fails
115
+ def at_least_once()
116
+ at_least(1)
117
+ self
118
+ end
119
+
120
+ # :call-seq: at_most(maximum_number_of_times) -> expectation
121
+ #
122
+ # Modifies expectation so that the expected method must be called at most a +maximum_number_of_times+.
123
+ # object = mock()
124
+ # object.expects(:expected_method).at_most(2)
125
+ # 2.times { object.expected_method } # => verify succeeds
126
+ #
127
+ # object = mock()
128
+ # object.expects(:expected_method).at_most(2)
129
+ # 3.times { object.expected_method } # => verify fails
130
+ def at_most(maximum_number_of_times)
131
+ times(Range.at_most(maximum_number_of_times))
132
+ self
133
+ end
134
+
135
+ # :call-seq: at_most_once() -> expectation
136
+ #
137
+ # Modifies expectation so that the expected method must be called at most once.
138
+ # object = mock()
139
+ # object.expects(:expected_method).at_most_once
140
+ # object.expected_method # => verify succeeds
141
+ #
142
+ # object = mock()
143
+ # object.expects(:expected_method).at_most_once
144
+ # 2.times { object.expected_method } # => verify fails
145
+ def at_most_once()
146
+ at_most(1)
147
+ self
148
+ end
149
+
150
+ # :call-seq: with(*arguments, &parameter_block) -> expectation
151
+ #
152
+ # Modifies expectation so that the expected method must be called with specified +arguments+.
153
+ # object = mock()
154
+ # object.expects(:expected_method).with(:param1, :param2)
155
+ # object.expected_method(:param1, :param2) # => verify succeeds
156
+ #
157
+ # object = mock()
158
+ # object.expects(:expected_method).with(:param1, :param2)
159
+ # object.expected_method(:param3) # => verify fails
160
+ # If a +parameter_block+ is given, the block is called with the parameters passed to the expected method.
161
+ # The expectation is matched if the block evaluates to +true+.
162
+ # object = mock()
163
+ # object.expects(:expected_method).with() { |value| value % 4 == 0 }
164
+ # object.expected_method(16) # => verify succeeds
165
+ #
166
+ # object = mock()
167
+ # object.expects(:expected_method).with() { |value| value % 4 == 0 }
168
+ # object.expected_method(17) # => verify fails
169
+ def with(*arguments, &parameter_block)
170
+ @parameters, @parameter_block = arguments, parameter_block
171
+ class << @parameters; def to_s; join(', '); end; end
172
+ self
173
+ end
174
+
175
+ # :call-seq: yields(*parameters) -> expectation
176
+ #
177
+ # Modifies expectation so that when the expected method is called, it yields with the specified +parameters+.
178
+ # object = mock()
179
+ # object.expects(:expected_method).yields('result')
180
+ # yielded_value = nil
181
+ # object.expected_method { |value| yielded_value = value }
182
+ # yielded_value # => 'result'
183
+ def yields(*parameters)
184
+ @yield = true
185
+ @parameters_to_yield = parameters
186
+ self
187
+ end
188
+
189
+ # :call-seq: returns(value) -> expectation
190
+ # :call-seq: returns(*values) -> expectation
191
+ #
192
+ # Modifies expectation so that when the expected method is called, it returns the specified +value+.
193
+ # object = mock()
194
+ # object.stubs(:stubbed_method).returns('result')
195
+ # object.stubbed_method # => 'result'
196
+ # object.stubbed_method # => 'result'
197
+ # If multiple +values+ are given, these are returned in turn on consecutive calls to the method.
198
+ # object = mock()
199
+ # object.stubs(:stubbed_method).returns(1, 2)
200
+ # object.stubbed_method # => 1
201
+ # object.stubbed_method # => 2
202
+ # If +value+ is a Proc, then expected method will return result of calling Proc.
203
+ # object = mock()
204
+ # object.stubs(:stubbed_method).returns(lambda { rand(100) })
205
+ # object.stubbed_method # => 41
206
+ # object.stubbed_method # => 77
207
+ def returns(*values)
208
+ @return_value = (values.size > 1) ? lambda { values.shift } : @return_value = values.first
209
+ self
210
+ end
211
+
212
+ # :call-seq: raises(exception = RuntimeError, message = nil) -> expectation
213
+ #
214
+ # Modifies expectation so that when the expected method is called, it raises the specified +exception+ with the specified +message+.
215
+ # object = mock()
216
+ # object.expects(:expected_method).raises(Exception, 'message')
217
+ # object.expected_method # => raises exception of class Exception and with message 'message'
218
+ def raises(exception = RuntimeError, message = nil)
219
+ @return_value = message ? lambda { raise exception, message } : lambda { raise exception }
220
+ self
221
+ end
222
+
223
+ # :stopdoc:
224
+
225
+ def invoke
226
+ @invoked += 1
227
+ yield(*@parameters_to_yield) if yield? and block_given?
228
+ @return_value.__is_a__(Proc) ? @return_value.call : @return_value
229
+ end
230
+
231
+ def verify
232
+ yield(self) if block_given?
233
+ unless (@count === @invoked) then
234
+ error = ExpectationError.new(error_message(@count, @invoked))
235
+ error.set_backtrace(filtered_backtrace)
236
+ raise error
237
+ end
238
+ end
239
+
240
+ def mocha_lib_directory
241
+ File.expand_path(File.join(File.dirname(__FILE__), "..")) + File::SEPARATOR
242
+ end
243
+
244
+ def filtered_backtrace
245
+ backtrace.reject { |location| Regexp.new(mocha_lib_directory).match(File.expand_path(location)) }
246
+ end
247
+
248
+ def method_signature
249
+ return "#{method_name}" if @parameters.__is_a__(AlwaysEqual)
250
+ "#{@method_name}(#{PrettyParameters.new(@parameters).pretty})"
251
+ end
252
+
253
+ def error_message(expected_count, actual_count)
254
+ "#{@mock.mocha_inspect}.#{method_signature} - expected calls: #{expected_count}, actual calls: #{actual_count}"
255
+ end
256
+
257
+ # :startdoc:
258
+
259
+ end
260
+
261
+ # :stopdoc:
262
+
263
+ class Stub < Expectation
264
+
265
+ def verify
266
+ true
267
+ end
268
+
269
+ end
270
+
271
+ class MissingExpectation < Expectation
272
+
273
+ def initialize(mock, method_name)
274
+ super
275
+ @invoked = true
276
+ end
277
+
278
+ def verify
279
+ msg = error_message(0, 1)
280
+ similar_expectations_list = similar_expectations.collect { |expectation| expectation.method_signature }.join("\n")
281
+ msg << "\nSimilar expectations:\n#{similar_expectations_list}" unless similar_expectations.empty?
282
+ error = ExpectationError.new(msg)
283
+ error.set_backtrace(filtered_backtrace)
284
+ raise error if @invoked
285
+ end
286
+
287
+ def similar_expectations
288
+ @mock.expectations.select { |expectation| expectation.method_name == self.method_name }
289
+ end
290
+
291
+ end
292
+
293
+ # :startdoc:
294
+
295
+ end
@@ -0,0 +1,6 @@
1
+ module Mocha
2
+
3
+ class ExpectationError < StandardError
4
+ end
5
+
6
+ end
@@ -0,0 +1,27 @@
1
+ class Range
2
+
3
+ def self.at_least(minimum_value)
4
+ Range.new(minimum_value, infinite)
5
+ end
6
+
7
+ def self.at_most(maximum_value)
8
+ Range.new(-infinite, maximum_value, false)
9
+ end
10
+
11
+ def self.infinite
12
+ 1/0.0
13
+ end
14
+
15
+ alias_method :__to_s__, :to_s
16
+
17
+ def to_s
18
+ if first.to_f.infinite? then
19
+ return "at most #{last}"
20
+ elsif last.to_f.infinite? then
21
+ return "at least #{first}"
22
+ else
23
+ __to_s__
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,37 @@
1
+ require 'date'
2
+
3
+ class Object
4
+ def mocha_inspect
5
+ inspect =~ /#</ ? "#<#{self.class}:0x#{self.__id__.to_s(16)}>" : inspect
6
+ end
7
+ end
8
+
9
+ class String
10
+ def mocha_inspect
11
+ inspect.gsub(/\"/, "'")
12
+ end
13
+ end
14
+
15
+ class Array
16
+ def mocha_inspect
17
+ "[#{collect { |member| member.mocha_inspect }.join(', ')}]"
18
+ end
19
+ end
20
+
21
+ class Hash
22
+ def mocha_inspect
23
+ "{#{collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')}}"
24
+ end
25
+ end
26
+
27
+ class Time
28
+ def mocha_inspect
29
+ "#{inspect} (#{to_f} secs)"
30
+ end
31
+ end
32
+
33
+ class Date
34
+ def mocha_inspect
35
+ to_s
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ require 'mocha/class_method'
2
+
3
+ module Mocha
4
+
5
+ class InstanceMethod < ClassMethod
6
+ end
7
+
8
+ end
@@ -0,0 +1,7 @@
1
+ class Object
2
+
3
+ def __metaclass__
4
+ class << self; self; end
5
+ end
6
+
7
+ end