sys-admin 1.8.0 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ###############################################################################
2
4
  # sys_admin_unix_rspec.rb
3
5
  #
4
6
  # Test suite for the Unix version of sys-admin. This test should be run
5
7
  # via the 'rake spec' task.
6
8
  ###############################################################################
7
- require 'rspec'
8
- require 'sys/admin'
9
+ require 'spec_helper'
9
10
 
10
11
  RSpec.describe Sys::Admin, :unix do
11
12
  let(:user) { 'nobody' }
@@ -13,237 +14,239 @@ RSpec.describe Sys::Admin, :unix do
13
14
  let(:group) { 'sys' }
14
15
  let(:group_id) { 3 }
15
16
 
16
- context "singleton methods" do
17
- describe "get_login" do
18
- example "get_login basic functionality" do
17
+ context 'singleton methods' do
18
+ describe 'get_login' do
19
+ example 'get_login basic functionality' do
19
20
  expect(described_class).to respond_to(:get_login)
20
21
  expect{ described_class.get_login }.not_to raise_error
21
22
  end
22
23
 
23
- example "get_login returns a string" do
24
+ example 'get_login returns a string' do
24
25
  expect(described_class.get_login).to be_kind_of(String)
25
26
  expect(described_class.get_login.length).to be > 0
26
27
  end
27
28
  end
28
29
 
29
- describe "get_user" do
30
- example "get_user basic functionality" do
30
+ describe 'get_user' do
31
+ example 'get_user basic functionality' do
31
32
  expect(described_class).to respond_to(:get_user)
32
33
  expect{ described_class.get_user(user) }.not_to raise_error
33
34
  expect{ described_class.get_user(user_id) }.not_to raise_error
34
35
  end
35
36
 
36
- example "get_user with a string argument works as expected" do
37
+ example 'get_user with a string argument works as expected' do
37
38
  expect(described_class.get_user(user)).to be_kind_of(Sys::Admin::User)
38
39
  end
39
40
 
40
- example "get_user with an integer argument works as expected" do
41
+ example 'get_user with an integer argument works as expected' do
41
42
  expect(described_class.get_user(user_id)).to be_kind_of(Sys::Admin::User)
42
43
  end
43
44
 
44
- example "get_user requires one argument only" do
45
+ example 'get_user requires at least one argument' do
45
46
  expect{ described_class.get_user }.to raise_error(ArgumentError)
46
- expect{ described_class.get_user(user, user) }.to raise_error(ArgumentError)
47
47
  end
48
48
 
49
- example "get_user requires a string or integer argument" do
49
+ example 'get_user requires a string or integer argument' do
50
50
  expect{ described_class.get_user([]) }.to raise_error(TypeError)
51
51
  end
52
52
 
53
- example "get_user raises an Error if the user cannot be found" do
53
+ example 'get_user raises an Error if the user cannot be found' do
54
54
  expect{ described_class.get_user('foofoofoo') }.to raise_error(Sys::Admin::Error)
55
55
  end
56
56
  end
57
57
 
58
- describe "users" do
59
- example "users basic functionality" do
58
+ describe 'users' do
59
+ example 'users basic functionality' do
60
60
  expect(described_class).to respond_to(:users)
61
61
  expect{ described_class.users }.not_to raise_error
62
62
  end
63
63
 
64
- example "users returns an array of User objects" do
64
+ example 'users returns an array of User objects' do
65
65
  users = described_class.users
66
66
  expect(users).to be_kind_of(Array)
67
67
  expect(users).to all(be_kind_of(Sys::Admin::User))
68
68
  end
69
69
 
70
- example "users does not accept any arguments" do
71
- expect{ described_class.users(user_id) }.to raise_error(ArgumentError)
70
+ example 'users accepts an optional lastlog argument on darwin', :darwin => true do
71
+ users = described_class.users(:lastlog => false)
72
+ expect(users).to be_kind_of(Array)
73
+ expect(users).to all(be_kind_of(Sys::Admin::User))
74
+ expect(users.first.login_time).to be_nil
72
75
  end
73
76
  end
74
77
 
75
- describe "get_group" do
76
- example "get_group basic functionality" do
78
+ describe 'get_group' do
79
+ example 'get_group basic functionality' do
77
80
  expect(described_class).to respond_to(:get_group)
78
81
  expect{ described_class.get_group(group) }.not_to raise_error
79
82
  expect{ described_class.get_group(group_id) }.not_to raise_error
80
83
  end
81
84
 
