ns-yapi 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/ns.gemspec CHANGED
@@ -1,23 +1,25 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
5
6
  Gem::Specification.new do |gem|
6
- gem.name = "ns-yapi"
7
- gem.version = '0.5.0'
8
- gem.authors = ["Stefan Hendriks", "Derek Kraan", "Bob Forma"]
9
- gem.email = ["stefanhen83@gmail.com"]
10
- gem.description = %q{Yet Another (Ruby) NS API client}
11
- gem.summary = %q{A Ruby client for the NS (Dutch Railways) API}
12
- gem.homepage = "https://github.com/zilverline/ns-api"
7
+ gem.name = 'ns-yapi'
8
+ gem.license = 'MIT'
9
+ gem.version = '0.6.0'
10
+ gem.authors = ['Stefan Hendriks', 'Derek Kraan', 'Bob Forma']
11
+ gem.email = ['info@zilverline.com']
12
+ gem.description = 'Yet Another (Ruby) NS API client'
13
+ gem.summary = 'A Ruby client for the NS (Dutch Railways) API'
14
+ gem.homepage = 'https://github.com/zilverline/ns-api'
13
15
 
14
- gem.files = `git ls-files`.split($/)
15
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
16
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
- gem.require_paths = ["lib"]
19
+ gem.require_paths = ['lib']
18
20
 
19
21
  gem.add_dependency 'addressable'
20
- gem.add_dependency 'httpclient'
21
- gem.add_dependency 'nori'
22
22
  gem.add_dependency 'nokogiri'
23
+ gem.add_dependency 'nori'
24
+ gem.add_dependency 'rest-client'
23
25
  end
data/rakefile.rb CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rspec/core/rake_task'
2
4
  require 'bundler/gem_tasks'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,45 +1,45 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe PricesUrl do
4
-
5
- it "takes a fixed url as constructor argument" do
6
- PricesUrl.new("www.somehost.com")
6
+ it 'takes a fixed url as constructor argument' do
7
+ PricesUrl.new('www.somehost.com')
7
8
  end
8
9
 
9
- it "raises an error when no url is given" do
10
- expect { PricesUrl.new(nil) }.to raise_error(PricesUrl::InvalidURL, "You must give an url, ie http://www.ns.nl/api")
10
+ it 'raises an error when no url is given' do
11
+ expect { PricesUrl.new(nil) }.to raise_error(PricesUrl::InvalidURL, 'You must give an url, ie http://www.ns.nl/api')
11
12
  end
12
13
 
13
- let(:prices_url) { PricesUrl.new("hostname") }
14
+ let(:prices_url) { PricesUrl.new('hostname') }
14
15
 
15
- it "uses given date" do
16
- prices_url.url(date: Date.new(2013, 7, 12)).should == "hostname?date=12072013"
16
+ it 'uses given date' do
17
+ expect(prices_url.url(date: Date.new(2013, 7, 12))).to eq('hostname?date=12072013')
17
18
  end
18
19
 
19
- it "uses from" do
20
- expected_from = "Amsterdam"
21
- prices_url.url(from:"Amsterdam").should == "hostname?from=#{expected_from}"
20
+ it 'uses from' do
21
+ expected_from = 'Amsterdam'
22
+ expect(prices_url.url(from: 'Amsterdam')).to eq("hostname?from=#{expected_from}")
22
23
  end
23
24
 
24
- it "uses to" do
25
- expected_to = "Purmerend"
26
- prices_url.url(to:"Purmerend").should == "hostname?to=#{expected_to}"
25
+ it 'uses to' do
26
+ expected_to = 'Purmerend'
27
+ expect(prices_url.url(to: 'Purmerend')).to eq("hostname?to=#{expected_to}")
27
28
  end
28
29
 
