spec/cucumber/ast/table_spec.rb in cucumber-1.2.1 vs spec/cucumber/ast/table_spec.rb in cucumber-1.2.2
- old
+ new
@@ -52,11 +52,11 @@
describe '#map_column!' do
it "should allow mapping columns" do
@table.map_column!('one') { |v| v.to_i }
@table.hashes.first['one'].should == 4444
end
-
+
it "applies the block once to each value" do
headers = ['header']
rows = ['value']
table = Table.new [headers, rows]
count = 0
@@ -100,11 +100,11 @@
@table = Table.new([
%w{one four seven},
%w{4444 55555 666666}
])
end
-
+
it "returns nil if headers do not match" do
@table.match('does,not,match').should be_nil
end
it "requires a table: prefix on match" do
@table.match('table:one,four,seven').should_not be_nil
@@ -119,18 +119,18 @@
@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
+
+ 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
-
+
describe "#rows_hash" do
-
+
it "should return a hash of the rows" do
table = Table.new([
%w{one 1111},
%w{two 22222}
])
@@ -199,10 +199,37 @@
end
table.hashes.first.keys.should =~ %w[hello foo]
end
+ it "should allow mapping of headers before table.hashes has been accessed" do
+ table = Table.new([
+ ['HELLO', 'WORLD'],
+ %w{4444 55555}
+ ])
+
+ table.map_headers! do |header|
+ header.downcase
+ end
+
+ table.hashes.first.keys.should =~ %w[hello world]
+ end
+
+ it "should allow mapping of headers after table.hashes has been accessed" do
+ table = Table.new([
+ ['HELLO', 'WORLD'],
+ %w{4444 55555}
+ ])
+
+ dev_null = table.hashes.size
+
+ table.map_headers! do |header|
+ header.downcase
+ end
+
+ table.hashes.first.keys.should =~ %w[hello world]
+ end
end
describe "replacing arguments" do
before(:each) do
@@ -241,11 +268,11 @@
table = Table.new([
%w{book},
%w{cat}
])
table_with_replaced_args = table.arguments_replaced({'<book>' => nil})
-
+
table_with_replaced_args.hashes[0]['book'].should == 'cat'
end
it "should not change the original table" do
@table.arguments_replaced({'<book>' => 'Unbearable lightness of being'})
@@ -256,30 +283,30 @@
it "should not raise an error when there are nil values in the table" do
table = Table.new([
['book', 'qty'],
['<book>', nil],
])
- lambda{
+ lambda{
table.arguments_replaced({'<book>' => nil, '<qty>' => '5'})
}.should_not raise_error
end
end
-
+
describe "diff!" do
it "should detect a complex diff" do
t1 = table(%{
| 1 | 22 | 333 | 4444 |
| 55555 | 666666 | 7777777 | 88888888 |
| 999999999 | 0000000000 | 01010101010 | 121212121212 |
| 4000 | ABC | DEF | 50000 |
}, __FILE__, __LINE__)
-
+
t2 = table(%{
- | a | 4444 | 1 |
- | bb | 88888888 | 55555 |
- | ccc | xxxxxxxx | 999999999 |
+ | a | 4444 | 1 |
+ | bb | 88888888 | 55555 |
+ | ccc | xxxxxxxx | 999999999 |
| dddd | 4000 | 300 |
| e | 50000 | 4000 |
}, __FILE__, __LINE__)
lambda{t1.diff!(t2)}.should raise_error
t1.to_s(:indent => 12, :color => false).should == %{
@@ -344,11 +371,11 @@
it "should allow column mapping of argument before diffing" do
t1 = Table.new([
['name', 'male'],
['aslak', true]
])
- t1.map_column!('male') {
+ t1.map_column!('male') {
'true'
}
t2 = Table.new([
['name', 'male'],
['aslak', 'true']
@@ -403,20 +430,20 @@
lambda do
t1.map_headers!(/uk/ => 'u')
t1.hashes
end.should raise_error(%{2 headers matched /uk/: ["Cuke", "Duke"]})
end
-
+
describe "raising" do
before do
@t = table(%{
| a | b |
| c | d |
}, __FILE__, __LINE__)
@t.should_not == nil
end
-
+
it "should raise on missing rows" do
t = table(%{
| a | b |
}, __FILE__, __LINE__)
lambda { @t.dup.diff!(t) }.should raise_error
@@ -446,17 +473,11 @@
| four | 4 |
| five | 5 |
}, __FILE__, __LINE__)
lambda { t1.dup.diff!(t2) }.should raise_error
- begin
- pending "http://groups.google.com/group/cukes/browse_thread/thread/5d96431c8245f05f" do
- lambda { t1.dup.diff!(t2, :surplus_row => false) }.should_not raise_error
- end
- rescue => e
- warn(e.message + " - see http://www.ruby-forum.com/topic/208508")
- end
+ lambda { t1.dup.diff!(t2, :surplus_row => false) }.should_not raise_error
end
it "should raise on missing columns" do
t = table(%{
| a |
@@ -492,25 +513,25 @@
describe "#new" do
it "should allow Array of Hash" do
t1 = Table.new([{'name' => 'aslak', 'male' => 'true'}])
t1.to_s(:indent => 12, :color => false).should == %{
- | name | male |
- | aslak | true |
+ | male | name |
+ | true | aslak |
}
end
end
it "should convert to sexp" do
- @table.to_sexp.should ==
- [:table,
+ @table.to_sexp.should ==
+ [:table,
[:row, -1,
- [:cell, "one"],
+ [:cell, "one"],
[:cell, "four"],
[:cell, "seven"]
],
[:row, -1,
- [:cell, "4444"],
+ [:cell, "4444"],
[:cell, "55555"],
[:cell, "666666"]]]
end
end
end