Skip to content

Fix diffing empty DataTables #1097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/cucumber/multiline_argument/data_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def pad_and_match(a_cell_matrix, other_cell_matrix) #:nodoc:
matched_cols << unmatched_cols.delete_at(mapped_index)
else
mark_as_missing(cols[i])
empty_col = other_cell_matrix.collect {SurplusCell.new(nil, self, -1)}
empty_col = ensure_2d(other_cell_matrix).collect {SurplusCell.new(nil, self, -1)}
empty_col.first.value = v
matched_cols << empty_col
end
Expand All @@ -601,7 +601,11 @@ def pad_and_match(a_cell_matrix, other_cell_matrix) #:nodoc:
cols << empty_col
end

return cols.transpose, (matched_cols + unmatched_cols).transpose
return ensure_2d(cols.transpose), ensure_2d((matched_cols + unmatched_cols).transpose)
end

def ensure_2d(array) #:nodoc:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should make this method private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already protected... is that good enough?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, that's great. I didn't see that.

Array === array[0] ? array : [array]
end

def ensure_table(table_or_array) #:nodoc:
Expand Down
6 changes: 6 additions & 0 deletions spec/cucumber/multiline_argument/data_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ module MultilineArgument
}
end

it 'should allow diffing empty tables' do
t1 = DataTable.from([[]])
t2 = DataTable.from([[]])
expect{ t1.diff!(t2) }.not_to raise_error
end

context 'in case of duplicate header values' do
it 'raises no error for two identical tables' do
t = DataTable.from(%{
Expand Down