Permalink
Browse files

New method to compare attributes with a Cucumber::Ast::Table

  • Loading branch information...
1 parent 4770c70 commit cd91e438343452067e3d08ba7b5445109bd9e9c3 @bjoernbur bjoernbur committed Feb 13, 2013
Showing with 7 additions and 13 deletions.
  1. +4 −0 lib/corner_stones/table.rb
  2. +3 −13 spec/integration/corner_stones/table_spec.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|
@@ -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

0 comments on commit cd91e43

Please sign in to comment.