nba 0.0.3 → 0.1.1
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/.travis.yml +0 -5
- data/README.md +31 -18
- data/Rakefile +1 -0
- data/bin/nba +7 -0
- data/lib/faraday_middleware/scrape_game.rb +14 -2
- data/lib/nba.rb +1 -0
- data/lib/nba/cli.rb +35 -0
- data/lib/nba/game.rb +22 -6
- data/lib/nba/player.rb +10 -6
- data/lib/nba/team.rb +95 -63
- data/lib/nba/version.rb +1 -1
- data/nba.gemspec +2 -1
- data/spec/fixtures/games.html +785 -0
- data/spec/fixtures/teams.json +16529 -0
- data/spec/game_spec.rb +40 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/team_spec.rb +93 -0
- metadata +29 -6
- data/spec/nba_spec.rb +0 -73
data/spec/game_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NBA::Game, '.all' do
|
4
|
+
before :all do
|
5
|
+
@date = '20140104'
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { described_class.scoreboard(@date) }
|
9
|
+
|
10
|
+
context 'with timeout' do
|
11
|
+
before do
|
12
|
+
stub_request(:get, 'http://scores.espn.go.com/nba/scoreboard').with(:query => {:date => @date}).to_timeout
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'does not raise an exception' do
|
16
|
+
expect { subject }.not_to raise_exception
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'without connection' do
|
21
|
+
before do
|
22
|
+
stub_request(:get, 'http://scores.espn.go.com/nba/scoreboard').with(:query => {:date => @date}).to_raise(SocketError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'does not raise an exception' do
|
26
|
+
expect { subject }.not_to raise_exception
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with no route to host' do
|
31
|
+
before do
|
32
|
+
stub_request(:get, 'http://scores.espn.go.com/nba/scoreboard').with(:query => {:date => @date}).to_raise(Errno::EHOSTUNREACH)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'does not raise an exception' do
|
36
|
+
expect { subject }.not_to raise_exception
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
data/spec/spec_helper.rb
CHANGED
data/spec/team_spec.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NBA::Team, '.all' do
|
4
|
+
subject { described_class.all }
|
5
|
+
|
6
|
+
context 'with connection' do
|
7
|
+
before do
|
8
|
+
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => described_class.mql_query}).to_return(:body => fixture('teams.json'))
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
described_class.reset
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'there are thirty teams' do
|
16
|
+
expect(subject.size).to eq 30
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'teams are sorted alphabetically, by name' do
|
20
|
+
expect(subject).to eq subject.sort_by(&:name)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'every team has a founding year' do
|
24
|
+
subject.each do |team|
|
25
|
+
expect(team.founded).to be_between(1870, 2008), "got: #{team.founded} for #{team.name}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'every player has a one- or two-digit number' do
|
30
|
+
subject.each do |team|
|
31
|
+
team.players.each do |player|
|
32
|
+
expect(player.number).to be_between(0, 99), "got: #{player.number} for #{player.name}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'every player has at least one position' do
|
38
|
+
subject.each do |team|
|
39
|
+
team.players.each do |player|
|
40
|
+
pending 'Some players do not have a position' # Delonte West
|
41
|
+
expect(player.positions.size).to be >= 1, "got: #{player.positions.size} for #{player.name}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'every player has a starting year' do
|
47
|
+
subject.each do |team|
|
48
|
+
team.players.each do |player|
|
49
|
+
pending 'Some players do not have a starting year' # 0 for Ivan Johnson
|
50
|
+
expect(player.from).to be >= 1995, "got: #{player.from} for #{player.name}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'every player is active' do
|
56
|
+
subject.each do |team|
|
57
|
+
team.players.each do |player|
|
58
|
+
expect(player.to).to eq('Present'), "got: #{player.to} for #{player.name}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with timeout' do
|
64
|
+
before do
|
65
|
+
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => described_class.mql_query}).to_timeout
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'does not raise an exception' do
|
69
|
+
expect { subject }.not_to raise_exception
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'without connection' do
|
75
|
+
before do
|
76
|
+
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => described_class.mql_query}).to_raise(SocketError)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'does not raise an exception' do
|
80
|
+
expect { subject }.not_to raise_exception
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'with no route to host' do
|
85
|
+
before do
|
86
|
+
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => described_class.mql_query}).to_raise(Errno::EHOSTUNREACH)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'does not raise an exception' do
|
90
|
+
expect { subject }.not_to raise_exception
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Lv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 1.6.1
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: thor
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.18.1
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.18.1
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: bundler
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,7 +104,8 @@ description: NBA.rb is a Ruby library for retrieving NBA League games, schedules
|
|
90
104
|
teams and players.
|
91
105
|
email:
|
92
106
|
- larrylv1990@gmail.com
|
93
|
-
executables:
|
107
|
+
executables:
|
108
|
+
- nba
|
94
109
|
extensions: []
|
95
110
|
extra_rdoc_files: []
|
96
111
|
files:
|
@@ -100,18 +115,23 @@ files:
|
|
100
115
|
- LICENSE.md
|
101
116
|
- README.md
|
102
117
|
- Rakefile
|
118
|
+
- bin/nba
|
103
119
|
- cache/teams.json
|
104
120
|
- lib/faraday_middleware/scrape_game.rb
|
105
121
|
- lib/nba.rb
|
122
|
+
- lib/nba/cli.rb
|
106
123
|
- lib/nba/game.rb
|
107
124
|
- lib/nba/player.rb
|
108
125
|
- lib/nba/request.rb
|
109
126
|
- lib/nba/team.rb
|
110
127
|
- lib/nba/version.rb
|
111
128
|
- nba.gemspec
|
112
|
-
- spec/
|
129
|
+
- spec/fixtures/games.html
|
130
|
+
- spec/fixtures/teams.json
|
131
|
+
- spec/game_spec.rb
|
113
132
|
- spec/spec_helper.rb
|
114
|
-
|
133
|
+
- spec/team_spec.rb
|
134
|
+
homepage: https://github.com/larrylv/nba
|
115
135
|
licenses:
|
116
136
|
- MIT
|
117
137
|
metadata: {}
|
@@ -137,5 +157,8 @@ specification_version: 4
|
|
137
157
|
summary: NBA.rb is a Ruby library for retrieving NBA League games, schedules, teams
|
138
158
|
and players.
|
139
159
|
test_files:
|
140
|
-
- spec/
|
160
|
+
- spec/fixtures/games.html
|
161
|
+
- spec/fixtures/teams.json
|
162
|
+
- spec/game_spec.rb
|
141
163
|
- spec/spec_helper.rb
|
164
|
+
- spec/team_spec.rb
|
data/spec/nba_spec.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe NBA::Team, '.all' do
|
4
|
-
context 'with connection' do
|
5
|
-
before do
|
6
|
-
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => NBA::Team.mql_query}).to_return(:body => fixture('teams.json'))
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
NBA::Team.reset
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'requests the correct resource' do
|
14
|
-
NBA::Team.all
|
15
|
-
expect(a_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => NBA::Team.mql_query})).to have_been_made
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'returns the correct team results' do
|
19
|
-
teams = NBA::Team.all
|
20
|
-
expect(teams.first.name).to eq 'Atlanta Hawks'
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns the correct player results' do
|
24
|
-
teams = NBA::Team.all
|
25
|
-
expect(teams.first.players.first.name).to_not be_nil
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'with timeout' do
|
30
|
-
before do
|
31
|
-
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => NBA::Team.mql_query}).to_timeout
|
32
|
-
end
|
33
|
-
|
34
|
-
after do
|
35
|
-
NBA::Team.reset
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'returns the correct results' do
|
39
|
-
teams = NBA::Team.all
|
40
|
-
expect(teams.first.name).to eq 'Atlanta Hawks'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'without connection' do
|
45
|
-
before do
|
46
|
-
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => NBA::Team.mql_query}).to_raise(SocketError)
|
47
|
-
end
|
48
|
-
|
49
|
-
after do
|
50
|
-
NBA::Team.reset
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'returns the correct results' do
|
54
|
-
teams = NBA::Team.all
|
55
|
-
expect(teams.first.name).to eq 'Atlanta Hawks'
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'with no route to host' do
|
60
|
-
before do
|
61
|
-
stub_request(:get, 'https://www.googleapis.com/freebase/v1/mqlread').with(:query => {:query => NBA::Team.mql_query}).to_raise(Errno::EHOSTUNREACH)
|
62
|
-
end
|
63
|
-
|
64
|
-
after do
|
65
|
-
NBA::Team.reset
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'returns the correct results' do
|
69
|
-
teams = NBA::Team.all
|
70
|
-
expect(teams.first.name).to eq 'Atlanta Hawks'
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|