new Table#hashes method to diff against AST::Tables #29

Merged
merged 1 commit into from Feb 14, 2013

Conversation

Projects
None yet
2 participants
Contributor

bjoernbur commented Feb 13, 2013

As a developer I would like to compare the data of a CornerStones::Table with the data of a Cucumber::Ast::Table.

At the moment I have to do the following:

  table = CornerStones::Table.new("table_selector")

  expected_data = expected_results.hashes

  actual_data = table.rows.map {|row| row.attributes.reject {|key, _value| !expected_data.first.has_key?(key)}}

  actual_data.should == expected_data

With this PR I can do:

  table = CornerStones::Table.new("table_selector")

  expected_data = expected_results.hashes

  table.equals?(expected_data).should == true
Contributor

bjoernbur commented Feb 13, 2013

@senny what do you think about that? a started with the idea of comparing a Cucumber::Ast::Table with a CornerStones::Table like this:

  co_table = CornerStones::Table.new("table_selector")

  co_table.equals?(expected_cucumber_table).should == true

but if we do so, we have a dependency on cucumber... what do you think?

Owner

senny commented Feb 13, 2013

What does this PR add over:

ast_table.diff! corner_stones_table.rows
Contributor

bjoernbur commented Feb 13, 2013

When I do this I get the following error:

can't convert CornerStones::Table::Row into Array (TypeError)

Owner

senny commented Feb 13, 2013

Ah completely forgot the refactoring on master that #rows no longer returns an array of hashes. This was introduced with: a0cd3cc

I would still use the ast_table.diff! method though. It creates the nice colored output in the cucumber scenarios. My suggestion would be to create a method called Table#hashes, which converts the rows to attributes and returns the old style Array of Hashes. This would then look like:

ast_table.diff! corner_stones_table.hashes

Let me know if you want to update the PR.

Contributor

bjoernbur commented Feb 13, 2013

Looks good to me...

I'll update the PR asap...

Contributor

bjoernbur commented Feb 13, 2013

Thanks by the way 👍

Contributor

bjoernbur commented Feb 13, 2013

@senny I changed the PR: now there's a hashes-method. this method returns an array with the attribute-hash of each row.

Owner

senny commented Feb 14, 2013

thanks! 💛

senny added a commit that referenced this pull request Feb 14, 2013

Merge pull request #29 from bjoernbur/method_on_table_to_compare_with…
…_expected_data

new Table#hashes method to diff against AST::Tables

@senny senny merged commit bdf094e into senny:master Feb 14, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment