test/unit/output/adapter/table_test.rb in hammer_cli-0.1.0 vs test/unit/output/adapter/table_test.rb in hammer_cli-0.1.1

- old
+ new

@@ -7,10 +7,11 @@ context "print_collection" do let(:field_name) { Fields::Field.new(:path => [:fullname], :label => "Name") } let(:field_firstname) { Fields::Field.new(:path => [:firstname], :label => "Firstname") } let(:field_lastname) { Fields::Field.new(:path => [:lastname], :label => "Lastname") } + let(:field_long) { Fields::Field.new(:path => [:long], :label => "Full") } let(:fields) { [field_name] } @@ -117,18 +118,40 @@ end context "formatters" do it "should apply formatters" do class DotFormatter < HammerCLI::Output::Formatters::FieldFormatter - def format(data) + def format(data, field_params={}) '-DOT-' end end adapter = HammerCLI::Output::Adapter::Table.new({}, { :Field => [ DotFormatter.new ]}) out, err = capture_io { adapter.print_collection(fields, data) } out.must_match(/.*-DOT-.*/) end + + it "should not break formatting" do + class SliceFormatter < HammerCLI::Output::Formatters::FieldFormatter + def format(data, field_params={}) + data[0..5] + end + end + + adapter = HammerCLI::Output::Adapter::Table.new({}, { :Field => [ SliceFormatter.new ]}) + + expected_output = [ + "------", + "FULL ", + "------", + "SomeVe", + "------", + "" + ].join("\n") + + proc { adapter.print_collection([field_long], data) }.must_output(expected_output) + end + end context "sort_columns" do let(:fields) { [field_firstname, field_lastname]