Skip to content

Commit d3af1ba

Browse files
Merge pull request #30 from GabrielNagy/maint/update-user-tests
(maint) Update user type specs to match new behavior
2 parents 333b8a0 + e5abd58 commit d3af1ba

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

spec/unit/type/user_spec.rb

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ def self.instances
5555
end
5656
end
5757

58-
context 'with no home directory specified' do
59-
it 'does not accept true' do
60-
expect {
58+
if Puppet.version.start_with?('6')
59+
context 'with no home directory specified' do
60+
before(:each) do
61+
Dir.stubs(:home).with('a').returns('/home/a')
62+
end
63+
64+
it 'does accept true' do
6165
described_class.new(name: 'a', purge_ssh_keys: true)
62-
}.to raise_error(Puppet::Error, %r{purge_ssh_keys can only be true for users with a defined home directory})
63-
end
66+
end
6467

65-
it 'does not accept the ~ wildcard' do
66-
expect {
68+
it 'does accept the ~ wildcard' do
6769
described_class.new(name: 'a', purge_ssh_keys: '~/keys')
68-
}.to raise_error(Puppet::Error, %r{meta character ~ or %h only allowed for users with a defined home directory})
69-
end
70+
end
7071

71-
it 'does not accept the %h wildcard' do
72-
expect {
72+
it 'does accept the %h wildcard' do
7373
described_class.new(name: 'a', purge_ssh_keys: '%h/keys')
74-
}.to raise_error(Puppet::Error, %r{meta character ~ or %h only allowed for users with a defined home directory})
74+
end
7575
end
7676
end
7777

@@ -82,6 +82,10 @@ def self.instances
8282
res
8383
end
8484

85+
before(:each) do
86+
Dir.stubs(:home).with('test').returns('/home/test')
87+
end
88+
8589
let(:paths) do
8690
['/dev/null', '/tmp/keyfile'].map { |path| File.expand_path(path) }
8791
end
@@ -106,6 +110,10 @@ def self.instances
106110
res
107111
end
108112

113+
before(:each) do
114+
Dir.stubs(:home).with('test_user_name').returns('/home/test_user_name')
115+
end
116+
109117
context 'when purging is disabled' do
110118
let(:purge_param) { false }
111119

0 commit comments

Comments
 (0)