29
- it "uses via" do
30
- expected_via = "Zaandam"
31
- prices_url.url(via:"Zaandam").should == "hostname?via=#{expected_via}"
30
+ it 'uses via' do
31
+ expected_via = 'Zaandam'
32
+ expect(prices_url.url(via: 'Zaandam')).to eq("hostname?via=#{expected_via}")
32
33
  end
33
34
 
34
- it "uses any all variables for from/to/via" do
35
- prices_url.url(from:"Purmerend",to: "Amsterdam", via:"Zaandam").should == "hostname?from=Purmerend&to=Amsterdam&via=Zaandam"
35
+ it 'uses any all variables for from/to/via' do
36
+ expect(prices_url.url(from: 'Purmerend', to: 'Amsterdam', via: 'Zaandam')).to eq('hostname?from=Purmerend&to=Amsterdam&via=Zaandam')
36
37
  end
37
38
 
38
- it "html encodes" do
39
- prices_url.url(from:"Purmerend",to: "Amsterdam Centraal").should == "hostname?from=Purmerend&to=Amsterdam%20Centraal"
39
+ it 'html encodes' do
40
+ expect(prices_url.url(from: 'Purmerend', to: 'Amsterdam Centraal')).to eq('hostname?from=Purmerend&to=Amsterdam%20Centraal')
40
41
  end
41
42
 
42
43
  ANY_DATE = Date.new(2013, 8, 13)
43
- ANY_DATE_STR = "13082013"
44
-
44
+ ANY_DATE_STR = '13082013'
45
45
  end
@@ -1,265 +1,250 @@
1
- #encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
  require 'yaml'
4
5
 
5
6
  describe NSClient do
7
+ let!(:client) { NSClient.new('username', 'password') }
6
8
 
7
- let! (:client) { NSClient.new("username", "password") }
8
-
9
- context "Stations" do
10
-
11
- context "with valid xml" do
12
-
9
+ context 'Stations' do
10
+ context 'with valid xml' do
13
11
  before :each do
14
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-stations-v2", load_fixture('stations.xml')
12
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-stations-v2', load_fixture('stations.xml')
15
13
  end
16
14
 
17
- it "should return all stations" do
15
+ it 'should return all stations' do
18
16
  stations = client.stations
19
- stations.size.should == 620
17
+ expect(stations.size).to eq(620)
20
18
  end
21
19
 
22
- it "should return expected first station from list" do
20
+ it 'should return expected first station from list' do
23
21
  stations = client.stations
24
22
  first_station = stations.first
25
- first_station.class.should == NSClient::Station
26
- first_station.type.should == "knooppuntIntercitystation"
27
- first_station.code.should == "HT"
28
- first_station.short_name.should == "H'bosch"
29
- first_station.name.should == "'s-Hertogenbosch"
30
- first_station.long_name.should == "'s-Hertogenbosch"
31
- first_station.country.should == "NL"
32
- first_station.uiccode.should == "8400319"
33
- first_station.lat.should == "51.69048"
34
- first_station.long.should == "5.29362"
23
+ expect(first_station.class).to eq(NSClient::Station)
24
+ expect(first_station.type).to eq('knooppuntIntercitystation')
25
+ expect(first_station.code).to eq('HT')
26
+ expect(first_station.short_name).to eq("H'bosch")
27
+ expect(first_station.name).to eq("'s-Hertogenbosch")
28
+ expect(first_station.long_name).to eq("'s-Hertogenbosch")
29
+ expect(first_station.country).to eq('NL')
30
+ expect(first_station.uiccode).to eq('8400319')
31
+ expect(first_station.lat).to eq('51.69048')
32
+ expect(first_station.long).to eq('5.29362')
35
33
  end
36
34
 
37
- it "should retrieve a convenient hash with usable station names and codes for prices usage" do
35
+ it 'should retrieve a convenient hash with usable station names and codes for prices usage' do
38
36
  stations = client.stations_short
39
- stations.size.should == 620
40
- stations["HT"].should == ["'s-Hertogenbosch", "NL"]
37
+ expect(stations.size).to eq(620)
38
+ expect(stations['HT']).to eq(["'s-Hertogenbosch", 'NL'])
41
39
  end
