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,126 @@
1
+ require 'rubygems'
2
+ require 'rake/rdoctask'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/contrib/sshpublisher'
5
+
6
+ module Mocha
7
+ VERSION = "0.4.0"
8
+ end
9
+
10
+ desc "Default task is currently to run all tests"
11
+ task :default => :test_all
12
+
13
+ desc "Run all tests"
14
+ task :test_all do
15
+ $: << "#{File.dirname(__FILE__)}/test"
16
+ require 'test/all_tests'
17
+ end
18
+
19
+ desc 'Generate RDoc'
20
+ Rake::RDocTask.new do |task|
21
+ task.main = 'README'
22
+ task.title = 'Mocha'
23
+ task.rdoc_dir = 'doc'
24
+ task.template = "html_with_google_analytics"
25
+ task.options << "--line-numbers" << "--inline-source"
26
+ task.rdoc_files.include('README', 'RELEASE', 'COPYING', 'MIT-LICENSE', 'agiledox.txt', 'lib/mocha/auto_verify.rb', 'lib/mocha/mock_methods.rb', 'lib/mocha/expectation.rb', 'lib/mocha/object.rb')
27
+ end
28
+ task :rdoc => :examples
29
+
30
+ desc "Upload RDoc to RubyForge"
31
+ task :publish_rdoc => [:rdoc, :examples] do
32
+ Rake::SshDirPublisher.new("jamesmead@rubyforge.org", "/var/www/gforge-projects/mocha", "doc").upload
33
+ end
34
+
35
+ desc "Generate agiledox-like documentation for tests"
36
+ file 'agiledox.txt' do
37
+ File.open('agiledox.txt', 'w') do |output|
38
+ tests = FileList['test/**/*_test.rb']
39
+ tests.each do |file|
40
+ m = %r".*/([^/].*)_test.rb".match(file)
41
+ output << m[1]+" should:\n"
42
+ test_definitions = File::readlines(file).select {|line| line =~ /.*def test.*/}
43
+ test_definitions.sort.each do |definition|
44
+ m = %r"test_(should_)?(.*)".match(definition)
45
+ output << " - "+m[2].gsub(/_/," ") << "\n"
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ desc "Convert example ruby files to syntax-highlighted html"
52
+ task :examples do
53
+ require 'coderay'
54
+ mkdir_p 'doc/examples'
55
+ File.open('doc/examples/coderay.css', 'w') do |output|
56
+ output << CodeRay::Encoders[:html]::CSS.new.stylesheet
57
+ end
58
+ ['mocha', 'stubba', 'misc'].each do |filename|
59
+ File.open("doc/examples/#{filename}.html", 'w') do |file|
60
+ file << "<html>"
61
+ file << "<head>"
62
+ file << %q(<link rel="stylesheet" media="screen" href="coderay.css" type="text/css">)
63
+ file << "</head>"
64
+ file << "<body>"
65
+ file << CodeRay.scan_file("examples/#{filename}.rb").html.div
66
+ file << "</body>"
67
+ file << "</html>"
68
+ end
69
+ end
70
+ end
71
+
72
+ Gem::manage_gems
73
+
74
+ specification = Gem::Specification.new do |s|
75
+ s.name = "mocha"
76
+ s.summary = "Mocking and stubbing library"
77
+ s.version = Mocha::VERSION
78
+ s.author = 'James Mead'
79
+ s.description = <<-EOF
80
+ Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
81
+ EOF
82
+ s.email = 'mocha-developer@rubyforge.org'
83
+ s.homepage = 'http://mocha.rubyforge.org'
84
+ s.rubyforge_project = 'mocha'
85
+
86
+ s.has_rdoc = true
87
+ s.extra_rdoc_files = ['README', 'COPYING']
88
+ s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers'
89
+
90
+ s.autorequire = 'mocha'
91
+ s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
92
+ s.test_file = "test/all_tests.rb"
93
+ end
94
+
95
+ Rake::GemPackageTask.new(specification) do |package|
96
+ package.need_zip = true
97
+ package.need_tar = true
98
+ end
99
+
100
+ task :verify_user do
101
+ raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
102
+ end
103
+
104
+ task :verify_password do
105
+ raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD']
106
+ end
107
+
108
+ desc "Publish package files on RubyForge."
109
+ task :publish_packages => [:verify_user, :verify_password, :package] do
110
+ require 'meta_project'
111
+ require 'rake/contrib/xforge'
112
+ release_files = FileList[
113
+ "pkg/mocha-#{Mocha::VERSION}.gem",
114
+ "pkg/mocha-#{Mocha::VERSION}.tgz",
115
+ "pkg/mocha-#{Mocha::VERSION}.zip"
116
+ ]
117
+
118
+ Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new('mocha')) do |release|
119
+ release.user_name = ENV['RUBYFORGE_USER']
120
+ release.password = ENV['RUBYFORGE_PASSWORD']
121
+ release.files = release_files.to_a
122
+ release.release_name = "Mocha #{Mocha::VERSION}"
123
+ release.release_changes = ''
124
+ release.release_notes = ''
125
+ end
126
+ end
@@ -0,0 +1,36 @@
1
+ # Mocking a class method
2
+
3
+ product = Product.new
4
+ Product.expects(:find).with(1).returns(product)
5
+ assert_equal product, Product.find(1)
6
+
7
+ # Mocking an instance method on a real object
8
+
9
+ product = Product.new
10
+ product.expects(:save).returns(true)
11
+ assert product.save
12
+
13
+ # Stubbing instance methods on real object
14
+
15
+ prices = [stub(:pence => 1000), stub(:pence => 2000)]
16
+ product = Product.new
17
+ product.stubs(:prices).returns(prices)
18
+ assert_equal [1000, 2000], product.prices.collect {|p| p.pence}
19
+
20
+ # Stubbing an instance method on all instances of a class
21
+
22
+ Product.any_instance.stubs(:name).returns('stubbed_name')
23
+ product = Product.new
24
+ assert_equal 'stubbed_name', product.name
25
+
26
+ # Traditional mocking
27
+
28
+ object = mock()
29
+ object.expects(:expected_method).with(:p1, :p2).returns(:result)
30
+ assert_equal :result, object.expected_method(:p1, :p2)
31
+
32
+ # Shortcuts
33
+
34
+ object = stub(:method1 => :result1, :method2 => :result2)
35
+ assert_equal :result1, object.method1
36
+ assert_equal :result2, object.method2
@@ -0,0 +1,26 @@
1
+ class Enterprise
2
+
3
+ def initialize(dilithium)
4
+ @dilithium = dilithium
5
+ end
6
+
7
+ def go(warp_factor)
8
+ warp_factor.times { @dilithium.nuke(:anti_matter) }
9
+ end
10
+
11
+ end
12
+
13
+ require 'test/unit'
14
+ require 'rubygems'
15
+ require 'mocha'
16
+
17
+ class EnterpriseTest < Test::Unit::TestCase
18
+
19
+ def test_should_boldly_go
20
+ dilithium = mock()
21
+ dilithium.expects(:nuke).with(:anti_matter).at_least_once # auto-verified at end of test
22
+ enterprise = Enterprise.new(dilithium)
23
+ enterprise.go(2)
24
+ end
25
+
26
+ end
@@ -0,0 +1,65 @@
1
+ class Order
2
+
3
+ attr_accessor :shipped_on
4
+
5
+ def total_cost
6
+ line_items.inject(0) { |total, line_item| total + line_item.price } + shipping_cost
7
+ end
8
+
9
+ def total_weight
10
+ line_items.inject(0) { |total, line_item| total + line_item.weight }
11
+ end
12
+
13
+ def shipping_cost
14
+ total_weight * 5 + 10
15
+ end
16
+
17
+ class << self
18
+
19
+ def find_all
20
+ # Database.connection.execute('select * from orders...
21
+ end
22
+
23
+ def number_shipped_since(date)
24
+ find_all.select { |order| order.shipped_on > date }.size
25
+ end
26
+
27
+ def unshipped_value
28
+ find_all.inject(0) { |total, order| order.shipped_on ? total : total + order.total_cost }
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
35
+ require 'test/unit'
36
+ require 'rubygems'
37
+ require 'stubba'
38
+
39
+ class OrderTest < Test::Unit::TestCase
40
+
41
+ # illustrates stubbing instance method
42
+ def test_should_calculate_shipping_cost_based_on_total_weight
43
+ order = Order.new
44
+ order.stubs(:total_weight).returns(10)
45
+ assert_equal 60, order.shipping_cost
46
+ end
47
+
48
+ # illustrates stubbing class method
49
+ def test_should_count_number_of_orders_shipped_after_specified_date
50
+ now = Time.now; week_in_secs = 7 * 24 * 60 * 60
51
+ order_1 = Order.new; order_1.shipped_on = now - 1 * week_in_secs
52
+ order_2 = Order.new; order_2.shipped_on = now - 3 * week_in_secs
53
+ Order.stubs(:find_all).returns([order_1, order_2])
54
+ assert_equal 1, Order.number_shipped_since(now - 2 * week_in_secs)
55
+ end
56
+
57
+ # illustrates stubbing instance method for all instances of a class
58
+ def test_should_calculate_value_of_unshipped_orders
59
+ Order.stubs(:find_all).returns([Order.new, Order.new, Order.new])
60
+ Order.any_instance.stubs(:shipped_on).returns(nil)
61
+ Order.any_instance.stubs(:total_cost).returns(10)
62
+ assert_equal 30, Order.unshipped_value
63
+ end
64
+
65
+ end
@@ -0,0 +1,19 @@
1
+ require 'mocha_standalone'
2
+ require 'mocha/test_case_adapter'
3
+
4
+ require 'test/unit/testcase'
5
+
6
+ module Test
7
+
8
+ module Unit
9
+
10
+ class TestCase
11
+
12
+ include Mocha::Standalone
13
+ include Mocha::TestCaseAdapter
14
+
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,35 @@
1
+ require 'mocha/class_method'
2
+
3
+ module Mocha
4
+
5
+ class AnyInstanceMethod < ClassMethod
6
+
7
+ def unstub
8
+ remove_new_method
9
+ restore_original_method
10
+ stubbee.any_instance.reset_mocha
11
+ end
12
+
13
+ def mock
14
+ stubbee.any_instance.mocha
15
+ end
16
+
17
+ def hide_original_method
18
+ stubbee.class_eval "alias_method :#{hidden_method}, :#{method}" if stubbee.method_defined?(method)
19
+ end
20
+
21
+ def define_new_method
22
+ stubbee.class_eval "def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end"
23
+ end
24
+
25
+ def remove_new_method
26
+ stubbee.class_eval "remove_method :#{method}"
27
+ end
28
+
29
+ def restore_original_method
30
+ stubbee.class_eval "alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}" if stubbee.method_defined?(hidden_method)
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,113 @@
1
+ require 'mocha/mock'
2
+
3
+ # Methods added to TestCase allowing creation of mock objects.
4
+ #
5
+ # Mocks created this way will have their expectations automatically verified at the end of the test.
6
+ #
7
+ # See Mocha::MockMethods for methods on mock objects.
8
+ module Mocha
9
+
10
+ module AutoVerify
11
+
12
+ def mocks # :nodoc:
13
+ @mocks ||= []
14
+ end
15
+
16
+ def reset_mocks # :nodoc:
17
+ @mocks = nil
18
+ end
19
+
20
+ # :call-seq: mock(name) -> mock object
21
+ # mock(expected_methods = {}) -> mock object
22
+ # mock(name, expected_methods = {}) -> mock object
23
+ #
24
+ # Creates a mock object.
25
+ #
26
+ # +name+ is a +String+ identifier for the mock object.
27
+ #
28
+ # +expected_methods+ is a +Hash+ with expected method name symbols as keys and corresponding return values as values.
29
+ #
30
+ # Note that (contrary to expectations set up by #stub) these expectations <b>must</b> be fulfilled during the test.
31
+ # def test_product
32
+ # product = mock('ipod_product', :manufacturer => 'ipod', :price => 100)
33
+ # assert_equal 'ipod', product.manufacturer
34
+ # assert_equal 100, product.price
35
+ # # an error will be raised unless both Product#manufacturer and Product#price have been called
36
+ # end
37
+ def mock(*args)
38
+ name, expectations = name_and_expectations_from_args(args)
39
+ build_mock_with_expectations(:expects, expectations, name)
40
+ end
41
+
42
+ # :call-seq: stub(name) -> mock object
43
+ # stub(stubbed_methods = {}) -> mock object
44
+ # stub(name, stubbed_methods = {}) -> mock object
45
+ #
46
+ # Creates a mock object.
47
+ #
48
+ # +name+ is a +String+ identifier for the mock object.
49
+ #
50
+ # +stubbed_methods+ is a +Hash+ with stubbed method name symbols as keys and corresponding return values as values.
51
+ #
52
+ # Note that (contrary to expectations set up by #mock) these expectations <b>need not</b> be fulfilled during the test.
53
+ # def test_product
54
+ # product = stub('ipod_product', :manufacturer => 'ipod', :price => 100)
55
+ # assert_equal 'ipod', product.manufacturer
56
+ # assert_equal 100, product.price
57
+ # # an error will not be raised even if Product#manufacturer and Product#price have not been called
58
+ # end
59
+ def stub(*args)
60
+ name, expectations = name_and_expectations_from_args(args)
61
+ build_mock_with_expectations(:stubs, expectations, name)
62
+ end
63
+
64
+ # :call-seq: stub_everything(name) -> mock object
65
+ # stub_everything(stubbed_methods = {}) -> mock object
66
+ # stub_everything(name, stubbed_methods = {}) -> mock object
67
+ #
68
+ # Creates a mock object that accepts calls to any method.
69
+ #
70
+ # By default it will return +nil+ for any method call.
71
+ #
72
+ # +name+ and +stubbed_methods+ work in the same way as for #stub.
73
+ # def test_product
74
+ # product = stub_everything('ipod_product', :price => 100)
75
+ # assert_nil product.manufacturer
76
+ # assert_nil product.any_old_method
77
+ # assert_equal 100, product.price
78
+ # end
79
+ def stub_everything(*args)
80
+ name, expectations = name_and_expectations_from_args(args)
81
+ build_mock_with_expectations(:stub_everything, expectations, name)
82
+ end
83
+
84
+ def verify_mocks # :nodoc:
85
+ mocks.each { |mock| mock.verify { yield if block_given? } }
86
+ end
87
+
88
+ def teardown_mocks # :nodoc:
89
+ reset_mocks
90
+ end
91
+
92
+ def build_mock_with_expectations(expectation_type = :expects, expectations = {}, name = nil) # :nodoc:
93
+ stub_everything = (expectation_type == :stub_everything)
94
+ expectation_type = :stubs if expectation_type == :stub_everything
95
+ mock = Mocha::Mock.new(stub_everything, name)
96
+ expectations.each do |method, result|
97
+ mock.__send__(expectation_type, method).returns(result)
98
+ end
99
+ mocks << mock
100
+ mock
101
+ end
102
+
103
+ private
104
+
105
+ def name_and_expectations_from_args(args) # :nodoc:
106
+ name = args.first.is_a?(String) ? args.delete_at(0) : nil
107
+ expectations = args.first || {}
108
+ [name, expectations]
109
+ end
110
+
111
+ end
112
+
113
+ end
@@ -0,0 +1,35 @@
1
+ module Mocha
2
+
3
+ class Central
4
+
5
+ attr_accessor :stubba_methods
6
+
7
+ def initialize
8
+ self.stubba_methods = []
9
+ end
10
+
11
+ def stub(method)
12
+ unless stubba_methods.include?(method)
13
+ method.stub
14
+ stubba_methods.push method
15
+ end
16
+ end
17
+
18
+ def verify_all(&block)
19
+ unique_mocks.each { |mock| mock.verify(&block) }
20
+ end
21
+
22
+ def unique_mocks
23
+ stubba_methods.inject({}) { |mocks, method| mocks[method.mock.__id__] = method.mock; mocks }.values
24
+ end
25
+
26
+ def unstub_all
27
+ while stubba_methods.size > 0
28
+ method = stubba_methods.pop
29
+ method.unstub
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ end