Skip to content

Commit 8843e24

Browse files
committed
(maint) Switch to rspec-mocks
1 parent 1487c20 commit 8843e24

File tree

9 files changed

+32
-32
lines changed

9 files changed

+32
-32
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Style/SymbolArray:
7777
EnforcedStyle: brackets
7878
RSpec/NamedSubject:
7979
Enabled: false
80+
RSpec/SubjectStub:
81+
Enabled: false
8082
Style/Documentation:
8183
Exclude:
8284
- lib/puppet/parser/functions/**/*

spec/integration/provider/ssh_authorized_key_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
end
5050

5151
before :each do
52-
File.stubs(:chown)
53-
File.stubs(:chmod)
54-
Puppet::Util::SUIDManager.stubs(:asuser).yields
52+
allow(File).to receive(:chown)
53+
allow(File).to receive(:chmod)
54+
allow(Puppet::Util::SUIDManager).to receive(:asuser).and_yield
5555
end
5656

5757
after :each do
@@ -74,18 +74,18 @@ def check_fake_key(username, expected_content)
7474
end
7575

7676
def run_in_catalog(*resources)
77-
Puppet::FileBucket::Dipper.any_instance.stubs(:backup) # rubocop:disable RSpec/AnyInstance
77+
allow_any_instance_of(Puppet::FileBucket::Dipper).to receive(:backup) # rubocop:disable RSpec/AnyInstance
7878
catalog = Puppet::Resource::Catalog.new
7979
catalog.host_config = false
8080
resources.each do |resource|
81-
resource.expects(:err).never
81+
expect(resource).not_to receive(:err)
8282
catalog.add_resource(resource)
8383
end
8484
catalog.apply
8585
end
8686

8787
it 'does not complain about empty lines and comments' do
88-
described_class.expects(:flush).never
88+
expect(described_class).not_to receive(:flush)
8989
sample = ['', sample_lines[0], ' ', sample_lines[1], '# just a comment', '#and another']
9090
create_fake_key(:user, sample)
9191
run_in_catalog(dummy)

spec/integration/provider/sshkey_spec.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212

1313
before :each do
1414
# Don't backup to filebucket
15-
Puppet::FileBucket::Dipper.any_instance.stubs(:backup) # rubocop:disable RSpec/AnyInstance
15+
allow_any_instance_of(Puppet::FileBucket::Dipper).to receive(:backup) # rubocop:disable RSpec/AnyInstance
1616
# We don't want to execute anything
17-
described_class.stubs(:filetype)
18-
.returns Puppet::Util::FileType::FileTypeFlat
17+
allow(described_class).to receive(:filetype).and_return Puppet::Util::FileType::FileTypeFlat
1918

2019
FileUtils.cp(my_fixture('sample'), sshkey_file)
2120
end
@@ -188,11 +187,9 @@
188187
it 'fetches an entry from resources' do
189188
resource_app = Puppet::Application[:resource]
190189
resource_app.preinit
191-
resource_app.command_line
192-
.stubs(:args)
193-
.returns([type_under_test, sshkey_name, "target=#{sshkey_file}"])
190+
allow(resource_app.command_line).to receive(:args).and_return([type_under_test, sshkey_name, "target=#{sshkey_file}"])
194191

