net-dnd 1.1.2
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.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +22 -0
- data/Rakefile +2 -0
- data/bin/dndwho +5 -0
- data/lib/net/dnd.rb +82 -0
- data/lib/net/dnd/connection.rb +89 -0
- data/lib/net/dnd/errors.rb +22 -0
- data/lib/net/dnd/expires.rb +25 -0
- data/lib/net/dnd/field.rb +58 -0
- data/lib/net/dnd/profile.rb +74 -0
- data/lib/net/dnd/response.rb +95 -0
- data/lib/net/dnd/session.rb +114 -0
- data/lib/net/dnd/user_spec.rb +56 -0
- data/lib/net/dnd/version.rb +11 -0
- data/net-dnd.gemspec +25 -0
- data/spec/dnd/connection_spec.rb +94 -0
- data/spec/dnd/field_spec.rb +72 -0
- data/spec/dnd/profile_spec.rb +66 -0
- data/spec/dnd/response_spec.rb +161 -0
- data/spec/dnd/session_spec.rb +254 -0
- data/spec/dnd/user_spec_spec.rb +70 -0
- data/spec/spec_helper.rb +14 -0
- metadata +128 -0
@@ -0,0 +1,254 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'net/dnd/session'
|
3
|
+
|
4
|
+
module Net ; module DND
|
5
|
+
|
6
|
+
describe Session, "when created with a bad host" do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@connection = flexmock("Bad Connection")
|
10
|
+
@connection.should_receive(:open?).once.and_return(false)
|
11
|
+
@connection.should_receive(:error).once.and_return("Could not connect to DND server")
|
12
|
+
flexmock(Connection).should_receive(:new).once.and_return(@connection)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should raise a Connection Error" do
|
16
|
+
lambda { Session.new('my.badhost.com') }.should raise_error(ConnectionError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe Session, "when created with a good host" do
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
@connection = flexmock("Good Connection")
|
24
|
+
@connection.should_receive(:open?).twice.and_return(true)
|
25
|
+
flexmock(Connection).should_receive(:new).once.and_return(@connection)
|
26
|
+
@session = Session.new('my.goodhost.com')
|
27
|
+
end
|
28
|
+
|
29
|
+
it do
|
30
|
+
@session.should be_open
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe Session, "after closing down" do
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
@connection = flexmock("Good Connection")
|
38
|
+
@connection.should_receive(:open?).times(3).and_return(true, true, false)
|
39
|
+
flexmock(Connection).should_receive(:new).once.and_return(@connection)
|
40
|
+
@response = flexmock(Response)
|
41
|
+
@connection.should_receive(:send).once.and_return(@response)
|
42
|
+
@session = Session.new('my.goodhost.com')
|
43
|
+
@session.close
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not be open" do
|
47
|
+
@session.should_not be_open
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "a connected session", :shared => true do
|
52
|
+
before(:each) do
|
53
|
+
@connection = flexmock("Good Connection")
|
54
|
+
@connection.should_receive(:open?).twice.and_return(true)
|
55
|
+
flexmock(Connection).should_receive(:new).once.and_return(@connection)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "a good response", :shared => true do
|
60
|
+
before(:each) do
|
61
|
+
@response = flexmock(Response)
|
62
|
+
@connection.should_receive(:send).once.and_return(@response)
|
63
|
+
@response.should_receive(:ok?).once.and_return(true)
|
64
|
+
@session = Session.new('my.goodhost.com')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe Session, "when setting fields with an unknown field" do
|
69
|
+
|
70
|
+
it_should_behave_like "a connected session"
|
71
|
+
|
72
|
+
before(:each) do
|
73
|
+
@response = flexmock(Response)
|
74
|
+
@connection.should_receive(:send).once.and_return(@response)
|
75
|
+
@response.should_receive(:ok?).once.and_return(false)
|
76
|
+
@response.should_receive(:error).once.and_return('unknown.')
|
77
|
+
@session = Session.new('my.goodhost.com')
|
78
|
+
@field_list = ['unknown']
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should raise a Field Not Found error" do
|
82
|
+
lambda { @session.set_fields(@field_list) }.
|
83
|
+
should raise_error(FieldNotFound, "unknown.")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe Session, "when setting fields with a bad field_list" do
|
88
|
+
|
89
|
+
it_should_behave_like "a connected session"
|
90
|
+
it_should_behave_like "a good response"
|
91
|
+
|
92
|
+
before(:each) do
|
93
|
+
@field_list = ['ssn']
|
94
|
+
@items = ['ssn N N']
|
95
|
+
@response.should_receive(:items).once.and_return(@items)
|
96
|
+
@ssn_field = flexmock("a bad field")
|
97
|
+
@ssn_field.should_receive(:read_all?).once.and_return(false)
|
98
|
+
@ssn_field.should_receive(:to_s).once.and_return('ssn')
|
99
|
+
flexmock(Field).should_receive(:from_field_line).once.and_return(@ssn_field)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should raise a Field Access Denied error" do
|
103
|
+
lambda { @session.set_fields(@field_list) }.
|
104
|
+
should raise_error(FieldAccessDenied, "#{@field_list[0]} is not world readable.")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe Session, "when setting fields with a good field_list" do
|
109
|
+
|
110
|
+
it_should_behave_like "a connected session"
|
111
|
+
it_should_behave_like "a good response"
|
112
|
+
|
113
|
+
before(:each) do
|
114
|
+
name_field = flexmock("a name field")
|
115
|
+
name_field.should_receive(:read_all?).once.and_return(true)
|
116
|
+
name_field.should_receive(:to_sym).once.and_return(:name)
|
117
|
+
nickname_field = flexmock("a nickname field")
|
118
|
+
nickname_field.should_receive(:read_all?).once.and_return(true)
|
119
|
+
nickname_field.should_receive(:to_sym).once.and_return(:nickname)
|
120
|
+
flexmock(Field).should_receive(:from_field_line).twice.and_return(name_field, nickname_field)
|
121
|
+
@response.should_receive(:items).once.and_return(['name N A', 'nickname U A'])
|
122
|
+
@session.set_fields(['name', 'nickname'])
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should have [:name, :nickname] as the fields attribute" do
|
126
|
+
@session.fields.should == [:name, :nickname]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "mock items for a started session", :shared => true do
|
131
|
+
before(:each) do
|
132
|
+
name_field = flexmock("a name field")
|
133
|
+
name_field.should_receive(:read_all?).once.and_return(true)
|
134
|
+
name_field.should_receive(:to_sym).once.and_return(:name)
|
135
|
+
nickname_field = flexmock("a nickname field")
|
136
|
+
nickname_field.should_receive(:read_all?).once.and_return(true)
|
137
|
+
nickname_field.should_receive(:to_sym).once.and_return(:nickname)
|
138
|
+
flexmock(Field).should_receive(:from_field_line).twice.and_return(name_field, nickname_field)
|
139
|
+
@fields_resp = flexmock(Response)
|
140
|
+
@fields_resp.should_receive(:items).once.and_return(['name N A', 'nickname U A'])
|
141
|
+
@connection = flexmock("A Started Connection")
|
142
|
+
@connection.should_receive(:open?).times(3).and_return(true)
|
143
|
+
flexmock(Connection).should_receive(:new).once.and_return(@connection)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe Session, "performing a find with no profiles returned" do
|
148
|
+
|
149
|
+
it_should_behave_like "mock items for a started session"
|
150
|
+
|
151
|
+
before(:each) do
|
152
|
+
@find_resp = flexmock(Response)
|
153
|
+
@find_resp.should_receive(:ok?).once.and_return(true)
|
154
|
+
@find_resp.should_receive(:items).once.and_return([])
|
155
|
+
@connection.should_receive(:send).twice.and_return(@fields_resp, @find_resp)
|
156
|
+
@session = Session.start('my.goodhost.com', ['name', 'nickname'])
|
157
|
+
@profiles = @session.find("Nothing returned")
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should return an empty array" do
|
161
|
+
@profiles.should == []
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
describe Session, "performing a find with one profile returned" do
|
167
|
+
|
168
|
+
it_should_behave_like "mock items for a started session"
|
169
|
+
|
170
|
+
before(:each) do
|
171
|
+
@find_resp = flexmock(Response)
|
172
|
+
@find_resp.should_receive(:ok?).once.and_return(true)
|
173
|
+
@find_resp.should_receive(:items).once.and_return([['Joe D. User', 'joey jdu']])
|
174
|
+
@joe = flexmock("Joe's Profile")
|
175
|
+
flexmock(Profile).should_receive(:new).once.and_return(@joe)
|
176
|
+
@connection.should_receive(:send).twice.and_return(@fields_resp, @find_resp)
|
177
|
+
@session = Session.start('my.goodhost.com', ['name', 'nickname'])
|
178
|
+
@profiles = @session.find("Joe User")
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should return a single item array of profiles" do
|
182
|
+
@profiles.length.should == 1
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should return Joe's profile as the first item" do
|
186
|
+
@profiles[0].should equal(@joe)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe Session, "performing a find with multiple profiles returned" do
|
191
|
+
|
192
|
+
it_should_behave_like "mock items for a started session"
|
193
|
+
|
194
|
+
before(:each) do
|
195
|
+
@joe = flexmock("Joe's Profile")
|
196
|
+
@jane = flexmock("Jane's Profile")
|
197
|
+
flexmock(Profile).should_receive(:new).twice.and_return(@joe, @jane)
|
198
|
+
@find_resp = flexmock(Response)
|
199
|
+
@find_resp.should_receive(:ok?).once.and_return(true)
|
200
|
+
@find_resp.should_receive(:items).once.
|
201
|
+
and_return([['Joe D. User', 'joey jdu'],['Jane P. User', 'janey jpu']])
|
202
|
+
@connection.should_receive(:send).twice.and_return(@fields_resp, @find_resp)
|
203
|
+
@session = Session.start('my.goodhost.com', ['name', 'nickname'])
|
204
|
+
@profiles = @session.find("User")
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should return a 2 item array of profiles" do
|
208
|
+
@profiles.length.should == 2
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should return Jane's profile as the second item" do
|
212
|
+
@profiles[1].should equal(@jane)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe Session, "performing an bad single find" do
|
217
|
+
|
218
|
+
it_should_behave_like "mock items for a started session"
|
219
|
+
|
220
|
+
before(:each) do
|
221
|
+
@find_resp = flexmock(Response)
|
222
|
+
@find_resp.should_receive(:ok?).once.and_return(true)
|
223
|
+
@find_resp.should_receive(:items).once.and_return([])
|
224
|
+
@connection.should_receive(:send).twice.and_return(@fields_resp, @find_resp)
|
225
|
+
@session = Session.start('my.goodhost.com', ['name', 'nickname'])
|
226
|
+
@profile = @session.find("Nothing", :one)
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should return nil for the profile object" do
|
230
|
+
@profile.should be_nil
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe Session, "performing a good single find" do
|
235
|
+
|
236
|
+
it_should_behave_like "mock items for a started session"
|
237
|
+
|
238
|
+
before(:each) do
|
239
|
+
@find_resp = flexmock(Response)
|
240
|
+
@find_resp.should_receive(:ok?).once.and_return(true)
|
241
|
+
@find_resp.should_receive(:items).twice.and_return([['Joe D. User', 'joey jdu']])
|
242
|
+
@joe = flexmock("Joe's Profile")
|
243
|
+
flexmock(Profile).should_receive(:new).once.and_return(@joe)
|
244
|
+
@connection.should_receive(:send).twice.and_return(@fields_resp, @find_resp)
|
245
|
+
@session = Session.start('my.goodhost.com', ['name', 'nickname'])
|
246
|
+
@profile = @session.find("Joe User", :one)
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should return Joe's profile" do
|
250
|
+
@profile.should equal(@joe)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
end ; end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'net/dnd/user_spec'
|
3
|
+
|
4
|
+
module Net ; module DND
|
5
|
+
|
6
|
+
describe UserSpec, "- with a normal (i.e. name) specifier" do
|
7
|
+
before :each do
|
8
|
+
@name = "Joe D. User"
|
9
|
+
@spec = UserSpec.new @name
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should report a specifier type of :name" do
|
13
|
+
@spec.type.should == :name
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return just the supplied specifier when coerced to a string" do
|
17
|
+
@spec.to_s.should == @name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe UserSpec, "- with a UID specifier" do
|
22
|
+
before :each do
|
23
|
+
@uid = "123456"
|
24
|
+
@spec = UserSpec.new @uid
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should report a specifier type of :uid" do
|
28
|
+
@spec.type.should == :uid
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return the specifier, with leading \"#\", when coerced to a string" do
|
32
|
+
@spec.to_s.should == "##{@uid}"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return the correct inspection string" do
|
36
|
+
@spec.inspect.should match(/<Net::DND::UserSpec specifier="\d+" type=\:.+>/)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe UserSpec, "- a standard DID specifier" do
|
41
|
+
before :each do
|
42
|
+
@did = "12345A"
|
43
|
+
@spec = UserSpec.new @did
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should report a specifier type of :did" do
|
47
|
+
@spec.type.should == :did
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return the specifier, with leading \"#*\", when coerced to a string" do
|
51
|
+
@spec.to_s.should == "#*#{@did}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe UserSpec, "- with a non-standard DID specifier" do
|
56
|
+
before :each do
|
57
|
+
@did = "Z12345"
|
58
|
+
@spec = UserSpec.new @did
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should report a specifier type of :did" do
|
62
|
+
@spec.type.should == :did
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return the specifier, with leading \"#*\", when coerced to a string" do
|
66
|
+
@spec.to_s.should == "#*#{@did}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end ; end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
+
require 'rubygems'
|
3
|
+
require 'spec'
|
4
|
+
|
5
|
+
Spec::Runner.configure do |config|
|
6
|
+
# == Mock Framework
|
7
|
+
#
|
8
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
9
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
10
|
+
#
|
11
|
+
# config.mock_with :mocha
|
12
|
+
config.mock_with :flexmock
|
13
|
+
# config.mock_with :rr
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: net-dnd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 1.1.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Brian V. Hughes
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-22 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
- 10
|
33
|
+
version: 1.0.10
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 27
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 5
|
48
|
+
- 0
|
49
|
+
version: 2.5.0
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
description: Ruby library for DND lookups.
|
53
|
+
email:
|
54
|
+
- brianvh@dartmouth.edu
|
55
|
+
executables:
|
56
|
+
- dndwho
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bin/dndwho
|
68
|
+
- lib/net/dnd.rb
|
69
|
+
- lib/net/dnd/connection.rb
|
70
|
+
- lib/net/dnd/errors.rb
|
71
|
+
- lib/net/dnd/expires.rb
|
72
|
+
- lib/net/dnd/field.rb
|
73
|
+
- lib/net/dnd/profile.rb
|
74
|
+
- lib/net/dnd/response.rb
|
75
|
+
- lib/net/dnd/session.rb
|
76
|
+
- lib/net/dnd/user_spec.rb
|
77
|
+
- lib/net/dnd/version.rb
|
78
|
+
- net-dnd.gemspec
|
79
|
+
- spec/dnd/connection_spec.rb
|
80
|
+
- spec/dnd/field_spec.rb
|
81
|
+
- spec/dnd/profile_spec.rb
|
82
|
+
- spec/dnd/response_spec.rb
|
83
|
+
- spec/dnd/session_spec.rb
|
84
|
+
- spec/dnd/user_spec_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
homepage: https://github.com/brianvh/net-dnd/
|
87
|
+
licenses: []
|
88
|
+
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 21
|
109
|
+
segments:
|
110
|
+
- 1
|
111
|
+
- 3
|
112
|
+
- 7
|
113
|
+
version: 1.3.7
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project: net-dnd
|
117
|
+
rubygems_version: 1.7.2
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: net-dnd-1.1.2
|
121
|
+
test_files:
|
122
|
+
- spec/dnd/connection_spec.rb
|
123
|
+
- spec/dnd/field_spec.rb
|
124
|
+
- spec/dnd/profile_spec.rb
|
125
|
+
- spec/dnd/response_spec.rb
|
126
|
+
- spec/dnd/session_spec.rb
|
127
|
+
- spec/dnd/user_spec_spec.rb
|
128
|
+
- spec/spec_helper.rb
|