82
- example "get_group accepts a string argument" do
85
+ example 'get_group accepts a string argument' do
83
86
  expect(described_class.get_group(group)).to be_kind_of(Sys::Admin::Group)
84
87
  end
85
88
 
86
- example "get_group accepts an integer argument" do
89
+ example 'get_group accepts an integer argument' do
87
90
  expect(described_class.get_group(group_id)).to be_kind_of(Sys::Admin::Group)
88
91
  end
89
92
 
90
- example "get_group requires one argument only" do
93
+ example 'get_group requires one argument only' do
91
94
  expect{ described_class.get_group }.to raise_error(ArgumentError)
92
95
  expect{ described_class.get_group(group_id, group_id) }.to raise_error(ArgumentError)
93
96
  end
94
97
 
95
- example "get_group raises a TypeError if an invalid type is passed" do
98
+ example 'get_group raises a TypeError if an invalid type is passed' do
96
99
  expect{ described_class.get_group([]) }.to raise_error(TypeError)
97
100
  end
98
101
 
99
- example "get_group raises an Error if the group cannot be found" do
102
+ example 'get_group raises an Error if the group cannot be found' do
100
103
  expect{ described_class.get_group('foofoofoo') }.to raise_error(Sys::Admin::Error)
101
104
  end
102
105
  end
103
106
 
104
- describe "groups" do
105
- example "groups basic functionality" do
107
+ describe 'groups' do
108
+ example 'groups basic functionality' do
106
109
  expect(described_class).to respond_to(:groups)
107
110
  expect{ described_class.groups }.not_to raise_error
108
111
  end
109
112
 
110
- example "groups returns an array of Group objects" do
113
+ example 'groups returns an array of Group objects' do
111
114
  groups = described_class.groups
112
115
  expect(groups).to be_kind_of(Array)
113
116
  expect(groups).to all(be_kind_of(Sys::Admin::Group))
114
117
  end
115
118
 
116
- example "groups method does not accept any arguments" do
119
+ example 'groups method does not accept any arguments' do
117
120
  expect{ described_class.groups(group_id) }.to raise_error(ArgumentError)
118
121
  end
119
122
  end
120
123
  end
121
124
 
122
- context "instance methods" do
123
- describe "User instance methods" do
124
- example "user.name behaves as expected" do
125
+ context 'instance methods' do
126
+ describe 'User instance methods' do
127
+ example 'user.name behaves as expected' do
125
128
  user = described_class.get_user(user_id)
126
129
  expect(user).to respond_to(:name)
127
130
  expect(user.name).to be_kind_of(String)
128
131
  end
129
132
 
130
- example "user.passwd behaves as expected" do
133
+ example 'user.passwd behaves as expected' do
131
134
  user = described_class.get_user(user_id)
132
135
  expect(user).to respond_to(:passwd)
133
136
  expect(user.passwd).to be_kind_of(String)
134
137
  end
135
138
 
136
- example "user.uid behaves as expected" do
139
+ example 'user.uid behaves as expected' do
137
140
  user = described_class.get_user(user_id)
138
141
  expect(user).to respond_to(:uid)
139
142
  expect(user.uid).to be_kind_of(Integer)
140
143
  end
141
144
 
142
- example "user.gid behaves as expected" do
145
+ example 'user.gid behaves as expected' do
143
146
  user = described_class.get_user(user_id)
144
147
  expect(user).to respond_to(:gid)
145
148
  expect(user.gid).to be_kind_of(Integer)
146
149
  end
147
150
 
148
- example "user.dir behaves as expected" do
151
+ example 'user.dir behaves as expected' do
149
152
  user = described_class.get_user(user_id)
150
153
  expect(user).to respond_to(:dir)
151
154
  expect(user.dir).to be_kind_of(String)
152
155
  end
153
156
 
154
- example "user.shell behaves as expected" do
157
+ example 'user.shell behaves as expected' do
155
158
  user = described_class.get_user(user_id)
156
159
  expect(user).to respond_to(:shell)
157
160
  expect(user.shell).to be_kind_of(String)
158
161
  end
159
162
 
160
- example "user.gecos behaves as expected" do
163
+ example 'user.gecos behaves as expected' do
161
164
  user = described_class.get_user(user_id)
162
165
  expect(user).to respond_to(:gecos)
163
166
  expect(user.gecos).to be_kind_of(String).or be_nil
164
167
  end
165
168
 
166
- example "user.quota behaves as expected" do
169
+ example 'user.quota behaves as expected' do
167
170
  user = described_class.get_user(user_id)
168
171
  expect(user).to respond_to(:quota)