195-
resource_app.expects(:puts).with do |args|
192+
expect(resource_app).to receive(:puts) do |args|
196193
expect(args).to match(%r{#{sshkey_name}})
197194
end
198195
resource_app.main

spec/lib/puppet_spec/compiler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def apply_compiled_manifest(manifest, prioritizer = Puppet::Graph::SequentialPri
4848

4949
def apply_with_error_check(manifest)
5050
apply_compiled_manifest(manifest) do |res|
51-
res.expects(:err).never
51+
expect(res).to receive(:err).never
5252
end
5353
end
5454

spec/lib/puppet_spec/files.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def self.cleanup
1111
until @global_tempfiles.empty?
1212
path = @global_tempfiles.pop
1313
begin
14-
Dir.unstub(:entries)
14+
allow(Dir).to receive(:entries).and_call_original
1515
FileUtils.rm_rf path, secure: true
1616
rescue Errno::ENOENT # rubocop:disable Lint/HandleExceptions
1717
# nothing to do

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
end
3232

3333
RSpec.configure do |c|
34+
c.mock_with :rspec
3435
c.default_facts = default_facts
3536
c.before :each do
3637
# set to strictest setting for testing

spec/unit/provider/sshkey/parsed_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def key
4242
['sample', 'sample_with_blank_lines'].each do |sample_file|
4343
let(:fixture) { my_fixture(sample_file) }
4444

45-
before(:each) { subject.stubs(:default_target).returns(fixture) }
45+
before(:each) { allow(subject).to receive(:default_target).and_return(fixture) }
4646

4747
it 'parses to records on prefetch' do
4848
expect(subject.target_records(fixture)).to be_empty
@@ -72,22 +72,22 @@ def key
7272
context 'default ssh_known_hosts target path' do
7373
['9.10', '9.11', '10.10'].each do |version|
7474
it 'is `/etc/ssh_known_hosts` when OSX version 10.10 or older`' do
75-
Facter.expects(:value).with(:operatingsystem).returns('Darwin')
76-
Facter.expects(:value).with(:macosx_productversion_major).returns(version)
75+
expect(Facter).to receive(:value).with(:operatingsystem).and_return('Darwin')
76+
expect(Facter).to receive(:value).with(:macosx_productversion_major).and_return(version)
7777
expect(subject.default_target).to eq('/etc/ssh_known_hosts')
7878
end
7979
end
8080

8181
['10.11', '10.13', '11.0', '11.11'].each do |version|
8282
it 'is `/etc/ssh/ssh_known_hosts` when OSX version 10.11 or newer`' do
83-
Facter.expects(:value).with(:operatingsystem).returns('Darwin')
84-
Facter.expects(:value).with(:macosx_productversion_major).returns(version)
83+
expect(Facter).to receive(:value).with(:operatingsystem).and_return('Darwin')
84+
expect(Facter).to receive(:value).with(:macosx_productversion_major).and_return(version)
8585
expect(subject.default_target).to eq('/etc/ssh/ssh_known_hosts')
8686
end
8787
end
8888

8989
it 'is `/etc/ssh/ssh_known_hosts` on other operating systems' do
90-
Facter.expects(:value).with(:operatingsystem).returns('RedHat')
90+
expect(Facter).to receive(:value).with(:operatingsystem).and_return('RedHat')
9191
expect(subject.default_target).to eq('/etc/ssh/ssh_known_hosts')
9292
end
9393
end

spec/unit/type/ssh_authorized_key_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
include PuppetSpec::Files
55

66
before(:each) do
7-
provider_class = stub 'provider_class', name: 'fake', suitable?: true, supports_parameter?: true
8-
described_class.stubs(:defaultprovider).returns(provider_class)
9-
described_class.stubs(:provider).returns(provider_class)
7+
provider_class = class_double('Puppet::Provider::SshAuthorizedKey', name: 'fake', suitable?: true, supports_parameter?: true)
8+
allow(described_class).to receive(:defaultprovider).and_return(provider_class)
9+
allow(described_class).to receive(:provider).and_return(provider_class)
1010

11-
provider = stub 'provider', class: provider_class, file_path: make_absolute('/tmp/whatever'), clear: nil
12-
provider_class.stubs(:new).returns(provider)
11+
provider = instance_double('Puppet::Provider::SshAuthorizedKey', class: provider_class, file_path: make_absolute('/tmp/whatever'), clear: nil)
12+
allow(provider_class).to receive(:new).and_return(provider)
1313
end
1414

1515
it 'has :name as its namevar' do

spec/unit/type/user_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def self.instances
2525
end
2626

2727
before :each do
28-
described_class.stubs(:defaultprovider).returns provider_class
28+
allow(described_class).to receive(:defaultprovider).and_return provider_class
2929
end
3030

3131
describe 'when purging ssh keys' do
@@ -58,7 +58,7 @@ def self.instances
5858
if Puppet.version.start_with?('6')
5959
context 'with no home directory specified' do
6060
before(:each) do
61-
Dir.stubs(:home).with('a').returns('/home/a')
61+
allow(Dir).to receive(:home).with('a').and_return('/home/a')
6262
end
6363

6464
it 'does accept true' do
@@ -83,21 +83,21 @@ def self.instances
8383
end
8484

8585
before(:each) do
86-
Dir.stubs(:home).with('test').returns('/home/test')
86+
allow(Dir).to receive(:home).with('test').and_return('/home/test')
8787
end
8888

8989
let(:paths) do
9090
['/dev/null', '/tmp/keyfile'].map { |path| File.expand_path(path) }
9191
end
9292

9393
it 'does not just return from generate' do
94-
subject.expects :find_unmanaged_keys
94+
expect(subject).to receive(:find_unmanaged_keys)
9595
subject.generate
9696
end
9797

9898
it 'checks each keyfile for readability' do
9999
paths.each do |path|
100-
File.expects(:readable?).with(path)
100+
expect(File).to receive(:readable?).with(path)
101101
end
102102
subject.generate
103103
end
@@ -111,7 +111,7 @@ def self.instances
111111
end
112112

113113
before(:each) do
114-
Dir.stubs(:home).with('test_user_name').returns('/home/test_user_name')
114+
allow(Dir).to receive(:home).with('test_user_name').and_return('/home/test_user_name')
115115
end
116116

117117
context 'when purging is disabled' do

0 commit comments

Comments
 (0)