diff --git a/lib/cucumber/ast/table.rb b/lib/cucumber/ast/table.rb
index ba838cb123..7b1419b46f 100644
--- a/lib/cucumber/ast/table.rb
+++ b/lib/cucumber/ast/table.rb
@@ -285,7 +285,8 @@ def map_column!(column_name, strict=true, &conversion_proc)
# #diff!. You can use #map_column! on either of the tables.
#
# A Different error is raised if there are missing rows or columns, or
- # surplus rows. An error is not raised for surplus columns.
+ # surplus rows. An error is not raised for surplus columns. An
+ # error is not raised for misplaced (out of sequence) columns.
# Whether to raise or not raise can be changed by setting values in
# +options+ to true or false:
#
@@ -293,6 +294,7 @@ def map_column!(column_name, strict=true, &conversion_proc)
# * surplus_row : Raise on surplus rows (defaults to true)
# * missing_col : Raise on missing columns (defaults to true)
# * surplus_col : Raise on surplus columns (defaults to false)
+ # * misplaced_col : Raise on misplaced columns (defaults to false)
#
# The +other_table+ argument can be another Table, an Array of Array or
# an Array of Hash (similar to the structure returned by #hashes).
@@ -301,7 +303,13 @@ def map_column!(column_name, strict=true, &conversion_proc)
# a Table argument, if you want to compare that table to some actual values.
#
def diff!(other_table, options={})
- options = {:missing_row => true, :surplus_row => true, :missing_col => true, :surplus_col => false}.merge(options)
+ options = {
+ :missing_row => true,
+ :surplus_row => true,
+ :missing_col => true,
+ :surplus_col => false,
+ :misplaced_col => false
+ }.merge(options)
other_table = ensure_table(other_table)
other_table.convert_headers!
@@ -317,6 +325,7 @@ def diff!(other_table, options={})
missing_col = cell_matrix[0].detect{|cell| cell.status == :undefined}
surplus_col = padded_width > original_width
+ misplaced_col = cell_matrix[0] != other_table.cell_matrix[0]
require_diff_lcs
cell_matrix.extend(Diff::LCS)
@@ -365,7 +374,8 @@ def diff!(other_table, options={})
missing_row_pos && options[:missing_row] ||
insert_row_pos && options[:surplus_row] ||
missing_col && options[:missing_col] ||
- surplus_col && options[:surplus_col]
+ surplus_col && options[:surplus_col] ||
+ misplaced_col && options[:misplaced_col]
raise Different.new(self) if should_raise
end
diff --git a/spec/cucumber/ast/table_spec.rb b/spec/cucumber/ast/table_spec.rb
index ee8a6068c4..90680b3ee5 100644
--- a/spec/cucumber/ast/table_spec.rb
+++ b/spec/cucumber/ast/table_spec.rb
@@ -474,6 +474,15 @@ def @table.columns; super; end
lambda { @t.dup.diff!(t) }.should_not raise_error
lambda { @t.dup.diff!(t, :surplus_col => true) }.should raise_error
end
+
+ it "should not raise on misplaced columns" do
+ t = table(%{
+ | b | a |
+ | d | c |
+ }, __FILE__, __LINE__)
+ lambda { @t.dup.diff!(t) }.should_not raise_error
+ lambda { @t.dup.diff!(t, :misplaced_col => true) }.should raise_error
+ end
end
def table(text, file, offset)