diff options
author | Jacob Helwig <jacob@technosorcery.net> | 2018-06-25 08:27:03 -0700 |
---|---|---|
committer | Jacob Helwig <jacob@technosorcery.net> | 2018-06-25 08:27:03 -0700 |
commit | 4345a09778021c45f92758d8b13b128c7c4732b1 (patch) | |
tree | a2f2338dcd8de9c78e70b749d71f1604a0b2aefe | |
parent | 5cd5a464c6d86c475aeb5309f102fecce8044bda (diff) | |
download | puppet-sshkeys_core-4345a09778021c45f92758d8b13b128c7c4732b1.tar.gz puppet-sshkeys_core-4345a09778021c45f92758d8b13b128c7c4732b1.tar.bz2 |
Remove Rubocop RSpec/InstanceVariable violations
-rw-r--r-- | spec/integration/provider/sshkey_spec.rb | 51 | ||||
-rw-r--r-- | spec/unit/type/ssh_authorized_key_spec.rb | 7 |
2 files changed, 31 insertions, 27 deletions
diff --git a/spec/integration/provider/sshkey_spec.rb b/spec/integration/provider/sshkey_spec.rb index ee74193..47af892 100644 --- a/spec/integration/provider/sshkey_spec.rb +++ b/spec/integration/provider/sshkey_spec.rb @@ -8,6 +8,8 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', include PuppetSpec::Files include PuppetSpec::Compiler + let(:sshkey_file) { tmpfile('sshkey_integration_specs') } + before :each do # Don't backup to filebucket Puppet::FileBucket::Dipper.any_instance.stubs(:backup) @@ -15,8 +17,7 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', described_class.stubs(:filetype) .returns Puppet::Util::FileType::FileTypeFlat - @sshkey_file = tmpfile('sshkey_integration_specs') - FileUtils.cp(my_fixture('sample'), @sshkey_file) + FileUtils.cp(my_fixture('sample'), sshkey_file) end after :each do @@ -44,18 +45,18 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', ensure => 'present', type => 'rsa', key => 'mykey', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(%r{#{super_unique}.*mykey}) + expect(File.read(sshkey_file)).to match(%r{#{super_unique}.*mykey}) end let(:sshkey_name) { 'kirby.madstop.com' } it 'deletes an entry for an SSH host key' do manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'absent', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) + expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) end it 'updates an entry for an SSH host key' do @@ -63,10 +64,10 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', ensure => 'present', type => 'rsa', key => 'mynewshinykey', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(%r{#{sshkey_name}.*mynewshinykey}) - expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) + expect(File.read(sshkey_file)).to match(%r{#{sshkey_name}.*mynewshinykey}) + expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}.*Yqk0=}) end # test all key types @@ -87,15 +88,15 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', ensure => 'present', type => '#{type}', key => 'mynewshinykey', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) if aliases.key?(type) full_type = aliases[type] - expect(File.read(@sshkey_file)) + expect(File.read(sshkey_file)) .to match(%r{#{sshkey_name}.*#{full_type}.*mynew}) else - expect(File.read(@sshkey_file)) + expect(File.read(sshkey_file)) .to match(%r{#{sshkey_name}.*#{type}.*mynew}) end end @@ -108,7 +109,7 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', ensure => 'present', type => '#{invalid_type}', key => 'mynewshinykey', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" expect { apply_compiled_manifest(manifest) }.to raise_error(Puppet::ResourceError, %r{Invalid value "#{invalid_type}"}) @@ -120,10 +121,10 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'present', host_aliases => '#{host_alias}', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) - expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}\s}) + expect(File.read(sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) + expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}\s}) end # array host_alias @@ -133,23 +134,23 @@ describe Puppet::Type.type(:sshkey).provider(:parsed), '(integration)', manifest = "#{type_under_test} { '#{sshkey_name}': ensure => 'present', host_aliases => '#{host_alias}', - target => '#{@sshkey_file}' }" + target => '#{sshkey_file}' }" apply_with_error_check(manifest) - expect(File.read(@sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) - expect(File.read(@sshkey_file)).not_to match(%r{#{sshkey_name}\s}) + expect(File.read(sshkey_file)).to match(%r{#{sshkey_name},#{host_alias}\s}) + expect(File.read(sshkey_file)).not_to match(%r{#{sshkey_name}\s}) end # puppet resource sshkey it 'fetches an entry from resources' do - @resource_app = Puppet::Application[:resource] - @resource_app.preinit - @resource_app.command_line.stubs(:args) - .returns([type_under_test, sshkey_name, "target=#{@sshkey_file}"]) + resource_app = Puppet::Application[:resource] + resource_app.preinit + resource_app.command_line.stubs(:args) + .returns([type_under_test, sshkey_name, "target=#{sshkey_file}"]) - @resource_app.expects(:puts).with do |args| + resource_app.expects(:puts).with do |args| expect(args).to match(%r{#{sshkey_name}}) end - @resource_app.main + resource_app.main end end end diff --git a/spec/unit/type/ssh_authorized_key_spec.rb b/spec/unit/type/ssh_authorized_key_spec.rb index 845cf46..ea32af9 100644 --- a/spec/unit/type/ssh_authorized_key_spec.rb +++ b/spec/unit/type/ssh_authorized_key_spec.rb @@ -169,8 +169,11 @@ describe Puppet::Type.type(:ssh_authorized_key), unless: Puppet.features.microso it 'informs about an absent user' do Puppet::Log.level = :debug - described_class.new(name: 'whev', user: 'idontexist').should(:target) - expect(@logs.map(&:message)).to include('The required user is not yet present on the system') + logs = [] + Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do + described_class.new(name: 'whev', user: 'idontexist').should(:target) + end + expect(logs.map(&:message)).to include('The required user is not yet present on the system') end end end |