linodians 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Linodians::Employee do
4
+ let(:employee) do
5
+ VCR.use_cassette('new_data') { Linodians::Group.new.lookup('rohara') }
6
+ end
7
+
8
+ describe '#photo' do
9
+ let(:photo) { VCR.use_cassette('photo') { employee.photo } }
10
+
11
+ it 'returns a string' do
12
+ expect(photo).to be_an_instance_of String
13
+ end
14
+
15
+ it 'is a PNG' do
16
+ expect(photo).to match "\x89PNG".force_encoding('binary')
17
+ end
18
+ end
19
+
20
+ describe '#[]' do
21
+ it 'accesses the employee info' do
22
+ expect(employee[:twitter]).to eql 'sirrohara'
23
+ end
24
+
25
+ it 'supports strings as keys' do
26
+ expect(employee['twitter']).to eql 'sirrohara'
27
+ end
28
+
29
+ it 'supports symbols as keys' do
30
+ expect(employee[:twitter]).to eql 'sirrohara'
31
+ end
32
+
33
+ it 'returns nil if the key does not exist' do
34
+ expect(employee[:other]).to be_nil
35
+ end
36
+ end
37
+
38
+ describe '#to_json' do
39
+ it 'returns data as json' do
40
+ expect(JSON.parse(employee.to_json)).to be_an_instance_of Hash
41
+ end
42
+ end
43
+
44
+ describe '#respond_to?' do
45
+ it 'truthfully responds for proxied methods' do
46
+ expect(employee.respond_to? :twitter).to be_truthy
47
+ end
48
+
49
+ it 'returns false for methods that it cannot handle' do
50
+ expect(employee.respond_to? :other).to be_falsey
51
+ end
52
+ end
53
+
54
+ describe '#to_h' do
55
+ it 'returns a hash' do
56
+ expect(employee.to_h).to be_an_instance_of Hash
57
+ end
58
+
59
+ it 'dups to allow modification' do
60
+ copy = employee.to_h
61
+ copy[:new_key] = :data
62
+ expect(copy[:new_key]).to eql :data
63
+ expect(employee[:new_key]).to be_nil
64
+ end
65
+ end
66
+
67
+ it 'proxies methods as data hash keys' do
68
+ expect(employee.twitter).to eql 'sirrohara'
69
+ end
70
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Linodians::Group do
4
+ let(:group) { VCR.use_cassette('new_data') { Linodians::Group.new } }
5
+
6
+ describe '@members' do
7
+ it 'is an array' do
8
+ expect(group.members).to be_an_instance_of Array
9
+ end
10
+
11
+ it 'is frozen' do
12
+ expect(group.members.frozen?).to be_truthy
13
+ end
14
+
15
+ it 'contains employees' do
16
+ expect(group.members).to all(be_an_instance_of Linodians::Employee)
17
+ end
18
+ end
19
+
20
+ describe '#lookup' do
21
+ it 'looks up employees' do
22
+ expect(group.lookup('rohara').username).to eql 'rohara'
23
+ end
24
+
25
+ it 'returns nil if no match exists' do
26
+ expect(group.lookup('akerl')).to be_nil
27
+ end
28
+ end
29
+
30
+ it 'proxies methods to @members' do
31
+ expect(group.size).to be_a Numeric
32
+ expect(group.size).to be > 1
33
+ end
34
+
35
+ it 'raises if the method does not exist' do
36
+ expect { group.fake }.to raise_error NoMethodError
37
+ end
38
+
39
+ it 'correctly responds to respond_to?' do
40
+ expect(group.respond_to? :size).to be_truthy
41
+ expect(group.respond_to? :fake).to be_falsey
42
+ end
43
+ end
@@ -1 +1,29 @@
1
1
  require 'spec_helper'
2
+
3
+ require 'json'
4
+
5
+ describe Linodians do
6
+ describe '#new' do
7
+ it 'creates Group objects' do
8
+ VCR.use_cassette('new_data') do
9
+ expect(Linodians.new).to be_an_instance_of Linodians::Group
10
+ end
11
+ end
12
+ end
13
+
14
+ describe '#load_data' do
15
+ let(:saved_data) { File.open('spec/examples/data') { |fh| JSON.load fh } }
16
+ let(:new_data) { VCR.use_cassette('new_data') { Linodians.load_data } }
17
+
18
+ it 'downloads data from linode.com' do
19
+ expect(new_data).to be_an_instance_of Array
20
+ expect(new_data.first).to be_an_instance_of Linodians::Employee
21
+ end
22
+
23
+ it 'accepts data as input' do
24
+ data = Linodians.load_data(saved_data)
25
+ expect(data).to be_an_instance_of Array
26
+ expect(data.first).to be_an_instance_of Linodians::Employee
27
+ end
28
+ end
29
+ end
data/spec/spec_helper.rb CHANGED
@@ -8,3 +8,9 @@ end
8
8
 
9
9
  require 'rspec'
10
10
  require 'linodians'
11
+
12
+ require 'vcr'
13
+ VCR.configure do |c|
14
+ c.cassette_library_dir = 'spec/fixtures/cassettes'
15
+ c.hook_into :webmock
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linodians
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-30 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.28.0
47
+ version: 0.29.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.28.0
54
+ version: 0.29.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 3.1.0
89
+ version: 3.2.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 3.1.0
96
+ version: 3.2.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: fuubar
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 2.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.20.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.20.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: vcr
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.9.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.9.2
111
139
  description: Library for viewing public Linode employee data
112
140
  email: me@lesaker.org
113
141
  executables:
@@ -119,6 +147,7 @@ files:
119
147
  - ".rspec"
120
148
  - ".rubocop.yml"
121
149
  - ".travis.yml"
150
+ - CHANGELOG.md
122
151
  - Gemfile
123
152
  - LICENSE
124
153
  - README.md
@@ -129,6 +158,11 @@ files:
129
158
  - lib/linodians/group.rb
130
159
  - lib/linodians/version.rb
131
160
  - linodians.gemspec
161
+ - spec/examples/data
162
+ - spec/fixtures/cassettes/new_data.yml
163
+ - spec/fixtures/cassettes/photo.yml
164
+ - spec/linodians/employee_spec.rb
165
+ - spec/linodians/group_spec.rb
132
166
  - spec/linodians_spec.rb
133
167
  - spec/spec_helper.rb
134
168
  homepage: https://github.com/akerl/linodians
@@ -156,5 +190,10 @@ signing_key:
156
190
  specification_version: 4
157
191
  summary: Parse Linode employees
158
192
  test_files:
193
+ - spec/examples/data
194
+ - spec/fixtures/cassettes/new_data.yml
195
+ - spec/fixtures/cassettes/photo.yml
196
+ - spec/linodians/employee_spec.rb
197
+ - spec/linodians/group_spec.rb
159
198
  - spec/linodians_spec.rb
160
199
  - spec/spec_helper.rb