Skip to content

Instantly share code, notes, and snippets.

@eliasp
Created June 29, 2013 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliasp/5890398 to your computer and use it in GitHub Desktop.
Save eliasp/5890398 to your computer and use it in GitHub Desktop.
diff --git a/spec/unit/macaddress_spec.rb b/spec/unit/macaddress_spec.rb
index 638ef2a..8bc26b1 100755
--- a/spec/unit/macaddress_spec.rb
+++ b/spec/unit/macaddress_spec.rb
@@ -49,6 +49,15 @@ describe "macaddress fact" do
proc { Facter.value(:macaddress) }.should_not raise_error
Facter.value(:macaddress).should be_nil
end
+
+ # when ifconfig isn't installed, nil is returned which should be handled gracefully without any
+ # errors raised
+ it "should not raise any errors when nil is returned" do
+ Facter::Util::IP.stubs(:exec_ifconfig).with(["-a","2>/dev/null"]).
+ returns(nil)
+ proc { Facter.value(:macaddress) }.should_not raise_error
+ Facter.value(:macaddress).should be_nil
+ end
end
describe "when run on BSD" do
@eliasp
Copy link
Author

eliasp commented Jun 29, 2013

1st attempt at adding tests for puppetlabs/facter#468.
When exec_ifconfig() returns nil (e.g. no ifconfig installed), the modules using its output should not raise any error message.

Unfortunately, this test obviously doesn't work: running facter macaddress shows Could not retrieve macaddress: undefined methodeach_line' for nil:NilClass, but runningrspec spec/unit/util/macaddress_spec.rbshows… 0 failures`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment