spec/unit/util/resolution.rb in facter-1.5.6 vs spec/unit/util/resolution.rb in facter-1.5.7
- old
+ new
@@ -23,10 +23,18 @@
it "should default to a timeout of 0 seconds" do
Facter::Util::Resolution.new("yay").limit.should == 0
end
+ it "should default to nil for code" do
+ Facter::Util::Resolution.new("yay").code.should be_nil
+ end
+
+ it "should default to nil for interpreter" do
+ Facter::Util::Resolution.new("yay").interpreter.should be_nil
+ end
+
it "should provide a 'limit' method that returns the timeout" do
res = Facter::Util::Resolution.new("yay")
res.timeout = "testing"
res.limit.should == "testing"
end
@@ -69,10 +77,17 @@
describe "when returning the value" do
before do
@resolve = Facter::Util::Resolution.new("yay")
end
+ describe "and setcode has not been called" do
+ it "should return nil" do
+ Facter::Util::Resolution.expects(:exec).with(nil, nil).never
+ @resolve.value.should be_nil
+ end
+ end
+
describe "and the code is a string" do
it "should return the result of executing the code with the interpreter" do
@resolve.setcode "/bin/foo"
Facter::Util::Resolution.expects(:exec).with("/bin/foo", "/bin/sh").returns "yup"
@@ -101,14 +116,20 @@
it "should return nil if the value is an empty string" do
@resolve.setcode { "" }
@resolve.value.should be_nil
end
+ it "should return nil if the value is an empty block" do
+ @resolve.setcode { "" }
+ @resolve.value.should be_nil
+ end
+
it "should use its limit method to determine the timeout, to avoid conflict when a 'timeout' method exists for some other reason" do
@resolve.expects(:timeout).never
@resolve.expects(:limit).returns "foo"
Timeout.expects(:timeout).with("foo")
+ @resolve.setcode { sleep 2; "raise This is a test"}
@resolve.value
end
it "should timeout after the provided timeout" do
@resolve.expects(:warn)