|
5 | 5 |
|
6 | 6 | before(:example) do |
7 | 7 | stub_request(:get, /https:\/\/maps.googleapis.com\/maps\/api\/directions\/.*/) |
| 8 | + .with(headers: {"X-goog-api-key" => api_key}) |
8 | 9 | .to_return(status: 200, headers: {"Content-Type" => "application/json"}, body: '{"status":"OK","results":[]}') |
9 | 10 | end |
10 | 11 |
|
11 | 12 | context "simple directions" do |
12 | 13 | it "should call Google Maps Web Service" do |
13 | 14 | # Simplest directions request. Driving directions by default. |
14 | 15 | client.directions("Sydney", "Melbourne") |
15 | | - expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Sydney&destination=Melbourne&key=%s" % |
16 | | - api_key)).to have_been_made |
| 16 | + expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Sydney&destination=Melbourne") |
| 17 | + .with(headers: {"X-goog-api-key" => api_key})).to have_been_made |
17 | 18 | end |
18 | 19 | end |
19 | 20 |
|
|
24 | 25 | avoid: ["highways", "tolls", "ferries"], |
25 | 26 | units: "metric", |
26 | 27 | region: "au") |
27 | | - expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Sydney&avoid=highways%%7Ctolls%%7Cferries&destination=Melbourne&mode=bicycling&key=%s&units=metric®ion=au" % |
28 | | - api_key)).to have_been_made |
| 28 | + expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Sydney&avoid=highways%%7Ctolls%%7Cferries&destination=Melbourne&mode=bicycling&units=metric®ion=au") |
| 29 | + .with(headers: {"X-goog-api-key" => api_key})).to have_been_made |
29 | 30 | end |
30 | 31 | end |
31 | 32 |
|
|
35 | 36 | client.directions("Sydney Town Hall", "Parramatta, NSW", |
36 | 37 | mode: "transit", |
37 | 38 | departure_time: now) |
38 | | - expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Sydney+Town+Hall&key=%s&destination=Parramatta%%2C+NSW&mode=transit&departure_time=%d" % |
39 | | - [api_key, now.to_i])).to have_been_made |
| 39 | + expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Sydney+Town+Hall&destination=Parramatta%%2C+NSW&mode=transit&departure_time=%d" % now.to_i) |
| 40 | + .with(headers: {"X-goog-api-key" => api_key})).to have_been_made |
40 | 41 | end |
41 | 42 | end |
42 | 43 |
|
|
46 | 47 | client.directions("Sydney Town Hall", "Parramatta, NSW", |
47 | 48 | mode: "transit", |
48 | 49 | arrival_time: an_hour_before_now) |
49 | | - expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Sydney+Town+Hall&arrival_time=%d&destination=Parramatta%%2C+NSW&mode=transit&key=%s" % |
50 | | - [an_hour_before_now.to_i, api_key])).to have_been_made |
| 50 | + expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Sydney+Town+Hall&arrival_time=%d&destination=Parramatta%%2C+NSW&mode=transit" % an_hour_before_now.to_i) |
| 51 | + .with(headers: {"X-goog-api-key" => api_key})).to have_been_made |
51 | 52 | end |
52 | 53 | end |
53 | 54 |
|
|
77 | 78 | it "should call Google Maps Web Service" do |
78 | 79 | client.directions("Town Hall, Sydney", "Parramatta, NSW", |
79 | 80 | mode: "bicycling") |
80 | | - expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Town+Hall%%2C+Sydney&destination=Parramatta%%2C+NSW&mode=bicycling&key=%s" % api_key)).to have_been_made |
| 81 | + expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Town+Hall%%2C+Sydney&destination=Parramatta%%2C+NSW&mode=bicycling") |
| 82 | + .with(headers: {"X-goog-api-key" => api_key})).to have_been_made |
81 | 83 | end |
82 | 84 | end |
83 | 85 |
|
|
87 | 89 | client.directions("Brooklyn", "Queens", |
88 | 90 | mode: "transit", |
89 | 91 | departure_time: now) |
90 | | - expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&key=%s&destination=Queens&mode=transit&departure_time=%d" % [api_key, now.to_i])).to have_been_made |
| 92 | + expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&mode=transit&departure_time=%d" % now.to_i) |
| 93 | + .with(headers: {"X-goog-api-key" => api_key})).to have_been_made |
91 | 94 | end |
92 | 95 | end |
93 | 96 |
|
94 | 97 | context "boston to concord via charlestown and lexington" do |
95 | 98 | it "should call Google Maps Web Service" do |
96 | 99 | client.directions("Boston, MA", "Concord, MA", |
97 | 100 | waypoints: ["Charlestown, MA", "Lexington, MA"]) |
98 | | - expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Boston%%2C+MA&destination=Concord%%2C+MA&waypoints=Charlestown%%2C+MA%%7CLexington%%2C+MA&key=%s" % api_key)).to have_been_made |
| 101 | + expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Boston%%2C+MA&destination=Concord%%2C+MA&waypoints=Charlestown%%2C+MA%%7CLexington%%2C+MA") |
| 102 | + .with(headers: {"X-goog-api-key" => api_key})).to have_been_made |
99 | 103 | end |
100 | 104 | end |
101 | 105 |
|
|
107 | 111 | "Connawarra, SA", |
108 | 112 | "McLaren Vale, SA"], |
109 | 113 | optimize_waypoints: true) |
110 | | - expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Adelaide%%2C+SA&destination=Adelaide%%2C+SA&waypoints=optimize%%3Atrue%%7CBarossa+Valley%%2C+SA%%7CClare%%2C+SA%%7CConnawarra%%2C+SA%%7CMcLaren+Vale%%2C+SA&key=%s" % api_key)).to have_been_made |
| 114 | + expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Adelaide%%2C+SA&destination=Adelaide%%2C+SA&waypoints=optimize%%3Atrue%%7CBarossa+Valley%%2C+SA%%7CClare%%2C+SA%%7CConnawarra%%2C+SA%%7CMcLaren+Vale%%2C+SA") |
| 115 | + .with(headers: {"X-goog-api-key" => api_key})).to have_been_made |
111 | 116 | end |
112 | 117 | end |
113 | 118 |
|
114 | 119 | context "toledo to madrid in spain" do |
115 | 120 | it "should call Google Maps Web Service" do |
116 | 121 | client.directions("Toledo", "Madrid", |
117 | 122 | region: "es") |
118 | | - expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Toledo®ion=es&destination=Madrid&key=%s" % |
119 | | - api_key)).to have_been_made |
| 123 | + expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Toledo®ion=es&destination=Madrid") |
| 124 | + .with(headers: {"X-goog-api-key" => api_key})).to have_been_made |
120 | 125 | end |
121 | 126 | end |
122 | 127 |
|
123 | 128 | context "zero results returns response" do |
124 | 129 | before(:example) do |
125 | 130 | stub_request(:get, /https:\/\/maps.googleapis.com\/maps\/api\/directions\/.*/) |
| 131 | + .with(headers: {"X-goog-api-key" => api_key}) |
126 | 132 | .to_return(status: 200, headers: {"Content-Type" => "application/json"}, body: '{"status":"ZERO_RESULTS","routes":[]}') |
127 | 133 | end |
128 | 134 |
|
|
135 | 141 | context "can return full response" do |
136 | 142 | before(:example) do |
137 | 143 | stub_request(:get, /https:\/\/maps.googleapis.com\/maps\/api\/directions\/.*/) |
| 144 | + .with(headers: {"X-goog-api-key" => api_key}) |
138 | 145 | .to_return(status: 200, headers: {"Content-Type" => "application/json"}, body: '{"status":"OK","routes":[]}') |
139 | 146 | end |
140 | 147 |
|
|
149 | 156 | client.directions("Toledo", "Madrid", |
150 | 157 | region: "es", |
151 | 158 | language: "es") |
152 | | - expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Toledo®ion=es&destination=Madrid&key=%s&language=es" % api_key)).to have_been_made |
| 159 | + expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Toledo®ion=es&destination=Madrid&language=es") |
| 160 | + .with(headers: {"X-goog-api-key" => api_key})).to have_been_made |
153 | 161 | end |
154 | 162 | end |
155 | 163 |
|
156 | 164 | context "alternatives" do |
157 | 165 | it "should call Google Maps Web Service" do |
158 | 166 | client.directions("Sydney Town Hall", "Parramatta Town Hall", |
159 | 167 | alternatives: true) |
160 | | - expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Sydney+Town+Hall&destination=Parramatta+Town+Hall&alternatives=true&key=%s" % api_key)).to have_been_made |
| 168 | + expect(a_request(:get, "https://maps.googleapis.com/maps/api/directions/json?origin=Sydney+Town+Hall&destination=Parramatta+Town+Hall&alternatives=true") |
| 169 | + .with(headers: {"X-goog-api-key" => api_key})).to have_been_made |
161 | 170 | end |
162 | 171 | end |
163 | 172 | end |
0 commit comments