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.
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,20 @@
1
+ require 'mocha/mock_methods'
2
+
3
+ module Mocha
4
+
5
+ class Mock
6
+
7
+ include MockMethods
8
+
9
+ def initialize(stub_everything = false, name = nil)
10
+ @stub_everything = stub_everything
11
+ @mock_name = name
12
+ end
13
+
14
+ def mocha_inspect
15
+ @mock_name ? "#<Mock:#{@mock_name}>" : "#<Mock:0x#{__id__.to_s(16)}>"
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,122 @@
1
+ require 'mocha/expectation'
2
+ require 'mocha/metaclass'
3
+
4
+ module Mocha
5
+ # Methods added to mock objects.
6
+ # These methods all return an expectation which can be further modified by methods on Mocha::Expectation.
7
+ module MockMethods
8
+
9
+ # :stopdoc:
10
+
11
+ attr_reader :stub_everything
12
+
13
+ def expectations
14
+ @expectations ||= []
15
+ end
16
+
17
+ # :startdoc:
18
+
19
+ # :call-seq: expects(method_name) -> expectation
20
+ # expects(method_names) -> last expectation
21
+ #
22
+ # Adds an expectation that a method identified by +method_name+ symbol must be called exactly once with any parameters.
23
+ # Returns the new expectation which can be further modified by methods on Mocha::Expectation.
24
+ # object = mock()
25
+ # object.expects(:method1)
26
+ # object.method1
27
+ # # no error raised
28
+ #
29
+ # object = mock()
30
+ # object.expects(:method1)
31
+ # # error raised, because method1 not called exactly once
32
+ # If +method_names+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+.
33
+ # object = mock()
34
+ # object.expects(:method1 => :result1, :method2 => :result2)
35
+ #
36
+ # # exactly equivalent to
37
+ #
38
+ # object = mock()
39
+ # object.expects(:method1).returns(:result1)
40
+ # object.expects(:method2).returns(:result2)
41
+ def expects(method_names, backtrace = nil)
42
+ method_names = method_names.is_a?(Hash) ? method_names : { method_names => nil }
43
+ method_names.each do |method_name, return_value|
44
+ expectations << Expectation.new(self, method_name, backtrace).returns(return_value)
45
+ self.__metaclass__.send(:undef_method, method_name) if self.__metaclass__.method_defined?(method_name)
46
+ end
47
+ expectations.last
48
+ end
49
+
50
+ alias_method :__expects__, :expects
51
+
52
+ # :call-seq: stubs(method_name) -> expectation
53
+ # stubs(method_names) -> last expectation
54
+ #
55
+ # Adds an expectation that a method identified by +method_name+ symbol may be called any number of times with any parameters.
56
+ # Returns the new expectation which can be further modified by methods on Mocha::Expectation.
57
+ # object = mock()
58
+ # object.stubs(:method1)
59
+ # object.method1
60
+ # object.method1
61
+ # # no error raised
62
+ # If +method_names+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+.
63
+ # object = mock()
64
+ # object.stubs(:method1 => :result1, :method2 => :result2)
65
+ #
66
+ # # exactly equivalent to
67
+ #
68
+ # object = mock()
69
+ # object.stubs(:method1).returns(:result1)
70
+ # object.stubs(:method2).returns(:result2)
71
+ def stubs(method_names, backtrace = nil)
72
+ method_names = method_names.is_a?(Hash) ? method_names : { method_names => nil }
73
+ method_names.each do |method_name, return_value|
74
+ expectations << Stub.new(self, method_name, backtrace).returns(return_value)
75
+ self.__metaclass__.send(:undef_method, method_name) if self.__metaclass__.method_defined?(method_name)
76
+ end
77
+ expectations.last
78
+ end
79
+
80
+ alias_method :__stubs__, :stubs
81
+
82
+ # :stopdoc:
83
+
84
+ def method_missing(symbol, *arguments, &block)
85
+ matching_expectation = matching_expectation(symbol, *arguments)
86
+ if matching_expectation then
87
+ matching_expectation.invoke(&block)
88
+ elsif stub_everything then
89
+ return
90
+ else
91
+ begin
92
+ super_method_missing(symbol, *arguments, &block)
93
+ rescue NoMethodError
94
+ unexpected_method_called(symbol, *arguments)
95
+ end
96
+ end
97
+ end
98
+
99
+ def respond_to?(symbol)
100
+ expectations.any? { |expectation| expectation.method_name == symbol }
101
+ end
102
+
103
+ def super_method_missing(symbol, *arguments, &block)
104
+ raise NoMethodError
105
+ end
106
+
107
+ def unexpected_method_called(symbol, *arguments)
108
+ MissingExpectation.new(self, symbol).with(*arguments).verify
109
+ end
110
+
111
+ def matching_expectation(symbol, *arguments)
112
+ expectations.reverse.detect { |expectation| expectation.match?(symbol, *arguments) }
113
+ end
114
+
115
+ def verify(&block)
116
+ expectations.each { |expectation| expectation.verify(&block) }
117
+ end
118
+
119
+ # :startdoc:
120
+
121
+ end
122
+ end
@@ -0,0 +1,100 @@
1
+ require 'mocha/mock'
2
+ require 'mocha/instance_method'
3
+ require 'mocha/class_method'
4
+ require 'mocha/any_instance_method'
5
+
6
+ # Methods added all Objects.
7
+ class Object
8
+
9
+ def mocha # :nodoc:
10
+ @mocha ||= Mocha::Mock.new
11
+ end
12
+
13
+ def reset_mocha # :nodoc:
14
+ @mocha = nil
15
+ end
16
+
17
+ def stubba_method # :nodoc:
18
+ Mocha::InstanceMethod
19
+ end
20
+
21
+ def stubba_object # :nodoc:
22
+ self
23
+ end
24
+
25
+ # :call-seq: expects(symbol) -> expectation
26
+ #
27
+ # Adds an expectation that a method identified by +symbol+ must be called exactly once with any parameters.
28
+ # Returns the new expectation which can be further modified by methods on Mocha::Expectation.
29
+ # product = Product.new
30
+ # product.expects(:save).returns(true)
31
+ # assert_equal false, product.save
32
+ def expects(symbol)
33
+ method = stubba_method.new(stubba_object, symbol)
34
+ $stubba.stub(method)
35
+ mocha.expects(symbol, caller)
36
+ end
37
+
38
+ # :call-seq: stubs(symbol) -> expectation
39
+ #
40
+ # Adds an expectation that a method identified by +symbol+ may be called any number of times with any parameters.
41
+ # Returns the new expectation which can be further modified by methods on Mocha::Expectation.
42
+ # product = Product.new
43
+ # product.stubs(:save).returns(true)
44
+ # assert_equal false, product.save
45
+ def stubs(symbol)
46
+ method = stubba_method.new(stubba_object, symbol)
47
+ $stubba.stub(method)
48
+ mocha.stubs(symbol, caller)
49
+ end
50
+
51
+ def verify # :nodoc:
52
+ mocha.verify
53
+ end
54
+
55
+ end
56
+
57
+ class Module # :nodoc:
58
+
59
+ def stubba_method
60
+ Mocha::ClassMethod
61
+ end
62
+
63
+ end
64
+
65
+ class Class
66
+
67
+ def stubba_method # :nodoc:
68
+ Mocha::ClassMethod
69
+ end
70
+
71
+ class AnyInstance # :nodoc:
72
+
73
+ def initialize(klass)
74
+ @stubba_object = klass
75
+ end
76
+
77
+ def stubba_method
78
+ Mocha::AnyInstanceMethod
79
+ end
80
+
81
+ def stubba_object
82
+ @stubba_object
83
+ end
84
+
85
+ end
86
+
87
+ # :call-seq: any_instance -> mock object
88
+ #
89
+ # Returns a mock object which will detect calls to any instance of this class.
90
+ # Product.any_instance.stubs(:save).returns(false)
91
+ # product_1 = Product.new
92
+ # assert_equal false, product_1.save
93
+ # product_2 = Product.new
94
+ # assert_equal false, product_2.save
95
+ def any_instance
96
+ @any_instance ||= AnyInstance.new(self)
97
+ end
98
+
99
+ end
100
+
@@ -0,0 +1,28 @@
1
+ require 'mocha/inspect'
2
+
3
+ module Mocha
4
+
5
+ class PrettyParameters
6
+
7
+ def initialize(params)
8
+ @params = params
9
+ @params_string = params.mocha_inspect
10
+ end
11
+
12
+ def pretty
13
+ remove_outer_array_braces!
14
+ remove_outer_hash_braces!
15
+ @params_string
16
+ end
17
+
18
+ def remove_outer_array_braces!
19
+ @params_string = @params_string.gsub(/^\[|\]$/, '')
20
+ end
21
+
22
+ def remove_outer_hash_braces!
23
+ @params_string = @params_string.gsub(/^\{|\}$/, '') if @params.size == 1
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,23 @@
1
+ require 'mocha/central'
2
+
3
+ module Mocha
4
+
5
+ module SetupAndTeardown
6
+
7
+ def setup_stubs
8
+ $stubba = Mocha::Central.new
9
+ end
10
+
11
+ def verify_stubs
12
+ $stubba.verify_all { yield if block_given? } if $stubba
13
+ end
14
+
15
+ def teardown_stubs
16
+ if $stubba then
17
+ $stubba.unstub_all
18
+ $stubba = nil
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ require 'mocha/auto_verify'
2
+ require 'mocha/setup_and_teardown'
3
+
4
+ module Mocha
5
+
6
+ module Standalone
7
+
8
+ include AutoVerify
9
+ include SetupAndTeardown
10
+
11
+ def mocha_setup
12
+ setup_stubs
13
+ end
14
+
15
+ def mocha_verify(&block)
16
+ verify_mocks(&block)
17
+ verify_stubs(&block)
18
+ end
19
+
20
+ def mocha_teardown
21
+ begin
22
+ teardown_mocks
23
+ ensure
24
+ teardown_stubs
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,49 @@
1
+ require 'mocha/expectation_error'
2
+
3
+ module Mocha
4
+
5
+ module TestCaseAdapter
6
+
7
+ def self.included(base)
8
+ base.class_eval do
9
+
10
+ alias_method :run_before_mocha_test_case_adapter, :run
11
+
12
+ def run(result)
13
+ yield(Test::Unit::TestCase::STARTED, name)
14
+ @_result = result
15
+ begin
16
+ mocha_setup
17
+ begin
18
+ setup
19
+ __send__(@method_name)
20
+ mocha_verify { add_assertion }
21
+ rescue Mocha::ExpectationError => e
22
+ add_failure(e.message, e.backtrace)
23
+ rescue Test::Unit::AssertionFailedError => e
24
+ add_failure(e.message, e.backtrace)
25
+ rescue StandardError, ScriptError
26
+ add_error($!)
27
+ ensure
28
+ begin
29
+ teardown
30
+ rescue Test::Unit::AssertionFailedError => e
31
+ add_failure(e.message, e.backtrace)
32
+ rescue StandardError, ScriptError
33
+ add_error($!)
34
+ end
35
+ end
36
+ ensure
37
+ mocha_teardown
38
+ end
39
+ result.add_run
40
+ yield(Test::Unit::TestCase::FINISHED, name)
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,2 @@
1
+ require 'mocha/standalone'
2
+ require 'mocha/object'
@@ -0,0 +1,2 @@
1
+ # for backwards compatibility
2
+ require 'mocha'
@@ -0,0 +1,36 @@
1
+ module ActiveRecordTestCase
2
+
3
+ def setup_with_fixtures
4
+ methods_called << :setup_with_fixtures
5
+ end
6
+
7
+ alias_method :setup, :setup_with_fixtures
8
+
9
+ def teardown_with_fixtures
10
+ methods_called << :teardown_with_fixtures
11
+ end
12
+
13
+ alias_method :teardown, :teardown_with_fixtures
14
+
15
+ def self.method_added(method)
16
+ case method.to_s
17
+ when 'setup'
18
+ unless method_defined?(:setup_without_fixtures)
19
+ alias_method :setup_without_fixtures, :setup
20
+ define_method(:setup) do
21
+ setup_with_fixtures
22
+ setup_without_fixtures
23
+ end
24
+ end
25
+ when 'teardown'
26
+ unless method_defined?(:teardown_without_fixtures)
27
+ alias_method :teardown_without_fixtures, :teardown
28
+ define_method(:teardown) do
29
+ teardown_without_fixtures
30
+ teardown_with_fixtures
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,75 @@
1
+ require 'test/unit/ui/console/testrunner'
2
+
3
+ require 'mocha/inspect_test'
4
+ require 'mocha/pretty_parameters_test'
5
+ require 'mocha/expectation_test'
6
+ require 'mocha/infinite_range_test'
7
+ require 'mocha/mock_methods_test'
8
+ require 'mocha/mock_test'
9
+ require 'mocha/auto_verify_test'
10
+
11
+ require 'mocha/central_test'
12
+ require 'mocha/class_method_test'
13
+ require 'mocha/any_instance_method_test'
14
+ require 'mocha/setup_and_teardown_test'
15
+ require 'mocha/object_test'
16
+ require 'mocha/metaclass_test'
17
+
18
+ class UnitTests
19
+
20
+ def self.suite
21
+ suite = Test::Unit::TestSuite.new('UnitTests')
22
+ suite << InspectTest.suite
23
+ suite << PrettyParametersTest.suite
24
+ suite << ExpectationTest.suite
25
+ suite << InfiniteRangeTest.suite
26
+ suite << MockMethodsTest.suite
27
+ suite << MockTest.suite
28
+ suite << AutoVerifyTest.suite
29
+ suite << CentralTest.suite
30
+ suite << ClassMethodTest.suite
31
+ suite << AnyInstanceMethodTest.suite
32
+ suite << SetupAndTeardownTest.suite
33
+ suite << ObjectTest.suite
34
+ suite << MetaclassTest.suite
35
+ suite
36
+ end
37
+
38
+ end
39
+
40
+ Test::Unit::UI::Console::TestRunner.run(UnitTests)
41
+
42
+ require 'mocha_test_result_integration_test'
43
+ require 'stubba_test_result_integration_test'
44
+ require 'stubba_integration_test'
45
+
46
+ class IntegrationTests
47
+
48
+ def self.suite
49
+ suite = Test::Unit::TestSuite.new('IntegrationTests')
50
+ suite << MochaTestResultIntegrationTest.suite
51
+ suite << StubbaTestResultIntegrationTest.suite
52
+ suite << StubbaIntegrationTest.suite
53
+ end
54
+
55
+ end
56
+
57
+ Test::Unit::UI::Console::TestRunner.run(IntegrationTests)
58
+
59
+ require 'mocha_acceptance_test'
60
+ require 'stubba_acceptance_test'
61
+ require 'standalone_acceptance_test'
62
+
63
+ class AcceptanceTests
64
+
65
+ def self.suite
66
+ suite = Test::Unit::TestSuite.new('AcceptanceTests')
67
+ suite << MochaAcceptanceTest.suite
68
+ suite << StubbaAcceptanceTest.suite
69
+ suite << StandaloneAcceptanceTest.suite
70
+ suite
71
+ end
72
+
73
+ end
74
+
75
+ Test::Unit::UI::Console::TestRunner.run(AcceptanceTests)