google_distance_matrix 0.4.0 → 0.5.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.
- checksums.yaml +4 -4
- data/.editorconfig +16 -0
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +2 -0
- data/Rakefile +9 -4
- data/google_distance_matrix.gemspec +20 -18
- 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 +37 -19
- 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 +6 -4
- data/lib/google_distance_matrix/matrix.rb +45 -22
- data/lib/google_distance_matrix/place.rb +32 -25
- data/lib/google_distance_matrix/places.rb +5 -4
- data/lib/google_distance_matrix/polyline_encoder/delta.rb +4 -2
- data/lib/google_distance_matrix/polyline_encoder/value_encoder.rb +11 -4
- data/lib/google_distance_matrix/polyline_encoder.rb +2 -2
- 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 +25 -29
- data/lib/google_distance_matrix/url_builder/polyline_encoder_buffer.rb +3 -0
- data/lib/google_distance_matrix/url_builder.rb +44 -16
- data/lib/google_distance_matrix/version.rb +3 -1
- data/lib/google_distance_matrix.rb +25 -23
- data/spec/lib/google_distance_matrix/client_cache_spec.rb +26 -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 +30 -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 +95 -81
- data/spec/lib/google_distance_matrix/url_builder_spec.rb +97 -48
- data/spec/spec_helper.rb +3 -1
- metadata +35 -7
@@ -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,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
4
|
-
let(:origin_1) { GoogleDistanceMatrix::Place.new address:
|
5
|
-
let(:origin_2) { GoogleDistanceMatrix::Place.new address:
|
6
|
+
let(:origin_1) { GoogleDistanceMatrix::Place.new address: 'Karl Johans gate, Oslo' }
|
7
|
+
let(:origin_2) { GoogleDistanceMatrix::Place.new address: 'Askerveien 1, Asker' }
|
6
8
|
|
7
|
-
let(:destination_1) { GoogleDistanceMatrix::Place.new address:
|
9
|
+
let(:destination_1) { GoogleDistanceMatrix::Place.new address: 'Drammensveien 1, Oslo' }
|
8
10
|
|
9
|
-
let(:destination_2_built_from) { double address:
|
11
|
+
let(:destination_2_built_from) { double address: 'Skjellestadhagen, Heggedal' }
|
10
12
|
let(:destination_2) { GoogleDistanceMatrix::Place.new destination_2_built_from }
|
11
13
|
|
12
14
|
let(:url_builder) { GoogleDistanceMatrix::UrlBuilder.new matrix }
|
13
|
-
let(:url) { url_builder.
|
15
|
+
let(:url) { url_builder.sensitive_url }
|
14
16
|
|
15
17
|
let(:matrix) do
|
16
18
|
GoogleDistanceMatrix::Matrix.new(
|
@@ -21,55 +23,61 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
|
21
23
|
|
22
24
|
subject { described_class.new matrix }
|
23
25
|
|
24
|
-
context
|
26
|
+
context 'success, with traffic data' do
|
25
27
|
before do
|
26
28
|
matrix.configure do |c|
|
27
29
|
c.departure_time = 'now'
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
|
-
let!(:api_request_stub)
|
33
|
+
let!(:api_request_stub) do
|
34
|
+
stub_request(:get, url).to_return body: recorded_request_for(:success_with_in_traffic)
|
35
|
+
end
|
32
36
|
|
33
|
-
describe
|
34
|
-
it
|
37
|
+
describe '#shortest_route_by_duration_in_traffic_to' do
|
38
|
+
it 'returns route representing shortest duration to given origin' do
|
35
39
|
expect(subject.shortest_route_by_duration_in_traffic_to(origin_1)).to eq matrix.data[0][0]
|
36
40
|
end
|
37
41
|
|
38
|
-
it
|
39
|
-
expect(subject.shortest_route_by_duration_in_traffic_to(destination_2))
|
42
|
+
it 'returns route representing shortest duration to given destination' do
|
43
|
+
expect(subject.shortest_route_by_duration_in_traffic_to(destination_2))
|
44
|
+
.to eq matrix.data[1][1]
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
43
|
-
describe
|
44
|
-
it
|
45
|
-
expect(subject.shortest_route_by_duration_in_traffic_to!(origin_1))
|
48
|
+
describe '#shortest_route_by_duration_in_traffic_to!' do
|
49
|
+
it 'returns the same as shortest_route_by_duration_in_traffic_to' do
|
50
|
+
expect(subject.shortest_route_by_duration_in_traffic_to!(origin_1))
|
51
|
+
.to eq subject.shortest_route_by_duration_in_traffic_to(origin_1)
|
46
52
|
end
|
47
53
|
end
|
48
54
|
end
|
49
55
|
|
50
|
-
context
|
51
|
-
let!(:api_request_stub)
|
56
|
+
context 'success, without in traffic data' do
|
57
|
+
let!(:api_request_stub) do
|
58
|
+
stub_request(:get, url).to_return body: recorded_request_for(:success)
|
59
|
+
end
|
52
60
|
|
53
|
-
describe
|
54
|
-
it
|
55
|
-
expect { subject.routes_for
|
61
|
+
describe '#routes_for' do
|
62
|
+
it 'fails if given place does not exist' do
|
63
|
+
expect { subject.routes_for 'foo' }.to raise_error ArgumentError
|
56
64
|
end
|
57
65
|
|
58
|
-
it
|
66
|
+
it 'returns routes for given origin' do
|
59
67
|
routes = subject.routes_for origin_1
|
60
68
|
|
61
69
|
expect(routes.length).to eq 2
|
62
70
|
expect(routes.map(&:origin).all? { |o| o == origin_1 }).to be true
|
63
71
|
end
|
64
72
|
|
65
|
-
it
|
73
|
+
it 'returns routes for given destination' do
|
66
74
|
routes = subject.routes_for destination_2
|
67
75
|
|
68
76
|
expect(routes.length).to eq 2
|
69
77
|
expect(routes.map(&:destination).all? { |d| d == destination_2 }).to be true
|
70
78
|
end
|
71
79
|
|
72
|
-
it
|
80
|
+
it 'returns routes for given object a place was built from' do
|
73
81
|
routes = subject.routes_for destination_2_built_from
|
74
82
|
|
75
83
|
expect(routes.length).to eq 2
|
@@ -77,40 +85,42 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
|
77
85
|
end
|
78
86
|
end
|
79
87
|
|
80
|
-
describe
|
81
|
-
it
|
82
|
-
expect(subject.routes_for!
|
88
|
+
describe '#routes_for!' do
|
89
|
+
it 'returns the same as routes_for' do
|
90
|
+
expect(subject.routes_for!(origin_1)).to eq subject.routes_for(origin_1)
|
83
91
|
end
|
84
92
|
end
|
85
93
|
|
86
|
-
describe
|
87
|
-
it
|
94
|
+
describe '#route_for' do
|
95
|
+
it 'returns route' do
|
88
96
|
route = subject.route_for(origin: origin_1, destination: destination_1)
|
89
97
|
expect(route.origin).to eq origin_1
|
90
98
|
expect(route.destination).to eq destination_1
|
91
99
|
end
|
92
100
|
|
93
|
-
it
|
101
|
+
it 'returns route when you give it the object a place was built from' do
|
94
102
|
route = subject.route_for(origin: origin_1, destination: destination_2_built_from)
|
95
103
|
expect(route.origin).to eq origin_1
|
96
104
|
expect(route.destination).to eq destination_2
|
97
105
|
end
|
98
106
|
|
99
|
-
it
|
107
|
+
it 'fails with argument error if origin is missing' do
|
100
108
|
expect { subject.route_for destination: destination_2 }.to raise_error ArgumentError
|
101
109
|
end
|
102
110
|
|
103
|
-
it
|
111
|
+
it 'fails with argument error if destination is missing' do
|
104
112
|
expect { subject.route_for origin: origin_1 }.to raise_error ArgumentError
|
105
113
|
end
|
106
114
|
|
107
|
-
it
|
108
|
-
expect
|
115
|
+
it 'fails with argument error if object is neither place nor something it was built from' do
|
116
|
+
expect do
|
117
|
+
subject.route_for origin: origin_1, destination: double
|
118
|
+
end.to raise_error ArgumentError
|
109
119
|
end
|
110
120
|
end
|
111
121
|
|
112
|
-
describe
|
113
|
-
it
|
122
|
+
describe '#route_for!' do
|
123
|
+
it 'returns the same as route_for' do
|
114
124
|
route = subject.route_for(origin: origin_1, destination: destination_1)
|
115
125
|
route_bang = subject.route_for!(origin: origin_1, destination: destination_1)
|
116
126
|
|
@@ -118,60 +128,64 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
|
118
128
|
end
|
119
129
|
end
|
120
130
|
|
121
|
-
describe
|
122
|
-
it
|
131
|
+
describe '#shortest_route_by_distance_to' do
|
132
|
+
it 'returns route representing shortest distance to given origin' do
|
123
133
|
expect(subject.shortest_route_by_distance_to(origin_1)).to eq matrix.data[0][0]
|
124
134
|
end
|
125
135
|
|
126
|
-
it
|
136
|
+
it 'returns route representing shortest distance to given destination' do
|
127
137
|
expect(subject.shortest_route_by_distance_to(destination_2)).to eq matrix.data[1][1]
|
128
138
|
end
|
129
139
|
end
|
130
140
|
|
131
|
-
describe
|
132
|
-
it
|
133
|
-
expect(subject.shortest_route_by_distance_to!(origin_1))
|
141
|
+
describe '#shortest_route_by_distance_to!' do
|
142
|
+
it 'returns the same as shortest_route_by_distance_to' do
|
143
|
+
expect(subject.shortest_route_by_distance_to!(origin_1))
|
144
|
+
.to eq subject.shortest_route_by_distance_to(origin_1)
|
134
145
|
end
|
135
146
|
end
|
136
147
|
|
137
|
-
describe
|
138
|
-
it
|
148
|
+
describe '#shortest_route_by_duration_to' do
|
149
|
+
it 'returns route representing shortest duration to given origin' do
|
139
150
|
expect(subject.shortest_route_by_duration_to(origin_1)).to eq matrix.data[0][0]
|
140
151
|
end
|
141
152
|
|
142
|
-
it
|
153
|
+
it 'returns route representing shortest duration to given destination' do
|
143
154
|
expect(subject.shortest_route_by_duration_to(destination_2)).to eq matrix.data[1][1]
|
144
155
|
end
|
145
156
|
end
|
146
157
|
|
147
|
-
describe
|
148
|
-
it
|
149
|
-
expect(subject.shortest_route_by_duration_to!(origin_1))
|
158
|
+
describe '#shortest_route_by_duration_to!' do
|
159
|
+
it 'returns the same as shortest_route_by_duration_to' do
|
160
|
+
expect(subject.shortest_route_by_duration_to!(origin_1))
|
161
|
+
.to eq subject.shortest_route_by_duration_to(origin_1)
|
150
162
|
end
|
151
163
|
end
|
152
164
|
|
153
|
-
describe
|
154
|
-
it
|
155
|
-
expect
|
165
|
+
describe '#shortest_route_by_duration_in_traffic_to' do
|
166
|
+
it 'returns route representing shortest duration to given origin' do
|
167
|
+
expect do
|
156
168
|
subject.shortest_route_by_duration_in_traffic_to(origin_1)
|
157
|
-
|
169
|
+
end.to raise_error GoogleDistanceMatrix::InvalidQuery
|
158
170
|
end
|
159
171
|
end
|
160
172
|
|
161
|
-
describe
|
162
|
-
it
|
163
|
-
expect
|
173
|
+
describe '#shortest_route_by_duration_in_traffic_to!' do
|
174
|
+
it 'returns the same as shortest_route_by_duration_in_traffic_to' do
|
175
|
+
expect do
|
164
176
|
subject.shortest_route_by_duration_in_traffic_to!(origin_1)
|
165
|
-
|
177
|
+
end.to raise_error GoogleDistanceMatrix::InvalidQuery
|
166
178
|
end
|
167
179
|
end
|
168
180
|
end
|
169
181
|
|
170
|
-
context
|
171
|
-
let!(:api_request_stub)
|
182
|
+
context 'routes mssing data' do
|
183
|
+
let!(:api_request_stub) do
|
184
|
+
stub_request(:get, url).to_return body: recorded_request_for(:zero_results)
|
185
|
+
end
|
172
186
|
|
173
|
-
describe
|
174
|
-
it
|
187
|
+
describe '#routes_for' do
|
188
|
+
it 'returns routes for given origin' do
|
175
189
|
routes = subject.routes_for origin_1
|
176
190
|
|
177
191
|
expect(routes.length).to eq 2
|
@@ -179,53 +193,53 @@ describe GoogleDistanceMatrix::RoutesFinder, :request_recordings do
|
|
179
193
|
end
|
180
194
|
end
|
181
195
|
|
182
|
-
describe
|
183
|
-
it
|
184
|
-
expect
|
196
|
+
describe '#routes_for!' do
|
197
|
+
it 'fails upon any non-ok route' do
|
198
|
+
expect do
|
185
199
|
subject.routes_for! origin_1
|
186
|
-
|
200
|
+
end.to raise_error GoogleDistanceMatrix::InvalidRoute
|
187
201
|
end
|
188
202
|
end
|
189
203
|
|
190
|
-
|
191
|
-
|
192
|
-
it "returns route" do
|
204
|
+
describe '#route_for' do
|
205
|
+
it 'returns route' do
|
193
206
|
route = subject.route_for origin: origin_1, destination: destination_2
|
194
207
|
expect(route.origin).to eq origin_1
|
195
208
|
expect(route.destination).to eq destination_2
|
196
209
|
end
|
197
210
|
end
|
198
211
|
|
199
|
-
describe
|
200
|
-
it
|
201
|
-
expect
|
212
|
+
describe '#route_for!' do
|
213
|
+
it 'fails upon non-ok route' do
|
214
|
+
expect do
|
202
215
|
subject.route_for! origin: origin_1, destination: destination_2
|
203
|
-
|
216
|
+
end.to raise_error GoogleDistanceMatrix::InvalidRoute
|
204
217
|
end
|
205
218
|
end
|
206
219
|
|
207
|
-
|
208
|
-
|
209
|
-
it "returns route representing shortest distance to given origin" do
|
220
|
+
describe '#shortest_route_by_distance_to' do
|
221
|
+
it 'returns route representing shortest distance to given origin' do
|
210
222
|
expect(subject.shortest_route_by_distance_to(origin_1)).to eq matrix.data[0][0]
|
211
223
|
end
|
212
224
|
end
|
213
225
|
|
214
|
-
describe
|
215
|
-
it
|
216
|
-
expect { subject.shortest_route_by_distance_to!(origin_1) }
|
226
|
+
describe '#shortest_route_by_distance_to!' do
|
227
|
+
it 'fails upon non-ok route' do
|
228
|
+
expect { subject.shortest_route_by_distance_to!(origin_1) }
|
229
|
+
.to raise_error GoogleDistanceMatrix::InvalidRoute
|
217
230
|
end
|
218
231
|
end
|
219
232
|
|
220
|
-
describe
|
221
|
-
it
|
233
|
+
describe '#shortest_route_by_duration_to' do
|
234
|
+
it 'returns route representing shortest distance to given origin' do
|
222
235
|
expect(subject.shortest_route_by_duration_to(origin_1)).to eq matrix.data[0][0]
|
223
236
|
end
|
224
237
|
end
|
225
238
|
|
226
|
-
describe
|
227
|
-
it
|
228
|
-
expect { subject.shortest_route_by_duration_to!(origin_1) }
|
239
|
+
describe '#shortest_route_by_duration_to!' do
|
240
|
+
it 'fails upon non-ok route' do
|
241
|
+
expect { subject.shortest_route_by_duration_to!(origin_1) }
|
242
|
+
.to raise_error GoogleDistanceMatrix::InvalidRoute
|
229
243
|
end
|
230
244
|
end
|
231
245
|
end
|