Sha256: 8366c948ca357a2cb04baf344bd0935686411981ecb3acc51d7fcb987c982536

Contents?: true

Size: 1.46 KB

Versions: 6

Compression:

Stored size: 1.46 KB

Contents

require File.dirname(__FILE__) + '/../../../test_helper'

module Graticule
  module Geocoder
    class MultiTest < Test::Unit::TestCase

      def setup
        @mock_geocoders = [mock("geocoder 1"), mock("geocoder 2")]
        @mock_geocoders.each {|g| g.stubs(:locate) }
        @geocoder = Multi.new(*@mock_geocoders)
      end

      def test_locate_calls_each_geocoder_and_raises_error
        @mock_geocoders.each do |g|
          g.expects(:locate).with('test').raises(Graticule::AddressError)
        end
        assert_raises(Graticule::AddressError) { @geocoder.locate 'test' }
      end

      def test_locate_returns_first_result_without_calling_others
        result = mock("result")
        @mock_geocoders.first.expects(:locate).returns(result)
        @mock_geocoders.last.expects(:locate).never
        assert_equal result, @geocoder.locate('test')
      end
      
      def test_locate_with_custom_block
        @mock_geocoders.first.expects(:locate).returns(1)
        @mock_geocoders.last.expects(:locate).returns(2)
        @geocoder = Multi.new(*@mock_geocoders) {|r| r == 2 }
        assert_equal 2, @geocoder.locate('test')
      end

      def test_locate_with_custom_block_and_no_match
        @mock_geocoders.first.expects(:locate).returns(1)
        @mock_geocoders.last.expects(:locate).returns(2)
        @geocoder = Multi.new(*@mock_geocoders) {|r| r == 3 }
        assert_raises(Graticule::AddressError) { @geocoder.locate('test') }
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
GUI-graticule-0.2.7.2 test/unit/graticule/geocoder/multi_test.rb
GUI-graticule-0.2.7.3 test/unit/graticule/geocoder/multi_test.rb
GUI-graticule-0.2.7.4 test/unit/graticule/geocoder/multi_test.rb
GUI-graticule-0.2.7.5 test/unit/graticule/geocoder/multi_test.rb
GUI-graticule-0.2.7.6 test/unit/graticule/geocoder/multi_test.rb
norman-graticule-0.2.7 test/unit/graticule/geocoder/multi_test.rb