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.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +16 -0
  3. data/.rubocop.yml +6 -0
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +4 -6
  6. data/CHANGELOG.md +40 -0
  7. data/Gemfile +2 -0
  8. data/README.md +0 -3
  9. data/Rakefile +9 -4
  10. data/google_distance_matrix.gemspec +21 -19
  11. data/lib/google_distance_matrix.rb +25 -23
  12. data/lib/google_distance_matrix/client.rb +32 -18
  13. data/lib/google_distance_matrix/client_cache.rb +9 -3
  14. data/lib/google_distance_matrix/configuration.rb +39 -24
  15. data/lib/google_distance_matrix/errors.rb +6 -3
  16. data/lib/google_distance_matrix/log_subscriber.rb +14 -14
  17. data/lib/google_distance_matrix/logger.rb +7 -5
  18. data/lib/google_distance_matrix/matrix.rb +45 -22
  19. data/lib/google_distance_matrix/place.rb +37 -28
  20. data/lib/google_distance_matrix/places.rb +5 -4
  21. data/lib/google_distance_matrix/polyline_encoder.rb +2 -2
  22. data/lib/google_distance_matrix/polyline_encoder/delta.rb +4 -2
  23. data/lib/google_distance_matrix/polyline_encoder/value_encoder.rb +13 -5
  24. data/lib/google_distance_matrix/railtie.rb +4 -1
  25. data/lib/google_distance_matrix/route.rb +22 -15
  26. data/lib/google_distance_matrix/routes_finder.rb +27 -29
  27. data/lib/google_distance_matrix/url_builder.rb +44 -16
  28. data/lib/google_distance_matrix/url_builder/polyline_encoder_buffer.rb +3 -0
  29. data/lib/google_distance_matrix/version.rb +3 -1
  30. data/spec/lib/google_distance_matrix/client_cache_spec.rb +27 -11
  31. data/spec/lib/google_distance_matrix/client_spec.rb +40 -30
  32. data/spec/lib/google_distance_matrix/configuration_spec.rb +36 -24
  33. data/spec/lib/google_distance_matrix/log_subscriber_spec.rb +13 -44
  34. data/spec/lib/google_distance_matrix/logger_spec.rb +16 -13
  35. data/spec/lib/google_distance_matrix/matrix_spec.rb +90 -57
  36. data/spec/lib/google_distance_matrix/place_spec.rb +38 -25
  37. data/spec/lib/google_distance_matrix/places_spec.rb +29 -28
  38. data/spec/lib/google_distance_matrix/polyline_encoder/delta_spec.rb +5 -3
  39. data/spec/lib/google_distance_matrix/polyline_encoder_spec.rb +7 -2
  40. data/spec/lib/google_distance_matrix/route_spec.rb +11 -9
  41. data/spec/lib/google_distance_matrix/routes_finder_spec.rb +124 -81
  42. data/spec/lib/google_distance_matrix/url_builder_spec.rb +97 -48
  43. data/spec/spec_helper.rb +3 -1
  44. metadata +46 -18
@@ -1,23 +1,25 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  describe GoogleDistanceMatrix::Place do
4
- let(:address) { "Karl Johans gate, Oslo" }
6
+ let(:address) { 'Karl Johans gate, Oslo' }
5
7
  let(:lat) { 1.4 }
6
8
  let(:lng) { 2.2 }
7
9
 
