Created
June 18, 2013 17:03
-
-
Save jhoblitt/5807254 to your computer and use it in GitHub Desktop.
Attempting to testing facter facts with rspec
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 'facter' | |
Facter.add(:tw_cli) do | |
confine :kernel => "Linux" | |
setcode do | |
Facter::Util::Resolution.which('tw_cli') | |
end | |
end |
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 'spec_helper' | |
RSpec.configure do |c| | |
c.include PuppetlabsSpec::Files | |
c.before :each do | |
# Ensure that we don't accidentally cache facts and environment | |
# between test cases. | |
Facter::Util::Loader.any_instance.stubs(:load_all) | |
Facter.clear | |
Facter.clear_messages | |
# Store any environment variables away to be restored later | |
@old_env = {} | |
ENV.each_key {|k| @old_env[k] = ENV[k]} | |
end | |
c.after :each do | |
PuppetlabsSpec::Files.cleanup | |
end | |
end | |
describe 'tw_cli fact', :type => :fact do | |
describe 'on linux' do | |
it "should find the tw_cli binary" do | |
Facter.fact(:kernel).stubs(:value).returns('Linux') | |
Facter::Util::Resolution.stubs(:which).with('tw_cli').returns('/usr/sbin/tw_cli') | |
Facter.fact(:tw_cli).value.should == '/usr/sbin/tw_cli' | |
end | |
it "should not find the tw_cli binary" do | |
Facter.fact(:kernel).stubs(:value).returns('Linux') | |
Facter::Util::Resolution.stubs(:which).with('tw_cli').returns(nil) | |
Facter.fact(:tw_cli).value.should == nil | |
end | |
end | |
describe 'on no kernel' do | |
it "should not find the tw_cli binary" do | |
Facter::Util::Resolution.stubs(:which).with('tw_cli').returns('/usr/sbin/tw_cli') | |
Facter.fact(:tw_cli).value.should == nil | |
end | |
it "should not find the tw_cli binary" do | |
Facter.fact(:tw_cli).value.should == nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment