Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@bjoernbur

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

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

What does this PR add over:

ast_table.diff! corner_stones_table.rows
@bjoernbur

When I do this I get the following error:

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

@senny
Owner

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.

@bjoernbur

Looks good to me...

I'll update the PR asap...

@bjoernbur

Thanks by the way :+1:

@bjoernbur

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

@senny
Owner

thanks! :yellow_heart:

@senny senny merged commit bdf094e into senny:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 lib/corner_stones/table.rb
@@ -27,6 +27,10 @@ def empty?
rows.empty?
end
+ def hashes
+ rows.map{|row| row.attributes}
+ end
+
def rows
within @scope do
all('tbody tr').map do |row|
View
16 spec/integration/corner_stones/table_spec.rb
@@ -50,11 +50,7 @@
expected_data = [{'ID' => '1', 'Title' => 'Clean Code', 'Author' => 'Robert C. Martin'},
{ 'ID' => '2', 'Title' => 'Domain Driven Design', 'Author' => 'Eric Evans'}]
- subject.rows.map {|r|
- r.attributes.reject do |key, _value|
- !expected_data.first.has_key?(key)
- end
- }.must_equal(expected_data)
+ subject.hashes.must_equal(expected_data)
end
it 'a row can be accessed with a single key' do
@@ -123,11 +119,7 @@
'Author' => 'Robert C. Martin'},
{ 'Book' => 'Domain Driven Design',
'Author' => 'Eric Evans'}]
- subject.rows.map {|r|
- r.attributes.reject do |key, _value|
- !expected_data.first.has_key?(key)
- end
- }.must_equal(expected_data)
+ subject.hashes.must_equal(expected_data)
end
end
@@ -155,10 +147,8 @@
it 'ignores empty cells' do
expected_data = [{'ID' => '1', 'Title' => 'Clean Code', 'Author' => nil}]
- actual = subject.rows
- actual = actual.map {|row| row.attributes.reject {|key, _value| !expected_data.first.has_key?(key)}}
- actual.must_equal(expected_data)
+ subject.hashes.must_equal(expected_data)
end
end
Something went wrong with that request. Please try again.