42
-
43
-
44
40
  end
45
41
 
46
- describe "integration specs", :integration do
47
-
42
+ describe 'integration specs', :integration do
48
43
  # requires a credentials.yml in spec/fixtures with a username and password
49
- it "should parse live data correctly", focus: true do
50
- found_error = false
44
+ it 'should parse live data correctly', focus: true do
51
45
  WebMock.allow_net_connect!
52
- #while (!found_error) do
53
- credentials = YAML.load_file(File.join($ROOT, "spec/fixtures/credentials.yml"))
54
- client = NSClient.new(credentials["username"], credentials["password"])
55
- stations = client.stations
56
- station = stations.find { |s| s.code == "OETZ" }
57
- expected_count = 613
58
- found_error = !(station.code == "OETZ" && station.country == "A" && station.name == "Ötztal" && stations.count == expected_count)
59
-
60
- if found_error
61
- f = File.open("/tmp/ns_stations_without_oztal.xml", "w")
62
- f.write(client.last_received_raw_xml)
63
- f.close
64
- raise "Could not find staiton with code 'OETZ', see /tmp/ns_stations_without_oztal.xml" if station.blank?
65
- raise "Found station, but with different properties or size differs? Country should be 'A' but is #{station.country}, station name should be 'Ötztal' but is #{station.name}, and the count should be #{expected_count}. (count is #{stations.count}) see /tmp/ns_stations_without_oztal.xml"
66
- else
67
- p "Test went OK, #{stations.count} stations found"
68
- end
69
- #end
46
+ # while (!found_error) do
47
+ credentials = YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures/credentials.yml'))
48
+ client = NSClient.new(credentials['username'], credentials['password'])
49
+ stations = client.stations
50
+ station = stations.find { |s| s.code == 'OETZ' }
51
+ expected_count = 628
52
+ found_error = !(
53
+ station.code == 'OETZ' &&
54
+ station.country == 'A' &&
55
+ station.name == 'Ötztal' &&
56
+ stations.count == expected_count
57
+ )
58
+
59
+ if found_error
60
+ f = File.open('/tmp/ns_stations_without_oztal.xml', 'w')
61
+ f.write(client.last_received_raw_xml)
62
+ f.close
63
+ raise "Could not find staiton with code 'OETZ', see /tmp/ns_stations_without_oztal.xml" if station.blank?
64
+
65
+ raise "Found station, but with different properties or size differs? Country should be 'A' but is #{station.country}, station name should be 'Ötztal' but is #{station.name}, and the count should be #{expected_count}. (count is #{stations.count}) see /tmp/ns_stations_without_oztal.xml"
66
+ else
67
+ p "Test went OK, #{stations.count} stations found"
68
+ end
69
+ # end
70
70
  # remove the loop to constantly check NS if we are doubting their source
71
71
  end
72
-
73
72
  end
74
-
75
73
  end
76
74
 
77
- describe "invalid stations xml" do
78
-
79
- context "with only newlines/spaces we can fix" do
80
-
81
- it "should return all stations" do
82
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-stations-v2", load_fixture('stations_list_with_invalid_new_lines.xml')
75
+ describe 'invalid stations xml' do
76
+ context 'with only newlines/spaces we can fix' do
77
+ it 'should return all stations' do
78
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-stations-v2', load_fixture('stations_list_with_invalid_new_lines.xml')
83
79
  stations = client.stations
84
- stations.size.should == 2
80
+ expect(stations.size).to eq(2)
85
81
  end
86
82
 
