diff options
| author | Richard Clamp <richardc@unixbeard.net> | 2011-03-18 00:10:00 +0000 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2011-04-06 03:46:49 +1000 |
| commit | d56bca8534bd21c046fd19a7fb2f776fe3e100b4 (patch) | |
| tree | e5af700326354cc68d80c645c6da1f934a074b7d /spec | |
| parent | 9f4c5c6ac79821700bf4e6beee81f3d865396f4b (diff) | |
| download | facter-d56bca8534bd21c046fd19a7fb2f776fe3e100b4.tar.gz facter-d56bca8534bd21c046fd19a7fb2f776fe3e100b4.tar.xz facter-d56bca8534bd21c046fd19a7fb2f776fe3e100b4.zip | |
refactor the mechanism for allowing for resolution ordering to be influenced
renames Facter::Util::Resolution#length to weight as a more generic
mechanism for allowing resolutions to state their importance
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/util/fact_spec.rb | 22 | ||||
| -rwxr-xr-x | spec/unit/util/resolution_spec.rb | 22 |
2 files changed, 31 insertions, 13 deletions
diff --git a/spec/unit/util/fact_spec.rb b/spec/unit/util/fact_spec.rb index db08670..523c855 100755 --- a/spec/unit/util/fact_spec.rb +++ b/spec/unit/util/fact_spec.rb @@ -56,10 +56,10 @@ describe Facter::Util::Fact do @fact.add { } end - it "should re-sort the resolutions by length, so the most restricted resolutions are first" do - r1 = stub 'r1', :length => 1 - r2 = stub 'r2', :length => 2 - r3 = stub 'r3', :length => 0 + it "should re-sort the resolutions by weight, so the most restricted resolutions are first" do + r1 = stub 'r1', :weight => 1 + r2 = stub 'r2', :weight => 2 + r3 = stub 'r3', :weight => 0 Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) @fact.add { } @fact.add { } @@ -83,9 +83,9 @@ describe Facter::Util::Fact do end it "should return the first value returned by a resolution" do - r1 = stub 'r1', :length => 2, :value => nil, :suitable? => true - r2 = stub 'r2', :length => 1, :value => "yay", :suitable? => true - r3 = stub 'r3', :length => 0, :value => "foo", :suitable? => true + r1 = stub 'r1', :weight => 2, :value => nil, :suitable? => true + r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true + r3 = stub 'r3', :weight => 0, :value => "foo", :suitable? => true Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) @fact.add { } @fact.add { } @@ -95,8 +95,8 @@ describe Facter::Util::Fact do end it "should short-cut returning the value once one is found" do - r1 = stub 'r1', :length => 2, :value => "foo", :suitable? => true - r2 = stub 'r2', :length => 1, :suitable? => true # would fail if 'value' were asked for + r1 = stub 'r1', :weight => 2, :value => "foo", :suitable? => true + r2 = stub 'r2', :weight => 1, :suitable? => true # would fail if 'value' were asked for Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) @fact.add { } @fact.add { } @@ -105,8 +105,8 @@ describe Facter::Util::Fact do end it "should skip unsuitable resolutions" do - r1 = stub 'r1', :length => 2, :suitable? => false # would fail if 'value' were asked for' - r2 = stub 'r2', :length => 1, :value => "yay", :suitable? => true + r1 = stub 'r1', :weight => 2, :suitable? => false # would fail if 'value' were asked for' + r2 = stub 'r2', :weight => 1, :value => "yay", :suitable? => true Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) @fact.add { } @fact.add { } diff --git a/spec/unit/util/resolution_spec.rb b/spec/unit/util/resolution_spec.rb index 581d0e1..3e13cdc 100755 --- a/spec/unit/util/resolution_spec.rb +++ b/spec/unit/util/resolution_spec.rb @@ -13,6 +13,10 @@ describe Facter::Util::Resolution do Facter::Util::Resolution.new("yay").name.should == "yay" end + it "should have a method for setting the weight" do + Facter::Util::Resolution.new("yay").should respond_to(:has_weight) + end + it "should have a method for setting the code" do Facter::Util::Resolution.new("yay").should respond_to(:setcode) end @@ -195,11 +199,25 @@ describe Facter::Util::Resolution do it "should provide a method for returning the number of confines" do @resolve = Facter::Util::Resolution.new("yay") @resolve.confine "one" => "foo", "two" => "fee" - @resolve.length.should == 2 + @resolve.weight.should == 2 end it "should return 0 confines when no confines have been added" do - Facter::Util::Resolution.new("yay").length.should == 0 + Facter::Util::Resolution.new("yay").weight.should == 0 + end + + it "should provide a way to set the weight" do + @resolve = Facter::Util::Resolution.new("yay") + @resolve.has_weight(45) + @resolve.weight.should == 45 + end + + it "should allow the weight to override the number of confines" do + @resolve = Facter::Util::Resolution.new("yay") + @resolve.confine "one" => "foo", "two" => "fee" + @resolve.weight.should == 2 + @resolve.has_weight(45) + @resolve.weight.should == 45 end it "should have a method for determining if it is suitable" do |