8
- describe "#initialize" do
9
- it "builds with an address" do
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 "builds with lat lng" do
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 "builds with an object responding to lat and lng" do
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 "builds with an object responding to address" do
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 "builds with an object responding to lat, lng and address" do
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 "fails if no valid attributes given" do
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 "fails if both address, lat ang lng is given" do
58
- expect { described_class.new(address: address, lat: lat, lng: lng) }.to raise_error ArgumentError
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 "#to_param" do
63
- context "with address" do
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 "with lat lng" do
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 "#equal?" do
77
- it "is considered equal when address is the same" do
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 "is considered equal when lat and lng are the same" do
82
- expect(described_class.new(lat: lat, lng: lng)).to be_eql 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 "is not considered equal when address differs" do
86
- expect(described_class.new(address: address)).to_not be_eql described_class.new(address: address + ", Norway")
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 "is not considered equal when lat or lng differs" do
90
- expect(described_class.new(lat: lat, lng: lng)).to_not be_eql described_class.new(lat: lat, lng: lng + 1)
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
- require "spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
2
4
 
3
5
  describe GoogleDistanceMatrix::Places do
4
- let(:values) { [{address: "one"}, {address: "two"}, {address: "three"}] }
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: "four" }
8
- let(:place_5) { GoogleDistanceMatrix::Place.new address: "five" }
9
- let(:place_6) { GoogleDistanceMatrix::Place.new address: "six" }
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 *places }
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 "#{attr}" do
19
- it "adds value" do
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
- }.to change { subject.include? place_4 }.to true
23
+ end.to change { subject.include? place_4 }.to true
23
24
  end
24
25
 
25
- it "keeps uniq values" do
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
- }.to_not change subject, :length
31
+ end.to_not change subject, :length
31
32
  end
32
33
 
33
- it "is chanable" do
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 "wraps values in a Place" do
40
- subject.public_send attr, {address: "four"}
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 == "four" }).to be true
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 "#{attr}" do
50
- it "adds multiple values at once" do
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 "#concat" do
58
+ describe '#concat' do
58
59
  let(:places_2) { [place_4, place_5, place_6] }
59
60
 
60
- it "adds the given array" do
61
+ it 'adds the given array' do
61
62
  subject.concat places_2
62
- expect(subject).to include *places_2
63
+ expect(subject).to include(*places_2)
63
64
  end
64
65
 
65
- it "keeps values uniq" do
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
- }.to_not change subject, :length
71
+ end.to_not change subject, :length
71
72
  end
72
73
 
73
- it "returns self" do
74
- expect(subject.concat places_2).to eq subject
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
- 3850000, -12020000,
10
- 220000, -75000,
11
- 255200, -550300
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
- [[41.3522171071184, -86.0456299662023],[41.3522171071183, -86.0454368471533]] => 'krk{FdxdlO?e@'
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 lat_lng_values).to eq expected
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
- require "spec_helper"
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
- "distance" => {"text" => "2.0 km", "value" => 2032},
7
- "duration" => {"text" =>"6 mins", "value" => 367},
8
- "duration_in_traffic" => {"text" =>"5 mins", "value" => 301},
9
- "status" =>"OK"
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 "ok" }
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 "2.0 km" }
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 "6 mins" }
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 "5 mins" }
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
- require "spec_helper"
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: "Karl Johans gate, Oslo" }
5
- let(:origin_2) { GoogleDistanceMatrix::Place.new address: "Askerveien 1, Asker" }
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: "Drammensveien 1, Oslo" }
10
+ let(:destination_1) { GoogleDistanceMatrix::Place.new address: 'Drammensveien 1, Oslo' }
8
11
 
