ns-yapi 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,52 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Stations>
3
+
4
+ <Station>
5
+ <Co
6
+ de>LC</Code>
7
+ <Typ
8
+ e>stoptreinstation</Type>
9
+ <Nam
10
+ en>
11
+ <Kort>L
12
+ ochem</Kort>
13
+ <
14
+ Middel>Lochem<
15
+ /Middel>
16
+ <Lang>Lochem</Lang>
17
+ </Nam
18
+ en>
19
+ <Land>NL</Land>
20
+ <UICCode>8400399< / UICCode >
21
+ <Lat>52.166668</Lat>
22
+ <Lon>6.4263887</Lon>
23
+ <Syno
24
+ niemen>
25
+
26
+ </Syno
27
+ niemen>
28
+ </Station>
29
+
30
+ <Station>
31
+ <C
32
+ ode>HT</Code>
33
+ <Type>intercitystation</Type>
34
+ <Nam
35
+ en>
36
+ <Kort>Den Bosch</Kort>
37
+ <Middel>'s-Hertogenbosch</Middel>
38
+ <Lang>'s-Hertogenbosch</Lang>
39
+ </N
40
+ amen>
41
+ <Land>NL</Land>
42
+ <UICC
43
+ ode>12</UICCode>
44
+ <Lat>52.166668</Lat>
45
+ <Lon>6.4263887</Lon>
46
+ <Synoniemen>
47
+
48
+ </Synoniemen>
49
+ </Station>
50
+
51
+
52
+ </Stations>
@@ -1,40 +1,41 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <Stations>
3
3
 
4
- <Station>
5
- <Code>LC</Code>
6
- <Type>stoptreinstation</Type>
7
- <Namen>
8
- <Kort>Lochem</Kort>
9
- <
10
- Middel>Lochem</Middel>
11
- <Lang>Lochem</Lang>
12
- </Namen>
13
- <Land>NL</Land>
14
- <UICCode>8400399</UICCode>
15
- <Lat>52.166668</Lat>
16
- <Lon>6.4263887</Lon>
17
- <Synoniemen>
18
-
19
- </Synoniemen>
20
- </Station>
4
+ <Station>
5
+ <Code>LC</Code>
6
+ <Type>stoptreinstation</Type>
7
+ <Namen>
8
+ <Kort>Lochem</Kort>
9
+ <
10
+ Middel>Lochem<
11
+ /Middel>
12
+ <Lang>Lochem</Lang>
13
+ </Namen>
14
+ <Land>NL</Land>
15
+ <UICCode>8400399< / UICCode >
16
+ <Lat>52.166668</Lat>
17
+ <Lon>6.4263887</Lon>
18
+ <Synoniemen>
21
19
 
22
- <Station>
23
- <Code>HT</Code>
24
- <Type>intercitystation</Type>
25
- <Namen>
26
- <Kort>Den Bosch</Kort>
27
- <Middel>'s-Hertogenbosch</Middel>
28
- <Lang>'s-Hertogenbosch</Lang>
29
- </Namen>
30
- <Land>NL</Land>
31
- <UICCode>12</UICCode>
32
- <Lat>52.166668</Lat>
33
- <Lon>6.4263887</Lon>
34
- <Synoniemen>
20
+ </Synoniemen>
21
+ </Station>
35
22
 
36
- </Synoniemen>
37
- </Station>
23
+ <Station>
24
+ <Code>HT</Code>
25
+ <Type>intercitystation</Type>
26
+ <Namen>
27
+ <Kort>Den Bosch</Kort>
28
+ <Middel>'s-Hertogenbosch</Middel>
29
+ <Lang>'s-Hertogenbosch</Lang>
30
+ </Namen>
31
+ <Land>NL</Land>
32
+ <UICCode>12</UICCode>
33
+ <Lat>52.166668</Lat>
34
+ <Lon>6.4263887</Lon>
35
+ <Synoniemen>
38
36
 
37
+ </Synoniemen>
38
+ </Station>
39
39
 
40
- </Stations>
40
+
41
+ </Stations>
@@ -1,11 +1,10 @@
1
1
  #encoding: utf-8
2
2
  require 'spec_helper'
3
+ require 'yaml'
3
4
 
4
5
  describe NSClient do
5
6
 
6
- before :each do
7
- @client = NSClient.new("username", "password")
8
- end
7
+ let! (:client) { NSClient.new("username", "password") }
9
8
 
10
9
  context "Stations" do
11
10
 
@@ -16,12 +15,12 @@ describe NSClient do
16
15
  end
17
16
 
18
17
  it "should return all stations" do
19
- stations = @client.stations
18
+ stations = client.stations
20
19
  stations.size.should == 620
21
20
  end
22
21
 
23
22
  it "should return expected first station from list" do
24
- stations = @client.stations
23
+ stations = client.stations
25
24
  first_station = stations.first
26
25
  first_station.class.should == NSClient::Station
27
26
  first_station.type.should == "knooppuntIntercitystation"
@@ -36,24 +35,81 @@ describe NSClient do
36
35
  end
37
36
 
38
37
  it "should retrieve a convenient hash with usable station names and codes for prices usage" do
39
- stations = @client.stations_short
38
+ stations = client.stations_short
40
39
  stations.size.should == 620
41
40
  stations["HT"].should == ["'s-Hertogenbosch", "NL"]
42
41
  end
43
42
 
44
- end
45
43
 
46
- describe "invalid stations xml" do
44
+ end
47
45
 
48
- before :each do
49
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-stations-v2", load_fixture('stations_list_with_invalid_new_lines.xml')
46
+ describe "integration specs", :integration do
47
+
48
+ # 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
51
+ 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
70
+ # remove the loop to constantly check NS if we are doubting their source
50
71
  end
51
72
 
73
+ end
74
+
75
+ end
76
+
77
+ describe "invalid stations xml" do
78
+
79
+ context "with only newlines/spaces we can fix" do
80
+
52
81
  it "should return all stations" do
53
- stations = @client.stations
82
+ stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-stations-v2", load_fixture('stations_list_with_invalid_new_lines.xml')
83
+ stations = client.stations
54
84
  stations.size.should == 2
55
85
  end
56
86
 
87
+ {
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
+ }.each do |k, v|
99
+ it "removes unwanted whitespace from #{k} , expecting #{v} (remove_unwanted_whitespace)" do
100
+ client.remove_unwanted_whitespace(k).should eq v
101
+ end
102
+ end
103
+
104
+ end
105
+
106
+ context "with mangled XML we cannot / won't fix" do
107
+
108
+ it "raises an error when xml is unparseable" do
109
+ stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-stations-v2", load_fixture('stations_list_mangled.xml')
110
+ expect { client.stations }.to raise_error(NSClient::UnparseableXMLError)
111
+ end
112
+
57
113
  end
58
114
 
59
115
  end
@@ -62,7 +118,7 @@ describe NSClient do
62
118
 
63
119
  it "should retrieve planned and unplanned disruptions" do
64
120
  stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?actual=true", load_fixture('disruptions.xml')
65
- disruptions = @client.disruptions
121
+ disruptions = client.disruptions
66
122
  disruptions.size.should == 2
67
123
  disruptions[:planned].size.should == 1
68
124
  disruptions[:unplanned].size.should == 1
@@ -70,7 +126,7 @@ describe NSClient do
70
126
 
71
127
  it "should retrieve expected planned disruption" do
72
128
  stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?actual=true", load_fixture('disruptions.xml')
73
- disruptions = @client.disruptions
129
+ disruptions = client.disruptions
74
130
  disruptions.size.should == 2
75
131
  planned_disruption = disruptions[:planned].first
76
132
  planned_disruption.class.should == NSClient::PlannedDisruption
@@ -87,7 +143,7 @@ describe NSClient do
87
143
 
88
144
  it "should retrieve expected unplanned disruption" do
89
145
  stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?actual=true", load_fixture('disruptions.xml')
90
- disruptions = @client.disruptions
146
+ disruptions = client.disruptions
91
147
  disruptions.size.should == 2
92
148
  unplanned_disruption = disruptions[:unplanned].first
93
149
  unplanned_disruption.class.should == NSClient::UnplannedDisruption
@@ -102,7 +158,7 @@ describe NSClient do
102
158
 
103
159
  it "should not return disruption when empty in response" do
104
160
  stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?actual=true", load_fixture('no_disruptions.xml')
105
- disruptions = @client.disruptions
161
+ disruptions = client.disruptions
106
162
  disruptions.size.should == 2
107
163
  disruptions[:planned].size.should == 0
108
164
  disruptions[:unplanned].size.should == 0
@@ -113,7 +169,7 @@ describe NSClient do
113
169
  it "should retrieve disruptions for station name" do
114
170
  # ie, for Amsterdam only (http://webservices.ns.nl/ns-api-storingen?station=Amsterdam)
115
171
  stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?station=Amsterdam", load_fixture('disruptions_amsterdam.xml')
116
- disruptions = @client.disruptions "Amsterdam"
172
+ disruptions = client.disruptions "Amsterdam"
117
173
  disruptions.size.should == 2
118
174
  disruptions[:planned].size.should == 4
119
175
  disruptions[:unplanned].size.should == 0
@@ -121,7 +177,7 @@ describe NSClient do
121
177
 
122
178
  it "should raise an error when using invalid station name" do
123
179
  stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-storingen?station=bla", load_fixture('disruption_invalid_station_name.xml')
124
- expect { @client.disruptions "bla" }.to raise_error(NSClient::InvalidStationNameError, "Could not find a station with name 'bla'")
180
+ expect { client.disruptions "bla" }.to raise_error(NSClient::InvalidStationNameError, "Could not find a station with name 'bla'")
125
181
  end
126
182
  end
127
183
 
@@ -133,7 +189,7 @@ describe NSClient do
133
189
  it "should retrieve prices for a trip" do
134
190
  stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-prijzen-v2?from=Purmerend&to=Amsterdam&via=Zaandam&date=17062013", load_fixture('prices.xml')
135
191
  date = Date.strptime('17-06-2013', '%d-%m-%Y')
136
- response = @client.prices from: "Purmerend", to: "Amsterdam", via: "Zaandam", date: date
192
+ response = client.prices from: "Purmerend", to: "Amsterdam", via: "Zaandam", date: date
137
193
  response.class.should == NSClient::PricesResponse
138
194
  response.tariff_units.should == 10
139
195
  response.products.size.should == 2
@@ -145,7 +201,7 @@ describe NSClient do
145
201
  it "should retrieve expected price data" do
146
202
  stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-prijzen-v2?from=Purmerend&to=Amsterdam&via=Zaandam&date=17062013", load_fixture('prices.xml')
147
203
  date = Date.strptime('17-06-2013', '%d-%m-%Y')
148
- response = @client.prices from: "Purmerend", to: "Amsterdam", via: "Zaandam", date: date
204
+ response = client.prices from: "Purmerend", to: "Amsterdam", via: "Zaandam", date: date
149
205
  response.class.should == NSClient::PricesResponse
150
206
  response.tariff_units.should == 10
151
207
  response.products.size.should == 2
@@ -160,7 +216,7 @@ describe NSClient do
160
216
 
161
217
  it "should raise error when from is not given" do
162
218
  expect {
163
- @client.prices from: nil, to: "Amsterdam"
219
+ client.prices from: nil, to: "Amsterdam"
164
220
  }.to raise_error(NSClient::MissingParameter, "from station is required")
165
221
  end
166
222
 
@@ -168,19 +224,19 @@ describe NSClient do
168
224
  date = Date.strptime('17-06-2013', '%d-%m-%Y')
169
225
  stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-prijzen-v2?from=Amsterdam&to=Purmerend&date=17062013", load_fixture('prices_invalid_station_name.xml')
170
226
  expect {
171
- @client.prices from: "Amsterdam", to: "Purmerend", date: date
227
+ client.prices from: "Amsterdam", to: "Purmerend", date: date
172
228
  }.to raise_error(NSClient::InvalidStationNameError, "'Amsterdam' is not a valid station name")
173
229
  end
174
230
 
175
231
  it "should raise error when to is not given" do
176
232
  expect {
177
- @client.prices from: "Purmerend", to: nil
233
+ client.prices from: "Purmerend", to: nil
178
234
  }.to raise_error(NSClient::MissingParameter, "to station is required")
179
235
  end
180
236
 
181
237
  it "should raise error complaining about from and to missing when both not given" do
182
238
  expect {
183
- @client.prices from: nil, to: nil
239
+ client.prices from: nil, to: nil
184
240
  }.to raise_error(NSClient::MissingParameter, "from and to station is required")
185
241
  end
186
242
 
data/spec/spec_helper.rb CHANGED
@@ -25,6 +25,17 @@ RSpec.configure do |config|
25
25
  Timecop.return # make sure timecop is disabled after each test
26
26
  end
27
27
 
28
+ config.treat_symbols_as_metadata_keys_with_true_values = true
29
+ config.filter_run :focus => true
30
+ config.run_all_when_everything_filtered = true
31
+
32
+ unless config.inclusion_filter[:integration]
33
+ p "Integration specs are DISABLED. To run integration specs only, use `rspec --tag integration`"
34
+ config.filter_run_excluding :integration => true
35
+ else
36
+ p "Running integrtion specs ONLY."
37
+ end
38
+
28
39
  end
29
40
 
30
41
  # END
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ns-yapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-05 00:00:00.000000000 Z
12
+ date: 2013-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httpclient
@@ -67,7 +67,8 @@ extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
69
  - .gitignore
70
- - .rvmrc
70
+ - .ruby-gemset
71
+ - .ruby-version
71
72
  - .travis.yml
72
73
  - Gemfile
73
74
  - Gemfile.lock
@@ -80,10 +81,13 @@ files:
80
81
  - spec/fixtures/disruption_invalid_station_name.xml
81
82
  - spec/fixtures/disruptions.xml
82
83
  - spec/fixtures/disruptions_amsterdam.xml
84
+ - spec/fixtures/invalid_stations_xml.xml
83
85
  - spec/fixtures/no_disruptions.xml
84
86
  - spec/fixtures/prices.xml
85
87
  - spec/fixtures/prices_invalid_station_name.xml
86
88
  - spec/fixtures/stations.xml
89
+ - spec/fixtures/stations_cannot_find_pmw.xml
90
+ - spec/fixtures/stations_list_mangled.xml
87
91
  - spec/fixtures/stations_list_with_invalid_new_lines.xml
88
92
  - spec/model/prices_url_spec.rb
89
93
  - spec/ns_client_spec.rb
@@ -103,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
107
  version: '0'
104
108
  segments:
105
109
  - 0
106
- hash: -1576565984611129262
110
+ hash: -3456481437934328000
107
111
  required_rubygems_version: !ruby/object:Gem::Requirement
108
112
  none: false
109
113
  requirements:
@@ -112,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
116
  version: '0'
113
117
  segments:
114
118
  - 0
115
- hash: -1576565984611129262
119
+ hash: -3456481437934328000
116
120
  requirements: []
117
121
  rubyforge_project:
118
122
  rubygems_version: 1.8.24
@@ -123,10 +127,13 @@ test_files:
123
127
  - spec/fixtures/disruption_invalid_station_name.xml
124
128
  - spec/fixtures/disruptions.xml
125
129
  - spec/fixtures/disruptions_amsterdam.xml
130
+ - spec/fixtures/invalid_stations_xml.xml
126
131
  - spec/fixtures/no_disruptions.xml
127
132
  - spec/fixtures/prices.xml
128
133
  - spec/fixtures/prices_invalid_station_name.xml
129
134
  - spec/fixtures/stations.xml
135
+ - spec/fixtures/stations_cannot_find_pmw.xml
136
+ - spec/fixtures/stations_list_mangled.xml
130
137
  - spec/fixtures/stations_list_with_invalid_new_lines.xml
131
138
  - spec/model/prices_url_spec.rb
132
139
  - spec/ns_client_spec.rb
data/.rvmrc DELETED
@@ -1,5 +0,0 @@
1
- if [[ -s "~/.rvm/environments/ruby-1.9.3-p194@ns-api" ]] ; then
2
- . "~/.rvm/environments/ruby-1.9.3-p194@ns-api"
3
- else
4
- rvm --create use "ruby-1.9.3-p194@ns-api"
5
- fi