senny / corner_stones

capybara building blocks for acceptance tests.
18 stars 8 forks source link

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

Closed bjoernbur closed 11 years ago

bjoernbur commented 11 years ago

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
bjoernbur commented 11 years ago

@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?

senny commented 11 years ago

What does this PR add over:

ast_table.diff! corner_stones_table.rows
bjoernbur commented 11 years ago

When I do this I get the following error:

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

senny commented 11 years ago

Ah completely forgot the refactoring on master that #rows no longer returns an array of hashes. This was introduced with: https://github.com/senny/corner_stones/commit/a0cd3ccb82e806ddc36e1271803d661cadfb97fa

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.

bjoernbur commented 11 years ago

Looks good to me...

I'll update the PR asap...

bjoernbur commented 11 years ago

Thanks by the way :+1:

bjoernbur commented 11 years ago

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

senny commented 11 years ago

thanks! :yellow_heart: