summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorDavid Schmitt <david@dasz.at>2010-06-14 17:05:20 +0200
committerJames Turnbull <james@lovedthanlost.net>2010-06-15 01:25:36 +1000
commit83b3ea6abbd1d382a6738fa731f9f7409867e135 (patch)
tree11158a2f610dba94c839809d5ea86ce5d3de6188 /spec
parentffcae46df5d5336995348544139540c0e564ae2e (diff)
downloadfacter-83b3ea6abbd1d382a6738fa731f9f7409867e135.tar.gz
facter-83b3ea6abbd1d382a6738fa731f9f7409867e135.tar.xz
facter-83b3ea6abbd1d382a6738fa731f9f7409867e135.zip
Fixed #3393 - Updates to Facter for MS Windows
This patch is originally by Daniel Berger <djberg96@gmail.com>, I changed using Facter.value instead of repeatedly testing Config['host_os'], removed Resolution::which, and fixed the specs. Thanks to Paul Nasrat for helping with cross-platform debugging. Signed-off-by: David Schmitt <david@dasz.at>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/util/resolution.rb54
1 files changed, 43 insertions, 11 deletions
diff --git a/spec/unit/util/resolution.rb b/spec/unit/util/resolution.rb
index 7cbfb31..396f800 100755
--- a/spec/unit/util/resolution.rb
+++ b/spec/unit/util/resolution.rb
@@ -44,9 +44,10 @@ describe Facter::Util::Resolution do
@resolve = Facter::Util::Resolution.new("yay")
end
- it "should default to /bin/sh as the interpreter if a string is provided" do
+ it "should default to the detected interpreter if a string is provided" do
+ Facter::Util::Resolution::INTERPRETER = "/bin/bar"
@resolve.setcode "foo"
- @resolve.interpreter.should == "/bin/sh"
+ @resolve.interpreter.should == "/bin/bar"
end
it "should set the code to any provided string" do
@@ -87,17 +88,44 @@ describe Facter::Util::Resolution do
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"
-
- @resolve.value.should == "yup"
+ describe "on windows" do
+ before do
+ Facter::Util::Resolution::WINDOWS = true
+ Facter::Util::Resolution::INTERPRETER = "cmd.exe"
+ end
+
+ it "should return the result of executing the code with the interpreter" do
+ @resolve.setcode "/bin/foo"
+ Facter::Util::Resolution.expects(:exec).once.with("/bin/foo", "cmd.exe").returns "yup"
+
+ @resolve.value.should == "yup"
+ end
+
+ it "should return nil if the value is an empty string" do
+ @resolve.setcode "/bin/foo"
+ Facter::Util::Resolution.expects(:exec).once.returns ""
+ @resolve.value.should be_nil
+ end
end
- it "should return nil if the value is an empty string" do
- @resolve.setcode "/bin/foo"
- Facter::Util::Resolution.stubs(:exec).returns ""
- @resolve.value.should be_nil
+ describe "on non-windows systems" do
+ before do
+ Facter::Util::Resolution::WINDOWS = false
+ Facter::Util::Resolution::INTERPRETER = "/bin/sh"
+ end
+
+ it "should return the result of executing the code with the interpreter" do
+ @resolve.setcode "/bin/foo"
+ Facter::Util::Resolution.expects(:exec).once.with("/bin/foo", "/bin/sh").returns "yup"
+
+ @resolve.value.should == "yup"
+ end
+
+ it "should return nil if the value is an empty string" do
+ @resolve.setcode "/bin/foo"
+ Facter::Util::Resolution.expects(:exec).once.returns ""
+ @resolve.value.should be_nil
+ end
end
end
@@ -233,5 +261,9 @@ describe Facter::Util::Resolution do
it "should fail if any interpreter other than /bin/sh is requested" do
lambda { Facter::Util::Resolution.exec("/something", "/bin/perl") }.should raise_error(ArgumentError)
end
+
+ it "should execute the binary" do
+ Facter::Util::Resolution.exec("echo foo").should == "foo"
+ end
end
end