dcmetro 0.0.3 → 0.1.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/.rspec +3 -0
- data/.simplecov +7 -0
- data/.travis.yml +1 -1
- data/README.md +30 -22
- data/Rakefile +19 -0
- data/bin/dcmetro +2 -2
- data/dcmetro.gemspec +4 -0
- data/features/alerts.feature +1 -1
- data/features/external.feature +7 -4
- data/features/lines.feature +14 -8
- data/features/station.feature +23 -6
- data/features/step_definitions/api_test_steps.rb +6 -6
- data/features/support/env.rb +16 -1
- data/lib/dcmetro/runner.rb +49 -0
- data/lib/dcmetro/version.rb +2 -2
- data/spec/information_spec.rb +111 -0
- data/spec/spec_helper.rb +146 -0
- data/spec/support/aruba.rb +1 -0
- data/spec/test_spec.rb +73 -0
- data/spec/use_aruba_with_rspec_spec.rb +10 -0
- metadata +58 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e79d901808e4b1c5951798e27677145aeca98436
|
4
|
+
data.tar.gz: 61fde7e7ae864372afd4fc826a4a11ecff696136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51048b6ce5da1ec877d45842a2dffd152a013b0bcc56c58af45e47c8479d3c4c3adcf1147ac4860b331960dcfa295281eca48db8be0b19ccd030f9c698b6bbbc
|
7
|
+
data.tar.gz: 0516b095f58722808556b9779c27a0801fc6355796bed3bb2b72b85199e966dd6f1fc6d68c8d8c762c389cfec4fc7914ee4dcb8e192b900a724d69b71b0dddec
|
data/.rspec
ADDED
data/.simplecov
ADDED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -40,21 +40,23 @@ With the gem installed, instantiate a new class in your controller:
|
|
40
40
|
```ruby
|
41
41
|
class WelcomeController < ApplicationController
|
42
42
|
|
43
|
-
|
44
43
|
def index
|
45
44
|
x = DCMetro::Information.new
|
46
|
-
@alerts = x.alerts
|
47
|
-
@lines = x.line
|
48
|
-
@stations = x.line "green"
|
49
|
-
@college_park = x.station "college"
|
50
|
-
@
|
51
|
-
|
52
|
-
|
45
|
+
@alerts = JSON.parse x.alerts
|
46
|
+
@lines = JSON.parse x.line
|
47
|
+
@stations = JSON.parse x.line "green"
|
48
|
+
@college_park = JSON.parse x.station "college"
|
49
|
+
@gallery_place = JSON.parse x.station "gallery"
|
50
|
+
#
|
51
|
+
# New in 0.0.3 - kind of a work in prorgress
|
52
|
+
@fare_info = JSON.parse x.station "college", "gallery"
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
56
56
|
```
|
57
57
|
|
58
|
+
For more info, see this [sample rails app](https://fathomless-reef-6180.herokuapp.com/), and [the repo](https://github.com/kencrocken/dcmetro_example) for the sample app.
|
59
|
+
|
58
60
|
###CLI
|
59
61
|
|
60
62
|
```
|
@@ -65,28 +67,34 @@ Commands:
|
|
65
67
|
dcmetro line COLOR # Display metro rail lines, if COLOR, displays rail stations on the COLOR line
|
66
68
|
dcmetro station STARTING,DEST # Display metro station train arrival and departure times and travel info.
|
67
69
|
```
|
68
|
-
|
70
|
+
|
69
71
|
### CHANGELOG
|
70
|
-
##### Changes in 0.0.2
|
71
72
|
|
72
|
-
1. Updates the api calls to the new format
|
73
|
-
2. Fixes a bug if multiple stations are returned
|
74
|
-
3. Requires the use of an env variable for the API key
|
75
|
-
4. Requires rest-client
|
76
73
|
##### Changes in 0.0.3
|
77
|
-
|
78
74
|
1. Adds station to station travel information
|
79
75
|
2. Expanded test coverage
|
80
76
|
3. Refactors code so that the Information Class merely returns information
|
81
|
-
Any parsing is now done in the CLI application
|
77
|
+
Any parsing is now done in the CLI application
|
82
78
|
|
83
|
-
|
84
|
-
|
79
|
+
##### Changes in 0.0.2
|
80
|
+
|
81
|
+
1. Updates the api calls to the new format
|
82
|
+
2. Fixes a bug if multiple stations are returned
|
83
|
+
3. Requires the use of an env variable for the API key
|
84
|
+
4. Requires rest-client
|
85
85
|
|
86
86
|
## Contributing
|
87
87
|
|
88
|
-
1. Fork it
|
89
|
-
2. Create your feature branch
|
90
|
-
3. Commit your changes
|
91
|
-
4. Push to the branch
|
88
|
+
1. Fork it - [https://github.com/kencrocken/dcmetro/fork](https://github.com/kencrocken/dcmetro/fork)
|
89
|
+
2. Create your feature branch `git checkout -b my-new-feature`
|
90
|
+
3. Commit your changes `git commit -am 'Add some feature'`
|
91
|
+
4. Push to the branch `git push origin my-new-feature`
|
92
92
|
5. Create a new Pull Request
|
93
|
+
|
94
|
+
|
95
|
+
###Development
|
96
|
+
|
97
|
+
`$ cd ~/path/to/dcmetro`
|
98
|
+
`bundle install` to get dependencies.
|
99
|
+
`bundle exec bin/dcmetro`
|
100
|
+
`cucumber features` to run tests.
|
data/Rakefile
CHANGED
@@ -2,9 +2,28 @@ require 'bundler'
|
|
2
2
|
require 'bundler/gem_tasks'
|
3
3
|
require 'cucumber'
|
4
4
|
require 'cucumber/rake/task'
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
require 'coveralls/rake/task'
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
Cucumber::Rake::Task.new
|
9
|
+
Coveralls::RakeTask.new
|
5
10
|
|
6
11
|
Cucumber::Rake::Task.new(:features) do |t|
|
7
12
|
t.cucumber_opts = "DCMETRO_KEY=#{ENV['DCMETRO_KEY']} features --format pretty"
|
8
13
|
end
|
9
14
|
|
15
|
+
desc "run rspec"
|
16
|
+
task :rspec do
|
17
|
+
puts "=== Running Rspec ==="
|
18
|
+
puts "DCMETRO_KEY=#{ENV['DCMETRO_KEY']} rspec"
|
19
|
+
system "DCMETRO_KEY=n2z9aq3redes6k7jekjfzk8q rspec"
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
task :tests => [:spec, :features, 'coveralls:push']
|
26
|
+
|
27
|
+
|
28
|
+
# task :test_with_coveralls => [:spec, :features, 'coveralls:push']
|
10
29
|
|
data/bin/dcmetro
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
require 'dcmetro'
|
3
3
|
# You need to set an ENV variable in the shell which will be the Api Key.
|
4
4
|
# It is free from WMATA, https://developer.wmata.com/
|
5
5
|
# Referenced below was the old generic key used for testing the API on WMATA's site.
|
@@ -22,6 +22,6 @@ SILVER="\033[0;90m" # IBlack
|
|
22
22
|
YELLOW="\033[0;93m" # IYellow
|
23
23
|
BLUE="\033[0;94m" # IBlue
|
24
24
|
|
25
|
-
|
25
|
+
|
26
26
|
|
27
27
|
DCMetro::Cli::Application.start(ARGV)
|
data/dcmetro.gemspec
CHANGED
@@ -26,4 +26,8 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "rake"
|
27
27
|
spec.add_development_dependency "aruba"
|
28
28
|
spec.add_development_dependency "coveralls"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
spec.add_development_dependency "codecov"
|
31
|
+
spec.add_development_dependency "simplecov"
|
32
|
+
|
29
33
|
end
|
data/features/alerts.feature
CHANGED
data/features/external.feature
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
@check
|
2
2
|
Feature: External calls to WMATA api
|
3
3
|
|
4
|
-
When I call WMATA api
|
4
|
+
When I call WMATA api
|
5
5
|
Then the response should be "200"
|
6
6
|
And should return "JSON"
|
7
7
|
And should contain "the desired information"
|
@@ -32,12 +32,15 @@ Feature: External calls to WMATA api
|
|
32
32
|
And should contain "Line"
|
33
33
|
And should contain "DestinationName"
|
34
34
|
And should contain "Min"
|
35
|
-
|
36
|
-
@wip
|
35
|
+
|
37
36
|
Scenario: Check travel time, distance and fare between two stations
|
38
37
|
When I send a GET request for "WMATA Station Gallery College"
|
39
38
|
Then the response should be "200"
|
40
39
|
And should return "JSON"
|
41
40
|
And should contain "CompositeMiles"
|
42
41
|
And should contain "RailFare"
|
43
|
-
And should contain "RailTime"
|
42
|
+
And should contain "RailTime"
|
43
|
+
|
44
|
+
Scenario: Check nonsense
|
45
|
+
When I send a GET request for "WMATA crazy"
|
46
|
+
Then should return "false"
|
data/features/lines.feature
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
Feature: check dcmetro lines
|
2
2
|
|
3
3
|
In order to check lines
|
4
|
-
When I run `dcmetro lines`
|
4
|
+
When I run `bundle exec dcmetro lines`
|
5
5
|
Then metro lines should be displayed
|
6
6
|
|
7
|
+
# check line - singular
|
7
8
|
Scenario: check lines
|
8
9
|
When I run `dcmetro line`
|
9
|
-
Then the stdout should contain "
|
10
|
+
Then the stdout should contain "Blue\nGreen\nOrange\nRed\nSilver\nYellow"
|
10
11
|
|
12
|
+
# check lines - plural
|
11
13
|
Scenario: check lines
|
12
14
|
When I run `dcmetro lines`
|
13
|
-
Then the stdout should contain "
|
15
|
+
Then the stdout should contain "Blue\nGreen\nOrange\nRed\nSilver\nYellow"
|
14
16
|
|
15
|
-
Scenario: check
|
16
|
-
When I run `dcmetro line
|
17
|
-
Then the stdout should contain "
|
17
|
+
Scenario: check blue line stations
|
18
|
+
When I run `dcmetro line blue`
|
19
|
+
Then the stdout should contain "Metro Center\nMcPherson Square\nFarragut West\nFoggy Bottom-GWU\nRosslyn\nArlington Cemetery\nPentagon\nPentagon City\nCrystal City\nRonald Reagan Washington National Airport\nBraddock Road\nKing St-Old Town\nFederal Triangle\nSmithsonian\nL'Enfant Plaza\nFederal Center SW\nCapitol South\nEastern Market\nPotomac Ave\nStadium-Armory\nBenning Road\nCapitol Heights\nAddison Road-Seat Pleasant\nMorgan Boulevard\nLargo Town Center\nVan Dorn Street\nFranconia-Springfield\n"
|
18
20
|
|
19
|
-
Scenario: check green line
|
21
|
+
Scenario: check green line stations
|
20
22
|
When I run `dcmetro line green`
|
21
|
-
Then the stdout should contain "
|
23
|
+
Then the stdout should contain "Mt Vernon Sq 7th St-Convention Center\nShaw-Howard U\nU Street/African-Amer Civil War Memorial/Cardozo\nColumbia Heights\nGeorgia Ave-Petworth\nFort Totten\nWest Hyattsville\nPrince George's Plaza\nCollege Park-U of MD\nGreenbelt\nGallery Pl-Chinatown\nArchives-Navy Memorial-Penn Quarter\nL'Enfant Plaza\nWaterfront\nNavy Yard-Ballpark\nAnacostia\nCongress Heights\nSouthern Avenue\nNaylor Road\nSuitland\nBranch Ave\n"
|
24
|
+
|
25
|
+
Scenario: check red line stations
|
26
|
+
When I run `dcmetro line red`
|
27
|
+
Then the stdout should contain "Metro Center\nFarragut North\nDupont Circle\nWoodley Park-Zoo/Adams Morgan\nCleveland Park\nVan Ness-UDC\nTenleytown-AU\nFriendship Heights\nBethesda\nMedical Center\nGrosvenor-Strathmore\nWhite Flint\nTwinbrook\nRockville\nShady Grove\nGallery Pl-Chinatown\nJudiciary Square\nUnion Station\nRhode Island Ave-Brentwood\nBrookland-CUA\nFort Totten\nTakoma\nSilver Spring\nForest Glen\nWheaton\nGlenmont\nNoMa-Gallaudet U"
|
data/features/station.feature
CHANGED
@@ -1,18 +1,35 @@
|
|
1
1
|
Feature: check dcmetro station predictions
|
2
|
-
|
3
2
|
In order to station predictions
|
4
3
|
When I run `dcmetro station STATION`
|
5
4
|
Then train predictions for STATION should be displayed
|
6
|
-
|
5
|
+
|
7
6
|
Scenario: check gallery predictions
|
8
7
|
When I run `dcmetro station gallery`
|
9
|
-
Then the stdout should contain
|
8
|
+
Then the stdout should contain:
|
9
|
+
""""
|
10
|
+
Gallery
|
11
|
+
"""
|
10
12
|
|
11
13
|
Scenario: check predictions from partial name
|
12
|
-
When I run `dcmetro station gall`
|
13
|
-
|
14
|
+
When I run `dcmetro station gall` interactively
|
15
|
+
And I type "0"
|
16
|
+
Then the stdout should contain:
|
17
|
+
"""
|
18
|
+
****Multiple stations found****
|
19
|
+
"""
|
20
|
+
Then the stdout should contain:
|
21
|
+
"""
|
22
|
+
Gallery
|
23
|
+
"""
|
14
24
|
|
15
25
|
Scenario: check predictions returning more than one station
|
16
26
|
When I run `dcmetro station g` interactively
|
17
27
|
And I type "5"
|
18
|
-
Then the stdout should contain
|
28
|
+
Then the stdout should contain:
|
29
|
+
"""
|
30
|
+
****Multiple stations found****
|
31
|
+
"""
|
32
|
+
Then the stdout should contain:
|
33
|
+
"""
|
34
|
+
Gallery
|
35
|
+
"""
|
@@ -1,17 +1,17 @@
|
|
1
1
|
When(/^I send a GET request for "([^"]*)"$/) do |path|
|
2
2
|
case path
|
3
3
|
when "WMATA Alerts"
|
4
|
-
@last_response =
|
4
|
+
@last_response = DCMETRO.alerts
|
5
5
|
when "WMATA Lines"
|
6
|
-
@last_response =
|
6
|
+
@last_response = DCMETRO.line
|
7
7
|
when "WMATA Lines Red"
|
8
|
-
@last_response =
|
8
|
+
@last_response = DCMETRO.line "Red"
|
9
9
|
when "WMATA Station Gallery"
|
10
|
-
@last_response =
|
10
|
+
@last_response = DCMETRO.station "Gallery"
|
11
11
|
when "WMATA Station Gallery College"
|
12
|
-
@last_response =
|
12
|
+
@last_response = DCMETRO.station "Gallery", "College"
|
13
13
|
else
|
14
|
-
false
|
14
|
+
@last_response = false
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
data/features/support/env.rb
CHANGED
@@ -1,16 +1,31 @@
|
|
1
|
+
require 'simplecov'
|
1
2
|
require 'coveralls'
|
2
3
|
Coveralls.wear!
|
4
|
+
# require 'simplecov'
|
5
|
+
# SimpleCov.start
|
3
6
|
|
7
|
+
# require 'codecov'
|
8
|
+
# SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
4
9
|
require 'aruba/cucumber'
|
5
10
|
require 'json'
|
6
11
|
require 'rest-client'
|
7
12
|
require 'dcmetro'
|
8
13
|
|
14
|
+
DCMetro::Cli::Application::COLOR_OFF="\033[0m" # Text Reset
|
15
|
+
|
16
|
+
# Line Colors
|
17
|
+
DCMetro::Cli::Application::RED="\033[0;31m" # Red
|
18
|
+
DCMetro::Cli::Application::GREEN="\033[0;32m" # Green
|
19
|
+
DCMetro::Cli::Application::ORANGE="\033[38;5;208m" # Orange
|
20
|
+
DCMetro::Cli::Application::SILVER="\033[0;90m" # IBlack
|
21
|
+
DCMetro::Cli::Application::YELLOW="\033[0;93m" # IYellow
|
22
|
+
DCMetro::Cli::Application::BLUE="\033[0;94m" # IBlue
|
23
|
+
|
9
24
|
DCMETRO_KEY=ENV['DCMETRO_KEY']
|
10
25
|
API_KEY = DCMETRO_KEY
|
11
26
|
BASE_URL="http://api.wmata.com"
|
12
27
|
|
13
|
-
|
28
|
+
DCMETRO = DCMetro::Information.new
|
14
29
|
|
15
30
|
Before ("@check ") do
|
16
31
|
def valid_json?(json)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'dcmetro'
|
2
|
+
|
3
|
+
module DCMetro
|
4
|
+
class Runner
|
5
|
+
# Allow everything fun to be injected from the outside while defaulting to normal implementations.
|
6
|
+
def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
|
7
|
+
@argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute!
|
11
|
+
exit_code = begin
|
12
|
+
# Thor accesses these streams directly rather than letting them be injected, so we replace them...
|
13
|
+
$stderr = @stderr
|
14
|
+
$stdin = @stdin
|
15
|
+
$stdout = @stdout
|
16
|
+
|
17
|
+
# Run our normal Thor app the way we know and love.
|
18
|
+
DCMetro::Cli::Application.start(ARGV)
|
19
|
+
|
20
|
+
# Thor::Base#start does not have a return value, assume success if no exception is raised.
|
21
|
+
0
|
22
|
+
rescue StandardError => e
|
23
|
+
# The ruby interpreter would pipe this to STDERR and exit 1 in the case of an unhandled exception
|
24
|
+
b = e.backtrace
|
25
|
+
@stderr.puts("#{b.shift}: #{e.message} (#{e.class})")
|
26
|
+
@stderr.puts(b.map{|s| "\tfrom #{s}"}.join("\n"))
|
27
|
+
1
|
28
|
+
rescue SystemExit => e
|
29
|
+
e.status
|
30
|
+
ensure
|
31
|
+
# TODO: reset your app here, free up resources, etc.
|
32
|
+
# Examples:
|
33
|
+
# MyApp.logger.flush
|
34
|
+
# MyApp.logger.close
|
35
|
+
# MyApp.logger = nil
|
36
|
+
#
|
37
|
+
# MyApp.reset_singleton_instance_variables
|
38
|
+
|
39
|
+
# ...then we put the streams back.
|
40
|
+
$stderr = STDERR
|
41
|
+
$stdin = STDIN
|
42
|
+
$stdout = STDOUT
|
43
|
+
end
|
44
|
+
|
45
|
+
# Proxy our exit code back to the injected kernel.
|
46
|
+
@kernel.exit(exit_code)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/dcmetro/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Dcmetro
|
2
|
-
VERSION = "0.0
|
2
|
+
VERSION = "0.1.0"
|
3
3
|
end
|
4
4
|
|
5
5
|
### Changes in 0.0.2
|
@@ -22,4 +22,4 @@ end
|
|
22
22
|
# Any parsing is now done in the CLI application
|
23
23
|
#
|
24
24
|
# Bug: If no stations are returned app pukes
|
25
|
-
# Bug: Pentagon and Pentagon City confuses app
|
25
|
+
# Bug: Pentagon and Pentagon City confuses app
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DCMetro::Information do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@dcmetro = DCMetro::Information.new
|
7
|
+
sleep 1
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "@dcmetro" do
|
11
|
+
it "returns a DCMetro::Information object" do
|
12
|
+
expect(@dcmetro).to be_an_instance_of DCMetro::Information
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#alerts" do
|
17
|
+
it "returns alert information" do
|
18
|
+
|
19
|
+
# puts @dcmetro.inspect
|
20
|
+
expect(@dcmetro).to respond_to :alerts
|
21
|
+
alerts = JSON.parse(@dcmetro.alerts)
|
22
|
+
# puts @dcmetro.metro_incidents
|
23
|
+
expect(@dcmetro.alerts.code).to eq 200
|
24
|
+
expect(alerts).to include 'Incidents'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#lines" do
|
29
|
+
it "returns metro lines" do
|
30
|
+
|
31
|
+
# puts @dcmetro.inspect
|
32
|
+
expect(@dcmetro).to respond_to :line
|
33
|
+
lines = JSON.parse @dcmetro.line
|
34
|
+
# puts @dcmetro.metro_lines
|
35
|
+
expect(@dcmetro.line.code).to eq 200
|
36
|
+
expect(lines).to include 'Lines'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#lines blue" do
|
41
|
+
# subject { DCMetro::Information.new(:lines => "blue" }
|
42
|
+
it "returns stations on blue line" do
|
43
|
+
# puts @dcmetro.inspect
|
44
|
+
expect(@dcmetro).to respond_to(:line).with(1).argument
|
45
|
+
stations = JSON.parse @dcmetro.line "blue"
|
46
|
+
# puts @dcmetro.metro_lines
|
47
|
+
expect(@dcmetro.line("blue").code).to eq 200
|
48
|
+
expect(stations).to include 'Stations'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#lines red" do
|
53
|
+
# subject { DCMetro::Information.new(:lines => "blue" }
|
54
|
+
it "returns stations on red line" do
|
55
|
+
# puts @dcmetro.inspect
|
56
|
+
expect(@dcmetro).to respond_to(:line).with(1).argument
|
57
|
+
stations = JSON.parse @dcmetro.line "red"
|
58
|
+
# puts @dcmetro.metro_lines
|
59
|
+
expect(@dcmetro.line("red").code).to eq 200
|
60
|
+
expect(stations).to include 'Stations'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#lines orange" do
|
65
|
+
# subject { DCMetro::Information.new(:lines => "blue" }
|
66
|
+
it "returns stations on orange line" do
|
67
|
+
# puts @dcmetro.inspect
|
68
|
+
expect(@dcmetro).to respond_to(:line).with(1).argument
|
69
|
+
stations = JSON.parse @dcmetro.line "orange"
|
70
|
+
# puts @dcmetro.metro_lines
|
71
|
+
expect(@dcmetro.line("orange").code).to eq 200
|
72
|
+
expect(stations).to include 'Stations'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#lines green" do
|
77
|
+
# subject { DCMetro::Information.new(:lines => "blue" }
|
78
|
+
it "returns stations on green line" do
|
79
|
+
# puts @dcmetro.inspect
|
80
|
+
expect(@dcmetro).to respond_to(:line).with(1).argument
|
81
|
+
stations = JSON.parse @dcmetro.line "green"
|
82
|
+
# puts @dcmetro.metro_lines
|
83
|
+
expect(@dcmetro.line("green").code).to eq 200
|
84
|
+
expect(stations).to include 'Stations'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#lines yellow" do
|
89
|
+
# subject { DCMetro::Information.new(:lines => "blue" }
|
90
|
+
it "returns stations on yellow line" do
|
91
|
+
# puts @dcmetro.inspect
|
92
|
+
expect(@dcmetro).to respond_to(:line).with(1).argument
|
93
|
+
stations = JSON.parse @dcmetro.line "yellow"
|
94
|
+
# puts @dcmetro.metro_lines
|
95
|
+
expect(@dcmetro.line("yellow").code).to eq 200
|
96
|
+
expect(stations).to include 'Stations'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#lines silver" do
|
101
|
+
# subject { DCMetro::Information.new(:lines => "blue" }
|
102
|
+
it "returns stations on silver line" do
|
103
|
+
# puts @dcmetro.inspect
|
104
|
+
expect(@dcmetro).to respond_to(:line).with(1).argument
|
105
|
+
stations = JSON.parse @dcmetro.line "silver"
|
106
|
+
# puts @dcmetro.metro_lines
|
107
|
+
expect(@dcmetro.line("silver").code).to eq 200
|
108
|
+
expect(stations).to include 'Stations'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
require 'codecov'
|
4
|
+
Coveralls.wear!
|
5
|
+
require "aruba/api"
|
6
|
+
require 'dcmetro'
|
7
|
+
# require 'simplecov'
|
8
|
+
# SimpleCov.start
|
9
|
+
|
10
|
+
|
11
|
+
# SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
14
|
+
|
15
|
+
::Dir.glob(::File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require_relative f }
|
16
|
+
|
17
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
18
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
19
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
20
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
21
|
+
# files.
|
22
|
+
#
|
23
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
24
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
25
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
26
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
27
|
+
# a separate helper file that requires the additional dependencies and performs
|
28
|
+
# the additional setup, and require it from the spec files that actually need
|
29
|
+
# it.
|
30
|
+
#
|
31
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
32
|
+
# users commonly want.
|
33
|
+
#
|
34
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
35
|
+
RSpec.configure do |config|
|
36
|
+
|
37
|
+
DCMetro::Cli::Application::COLOR_OFF="\033[0m" # Text Reset
|
38
|
+
|
39
|
+
# Line Colors
|
40
|
+
DCMetro::Cli::Application::RED="\033[0;31m" # Red
|
41
|
+
DCMetro::Cli::Application::GREEN="\033[0;32m" # Green
|
42
|
+
DCMetro::Cli::Application::ORANGE="\033[38;5;208m" # Orange
|
43
|
+
DCMetro::Cli::Application::SILVER="\033[0;90m" # IBlack
|
44
|
+
DCMetro::Cli::Application::YELLOW="\033[0;93m" # IYellow
|
45
|
+
DCMetro::Cli::Application::BLUE="\033[0;94m" # IBlue
|
46
|
+
# rspec-expectations config goes here. You can use an alternate
|
47
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
48
|
+
# assertions if you prefer.
|
49
|
+
def capture(stream)
|
50
|
+
begin
|
51
|
+
stream = stream.to_s
|
52
|
+
eval "$#{stream} = StringIO.new"
|
53
|
+
yield
|
54
|
+
result = eval("$#{stream}").string
|
55
|
+
ensure
|
56
|
+
eval("$#{stream} = #{stream.upcase}")
|
57
|
+
end
|
58
|
+
|
59
|
+
result
|
60
|
+
end
|
61
|
+
|
62
|
+
# config.include(Aruba::Api)
|
63
|
+
# Aruba.config.working_directory = "./aruba_test"
|
64
|
+
DCMetro::Information::API_KEY = ENV['DCMETRO_KEY']
|
65
|
+
|
66
|
+
config.expect_with :rspec do |expectations|
|
67
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
68
|
+
# and `failure_message` of custom matchers include text for helper methods
|
69
|
+
# defined using `chain`, e.g.:
|
70
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
71
|
+
# # => "be bigger than 2 and smaller than 4"
|
72
|
+
# ...rather than:
|
73
|
+
# # => "be bigger than 2"
|
74
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
75
|
+
end
|
76
|
+
|
77
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
78
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
79
|
+
config.mock_with :rspec do |mocks|
|
80
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
81
|
+
# a real object. This is generally recommended, and will default to
|
82
|
+
# `true` in RSpec 4.
|
83
|
+
mocks.verify_partial_doubles = true
|
84
|
+
end
|
85
|
+
|
86
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
87
|
+
# have no way to turn it off -- the option exists only for backwards
|
88
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
89
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
90
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
91
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
92
|
+
|
93
|
+
# The settings below are suggested to provide a good initial experience
|
94
|
+
# with RSpec, but feel free to customize to your heart's content.
|
95
|
+
=begin
|
96
|
+
# This allows you to limit a spec run to individual examples or groups
|
97
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
98
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
99
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
100
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
101
|
+
config.filter_run_when_matching :focus
|
102
|
+
|
103
|
+
# Allows RSpec to persist some state between runs in order to support
|
104
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
105
|
+
# you configure your source control system to ignore this file.
|
106
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
107
|
+
|
108
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
109
|
+
# recommended. For more details, see:
|
110
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
111
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
112
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
113
|
+
config.disable_monkey_patching!
|
114
|
+
|
115
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
116
|
+
# be too noisy due to issues in dependencies.
|
117
|
+
config.warnings = true
|
118
|
+
|
119
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
120
|
+
# file, and it's useful to allow more verbose output when running an
|
121
|
+
# individual spec file.
|
122
|
+
if config.files_to_run.one?
|
123
|
+
# Use the documentation formatter for detailed output,
|
124
|
+
# unless a formatter has already been configured
|
125
|
+
# (e.g. via a command-line flag).
|
126
|
+
config.default_formatter = 'doc'
|
127
|
+
end
|
128
|
+
|
129
|
+
# Print the 10 slowest examples and example groups at the
|
130
|
+
# end of the spec run, to help surface which specs are running
|
131
|
+
# particularly slow.
|
132
|
+
config.profile_examples = 10
|
133
|
+
|
134
|
+
# Run specs in random order to surface order dependencies. If you find an
|
135
|
+
# order dependency and want to debug it, you can fix the order by providing
|
136
|
+
# the seed, which is printed after each run.
|
137
|
+
# --seed 1234
|
138
|
+
config.order = :random
|
139
|
+
|
140
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
141
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
142
|
+
# test failures related to randomization by passing the same `--seed` value
|
143
|
+
# as the one that triggered the failure.
|
144
|
+
Kernel.srand config.seed
|
145
|
+
=end
|
146
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# require 'aruba/rspec'
|
data/spec/test_spec.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DCMetro::Cli do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
sleep 1
|
7
|
+
end
|
8
|
+
describe "#dcmetro" do
|
9
|
+
it "should show commands" do
|
10
|
+
output = `bundle exec bin/dcmetro`.chomp
|
11
|
+
expect(output).to include "Commands:"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#dcmetro alerts" do
|
16
|
+
it "should echo alerts" do
|
17
|
+
echo_task = capture(:stdout) { DCMetro::Cli::Application.start(['alert']) }
|
18
|
+
expect(echo_task).to include "***"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#dcmetro lines" do
|
23
|
+
it "should echo metro lines" do
|
24
|
+
echo_task = capture(:stdout) { DCMetro::Cli::Application.start(['lines']) }
|
25
|
+
expect(echo_task).to eq "\e[0;94mBlue\e[0m\n\e[0;32mGreen\e[0m\n\e[38;5;208mOrange\e[0m\n\e[0;31mRed\e[0m\n\e[0;90mSilver\e[0m\n\e[0;93mYellow\e[0m\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#dcmetro line" do
|
30
|
+
it "should echo metro line" do
|
31
|
+
echo_task = capture(:stdout) { DCMetro::Cli::Application.start(['line']) }
|
32
|
+
expect(echo_task).to eq "\e[0;94mBlue\e[0m\n\e[0;32mGreen\e[0m\n\e[38;5;208mOrange\e[0m\n\e[0;31mRed\e[0m\n\e[0;90mSilver\e[0m\n\e[0;93mYellow\e[0m\n"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#dcmetro lines red" do
|
37
|
+
it "should echo metro stations on the red line" do
|
38
|
+
echo_task = capture(:stdout) { DCMetro::Cli::Application.start(['lines', 'red']) }
|
39
|
+
expect(echo_task).to include "Metro Center"
|
40
|
+
expect(echo_task).to include "Farragut North"
|
41
|
+
expect(echo_task).to include "Dupont Circle"
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
describe "#dcmetro station gallery" do
|
48
|
+
it "should echo predictions for Gallery Place" do
|
49
|
+
echo_task = capture(:stdout) { DCMetro::Cli::Application.start(['station','gallery']) }
|
50
|
+
expect(echo_task).to include "Gallery"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#dcmetro station gallery -a" do
|
55
|
+
it "should echo predictions for Gallery Place with alerts" do
|
56
|
+
echo_task = capture(:stdout) { DCMetro::Cli::Application.start(['station','gallery','-a']) }
|
57
|
+
expect(echo_task).to include "***"
|
58
|
+
expect(echo_task).to include "Gallery"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#dcmetro station college gallery" do
|
63
|
+
it "should echo fare information from college park to gallery place" do
|
64
|
+
echo_task = capture(:stdout) { DCMetro::Cli::Application.start(['station','college','gallery']) }
|
65
|
+
expect(echo_task).to include "Distance"
|
66
|
+
expect(echo_task).to include "Travel Time"
|
67
|
+
expect(echo_task).to include "*** Fare Information ***"
|
68
|
+
expect(echo_task).to include "Off Peak Time"
|
69
|
+
expect(echo_task).to include "Peak Time"
|
70
|
+
expect(echo_task).to include "Senior/Disabled"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dcmetro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Crocken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -108,6 +108,48 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: codecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
111
153
|
description: Washington, DC Metro Rails information, including lines, stations and
|
112
154
|
arrival/departure predictions.
|
113
155
|
email:
|
@@ -119,6 +161,8 @@ extra_rdoc_files: []
|
|
119
161
|
files:
|
120
162
|
- ".coveralls.yml"
|
121
163
|
- ".gitignore"
|
164
|
+
- ".rspec"
|
165
|
+
- ".simplecov"
|
122
166
|
- ".travis.yml"
|
123
167
|
- Gemfile
|
124
168
|
- LICENSE.txt
|
@@ -134,7 +178,13 @@ files:
|
|
134
178
|
- features/support/env.rb
|
135
179
|
- lib/dcmetro.rb
|
136
180
|
- lib/dcmetro/cli/application.rb
|
181
|
+
- lib/dcmetro/runner.rb
|
137
182
|
- lib/dcmetro/version.rb
|
183
|
+
- spec/information_spec.rb
|
184
|
+
- spec/spec_helper.rb
|
185
|
+
- spec/support/aruba.rb
|
186
|
+
- spec/test_spec.rb
|
187
|
+
- spec/use_aruba_with_rspec_spec.rb
|
138
188
|
homepage: https://github.com/kencrocken/dcmetro
|
139
189
|
licenses:
|
140
190
|
- MIT
|
@@ -155,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
205
|
version: '0'
|
156
206
|
requirements: []
|
157
207
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
208
|
+
rubygems_version: 2.6.10
|
159
209
|
signing_key:
|
160
210
|
specification_version: 4
|
161
211
|
summary: Returns DC Metro Rails information, including train schedules.
|
@@ -166,3 +216,8 @@ test_files:
|
|
166
216
|
- features/station.feature
|
167
217
|
- features/step_definitions/api_test_steps.rb
|
168
218
|
- features/support/env.rb
|
219
|
+
- spec/information_spec.rb
|
220
|
+
- spec/spec_helper.rb
|
221
|
+
- spec/support/aruba.rb
|
222
|
+
- spec/test_spec.rb
|
223
|
+
- spec/use_aruba_with_rspec_spec.rb
|