Skip to content

Instantly share code, notes, and snippets.

@rodjek
Created June 21, 2018 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rodjek/3893fdcb294f075a5cb920855736115c to your computer and use it in GitHub Desktop.
Save rodjek/3893fdcb294f075a5cb920855736115c to your computer and use it in GitHub Desktop.
Facter stubbing examples
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