spec/cucumber/ast/table_spec.rb in cucumber-0.8.5 vs spec/cucumber/ast/table_spec.rb in cucumber-0.8.6
- old
+ new
@@ -1,7 +1,7 @@
# encoding: utf-8
-require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+require 'spec_helper'
require 'cucumber/ast/table'
module Cucumber
module Ast
describe Table do
@@ -43,15 +43,30 @@
it "should accept symbols as keys for the hashes" do
@table.hashes.first[:one].should == '4444'
end
- it "should allow map'ing columns" do
+ it "should allow mapping columns" do
@table.map_column!('one') { |v| v.to_i }
@table.hashes.first['one'].should == 4444
end
+ it "should allow mapping columns and take a symbol as the column name" do
+ @table.map_column!(:one) { |v| v.to_i }
+ @table.hashes.first['one'].should == 4444
+ end
+
+ it "should allow mapping columns and modify the rows as well" do
+ @table.map_column!(:one) { |v| v.to_i }
+ @table.rows.first.should include(4444)
+ @table.rows.first.should_not include('4444')
+ end
+
+ it "should return the row values in order" do
+ @table.rows.first.should == %w{4444 55555 666666}
+ end
+
it "should pass silently if a mapped column does not exist in non-strict mode" do
lambda {
@table.map_column!('two', false) { |v| v.to_i }
}.should_not raise_error
end
@@ -60,10 +75,14 @@
lambda {
@table.map_column!('two', true) { |v| v.to_i }
}.should raise_error('The column named "two" does not exist')
end
+ it "should return the table" do
+ (@table.map_column!(:one) { |v| v.to_i }).should == @table
+ end
+
describe "#match" do
before(:each) do
@table = Table.new([
%w{one four seven},
%w{4444 55555 666666}
@@ -330,9 +349,26 @@
])
t1.diff!(t2)
t1.to_s(:indent => 12, :color => false).should == %{
| name | male |
| aslak | true |
+ }
+ end
+
+ it "should detect seemingly identical tables as different" do
+ t1 = Table.new([
+ ['X', 'Y'],
+ ['2', '1']
+ ])
+ t2 = Table.new([
+ ['X', 'Y'],
+ [2, 1]
+ ])
+ lambda{t1.diff!(t2)}.should raise_error
+ t1.to_s(:indent => 12, :color => false).should == %{
+ | X | Y |
+ | (-) (i) "2" | (-) (i) "1" |
+ | (+) (i) 2 | (+) (i) 1 |
}
end
it "should not allow mappings that match more than 1 column" do
t1 = Table.new([