Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from mocha to rspec mocks #88

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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/facter/oscap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
end

before :each do
Facter::Core::Execution.stubs(:which).with('oscap').returns('/bin/oscap').at_least_once
Facter::Core::Execution.stubs(:execute).with('/bin/oscap version').returns(<<-EOM
allow(Facter::Core::Execution).to receive(:which).with('oscap').and_return('/bin/oscap').at_least(:once)
allow(Facter::Core::Execution).to receive(:execute).with('/bin/oscap version').and_return(<<-EOM
OpenSCAP command line tool (oscap) 1.2.16
Copyright 2009--2017 Red Hat Inc., Durham, North Carolina.

Expand Down Expand Up @@ -39,7 +39,7 @@
@data_streams['/usr/share/xml/scap/ssg/content/' + File.basename(stream)] = IO.read(stream)
end

Dir.stubs(:glob).with('/usr/share/xml/scap/*/content/*-ds.xml').returns(@data_streams.keys).at_least_once
allow(Dir).to receive(:glob).with('/usr/share/xml/scap/*/content/*-ds.xml').and_return(@data_streams.keys).at_least(:once)
end

context 'with a valid environment' do
Expand All @@ -61,7 +61,7 @@

it 'returns a valid hash of all available profiles' do
@data_streams.each_pair do |stream, content|
File.stubs(:read).with(stream).returns(content)
allow(File).to receive(:read).with(stream).and_return(content)
end

value = Facter.fact(:oscap).value
Expand Down Expand Up @@ -90,9 +90,9 @@
i = 0
@data_streams.each_pair do |stream, content|
if ( (i % 2) == 1 )
File.stubs(:read).with(stream).returns("Look, some random garbage with Profile and title!")
allow(File).to receive(:read).with(stream).and_return("Look, some random garbage with Profile and title!")
else
File.stubs(:read).with(stream).returns(content)
allow(File).to receive(:read).with(stream).and_return(content)
end

i += 1
Expand Down Expand Up @@ -122,7 +122,7 @@
context 'with all invalid oscap output' do
it 'returns only the valid portions' do
@data_streams.each_pair do |stream, content|
File.stubs(:read).with(stream).returns("\n")
allow(File).to receive(:read).with(stream).and_return("\n")
end

value = Facter.fact(:oscap).value
Expand Down
Loading