169
172
  expect(user.quota).to be_kind_of(Integer).or be_nil
170
173
  end
171
174
 
172
- example "user.age behaves as expected" do
175
+ example 'user.age behaves as expected' do
173
176
  user = described_class.get_user(user_id)
174
177
  expect(user).to respond_to(:age)
175
178
  expect(user.age).to be_kind_of(Integer).or be_nil
176
179
  end
177
180
 
178
- example "user.access behaves as expected" do
181
+ example 'user.access behaves as expected' do
179
182
  user = described_class.get_user(user_id)
180
183
  expect(user).to respond_to(:access_class)
181
184
  expect(user.access_class).to be_kind_of(String).or be_nil
182
185
  end
183
186
 
184
- example "user.comment behaves as expected" do
187
+ example 'user.comment behaves as expected' do
185
188
  user = described_class.get_user(user_id)
186
189
  expect(user).to respond_to(:comment)
187
190
  expect(user.comment).to be_kind_of(String).or be_nil
188
191
  end
189
192
 
190
- example "user.expire behaves as expected" do
193
+ example 'user.expire behaves as expected' do
191
194
  user = described_class.get_user(user_id)
192
195
  expect(user).to respond_to(:expire)
193
196
  expect(user.expire).to be_kind_of(Time).or be_nil
194
197
  end
195
198
 
196
- example "user.change behaves as expected" do
199
+ example 'user.change behaves as expected' do
197
200
  user = described_class.get_user(user_id)
198
201
  expect(user).to respond_to(:change)
199
202
  expect(user.change).to be_kind_of(Time).or be_nil
200
203
  end
201
204
 
202
- example "user.login_time behaves as expected" do
205
+ example 'user.login_time behaves as expected' do
203
206
  user = described_class.get_user(user_id)
204
207
  expect(user).to respond_to(:login_time)
205
208
  expect(user.login_time).to be_kind_of(Time).or be_nil
206
209
  end
207
210
 
208
- example "user.login_device behaves as expected" do
211
+ example 'user.login_device behaves as expected' do
209
212
  user = described_class.get_user(user_id)
210
213
  expect(user).to respond_to(:login_device)
211
214
  expect(user.login_device).to be_kind_of(String).or be_nil
212
215
  end
213
216
 
214
- example "user.login_host behaves as expected" do
217
+ example 'user.login_host behaves as expected' do
215
218
  user = described_class.get_user(user_id)
216
219
  expect(user).to respond_to(:login_host)
217
220
  expect(user.login_host).to be_kind_of(String).or be_nil
218
221
  end
219
222
 
220
- example "user.groups behaves as expected" do
223
+ example 'user.groups behaves as expected' do
221
224
  user = described_class.get_user(user_id)
222
225
  expect(user).to respond_to(:groups)
223
226
  expect(user.groups).to be_kind_of(Array)
224
227
  end
225
228
  end
226
229
 
227
- describe "Group instance methods" do
228
- example "group.name behaves as expected" do
230
+ describe 'Group instance methods' do
231
+ example 'group.name behaves as expected' do
229
232
  group = described_class.get_group(group_id)
230
233
  expect(group).to respond_to(:name)
231
234
  expect(group.name).to be_kind_of(String)
232
235
  end
233
236
 
234
- example "group.gid behaves as expected" do
237
+ example 'group.gid behaves as expected' do
235
238
  group = described_class.get_group(group_id)
236
239
  expect(group).to respond_to(:gid)
237
240
  expect(group.gid).to be_kind_of(Integer)
238
241
  end
239
242
 
240
- example "group.members behaves as expected" do
243
+ example 'group.members behaves as expected' do
241
244
  group = described_class.get_group(group_id)
242
245
  expect(group).to respond_to(:members)
243
246
  expect(group.members).to be_kind_of(Array)
244
247
  end
245
248
 
246
- example "group.passwd behaves as expected" do
249
+ example 'group.passwd behaves as expected' do
247
250
  group = described_class.get_group(group_id)
248
251
  expect(group).to respond_to(:passwd)
249
252
  expect(group.passwd).to be_kind_of(String)
@@ -251,8 +254,8 @@ RSpec.describe Sys::Admin, :unix do
251
254
  end
252
255
  end
253
256
 
254
- context "ffi functions" do
255
- example "ffi functions are private" do
257
+ context 'ffi functions' do
258
+ example 'ffi functions are private' do
256
259
  methods = described_class.methods(false).map(&:to_s)
257
260
  expect(methods).not_to include('getlogin')
258
261
  expect(methods).not_to include('getlogin_r')