Skip to content

Commit

Permalink
Correct file mocks in tests
Browse files Browse the repository at this point in the history
In 7285844 the method was changed from
File.open to File.write, but the mocks weren't modified. This changes
from allow to expect so that if it's refactored, it will fail the tests.

Fixes: 7285844 ("Auto-correct rubocop offenses")
  • Loading branch information
ekohl committed May 22, 2024
1 parent 3a27035 commit aeb88ae
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions spec/unit/puppet/provider/ssl_pkey/openssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
context 'when creating a key with defaults' do
it 'creates an rsa key' do
allow(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_return(key)
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end

context 'when setting size' do
it 'creates with given size' do
resource[:size] = 1024
allow(OpenSSL::PKey::RSA).to receive(:new).with(1024).and_return(key)
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
end
Expand All @@ -43,7 +43,7 @@
resource[:password] = '2x$5{'
allow(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_return(key)
allow(OpenSSL::Cipher).to receive(:new).with('des3')
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
end
Expand All @@ -53,7 +53,7 @@
it 'creates a dsa key' do
resource[:authentication] = :rsa
allow(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_return(key)
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end

Expand All @@ -62,7 +62,7 @@
resource[:authentication] = :rsa
resource[:size] = 1024
allow(OpenSSL::PKey::RSA).to receive(:new).with(1024).and_return(key)
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
end
Expand All @@ -73,7 +73,7 @@
resource[:password] = '2x$5{'
allow(OpenSSL::PKey::RSA).to receive(:new).with(2048).and_return(key)
allow(OpenSSL::Cipher).to receive(:new).with('des3')
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
end
Expand All @@ -83,7 +83,7 @@
it 'creates a dsa key' do
resource[:authentication] = :dsa
allow(OpenSSL::PKey::DSA).to receive(:new).with(2048).and_return(key)
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end

Expand All @@ -92,7 +92,7 @@
resource[:authentication] = :dsa
resource[:size] = 1024
allow(OpenSSL::PKey::DSA).to receive(:new).with(1024).and_return(key)
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
end
Expand All @@ -103,7 +103,7 @@
resource[:password] = '2x$5{'
allow(OpenSSL::PKey::DSA).to receive(:new).with(2048).and_return(key)
allow(OpenSSL::Cipher).to receive(:new).with('des3')
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
end
Expand All @@ -115,7 +115,7 @@
it 'creates an ec key' do
resource[:authentication] = :ec
allow(OpenSSL::PKey::EC).to receive(:new).with('secp384r1').and_return(key)
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end

Expand All @@ -124,7 +124,7 @@
resource[:authentication] = :ec
resource[:curve] = 'prime239v1'
allow(OpenSSL::PKey::EC).to receive(:new).with('prime239v1').and_return(key)
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
end
Expand All @@ -135,7 +135,7 @@
resource[:password] = '2x$5{'
allow(OpenSSL::PKey::EC).to receive(:new).with('secp384r1').and_return(key)
allow(OpenSSL::Cipher).to receive(:new).with('des3')
allow(File).to receive(:open).with('/tmp/foo.key', 'w')
expect(File).to receive(:write).with('/tmp/foo.key', kind_of(String))
resource.provider.create
end
end
Expand Down

0 comments on commit aeb88ae

Please sign in to comment.