diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-05-04 12:29:03 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-05-04 12:29:03 -0700 |
| commit | 4533aa16ec8c9ea4db2fc7de75b01ea056bcf624 (patch) | |
| tree | 1f9a972820ee888e4668d36c981082a92b7754c2 /spec | |
| parent | e5b62d7424da24799c4d16f0e104fac3008e2b89 (diff) | |
| parent | dda32647b4c11ecb352e469088f2438835ff99d7 (diff) | |
Merge branch 'bug/2.7.x/7353-unify-face-rendering-with-network-formathandler' into 2.7.x
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/application/face_base_spec.rb | 24 | ||||
| -rwxr-xr-x | spec/unit/interface/action_builder_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/network/formats_spec.rb | 62 |
3 files changed, 82 insertions, 6 deletions
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb index 133e6b2e9..25797ea3e 100755 --- a/spec/unit/application/face_base_spec.rb +++ b/spec/unit/application/face_base_spec.rb @@ -246,14 +246,14 @@ describe Puppet::Application::FaceBase do end [[1, 2], ["one"], [{ 1 => 1 }]].each do |input| - it "should render #{input.class} using the 'pp' library" do - app.render(input).should == input.pretty_inspect + it "should render #{input.class} using JSON" do + app.render(input).should == input.to_pson.chomp end end - it "should render a non-trivially-keyed Hash with the 'pp' library" do + it "should render a non-trivially-keyed Hash with using JSON" do hash = { [1,2] => 3, [2,3] => 5, [3,4] => 7 } - app.render(hash).should == hash.pretty_inspect + app.render(hash).should == hash.to_pson.chomp end it "should render a {String,Numeric}-keyed Hash into a table" do @@ -266,7 +266,7 @@ describe Puppet::Application::FaceBase do app.render(hash).should == <<EOT 5 5 6.0 6 -four #{object.pretty_inspect.chomp} +four #{object.to_pson.chomp} one 1 three {} two [] @@ -274,6 +274,7 @@ EOT end it "should render a hash nicely with a multi-line value" do + pending "Moving to PSON rather than PP makes this unsupportable." hash = { "number" => { "1" => '1' * 40, "2" => '2' * 40, '3' => '3' * 40 }, "text" => { "a" => 'a' * 40, 'b' => 'b' * 40, 'c' => 'c' * 40 } @@ -289,7 +290,7 @@ EOT end it "should invoke the action rendering hook while rendering" do - app.action.set_rendering_method_for(:for_humans, proc { |value| "bi-winning!" }) + app.action.set_rendering_method_for(:console, proc { |value| "bi-winning!" }) app.render("bi-polar?").should == "bi-winning!" end @@ -328,4 +329,15 @@ EOT }.to have_printed(/you invoked the 's' rendering hook/) end end + + describe "#render_as=" do + # This is for compatibility with the format name in 2.7.0rc1, but isn't a + # long term desirable name. We can't just randomly drop it since it was + # released, though, so it will live for a couple of major versions. + # --daniel 2011-05-04 + it "should treat :for_humans as a synonym for :console" do + app.render_as = :for_humans + app.render_as.name.should == :console + end + end end diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb index e0d0ebe72..89aef26d0 100755 --- a/spec/unit/interface/action_builder_spec.rb +++ b/spec/unit/interface/action_builder_spec.rb @@ -200,6 +200,8 @@ describe Puppet::Interface::ActionBuilder do end end + # :for_humans is an alias for :console, and deprecated, but since we + # shipped it in 2.7.0rc1 we need to support it. --daniel 2011-05-04 it "should accept :for_humans format" do action = Puppet::Interface::ActionBuilder.build(face, :foo) do when_invoked do true end diff --git a/spec/unit/network/formats_spec.rb b/spec/unit/network/formats_spec.rb index 72d355192..62c2dbb9d 100755 --- a/spec/unit/network/formats_spec.rb +++ b/spec/unit/network/formats_spec.rb @@ -330,4 +330,66 @@ describe "Puppet Network Format" do end end end + + describe ":console format" do + subject { Puppet::Network::FormatHandler.format(:console) } + it { should be_an_instance_of Puppet::Network::Format } + let :json do Puppet::Network::FormatHandler.format(:pson) end + + [:intern, :intern_multiple].each do |method| + it "should not implement #{method}" do + expect { subject.send(method, String, 'blah') }.to raise_error NotImplementedError + end + end + + ["hello", 1, 1.0].each do |input| + it "should just return a #{input.inspect}" do + subject.render(input).should == input + end + end + + [[1, 2], ["one"], [{ 1 => 1 }]].each do |input| + it "should render #{input.inspect} as JSON" do + subject.render(input).should == json.render(input).chomp + end + end + + it "should render a non-trivially-keyed Hash as JSON" do + hash = { [1,2] => 3, [2,3] => 5, [3,4] => 7 } + subject.render(hash).should == json.render(hash).chomp + end + + it "should render a {String,Numeric}-keyed Hash into a table" do + object = Object.new + hash = { "one" => 1, "two" => [], "three" => {}, "four" => object, + 5 => 5, 6.0 => 6 } + + # Gotta love ASCII-betical sort order. Hope your objects are better + # structured for display than my test one is. --daniel 2011-04-18 + subject.render(hash).should == <<EOT +5 5 +6.0 6 +four #{json.render(object).chomp} +one 1 +three {} +two [] +EOT + end + + it "should render a hash nicely with a multi-line value" do + pending "Moving to PSON rather than PP makes this unsupportable." + hash = { + "number" => { "1" => '1' * 40, "2" => '2' * 40, '3' => '3' * 40 }, + "text" => { "a" => 'a' * 40, 'b' => 'b' * 40, 'c' => 'c' * 40 } + } + subject.render(hash).should == <<EOT +number {"1"=>"1111111111111111111111111111111111111111", + "2"=>"2222222222222222222222222222222222222222", + "3"=>"3333333333333333333333333333333333333333"} +text {"a"=>"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "b"=>"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "c"=>"cccccccccccccccccccccccccccccccccccccccc"} +EOT + end + end end |
