google_distance_matrix 0.4.0 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.editorconfig +16 -0
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -1
- data/.travis.yml +4 -6
- data/CHANGELOG.md +40 -0
- data/Gemfile +2 -0
- data/README.md +0 -3
- data/Rakefile +9 -4
- data/google_distance_matrix.gemspec +21 -19
- data/lib/google_distance_matrix.rb +25 -23
- data/lib/google_distance_matrix/client.rb +32 -18
- data/lib/google_distance_matrix/client_cache.rb +9 -3
- data/lib/google_distance_matrix/configuration.rb +39 -24
- data/lib/google_distance_matrix/errors.rb +6 -3
- data/lib/google_distance_matrix/log_subscriber.rb +14 -14
- data/lib/google_distance_matrix/logger.rb +7 -5
- data/lib/google_distance_matrix/matrix.rb +45 -22
- data/lib/google_distance_matrix/place.rb +37 -28
- data/lib/google_distance_matrix/places.rb +5 -4
- data/lib/google_distance_matrix/polyline_encoder.rb +2 -2
- data/lib/google_distance_matrix/polyline_encoder/delta.rb +4 -2
- data/lib/google_distance_matrix/polyline_encoder/value_encoder.rb +13 -5
- data/lib/google_distance_matrix/railtie.rb +4 -1
- data/lib/google_distance_matrix/route.rb +22 -15
- data/lib/google_distance_matrix/routes_finder.rb +27 -29
- data/lib/google_distance_matrix/url_builder.rb +44 -16
- data/lib/google_distance_matrix/url_builder/polyline_encoder_buffer.rb +3 -0
- data/lib/google_distance_matrix/version.rb +3 -1
- data/spec/lib/google_distance_matrix/client_cache_spec.rb +27 -11
- data/spec/lib/google_distance_matrix/client_spec.rb +40 -30
- data/spec/lib/google_distance_matrix/configuration_spec.rb +36 -24
- data/spec/lib/google_distance_matrix/log_subscriber_spec.rb +13 -44
- data/spec/lib/google_distance_matrix/logger_spec.rb +16 -13
- data/spec/lib/google_distance_matrix/matrix_spec.rb +90 -57
- data/spec/lib/google_distance_matrix/place_spec.rb +38 -25
- data/spec/lib/google_distance_matrix/places_spec.rb +29 -28
- data/spec/lib/google_distance_matrix/polyline_encoder/delta_spec.rb +5 -3
- data/spec/lib/google_distance_matrix/polyline_encoder_spec.rb +7 -2
- data/spec/lib/google_distance_matrix/route_spec.rb +11 -9
- data/spec/lib/google_distance_matrix/routes_finder_spec.rb +124 -81
- data/spec/lib/google_distance_matrix/url_builder_spec.rb +97 -48
- data/spec/spec_helper.rb +3 -1
- metadata +46 -18
@@ -1,23 +1,25 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
describe GoogleDistanceMatrix::Place do
|
4
|
-
let(:address) {
|
6
|
+
let(:address) { 'Karl Johans gate, Oslo' }
|
5
7
|
let(:lat) { 1.4 }
|
6
8
|
let(:lng) { 2.2 }
|
7
9
|
|
8
|
-
describe
|
9
|
-
it
|
10
|
+
describe '#initialize' do
|
11
|
+
it 'builds with an address' do
|
10
12
|
place = described_class.new(address: address)
|
11
13
|
expect(place.address).to eq address
|
12
14
|
end
|
13
15
|
|
14
|
-
it
|
16
|
+
it 'builds with lat lng' do
|
15
17
|
place = described_class.new(lat: lat, lng: lng)
|
16
18
|
expect(place.lat).to eq lat
|
17
19
|
expect(place.lng).to eq lng
|
18
20
|
end
|
19
21
|
|
20
|
-
it
|
22
|
+
it 'builds with an object responding to lat and lng' do
|
21
23
|
point = double lat: 1, lng: 2
|
22
24
|
place = described_class.new(point)
|
23
25
|
|
@@ -25,22 +27,21 @@ describe GoogleDistanceMatrix::Place do
|
|
25
27
|
expect(place.lng).to eq point.lng
|
26
28
|
end
|
27
29
|
|
28
|
-
|
29
|
-
it "keeps a record of the object it built itself from" do
|
30
|
+
it 'keeps a record of the object it built itself from' do
|
30
31
|
point = double lat: 1, lng: 2
|
31
32
|
place = described_class.new(point)
|
32
33
|
|
33
34
|
expect(place.extracted_attributes_from).to eq point
|
34
35
|
end
|
35
|
-
it
|
36
|
+
it 'builds with an object responding to address' do
|
36
37
|
object = double address: address
|
37
38
|
place = described_class.new(object)
|
38
39
|
|
39
40
|
expect(place.address).to eq object.address
|
40
41
|
end
|
41
42
|
|
42
|
-
it
|
43
|
-
object = double lat: 1, lng:2, address: address
|
43
|
+
it 'builds with an object responding to lat, lng and address' do
|
44
|
+
object = double lat: 1, lng: 2, address: address
|
44
45
|
place = described_class.new(object)
|
45
46
|
|
46
47
|
expect(place.lat).to eq object.lat
|
@@ -48,46 +49,58 @@ describe GoogleDistanceMatrix::Place do
|
|
48
49
|
expect(place.address).to be_nil
|
49
50
|
end
|
50
51
|
|
51
|
-
it
|
52
|
+
it 'fails if no valid attributes given' do
|
52
53
|
expect { described_class.new }.to raise_error ArgumentError
|
53
54
|
expect { described_class.new(lat: lat) }.to raise_error ArgumentError
|
54
55
|
expect { described_class.new(lng: lng) }.to raise_error ArgumentError
|
55
56
|
end
|
56
57
|
|
57
|
-
it
|
58
|
-
expect { described_class.new(address: address, lat: lat, lng: lng) }
|
58
|
+
it 'fails if both address, lat ang lng is given' do
|
59
|
+
expect { described_class.new(address: address, lat: lat, lng: lng) }
|
60
|
+
.to raise_error ArgumentError
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
62
|
-
describe
|
63
|
-
context
|
64
|
+
describe '#to_param' do
|
65
|
+
context 'with address' do
|
64
66
|
subject { described_class.new address: address }
|
65
67
|
|
66
68
|
it { expect(subject.to_param).to eq address }
|
67
69
|
end
|
68
70
|
|
69
|
-
context
|
71
|
+
context 'with lat lng' do
|
70
72
|
subject { described_class.new lng: lng, lat: lat }
|
71
73
|
|
72
74
|
it { expect(subject.to_param).to eq "#{lat},#{lng}" }
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
|
-
describe
|
77
|
-
it
|
78
|
+
describe '#equal?' do
|
79
|
+
it 'is considered equal when address is the same' do
|
78
80
|
expect(described_class.new(address: address)).to be_eql described_class.new(address: address)
|
79
81
|
end
|
80
82
|
|
81
|
-
it
|
82
|
-
expect(described_class.new(lat: lat, lng: lng))
|
83
|
+
it 'is considered equal when lat and lng are the same' do
|
84
|
+
expect(described_class.new(lat: lat, lng: lng))
|
85
|
+
.to be_eql described_class.new(lat: lat, lng: lng)
|
83
86
|
end
|
84
87
|
|
85
|
-
it
|
86
|
-
expect(described_class.new(address: address))
|
88
|
+
it 'is not considered equal when address differs' do
|
89
|
+
expect(described_class.new(address: address))
|
90
|
+
.to_not be_eql described_class.new(address: address + ', Norway')
|
87
91
|
end
|
88
92
|
|
89
|
-
it
|
90
|
-
expect(described_class.new(lat: lat, lng: lng))
|
93
|
+
it 'is not considered equal when lat or lng differs' do
|
94
|
+
expect(described_class.new(lat: lat, lng: lng))
|
95
|
+
.to_not be_eql described_class.new(lat: lat, lng: lng + 1)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#==' do
|
100
|
+
it 'is considered equal when places are compared with ==' do
|
101
|
+
expect(described_class.new(address: address) ==
|
102
|
+
GoogleDistanceMatrix::Place.new(address: address))
|
103
|
+
.to be_truthy
|
91
104
|
end
|
92
105
|
end
|
93
106
|
end
|
@@ -1,77 +1,78 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
describe GoogleDistanceMatrix::Places do
|
4
|
-
let(:values) { [{address:
|
6
|
+
let(:values) { [{ address: 'one' }, { address: 'two' }, { address: 'three' }] }
|
5
7
|
let(:places) { values.map { |v| GoogleDistanceMatrix::Place.new v } }
|
6
8
|
|
7
|
-
let(:place_4) { GoogleDistanceMatrix::Place.new address:
|
8
|
-
let(:place_5) { GoogleDistanceMatrix::Place.new address:
|
9
|
-
let(:place_6) { GoogleDistanceMatrix::Place.new address:
|
9
|
+
let(:place_4) { GoogleDistanceMatrix::Place.new address: 'four' }
|
10
|
+
let(:place_5) { GoogleDistanceMatrix::Place.new address: 'five' }
|
11
|
+
let(:place_6) { GoogleDistanceMatrix::Place.new address: 'six' }
|
10
12
|
|
11
13
|
subject { described_class.new places }
|
12
14
|
|
13
|
-
it { should include
|
15
|
+
it { should include(*places) }
|
14
16
|
it { should_not include 5 }
|
15
17
|
|
16
|
-
|
17
18
|
%w[<< push unshift].each do |attr|
|
18
|
-
describe
|
19
|
-
it
|
20
|
-
expect
|
19
|
+
describe attr.to_s do
|
20
|
+
it 'adds value' do
|
21
|
+
expect do
|
21
22
|
subject.public_send attr, place_4
|
22
|
-
|
23
|
+
end.to change { subject.include? place_4 }.to true
|
23
24
|
end
|
24
25
|
|
25
|
-
it
|
26
|
+
it 'keeps uniq values' do
|
26
27
|
subject.public_send attr, place_4
|
27
28
|
|
28
|
-
expect
|
29
|
+
expect do
|
29
30
|
subject.public_send attr, place_4
|
30
|
-
|
31
|
+
end.to_not change subject, :length
|
31
32
|
end
|
32
33
|
|
33
|
-
it
|
34
|
+
it 'is chanable' do
|
34
35
|
subject.public_send(attr, place_5).public_send(attr, place_6)
|
35
36
|
|
36
37
|
expect(subject).to include place_5, place_6
|
37
38
|
end
|
38
39
|
|
39
|
-
it
|
40
|
-
subject.public_send attr,
|
40
|
+
it 'wraps values in a Place' do
|
41
|
+
subject.public_send attr, address: 'four'
|
41
42
|
|
42
43
|
expect(subject.all? { |place| place.is_a? GoogleDistanceMatrix::Place }).to be true
|
43
|
-
expect(subject.any? { |place| place.address ==
|
44
|
+
expect(subject.any? { |place| place.address == 'four' }).to be true
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
49
|
%w[push unshift].each do |attr|
|
49
|
-
describe
|
50
|
-
it
|
50
|
+
describe attr.to_s do
|
51
|
+
it 'adds multiple values at once' do
|
51
52
|
subject.public_send attr, place_4, place_5
|
52
53
|
expect(subject).to include place_4, place_5
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
|
-
describe
|
58
|
+
describe '#concat' do
|
58
59
|
let(:places_2) { [place_4, place_5, place_6] }
|
59
60
|
|
60
|
-
it
|
61
|
+
it 'adds the given array' do
|
61
62
|
subject.concat places_2
|
62
|
-
expect(subject).to include
|
63
|
+
expect(subject).to include(*places_2)
|
63
64
|
end
|
64
65
|
|
65
|
-
it
|
66
|
+
it 'keeps values uniq' do
|
66
67
|
subject.concat places_2
|
67
68
|
|
68
|
-
expect
|
69
|
+
expect do
|
69
70
|
subject.concat places_2
|
70
|
-
|
71
|
+
end.to_not change subject, :length
|
71
72
|
end
|
72
73
|
|
73
|
-
it
|
74
|
-
expect(subject.concat
|
74
|
+
it 'returns self' do
|
75
|
+
expect(subject.concat(places_2)).to eq subject
|
75
76
|
end
|
76
77
|
end
|
77
78
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module GoogleDistanceMatrix
|
@@ -6,9 +8,9 @@ module GoogleDistanceMatrix
|
|
6
8
|
deltas = subject.deltas_rounded [[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]]
|
7
9
|
|
8
10
|
expect(deltas).to eq [
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
3_850_000, -12_020_000,
|
12
|
+
220_000, -75_000,
|
13
|
+
255_200, -550_300
|
12
14
|
]
|
13
15
|
end
|
14
16
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module GoogleDistanceMatrix
|
@@ -5,12 +7,15 @@ module GoogleDistanceMatrix
|
|
5
7
|
tests = {
|
6
8
|
[[-179.9832104, -179.9832104]] => '`~oia@`~oia@',
|
7
9
|
[[38.5, -120.2], [40.7, -120.95], [43.252, -126.453]] => '_p~iF~ps|U_ulLnnqC_mqNvxq`@',
|
8
|
-
[
|
10
|
+
[
|
11
|
+
[41.3522171071184, -86.0456299662023],
|
12
|
+
[41.3522171071183, -86.0454368471533]
|
13
|
+
] => 'krk{FdxdlO?e@'
|
9
14
|
}
|
10
15
|
|
11
16
|
tests.each_pair do |lat_lng_values, expected|
|
12
17
|
it "encodes #{lat_lng_values} to #{expected}" do
|
13
|
-
expect(described_class.encode
|
18
|
+
expect(described_class.encode(lat_lng_values)).to eq expected
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
@@ -1,24 +1,26 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
describe GoogleDistanceMatrix::Route do
|
4
6
|
let(:attributes) do
|
5
7
|
{
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
'distance' => { 'text' => '2.0 km', 'value' => 2032 },
|
9
|
+
'duration' => { 'text' => '6 mins', 'value' => 367 },
|
10
|
+
'duration_in_traffic' => { 'text' => '5 mins', 'value' => 301 },
|
11
|
+
'status' => 'OK'
|
10
12
|
}
|
11
13
|
end
|
12
14
|
|
13
15
|
subject { described_class.new attributes }
|
14
16
|
|
15
|
-
it { expect(subject.status).to eq
|
17
|
+
it { expect(subject.status).to eq 'ok' }
|
16
18
|
it { expect(subject.distance_in_meters).to eq 2032 }
|
17
|
-
it { expect(subject.distance_text).to eq
|
19
|
+
it { expect(subject.distance_text).to eq '2.0 km' }
|
18
20
|
it { expect(subject.duration_in_seconds).to eq 367 }
|
19
|
-
it { expect(subject.duration_text).to eq
|
21
|
+
it { expect(subject.duration_text).to eq '6 mins' }
|
20
22
|
it { expect(subject.duration_in_traffic_in_seconds).to eq 301 }
|
21
|
-
it { expect(subject.duration_in_traffic_text).to eq
|
23
|
+
it { expect(subject.duration_in_traffic_text).to eq '5 mins' }
|
22
24
|
|
23
25
|
it { is_expected.to be_ok }
|
24
26
|
end
|
@@ -1,16 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
+
let(:origin_1_attributes) { { address: 'Karl Johans gate, Oslo' } }
|
7
|
+
let(:origin_1) { GoogleDistanceMatrix::Place.new origin_1_attributes }
|
8
|
+
let(:origin_2) { GoogleDistanceMatrix::Place.new address: 'Askerveien 1, Asker' }
|
6
9
|
|
7
|
-
let(:destination_1) { GoogleDistanceMatrix::Place.new address:
|
10
|
+
let(:destination_1) { GoogleDistanceMatrix::Place.new address: 'Drammensveien 1, Oslo' }
|
8
11
|
|
9
|
-
let(:destination_2_built_from) { double address:
|
12
|
+
let(:destination_2_built_from) { double address: 'Skjellestadhagen, Heggedal' }
|
10
13
|
let(:destination_2) { GoogleDistanceMatrix::Place.new destination_2_built_from }
|
11
14
|
|
12
15
|
let(:url_builder) { GoogleDistanceMatrix::UrlBuilder.new matrix }
|
13
|
-
let(:url) { url_builder.
|
16
|
+
let(:url) { url_builder.sensitive_url }
|
14
17
|
|
15
18
|
let(:matrix) do
|
16
19
|
GoogleDistanceMatrix::Matrix.new(
|
@@ -21,96 +24,132 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
|
21
24
|
|
22
25
|
subject { described_class.new matrix }
|
23
26
|
|
24
|
-
context
|
27
|
+
context 'success, with traffic data' do
|
25
28
|
before do
|
26
29
|
matrix.configure do |c|
|
27
30
|
c.departure_time = 'now'
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
|
-
let!(:api_request_stub)
|
34
|
+
let!(:api_request_stub) do
|
35
|
+
stub_request(:get, url).to_return body: recorded_request_for(:success_with_in_traffic)
|
36
|
+
end
|
32
37
|
|
33
|
-
describe
|
34
|
-
it
|
38
|
+
describe '#shortest_route_by_duration_in_traffic_to' do
|
39
|
+
it 'returns route representing shortest duration to given origin' do
|
35
40
|
expect(subject.shortest_route_by_duration_in_traffic_to(origin_1)).to eq matrix.data[0][0]
|
36
41
|
end
|
37
42
|
|
38
|
-
it
|
39
|
-
expect(subject.shortest_route_by_duration_in_traffic_to(destination_2))
|
43
|
+
it 'returns route representing shortest duration to given destination' do
|
44
|
+
expect(subject.shortest_route_by_duration_in_traffic_to(destination_2))
|
45
|
+
.to eq matrix.data[1][1]
|
40
46
|
end
|
41
47
|
end
|
42
48
|
|
43
|
-
describe
|
44
|
-
it
|
45
|
-
expect(subject.shortest_route_by_duration_in_traffic_to!(origin_1))
|
49
|
+
describe '#shortest_route_by_duration_in_traffic_to!' do
|
50
|
+
it 'returns the same as shortest_route_by_duration_in_traffic_to' do
|
51
|
+
expect(subject.shortest_route_by_duration_in_traffic_to!(origin_1))
|
52
|
+
.to eq subject.shortest_route_by_duration_in_traffic_to(origin_1)
|
46
53
|
end
|
47
54
|
end
|
48
55
|
end
|
49
56
|
|
50
|
-
context
|
51
|
-
let!(:api_request_stub)
|
57
|
+
context 'success, without in traffic data' do
|
58
|
+
let!(:api_request_stub) do
|
59
|
+
stub_request(:get, url).to_return body: recorded_request_for(:success)
|
60
|
+
end
|
52
61
|
|
53
|
-
describe
|
54
|
-
it
|
55
|
-
expect { subject.routes_for
|
62
|
+
describe '#routes_for' do
|
63
|
+
it 'fails if given place does not exist' do
|
64
|
+
expect { subject.routes_for 'foo' }.to raise_error ArgumentError
|
56
65
|
end
|
57
66
|
|
58
|
-
it
|
67
|
+
it 'returns routes for given origin' do
|
59
68
|
routes = subject.routes_for origin_1
|
60
69
|
|
61
70
|
expect(routes.length).to eq 2
|
62
71
|
expect(routes.map(&:origin).all? { |o| o == origin_1 }).to be true
|
63
72
|
end
|
64
73
|
|
65
|
-
it
|
74
|
+
it 'still returns routes for origin if it has same address but different object_id' do
|
75
|
+
routes = subject.routes_for GoogleDistanceMatrix::Place.new origin_1_attributes
|
76
|
+
|
77
|
+
expect(routes.length).to eq 2
|
78
|
+
expect(routes.map(&:origin).all? { |o| o == origin_1 }).to be true
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns routes for given destination' do
|
66
82
|
routes = subject.routes_for destination_2
|
67
83
|
|
68
84
|
expect(routes.length).to eq 2
|
69
85
|
expect(routes.map(&:destination).all? { |d| d == destination_2 }).to be true
|
70
86
|
end
|
71
87
|
|
72
|
-
it
|
88
|
+
it 'returns routes for given object a place was built from' do
|
73
89
|
routes = subject.routes_for destination_2_built_from
|
74
90
|
|
75
91
|
expect(routes.length).to eq 2
|
76
92
|
expect(routes.map(&:destination).all? { |d| d == destination_2 }).to be true
|
77
93
|
end
|
94
|
+
|
95
|
+
context 'place built from hash' do
|
96
|
+
let(:destination_2_built_from) { { address: 'Skjellestadhagen, Heggedal' } }
|
97
|
+
|
98
|
+
it 'returns routes for given hash a place was built from' do
|
99
|
+
routes = subject.routes_for destination_2_built_from
|
100
|
+
|
101
|
+
expect(routes.length).to eq 2
|
102
|
+
expect(routes.map(&:destination).all? { |d| d == destination_2 }).to be true
|
103
|
+
end
|
104
|
+
end
|
78
105
|
end
|
79
106
|
|
80
|
-
describe
|
81
|
-
it
|
82
|
-
expect(subject.routes_for!
|
107
|
+
describe '#routes_for!' do
|
108
|
+
it 'returns the same as routes_for' do
|
109
|
+
expect(subject.routes_for!(origin_1)).to eq subject.routes_for(origin_1)
|
83
110
|
end
|
84
111
|
end
|
85
112
|
|
86
|
-
describe
|
87
|
-
it
|
113
|
+
describe '#route_for' do
|
114
|
+
it 'returns route' do
|
88
115
|
route = subject.route_for(origin: origin_1, destination: destination_1)
|
89
116
|
expect(route.origin).to eq origin_1
|
90
117
|
expect(route.destination).to eq destination_1
|
91
118
|
end
|
92
119
|
|
93
|
-
it
|
120
|
+
it 'returns route when you give it the object a place was built from' do
|
94
121
|
route = subject.route_for(origin: origin_1, destination: destination_2_built_from)
|
95
122
|
expect(route.origin).to eq origin_1
|
96
123
|
expect(route.destination).to eq destination_2
|
97
124
|
end
|
98
125
|
|
99
|
-
|
126
|
+
context 'place built from hash' do
|
127
|
+
let(:destination_2_built_from) { { address: 'Skjellestadhagen, Heggedal' } }
|
128
|
+
|
129
|
+
it 'returns route when you give it the hash the place was built from' do
|
130
|
+
route = subject.route_for(origin: origin_1, destination: destination_2_built_from)
|
131
|
+
expect(route.origin).to eq origin_1
|
132
|
+
expect(route.destination).to eq destination_2
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'fails with argument error if origin is missing' do
|
100
137
|
expect { subject.route_for destination: destination_2 }.to raise_error ArgumentError
|
101
138
|
end
|
102
139
|
|
103
|
-
it
|
140
|
+
it 'fails with argument error if destination is missing' do
|
104
141
|
expect { subject.route_for origin: origin_1 }.to raise_error ArgumentError
|
105
142
|
end
|
106
143
|
|
107
|
-
it
|
108
|
-
expect
|
144
|
+
it 'fails with argument error if object is neither place nor something it was built from' do
|
145
|
+
expect do
|
146
|
+
subject.route_for origin: origin_1, destination: double
|
147
|
+
end.to raise_error ArgumentError
|
109
148
|
end
|
110
149
|
end
|
111
150
|
|
112
|
-
describe
|
113
|
-
it
|
151
|
+
describe '#route_for!' do
|
152
|
+
it 'returns the same as route_for' do
|
114
153
|
route = subject.route_for(origin: origin_1, destination: destination_1)
|
115
154
|
route_bang = subject.route_for!(origin: origin_1, destination: destination_1)
|
116
155
|
|
@@ -118,60 +157,64 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
|
118
157
|
end
|
119
158
|
end
|
120
159
|
|
121
|
-
describe
|
122
|
-
it
|
160
|
+
describe '#shortest_route_by_distance_to' do
|
161
|
+
it 'returns route representing shortest distance to given origin' do
|
123
162
|
expect(subject.shortest_route_by_distance_to(origin_1)).to eq matrix.data[0][0]
|
124
163
|
end
|
125
164
|
|
126
|
-
it
|
165
|
+
it 'returns route representing shortest distance to given destination' do
|
127
166
|
expect(subject.shortest_route_by_distance_to(destination_2)).to eq matrix.data[1][1]
|
128
167
|
end
|
129
168
|
end
|
130
169
|
|
131
|
-
describe
|
132
|
-
it
|
133
|
-
expect(subject.shortest_route_by_distance_to!(origin_1))
|
170
|
+
describe '#shortest_route_by_distance_to!' do
|
171
|
+
it 'returns the same as shortest_route_by_distance_to' do
|
172
|
+
expect(subject.shortest_route_by_distance_to!(origin_1))
|
173
|
+
.to eq subject.shortest_route_by_distance_to(origin_1)
|
134
174
|
end
|
135
175
|
end
|
136
176
|
|
137
|
-
describe
|
138
|
-
it
|
177
|
+
describe '#shortest_route_by_duration_to' do
|
178
|
+
it 'returns route representing shortest duration to given origin' do
|
139
179
|
expect(subject.shortest_route_by_duration_to(origin_1)).to eq matrix.data[0][0]
|
140
180
|
end
|
141
181
|
|
142
|
-
it
|
182
|
+
it 'returns route representing shortest duration to given destination' do
|
143
183
|
expect(subject.shortest_route_by_duration_to(destination_2)).to eq matrix.data[1][1]
|
144
184
|
end
|
145
185
|
end
|
146
186
|
|
147
|
-
describe
|
148
|
-
it
|
149
|
-
expect(subject.shortest_route_by_duration_to!(origin_1))
|
187
|
+
describe '#shortest_route_by_duration_to!' do
|
188
|
+
it 'returns the same as shortest_route_by_duration_to' do
|
189
|
+
expect(subject.shortest_route_by_duration_to!(origin_1))
|
190
|
+
.to eq subject.shortest_route_by_duration_to(origin_1)
|
150
191
|
end
|
151
192
|
end
|
152
193
|
|
153
|
-
describe
|
154
|
-
it
|
155
|
-
expect
|
194
|
+
describe '#shortest_route_by_duration_in_traffic_to' do
|
195
|
+
it 'returns route representing shortest duration to given origin' do
|
196
|
+
expect do
|
156
197
|
subject.shortest_route_by_duration_in_traffic_to(origin_1)
|
157
|
-
|
198
|
+
end.to raise_error GoogleDistanceMatrix::InvalidQuery
|
158
199
|
end
|
159
200
|
end
|
160
201
|
|
161
|
-
describe
|
162
|
-
it
|
163
|
-
expect
|
202
|
+
describe '#shortest_route_by_duration_in_traffic_to!' do
|
203
|
+
it 'returns the same as shortest_route_by_duration_in_traffic_to' do
|
204
|
+
expect do
|
164
205
|
subject.shortest_route_by_duration_in_traffic_to!(origin_1)
|
165
|
-
|
206
|
+
end.to raise_error GoogleDistanceMatrix::InvalidQuery
|
166
207
|
end
|
167
208
|
end
|
168
209
|
end
|
169
210
|
|
170
|
-
context
|
171
|
-
let!(:api_request_stub)
|
211
|
+
context 'routes mssing data' do
|
212
|
+
let!(:api_request_stub) do
|
213
|
+
stub_request(:get, url).to_return body: recorded_request_for(:zero_results)
|
214
|
+
end
|
172
215
|
|
173
|
-
describe
|
174
|
-
it
|
216
|
+
describe '#routes_for' do
|
217
|
+
it 'returns routes for given origin' do
|
175
218
|
routes = subject.routes_for origin_1
|
176
219
|
|
177
220
|
expect(routes.length).to eq 2
|
@@ -179,53 +222,53 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
|
179
222
|
end
|
180
223
|
end
|
181
224
|
|
182
|
-
describe
|
183
|
-
it
|
184
|
-
expect
|
225
|
+
describe '#routes_for!' do
|
226
|
+
it 'fails upon any non-ok route' do
|
227
|
+
expect do
|
185
228
|
subject.routes_for! origin_1
|
186
|
-
|
229
|
+
end.to raise_error GoogleDistanceMatrix::InvalidRoute
|
187
230
|
end
|
188
231
|
end
|
189
232
|
|
190
|
-
|
191
|
-
|
192
|
-
it "returns route" do
|
233
|
+
describe '#route_for' do
|
234
|
+
it 'returns route' do
|
193
235
|
route = subject.route_for origin: origin_1, destination: destination_2
|
194
236
|
expect(route.origin).to eq origin_1
|
195
237
|
expect(route.destination).to eq destination_2
|
196
238
|
end
|
197
239
|
end
|
198
240
|
|
199
|
-
describe
|
200
|
-
it
|
201
|
-
expect
|
241
|
+
describe '#route_for!' do
|
242
|
+
it 'fails upon non-ok route' do
|
243
|
+
expect do
|
202
244
|
subject.route_for! origin: origin_1, destination: destination_2
|
203
|
-
|
245
|
+
end.to raise_error GoogleDistanceMatrix::InvalidRoute
|
204
246
|
end
|
205
247
|
end
|
206
248
|
|
207
|
-
|
208
|
-
|
209
|
-
it "returns route representing shortest distance to given origin" do
|
249
|
+
describe '#shortest_route_by_distance_to' do
|
250
|
+
it 'returns route representing shortest distance to given origin' do
|
210
251
|
expect(subject.shortest_route_by_distance_to(origin_1)).to eq matrix.data[0][0]
|
211
252
|
end
|
212
253
|
end
|
213
254
|
|
214
|
-
describe
|
215
|
-
it
|
216
|
-
expect { subject.shortest_route_by_distance_to!(origin_1) }
|
255
|
+
describe '#shortest_route_by_distance_to!' do
|
256
|
+
it 'fails upon non-ok route' do
|
257
|
+
expect { subject.shortest_route_by_distance_to!(origin_1) }
|
258
|
+
.to raise_error GoogleDistanceMatrix::InvalidRoute
|
217
259
|
end
|
218
260
|
end
|
219
261
|
|
220
|
-
describe
|
221
|
-
it
|
262
|
+
describe '#shortest_route_by_duration_to' do
|
263
|
+
it 'returns route representing shortest distance to given origin' do
|
222
264
|
expect(subject.shortest_route_by_duration_to(origin_1)).to eq matrix.data[0][0]
|
223
265
|
end
|
224
266
|
end
|
225
267
|
|
226
|
-
describe
|
227
|
-
it
|
228
|
-
expect { subject.shortest_route_by_duration_to!(origin_1) }
|
268
|
+
describe '#shortest_route_by_duration_to!' do
|
269
|
+
it 'fails upon non-ok route' do
|
270
|
+
expect { subject.shortest_route_by_duration_to!(origin_1) }
|
271
|
+
.to raise_error GoogleDistanceMatrix::InvalidRoute
|
229
272
|
end
|
230
273
|
end
|
231
274
|
end
|