9
- let(:destination_2_built_from) { double address: "Skjellestadhagen, Heggedal" }
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.url }
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 "success, with traffic data" do
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) { stub_request(:get, url).to_return body: recorded_request_for(:success_with_in_traffic) }
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 "#shortest_route_by_duration_in_traffic_to" do
34
- it "returns route representing shortest duration to given origin" do
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 "returns route representing shortest duration to given destination" do
39
- expect(subject.shortest_route_by_duration_in_traffic_to(destination_2)).to eq matrix.data[1][1]
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 "#shortest_route_by_duration_in_traffic_to!" do
44
- it "returns the same as shortest_route_by_duration_in_traffic_to" do
45
- expect(subject.shortest_route_by_duration_in_traffic_to!(origin_1)).to eq 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 "success, without in traffic data" do
51
- let!(:api_request_stub) { stub_request(:get, url).to_return body: recorded_request_for(:success) }
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 "#routes_for" do
54
- it "fails if given place does not exist" do
55
- expect { subject.routes_for "foo" }.to raise_error ArgumentError
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 "returns routes for given origin" do
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 "returns routes for given destination" do
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 "returns routes for given object a place was built from" do
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 "#routes_for!" do
81
- it "returns the same as routes_for" do
82
- expect(subject.routes_for! origin_1).to eq subject.routes_for(origin_1)
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 "#route_for" do
87
- it "returns route" do
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 "returns route when you give it the object a place was built from" do
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
- it "fails with argument error if origin is missing" do
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 "fails with argument error if destination is missing" do
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 "fails with argument error if sent in object is neither place nor something it was built from" do
108
- expect { subject.route_for origin: origin_1, destination: double }.to raise_error ArgumentError
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 "#route_for!" do
113
- it "returns the same as route_for" do
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 "#shortest_route_by_distance_to" do
122
- it "returns route representing shortest distance to given origin" do
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 "returns route representing shortest distance to given destination" do
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 "#shortest_route_by_distance_to!" do
132
- it "returns the same as shortest_route_by_distance_to" do
133
- expect(subject.shortest_route_by_distance_to!(origin_1)).to eq 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 "#shortest_route_by_duration_to" do
138
- it "returns route representing shortest duration to given origin" do
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 "returns route representing shortest duration to given destination" do
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 "#shortest_route_by_duration_to!" do
148
- it "returns the same as shortest_route_by_duration_to" do
149
- expect(subject.shortest_route_by_duration_to!(origin_1)).to eq 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 "#shortest_route_by_duration_in_traffic_to" do
154
- it "returns route representing shortest duration to given origin" do
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
- }.to raise_error GoogleDistanceMatrix::InvalidQuery
198
+ end.to raise_error GoogleDistanceMatrix::InvalidQuery
158
199
  end
159
200
  end
160
201
 
161
- describe "#shortest_route_by_duration_in_traffic_to!" do
162
- it "returns the same as shortest_route_by_duration_in_traffic_to" do
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
- }.to raise_error GoogleDistanceMatrix::InvalidQuery
206
+ end.to raise_error GoogleDistanceMatrix::InvalidQuery
166
207
  end
167
208
  end
168
209
  end
169
210
 
170
- context "routes mssing data" do
171
- let!(:api_request_stub) { stub_request(:get, url).to_return body: recorded_request_for(:zero_results) }
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 "#routes_for" do
174
- it "returns routes for given origin" do
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 "#routes_for!" do
183
- it "fails upon any non-ok route" do
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
- }.to raise_error GoogleDistanceMatrix::InvalidRoute
229
+ end.to raise_error GoogleDistanceMatrix::InvalidRoute
187
230
  end
188
231
  end
189
232
 
190
-
191
- describe "#route_for" do
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 "#route_for!" do
200
- it "fails upon non-ok route" do
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
- }.to raise_error GoogleDistanceMatrix::InvalidRoute
245
+ end.to raise_error GoogleDistanceMatrix::InvalidRoute
204
246
  end
205
247
  end
206
248
 
207
-
208
- describe "#shortest_route_by_distance_to" do
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 "#shortest_route_by_distance_to!" do
215
- it "fails upon non-ok route" do
216
- expect { subject.shortest_route_by_distance_to!(origin_1) }.to raise_error GoogleDistanceMatrix::InvalidRoute
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 "#shortest_route_by_duration_to" do
221
- it "returns route representing shortest distance to given origin" do
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 "#shortest_route_by_duration_to!" do
227
- it "fails upon non-ok route" do
228
- expect { subject.shortest_route_by_duration_to!(origin_1) }.to raise_error GoogleDistanceMatrix::InvalidRoute
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