-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Diffing empty DataTables crashes with a nil error #1096
Comments
As an aside, it seems that Cucumber presently has a preference of
FWIW. |
Also, I think this last part shows that since Cucumber thinks Thoughts? |
Thank you for the issue report and PR, @botandrose! I'm going to take a look at this after I get out of my current meeting but wanted to respond right away :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Current Behavior
Opinions seem to vary on exactly how to construct an empty (0x0) DataTable, but in either case:
This ends up boiling down to
C::MA::DT#pad_and_match
callingArray#transpose
on the internal 2d array, and both[[]].transpose
and[].transpose
both return[]
, which causes the DataTable implementation to crash with a nil error, because its expecting a 2d array, but it only has a 1d array to work with.Expected Behavior
One might argue that the bug is truly in Ruby's
Array#transpose
function (confirmed same behavior in ruby-head, btw), but regardless, I think we can agree that#diff!
shouldn't nil crash in this circumstance. I would like to see at least one of those two invocations succeed, and possibly both.Context & Motivation
The motivation behind this request is that I am heavily using DataTables in my cucumber scenarios, and have even written a library named chop that makes DataTables much more powerful when used in conjunction with ActiveRecord and Capybara. The specific use-case is as follows:
I have a method that creates a data structure based off of the current state of the Capybara page, lets say its a table of users, and I want to use the
#diff!
method to assert that it matches an expected state, which could include being completely empty.This may seem a bit awkward, like why not just do
expect(users_table).to eq([])
, but this is a gross simplification of the actual system. Suffice it to say that usingC::MA::DT#diff!
in both circumstances is greatly preferable. One could look at the implementation and usage ofChop::Diff
for a better understanding of the actual system, if desired.Next Steps
Would a PR addressing this issue be considered for merging? If so, I am happy and eager to do the work.
The text was updated successfully, but these errors were encountered: