diff options
| author | Luke Kanies <luke@madstop.com> | 2008-08-24 14:10:39 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-08-26 22:40:40 -0700 |
| commit | 90e70227b0bb7cfd104ae34de8f7c2b7250edb09 (patch) | |
| tree | d94b5b375b5ea4a0532ef49dafd00eab5569d85c /spec/unit | |
| parent | 5a195e0c06daa2bfa008cfd94c660e50b9d0ae56 (diff) | |
Adding weights to network formats, and sorting them based on the weight.
This way the new hackish RAW format will only ever be used if it's
specifically chosen.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit')
| -rwxr-xr-x | spec/unit/network/format.rb | 12 | ||||
| -rwxr-xr-x | spec/unit/network/format_handler.rb | 31 | ||||
| -rwxr-xr-x | spec/unit/network/formats.rb | 4 |
3 files changed, 38 insertions, 9 deletions
diff --git a/spec/unit/network/format.rb b/spec/unit/network/format.rb index 818ecdce3..244bff306 100755 --- a/spec/unit/network/format.rb +++ b/spec/unit/network/format.rb @@ -83,6 +83,18 @@ describe Puppet::Network::Format do @format.mime = "Foo/Bar" @format.mime.should == "foo/bar" end + + it "should support having a weight" do + @format.should respond_to(:weight) + end + + it "should default to a weight of of 5" do + @format.weight.should == 5 + end + + it "should be able to override its weight at initialization" do + Puppet::Network::Format.new(:foo, :weight => 1).weight.should == 1 + end end describe "when converting between instances and formatted text" do diff --git a/spec/unit/network/format_handler.rb b/spec/unit/network/format_handler.rb index 35e996516..3dcff6199 100755 --- a/spec/unit/network/format_handler.rb +++ b/spec/unit/network/format_handler.rb @@ -21,18 +21,31 @@ describe Puppet::Network::FormatHandler do end it "should include all supported formats" do - one = stub 'supported', :supported? => true, :name => "one" - two = stub 'supported', :supported? => false, :name => "two" - three = stub 'supported', :supported? => true, :name => "three" - four = stub 'supported', :supported? => false, :name => "four" - Puppet::Network::FormatHandler.expects(:formats).returns %w{one two three four} - Puppet::Network::FormatHandler.expects(:format).with("one").returns one - Puppet::Network::FormatHandler.expects(:format).with("two").returns two - Puppet::Network::FormatHandler.expects(:format).with("three").returns three - Puppet::Network::FormatHandler.expects(:format).with("four").returns four + one = stub 'supported', :supported? => true, :name => "one", :weight => 1 + two = stub 'supported', :supported? => false, :name => "two", :weight => 1 + three = stub 'supported', :supported? => true, :name => "three", :weight => 1 + four = stub 'supported', :supported? => false, :name => "four", :weight => 1 + Puppet::Network::FormatHandler.stubs(:formats).returns %w{one two three four} + Puppet::Network::FormatHandler.stubs(:format).with("one").returns one + Puppet::Network::FormatHandler.stubs(:format).with("two").returns two + Puppet::Network::FormatHandler.stubs(:format).with("three").returns three + Puppet::Network::FormatHandler.stubs(:format).with("four").returns four FormatTester.supported_formats.sort.should == %w{one three}.sort end + it "should return the supported formats in decreasing order of weight" do + one = stub 'supported', :supported? => true, :name => "one", :weight => 1 + two = stub 'supported', :supported? => true, :name => "two", :weight => 6 + three = stub 'supported', :supported? => true, :name => "three", :weight => 2 + four = stub 'supported', :supported? => true, :name => "four", :weight => 8 + Puppet::Network::FormatHandler.stubs(:formats).returns %w{one two three four} + Puppet::Network::FormatHandler.stubs(:format).with("one").returns one + Puppet::Network::FormatHandler.stubs(:format).with("two").returns two + Puppet::Network::FormatHandler.stubs(:format).with("three").returns three + Puppet::Network::FormatHandler.stubs(:format).with("four").returns four + FormatTester.supported_formats.should == %w{four two three one} + end + it "should return the first format as the default format" do FormatTester.expects(:supported_formats).returns %w{one two} FormatTester.default_format.should == "one" diff --git a/spec/unit/network/formats.rb b/spec/unit/network/formats.rb index 527fd9d79..0e21fefa7 100755 --- a/spec/unit/network/formats.rb +++ b/spec/unit/network/formats.rb @@ -124,5 +124,9 @@ describe "Puppet Network Format" do it "should fail if its multiple_intern method is used" do lambda { @format.intern_multiple(String, "foo") }.should raise_error(NotImplementedError) end + + it "should have a weight of 1" do + @format.weight.should == 1 + end end end |
