Skip to content

Commit

Permalink
Switch from mocha to rspec mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
silug committed Jun 18, 2024
1 parent 08b6d59 commit aa393f8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def set_hieradata(hieradata)
}

c.mock_framework = :rspec
c.mock_with :mocha
c.mock_with :rspec

c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests') if c.respond_to?(:manifest_dir)
Expand Down
14 changes: 7 additions & 7 deletions spec/unit/puppet/provider/incron_system_table/manage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
FileUtils.mkdir_p(File.join(@tmpdir, 'that', 'is', '2', 'test'))
FileUtils.mkdir_p(File.join(@tmpdir, 'other', 'is', '3', 'test'))

File.stubs(:read).with('/etc/incron.conf').
allow(File).to receive(:read).with('/etc/incron.conf').
returns("system_table_dir = #{@tmpdir}")

# Must be mocked, but does't really matter what it returns in these tests
Facter.stubs(:value).with(:incrond_version)
allow(Facter).to receive(:value).with(:incrond_version)
end

after(:each) do
Expand Down Expand Up @@ -51,8 +51,8 @@
context 'does exist' do
context 'does match' do
it do
File.stubs(:readable?).with(File.join(@tmpdir, resource_name)).returns(true)
File.stubs(:read).with(File.join(@tmpdir, resource_name)).
allow(File).to receive(:readable?).with(File.join(@tmpdir, resource_name)).and_return(true)
allow(File).to receive(:read).with(File.join(@tmpdir, resource_name)).
returns("#{path} #{mask} #{command}")

expect(provider.exists?).to be true
Expand All @@ -61,16 +61,16 @@

context 'is not readable' do
it do
File.stubs(:readable?).with(File.join(@tmpdir, resource_name)).returns(false)
allow(File).to receive(:readable?).with(File.join(@tmpdir, resource_name)).and_return(false)

expect(provider.exists?).to be false
end
end

context 'does not match' do
it do
File.stubs(:readable?).with(File.join(@tmpdir, resource_name)).returns(true)
File.stubs(:read).with(File.join(@tmpdir, resource_name)).
allow(File).to receive(:readable?).with(File.join(@tmpdir, resource_name)).and_return(true)
allow(File).to receive(:read).with(File.join(@tmpdir, resource_name)).
returns("#{path} #{mask} #{command} and stuff")

expect(provider.exists?).to be false
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/puppet/type/incron_system_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

context 'on a system with no incrond_version fact' do
it 'should strip out the new parameters' do
Facter.stubs(:value).with(:incrond_version).returns(nil)
allow(Facter).to receive(:value).with(:incrond_version).and_return(nil)

resource = incron_system_table_type.new(
:name => name,
Expand All @@ -94,7 +94,7 @@

context 'on a system with an older version of incrond' do
it 'should strip out the new parameters' do
Facter.stubs(:value).with(:incrond_version).returns('0.5.10')
allow(Facter).to receive(:value).with(:incrond_version).and_return('0.5.10')

resource = incron_system_table_type.new(
:name => name,
Expand All @@ -109,7 +109,7 @@

context 'on a system with 0.5.12' do
it 'should retain the new parameters' do
Facter.stubs(:value).with(:incrond_version).returns('0.5.12')
allow(Facter).to receive(:value).with(:incrond_version).and_return('0.5.12')

resource = incron_system_table_type.new(
:name => name,
Expand All @@ -124,7 +124,7 @@

context 'on a system with incrond newer than 0.5.12' do
it 'should retain the new parameters' do
Facter.stubs(:value).with(:incrond_version).returns('0.5.13')
allow(Facter).to receive(:value).with(:incrond_version).and_return('0.5.13')

resource = incron_system_table_type.new(
:name => name,
Expand Down

0 comments on commit aa393f8

Please sign in to comment.