87
83
  {
88
- "< Code>" => "<Code>",
89
- "< Code >" => "<Code>",
90
- "< Code >" => "<Code>",
91
- "< Code>" => "<Code>",
92
- "</ Code>" => "</Code>",
93
- "< / Code>" => "</Code>",
94
- "</ Code >" => "</Code>",
95
- "</ Code >" => "</Code>",
96
- "</\n\nCode >" => "</Code>",
97
- "</\r\tCode\n>" => "</Code>",
98
- "</Co\nde\n>" => "</Code>",
84
+ '< Code>' => '<Code>',
85
+ '< Code >' => '<Code>',
86
+ '< Code >' => '<Code>',
87
+ '< Code>' => '<Code>',
88
+ '</ Code>' => '</Code>',
89
+ '< / Code>' => '</Code>',
90
+ '</ Code >' => '</Code>',
91
+ '</ Code >' => '</Code>',
92
+ "</\n\nCode >" => '</Code>',
93
+ "</\r\tCode\n>" => '</Code>',
94
+ "</Co\nde\n>" => '</Code>'
99
95
  }.each do |k, v|
100
96
  it "removes unwanted whitespace from #{k} , expecting #{v} (remove_unwanted_whitespace)" do
101
- client.remove_unwanted_whitespace(k).should eq v
97
+ expect(client.remove_unwanted_whitespace(k)).to eq v
102
98
  end
103
99
  end
104
-
105
100
  end
106
101
 
107
102
  context "with mangled XML we cannot / won't fix" do
108
-
109
- it "raises an error when xml is unparseable" do
110
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-stations-v2", load_fixture('stations_list_mangled.xml')
103
+ it 'raises an error when xml is unparseable' do
104
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-stations-v2', load_fixture('stations_list_mangled.xml')
111
105
  expect { client.stations }.to raise_error(NSClient::UnparseableXMLError)
112
106
  end
113
-
114
107
  end
115
-
116
108
  end
117
109
 
118
- context "Disruptions" do
119
-
120
- it "should retrieve planned and unplanned disruptions" do
121
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?actual=true", load_fixture('disruptions.xml')
110
+ context 'Disruptions' do
111
+ it 'should retrieve planned and unplanned disruptions' do
112
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-storingen?actual=true', load_fixture('disruptions.xml')
122
113
  disruptions = client.disruptions
123
- disruptions.size.should == 2
124
- disruptions[:planned].size.should == 1
125
- disruptions[:unplanned].size.should == 1
114
+ expect(disruptions.size).to eq(2)
115
+ expect(disruptions[:planned].size).to eq(1)
116
+ expect(disruptions[:unplanned].size).to eq(1)
126
117
  end
127
118
 
128
- it "should retrieve expected planned disruption" do
129
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?actual=true", load_fixture('disruptions.xml')
119
+ it 'should retrieve expected planned disruption' do
120
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-storingen?actual=true', load_fixture('disruptions.xml')
130
121
  disruptions = client.disruptions
131
- disruptions.size.should == 2
122
+ expect(disruptions.size).to eq(2)
132
123
  planned_disruption = disruptions[:planned].first
133
- planned_disruption.class.should == NSClient::PlannedDisruption
124
+ expect(planned_disruption.class).to eq(NSClient::PlannedDisruption)
134
125
 
