spec/lib/mohawk/accessors/table_spec.rb in mohawk-0.0.5 vs spec/lib/mohawk/accessors/table_spec.rb in mohawk-0.0.6
- old
+ new
@@ -36,18 +36,39 @@
it 'can select a row by value' do
table.should_receive(:select).with 'John Elway'
screen.top = 'John Elway'
end
+ it 'can find a row by hash' do
+ TableStubber.stub(table)
+ .with_headers('Favorite Color', 'Favorite Number', 'Name')
+ .and_row('Blue', '7', 'Levi')
+ .and_row('Purple', '9', 'Larry')
+
+ found_row = screen.find_top :favorite_number => 9
+ found_row.favorite_color.should eq('Purple')
+ found_row.favorite_number.should eq('9')
+ found_row.name.should eq('Larry')
+ end
+
context 'selecting a row by hash' do
it 'selects the row if all values match' do
TableStubber.stub(table)
.with_headers('Column One', 'Column Two', 'Column Three')
.and_row('first', 'something', 'foo')
.and_row('second', 'another', 'bar')
table.should_receive(:select).with(1)
screen.select_top :column_one => 'second', :column_three => 'bar'
+ end
+
+ it 'returns the row that it selected' do
+ TableStubber.stub(table)
+ .with_headers('name', 'age')
+ .and_row('Levi', '33')
+
+ table.should_receive(:select).with(0)
+ screen.select_top(:age => 33).name.should eq('Levi')
end
it 'can handle non-string values' do
TableStubber.stub(table)
.with_headers('name', 'age')