Skip to content

Commit

Permalink
specs
Browse files Browse the repository at this point in the history
  • Loading branch information
raphink committed Jan 7, 2020
1 parent a3f307c commit bbed0b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ def ensure_module_defined(module_name)
last_module.const_set(next_module, Module.new) unless last_module.const_defined?(next_module, false)
last_module.const_get(next_module, false)
end

c.mock_with :rspec
c.before :each do
# Ensure that we don't accidentally cache facts and environment between
# test cases. This requires each example group to explicitly load the
# facts being exercised with something like
# Facter.collection.loader.load(:ipaddress)
Facter.clear
Facter.clear_messages

RSpec::Mocks.setup
end

c.after :each do
RSpec::Mocks.verify
RSpec::Mocks.teardown
end
end

# 'spec_overrides' from sync.yml will appear below this line
11 changes: 11 additions & 0 deletions spec/unit/puppet/provider/loginctl_user/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
}
end

context 'when listing instances' do
it 'should find all entries' do
allow(provider_class).to receive(:loginctl).with('list-users', '--no-legend').and_return("0 root\n42 foo\n314 bar\n")
allow(provider_class).to receive(:loginctl).with('show-user', '-p', 'Name', '-p', 'Linger', 'root', 'foo', 'bar').and_return("Name=root\nLinger=no\n\nName=foo\nLinger=yes\n\nName=bar\nLinger=no\n")
inst = provider_class.instances.map do |p|
end

inst.size.is_expected.to eq(3)
end
end

context 'when enabling linger' do
it 'should enable linger' do
resource = Puppet::Type::LoginctlUser.new(common_params)
Expand Down

0 comments on commit bbed0b8

Please sign in to comment.