135
- planned_disruption.id.should == "2010_almo_wp_18_19dec"
136
- planned_disruption.trip.should == "Almere Oostvaarders-Weesp/Naarden-Bussum"
137
- planned_disruption.reason.should == "Beperkt treinverkeer, businzet en/of omreizen, extra reistijd 15-30 min."
138
- planned_disruption.advice.should == "Maak gebruik van de overige treinen of de bussen: reis tussen Weesp en Almere Centrum met de NS-bus in
126
+ expect(planned_disruption.id).to eq('2010_almo_wp_18_19dec')
127
+ expect(planned_disruption.trip).to eq('Almere Oostvaarders-Weesp/Naarden-Bussum')
128
+ expect(planned_disruption.reason).to eq('Beperkt treinverkeer, businzet en/of omreizen, extra reistijd 15-30 min.')
129
+ expect(planned_disruption.advice).to eq("Maak gebruik van de overige treinen of de bussen: reis tussen Weesp en Almere Centrum met de NS-bus in
139
130
  plaats van de trein tussen Almere Centrum en Lelystad Centrum rijden vier Sprinters per uur reis tussen Almere
140
- Muziekwijk en Naarden-Bussum via Weesp"
141
- planned_disruption.message.should == "Test message"
142
- planned_disruption.cause.should == "oorzaak"
131
+ Muziekwijk en Naarden-Bussum via Weesp")
132
+ expect(planned_disruption.message).to eq('Test message')
133
+ expect(planned_disruption.cause).to eq('oorzaak')
143
134
  end
144
135
 
145
- it "should retrieve expected unplanned disruption" do
146
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?actual=true", load_fixture('disruptions.xml')
136
+ it 'should retrieve expected unplanned disruption' do
137
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-storingen?actual=true', load_fixture('disruptions.xml')
147
138
  disruptions = client.disruptions
148
- disruptions.size.should == 2
139
+ expect(disruptions.size).to eq(2)
149
140
  unplanned_disruption = disruptions[:unplanned].first
150
- unplanned_disruption.class.should == NSClient::UnplannedDisruption
141
+ expect(unplanned_disruption.class).to eq(NSClient::UnplannedDisruption)
151
142
 
152
- unplanned_disruption.id.should == "prio-13345"
153
- unplanned_disruption.trip.should == "'s-Hertogenbosch-Nijmegen"
154
- unplanned_disruption.reason.should == "beperkingen op last van de politie"
155
- unplanned_disruption.cause.should == "oorzaak"
156
- unplanned_disruption.message.should == "Another test message"
157
- unplanned_disruption.datetime_string == "2010-12-16T11:16:00+0100" #intentional, give raw data. Let user parse if needed.
143
+ expect(unplanned_disruption.id).to eq('prio-13345')
144
+ expect(unplanned_disruption.trip).to eq("'s-Hertogenbosch-Nijmegen")
145
+ expect(unplanned_disruption.reason).to eq('beperkingen op last van de politie')
146
+ expect(unplanned_disruption.cause).to eq('oorzaak')
147
+ expect(unplanned_disruption.message).to eq('Another test message')
148
+ unplanned_disruption.datetime_string == '2010-12-16T11:16:00+0100' # intentional, give raw data. Let user parse if needed.
158
149
  end
159
150
 
160
- it "should not return disruption when empty in response" do
161
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?actual=true", load_fixture('no_disruptions.xml')
151
+ it 'should not return disruption when empty in response' do
152
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-storingen?actual=true', load_fixture('no_disruptions.xml')
162
153
  disruptions = client.disruptions
163
- disruptions.size.should == 2
164
- disruptions[:planned].size.should == 0
165
- disruptions[:unplanned].size.should == 0
166
- end
167
-
168
- describe "for a specific station" do
169
-
170
- it "should retrieve disruptions for station name" do
171
- # ie, for Amsterdam only (http://webservices.ns.nl/ns-api-storingen?station=Amsterdam)
172
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?station=Amsterdam", load_fixture('disruptions_amsterdam.xml')
173
- disruptions = client.disruptions "Amsterdam"
174
- disruptions.size.should == 2
175
- disruptions[:planned].size.should == 4
176
- disruptions[:unplanned].size.should == 0
154
+ expect(disruptions.size).to eq(2)
155
+ expect(disruptions[:planned].size).to eq(0)
156
+ expect(disruptions[:unplanned].size).to eq(0)
157
+ end
158
+
159
+ describe 'for a specific station' do
160
+ it 'should retrieve disruptions for station name' do
161
+ # ie, for Amsterdam only (https://webservices.ns.nl/ns-api-storingen?station=Amsterdam)
162
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-storingen?station=Amsterdam', load_fixture('disruptions_amsterdam.xml')
163
+ disruptions = client.disruptions 'Amsterdam'
164
+ expect(disruptions.size).to eq(2)
165
+ expect(disruptions[:planned].size).to eq(4)
166
+ expect(disruptions[:unplanned].size).to eq(0)
177
167
  end
178
168
 
179
- it "should raise an error when using invalid station name" do
180
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?station=bla", load_fixture('disruption_invalid_station_name.xml')
181
- expect { client.disruptions "bla" }.to raise_error(NSClient::InvalidStationNameError, "Could not find a station with name 'bla'")
169
+ it 'should raise an error when using invalid station name' do
170
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-storingen?station=bla', load_fixture('disruption_invalid_station_name.xml')
171
+ expect { client.disruptions 'bla' }.to raise_error(NSClient::InvalidStationNameError, "Could not find a station with name 'bla'")
182
172
  end
183
173
  end
184
-
185
-
186
174
  end
187
175
 
188
- context "Prices" do
189
-
190
- it "should retrieve prices for a trip" do
191
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-prijzen-v3?from=Rotterdam&to=Glanerbrug&date=17062013", load_fixture('prices.xml')
176
+ context 'Prices' do
177
+ it 'should retrieve prices for a trip' do
178
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-prijzen-v3?from=Rotterdam&to=Glanerbrug&date=17062013', load_fixture('prices.xml')
192
179
  date = Date.strptime('17-06-2013', '%d-%m-%Y')
193
- response = client.prices from: "Rotterdam", to: "Glanerbrug", date: date
194
- response.class.should == NSClient::PricesResponse
195
- response.tariff_units.should == 205
196
- response.products.size.should == 2
180
+ response = client.prices from: 'Rotterdam', to: 'Glanerbrug', date: date
181
+ expect(response.class).to eq(NSClient::PricesResponse)
182
+ expect(response.tariff_units).to eq(205)
183
+ expect(response.products.size).to eq(2)
197
184
 
198
- response.enkele_reis.size.should == 6
199
- response.dagretour.size.should == 6
185
+ expect(response.enkele_reis.size).to eq(6)
186
+ expect(response.dagretour.size).to eq(6)
200
187
  end
201
188
 
202
- it "should retrieve expected price data" do
203
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-prijzen-v3?from=Rotterdam&to=Glanerbrug&date=17062013", load_fixture('prices.xml')
189
+ it 'should retrieve expected price data' do
190
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-prijzen-v3?from=Rotterdam&to=Glanerbrug&date=17062013', load_fixture('prices.xml')
204
191
  date = Date.strptime('17-06-2013', '%d-%m-%Y')
205
- response = client.prices from: "Rotterdam", to: "Glanerbrug", date: date
206
- response.class.should == NSClient::PricesResponse
207
- response.tariff_units.should == 205
208
- response.products.size.should == 2
192
+ response = client.prices from: 'Rotterdam', to: 'Glanerbrug', date: date
193
+ expect(response.class).to eq(NSClient::PricesResponse)
194
+ expect(response.tariff_units).to eq(205)
195
+ expect(response.products.size).to eq(2)
209
196
 
210
- assert_price(response.enkele_reis[0], "vol tarief", "1", 41.5)
211
- assert_price(response.enkele_reis[1], "reductie_20", "1", 33.2)
212
- assert_price(response.enkele_reis[2], "reductie_40", "1", 24.9)
213
- assert_price(response.enkele_reis[3], "vol tarief", "2", 24.4)
214
- assert_price(response.enkele_reis[4], "reductie_20", "2", 19.5)
215
- assert_price(response.enkele_reis[5], "reductie_40", "2", 14.6)
197
+ assert_price(response.enkele_reis[0], 'vol tarief', '1', 41.5)
198
+ assert_price(response.enkele_reis[1], 'reductie_20', '1', 33.2)
199
+ assert_price(response.enkele_reis[2], 'reductie_40', '1', 24.9)
200
+ assert_price(response.enkele_reis[3], 'vol tarief', '2', 24.4)
201
+ assert_price(response.enkele_reis[4], 'reductie_20', '2', 19.5)
202
+ assert_price(response.enkele_reis[5], 'reductie_40', '2', 14.6)
216
203
  end
217
204
 
218
- it "should raise error when from is not given" do
219
- expect {
220
- client.prices from: nil, to: "Amsterdam"
221
- }.to raise_error(NSClient::MissingParameter, "from station is required")
205
+ it 'should raise error when from is not given' do
206
+ expect do
207
+ client.prices from: nil, to: 'Amsterdam'
208
+ end.to raise_error(NSClient::MissingParameter, 'from station is required')
222
209
  end
223
210
 
224
- it "should raise an error when from is not a valid station name" do
211
+ it 'should raise an error when from is not a valid station name' do
225
212
  date = Date.strptime('17-06-2013', '%d-%m-%Y')
226
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-prijzen-v3?from=Amsterdam&to=Purmerend&date=17062013", load_fixture('prices_invalid_station_name.xml')
227
- expect {
228
- client.prices from: "Amsterdam", to: "Purmerend", date: date
229
- }.to raise_error(NSClient::InvalidStationNameError, "'Amsterdam' is not a valid station name")
213
+ stub_ns_client_request 'https://webservices.ns.nl/ns-api-prijzen-v3?from=Amsterdam&to=Purmerend&date=17062013', load_fixture('prices_invalid_station_name.xml')
214
+ expect do
215
+ client.prices from: 'Amsterdam', to: 'Purmerend', date: date
216
+ end.to raise_error(NSClient::InvalidStationNameError, "'Amsterdam' is not a valid station name")
230
217
  end
231
218
 
232
- it "should raise error when to is not given" do
233
- expect {
234
- client.prices from: "Purmerend", to: nil
235
- }.to raise_error(NSClient::MissingParameter, "to station is required")
219
+ it 'should raise error when to is not given' do
220
+ expect do
221
+ client.prices from: 'Purmerend', to: nil
222
+ end.to raise_error(NSClient::MissingParameter, 'to station is required')
236
223
  end
237
224
 
238
- it "should raise error complaining about from and to missing when both not given" do
239
- expect {
225
+ it 'should raise error complaining about from and to missing when both not given' do
226
+ expect do
240
227
  client.prices from: nil, to: nil
241
- }.to raise_error(NSClient::MissingParameter, "from and to station is required")
228
+ end.to raise_error(NSClient::MissingParameter, 'from and to station is required')
242
229
  end
243
230
 
244
- it "should raise an error when from and to are the same" do
245
- expect {
231
+ it 'should raise an error when from and to are the same' do
232
+ expect do
246
233
  client.prices from: 'AMA', to: 'AMA'
247
- }.to raise_error(NSClient::SameDestinationError, "from (AMA) and to (AMA) parameters should not be equal")
234
+ end.to raise_error(NSClient::SameDestinationError, 'from (AMA) and to (AMA) parameters should not be equal')
248
235
  end
249
-
250
236
  end
251
237
 
252
238
  def assert_price(element, expected_type, expected_train_class, expected_amount)
253
- element.type.should == expected_type
254
- element.train_class.should == expected_train_class
255
- element.amount.should == expected_amount
239
+ expect(element.type).to eq(expected_type)
240
+ expect(element.train_class).to eq(expected_train_class)
241
+ expect(element.amount).to eq(expected_amount)
256
242
  end
257
243
 
258
244
  def stub_ns_client_request(url, response)
259
245
  # headers based on "username", "password"
260
- stub_request(:get, url).
261
- with(:headers => {'Authorization' => 'Basic dXNlcm5hbWU6cGFzc3dvcmQ='}).
262
- to_return(:status => 200, :body => response, :headers => {})
246
+ stub_request(:get, url)
247
+ .with(headers: { 'Authorization' => 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=' })
248
+ .to_return(status: 200, body: response, headers: {})
263
249
  end
264
-
265
250
  end