summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorPeter Meier <peter.meier@immerda.ch>2009-04-07 18:45:21 +0200
committerPeter Meier <peter.meier@immerda.ch>2009-04-07 18:45:21 +0200
commit7a819454febdf34f4384e1bc64c5b2599df4bd38 (patch)
tree2d3eec5d0ae55a19189c0cc38e24ce167dead6cd /spec
parent1288b26e35a2a9e126d4ae260f377d854b3c3848 (diff)
downloadfacter-7a819454febdf34f4384e1bc64c5b2599df4bd38.tar.gz
facter-7a819454febdf34f4384e1bc64c5b2599df4bd38.tar.xz
facter-7a819454febdf34f4384e1bc64c5b2599df4bd38.zip
correctly compare values - fixes #2021
this ensures we can compare all kind of objects and not only instances of strings. It compares strings in a case-insensitive manner and converts symbols to strings. introducing this behavior required that we introduce a convert util method, to ensure that we convert the value correctly. Introduced this method in other places as well. This behavior change requires that we drop one test, which have become anyway deprecated.
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/util/confine.rb75
1 files changed, 70 insertions, 5 deletions
diff --git a/spec/unit/util/confine.rb b/spec/unit/util/confine.rb
index 5c1ce3b..757ca26 100755
--- a/spec/unit/util/confine.rb
+++ b/spec/unit/util/confine.rb
@@ -3,6 +3,9 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'facter/util/confine'
+require 'facter/util/values'
+
+include Facter::Util::Values
describe Facter::Util::Confine do
it "should require a fact name" do
@@ -17,10 +20,6 @@ describe Facter::Util::Confine do
Facter::Util::Confine.new("yay", "test", "other").values.should == ["test", "other"]
end
- it "should convert all values to strings" do
- Facter::Util::Confine.new("yay", :test).values.should == %w{test}
- end
-
it "should fail if no fact name is provided" do
lambda { Facter::Util::Confine.new(nil, :test) }.should raise_error(ArgumentError)
end
@@ -35,7 +34,7 @@ describe Facter::Util::Confine do
describe "when evaluating" do
before do
- @confine = Facter::Util::Confine.new("yay", "one", "two")
+ @confine = Facter::Util::Confine.new("yay", "one", "two", "Four", :xy, true, 1, [3,4])
@fact = mock 'fact'
Facter.stubs(:[]).returns @fact
end
@@ -66,10 +65,76 @@ describe Facter::Util::Confine do
@confine.true?.should be_true
end
+ it "should return true if any of the provided symbol values matches the fact's value" do
+ @fact.stubs(:value).returns :xy
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided integer values matches the fact's value" do
+ @fact.stubs(:value).returns 1
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided boolan values matches the fact's value" do
+ @fact.stubs(:value).returns true
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided array values matches the fact's value" do
+ @fact.stubs(:value).returns [3,4]
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided symbol values matches the fact's string value" do
+ @fact.stubs(:value).returns :one
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided string values matches case-insensitive the fact's value" do
+ @fact.stubs(:value).returns "four"
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided symbol values matches case-insensitive the fact's string value" do
+ @fact.stubs(:value).returns :four
+
+ @confine.true?.should be_true
+ end
+
+ it "should return true if any of the provided symbol values matches the fact's string value" do
+ @fact.stubs(:value).returns :Xy
+
+ @confine.true?.should be_true
+ end
+
it "should return false if none of the provided values matches the fact's value" do
@fact.stubs(:value).returns "three"
@confine.true?.should be_false
end
+
+ it "should return false if none of the provided integer values matches the fact's value" do
+ @fact.stubs(:value).returns 2
+
+ @confine.true?.should be_false
+ end
+
+ it "should return false if none of the provided boolan values matches the fact's value" do
+ @fact.stubs(:value).returns false
+
+ @confine.true?.should be_false
+ end
+
+ it "should return false if none of the provided array values matches the fact's value" do
+ @fact.stubs(:value).returns [1,2]
+
+ @confine.true?.should be_false
+ end
end
end