spec/cucumber/ast/table_spec.rb in aslakhellesoy-cucumber-0.1.99.22 vs spec/cucumber/ast/table_spec.rb in aslakhellesoy-cucumber-0.1.99.23

- old
+ new

@@ -7,13 +7,10 @@ before do @table = Table.new([ %w{one four seven}, %w{4444 55555 666666} ]) - @table.extend(Module.new{ - attr_reader :raw - }) def @table.cells_rows; super; end def @table.columns; super; end end it "should have rows" do @@ -58,10 +55,34 @@ lambda { @table.map_column!('two', true) { |v| v.to_i } }.should raise_error('The column named "two" does not exist') end + describe ".transpose" do + before(:each) do + @table = Table.new([ + %w{one 1111}, + %w{two 22222} + ]) + end + + it "should be convertible in to an array where each row is a hash" do + @table.transpose.hashes[0].should == {'one' => '1111', 'two' => '22222'} + end + end + + it "should allow renaming columns" do + table2 = @table.map_headers('one' => :three) + table2.hashes.first[:three].should == '4444' + end + + it "should copy column mappings when mapping headers" do + @table.map_column!('one') { |v| v.to_i } + table2 = @table.map_headers('one' => 'three') + table2.hashes.first['three'].should == 4444 + end + describe "replacing arguments" do before(:each) do @table = table = Table.new([ %w{qty book}, @@ -81,12 +102,22 @@ table_with_replaced_args.hashes[0]['book'].should == nil end it "should not change the original table" do - table_with_replaced_args = @table.arguments_replaced({'<book>' => 'Unbearable lightness of being'}) + @table.arguments_replaced({'<book>' => 'Unbearable lightness of being'}) @table.hashes[0]['book'].should_not == 'Unbearable lightness of being' + end + + it "should not raise an error when there are nil values in the table" do + table = Table.new([ + ['book'], + [nil] + ]) + lambda{ + table.arguments_replaced({'<book>' => 'The great sheep chase'}) + }.should_not raise_error end end it "should convert to sexp" do