diff options
| -rw-r--r-- | lib/puppet/network/format.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/network/format_handler.rb | 9 | ||||
| -rwxr-xr-x | spec/unit/network/format.rb | 4 | ||||
| -rwxr-xr-x | spec/unit/network/format_handler.rb | 11 |
4 files changed, 6 insertions, 20 deletions
diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb index 832697836..256e9a8d4 100644 --- a/lib/puppet/network/format.rb +++ b/lib/puppet/network/format.rb @@ -9,7 +9,7 @@ class Puppet::Network::Format attr_accessor :mime def initialize(name, options = {}, &block) - @name = name + @name = name.to_s.downcase.intern if mime = options[:mime] @mime = mime diff --git a/lib/puppet/network/format_handler.rb b/lib/puppet/network/format_handler.rb index e42cc4c46..6700c42a8 100644 --- a/lib/puppet/network/format_handler.rb +++ b/lib/puppet/network/format_handler.rb @@ -40,17 +40,14 @@ module Puppet::Network::FormatHandler end def convert_from(format, data) - raise ArgumentError, "Format %s not supported" % format unless support_format?(format) format_handler.format(format).intern(self, data) end def convert_from_multiple(format, data) - raise ArgumentError, "Format %s not supported" % format unless support_format?(format) format_handler.format(format).intern_multiple(self, data) end def render_multiple(format, instances) - raise ArgumentError, "Format %s not supported" % format unless support_format?(format) format_handler.format(format).render_multiple(instances) end @@ -77,11 +74,7 @@ module Puppet::Network::FormatHandler module InstanceMethods def render(format = nil) - if format - raise ArgumentError, "Format %s not supported" % format unless support_format?(format) - else - format = self.class.default_format - end + format ||= self.class.default_format Puppet::Network::FormatHandler.format(format).render(self) end diff --git a/spec/unit/network/format.rb b/spec/unit/network/format.rb index 34a841603..b746f8080 100755 --- a/spec/unit/network/format.rb +++ b/spec/unit/network/format.rb @@ -30,6 +30,10 @@ describe Puppet::Network::Format do Puppet::Network::Format.new(:my_format).name.should == :my_format end + it "should always convert its name to a downcased symbol" do + Puppet::Network::Format.new(:My_Format).name.should == :my_format + end + it "should be able to set its mime type at initialization" do format = Puppet::Network::Format.new(:my_format, :mime => "foo/bar") format.mime.should == "foo/bar" diff --git a/spec/unit/network/format_handler.rb b/spec/unit/network/format_handler.rb index 5071196c3..b5f981b1c 100755 --- a/spec/unit/network/format_handler.rb +++ b/spec/unit/network/format_handler.rb @@ -58,11 +58,6 @@ describe Puppet::Network::FormatHandler do FormatTester.should respond_to(:convert_from) end - it "should fail if asked to convert from an unsupported format" do - @format.expects(:supported?).with(FormatTester).returns false - lambda { FormatTester.convert_from(:my_format, "mydata") }.should raise_error(ArgumentError) - end - it "should call the format-specific converter when asked to convert from a given format" do @format.expects(:intern).with(FormatTester, "mydata") FormatTester.convert_from(:my_format, "mydata") @@ -135,12 +130,6 @@ describe Puppet::Network::FormatHandler do FormatTester.new.should respond_to(:render) end - it "should fail if asked to convert to an unsupported format" do - tester = FormatTester.new - tester.expects(:support_format?).with(:nope).returns false - lambda { tester.render(:nope) }.should raise_error(ArgumentError) - end - it "should call the format-specific converter when asked to convert to a given format" do format = stub 'rendering format', :supported? => true |
