Created
June 21, 2018 00:21
-
-
Save rodjek/3893fdcb294f075a5cb920855736115c to your computer and use it in GitHub Desktop.
Facter stubbing examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
require 'facter' | |
describe 'facter_value' do | |
context 'when stubbing Facter::Util::Collection#fact' do | |
before(:each) do | |
stub_fact = instance_double(Facter::Util::Fact, :value => 'foo') | |
allow(Facter.collection).to receive(:fact).with(:test_fact).and_return(stub_fact) | |
end | |
it 'can be accessed via Facter.value' do | |
expect(Facter.value(:test_fact)).to eq('foo') | |
end | |
it 'can be accessed via Facter::Util::Fact#value' do | |
expect(Facter.fact(:test_fact).value).to eq('foo') | |
end | |
it 'is present in the fact collection' do | |
expect(Facter.collection.fact(:test_fact)).not_to be_nil | |
end | |
end | |
context 'when stubbing Facter::Util::Fact#value' do | |
before(:each) do | |
allow(Facter.fact(:test_fact)).to receive(:value).and_return('foo') | |
end | |
it 'can be accessed via Facter::Util::Fact#value' do | |
expect(Facter.fact(:test_fact).value).to eq('foo') | |
end | |
it 'can not be accessed via Facter.value' do | |
expect(Facter.value(:test_fact)).to be_nil | |
end | |
it 'is not actually present in the fact collection' do | |
expect(Facter.collection.fact(:test_fact)).to be_nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment