diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-18 13:27:17 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-19 10:53:31 -0700 |
| commit | be23b8423ba77a5935586e277bf543cd54b9dec7 (patch) | |
| tree | 96e2d4c93c63605c469e22d16417170216012abf /spec/unit/application | |
| parent | e6caa2459a75cdfb015e7f4754dd5b44d166b0b5 (diff) | |
(#7013) better default rendering support for faces
We have some specific requirements around rendering, including the ability of
authors of actions to add nice, custom rendering. To support that we want
solid "basic" rendering for human-focused output.
This implements that generic rendering correctly and to spec, to give a sound
basis that we can build on for extensible rendering.
(#7013) better default rendering support for faces
We have some specific requirements around rendering, including the ability of
authors of actions to add nice, custom rendering. To support that we want
solid "basic" rendering for human-focused output.
This implements that generic rendering correctly and to spec, to give a sound
basis that we can build on for extensible rendering.
Reviewed-By: Max Martin <max@puppetlabs.com>
Diffstat (limited to 'spec/unit/application')
| -rwxr-xr-x | spec/unit/application/face_base_spec.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb index 7e13d4be6..0d39aa1ff 100755 --- a/spec/unit/application/face_base_spec.rb +++ b/spec/unit/application/face_base_spec.rb @@ -214,4 +214,53 @@ describe Puppet::Application::FaceBase do app.main end end + + describe "#render" do + it "should just return a String" do + app.render("hello").should == "hello" + end + + [1, 1.000, [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 + end + end + + it "should render a non-trivially-keyed Hash with the 'pp' library" do + hash = { [1,2] => 3, [2,3] => 5, [3,4] => 7 } + app.render(hash).should == hash.pretty_inspect + 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 + app.render(hash).should == <<EOT +5 5 +6.0 6 +four #{object.pretty_inspect.chomp} +one 1 +three {} +two [] +EOT + end + + it "should render a hash nicely with a multi-line value" do + hash = { + "number" => { "1" => '1' * 40, "2" => '2' * 40, '3' => '3' * 40 }, + "text" => { "a" => 'a' * 40, 'b' => 'b' * 40, 'c' => 'c' * 40 } + } + app.render(hash).should == <<EOT +number {"1"=>"1111111111111111111111111111111111111111", + "2"=>"2222222222222222222222222222222222222222", + "3"=>"3333333333333333333333333333333333333333"} +text {"a"=>"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "b"=>"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "c"=>"cccccccccccccccccccccccccccccccccccccccc"} +EOT + end + end end |
