Permalink
Browse files

added tests for matching on class

  • Loading branch information...
1 parent 14fdea1 commit 6f54d94293e49fcb2c031aae7e14daf019607d10 bendycode committed Jul 12, 2009
Showing with 22 additions and 1 deletion.
  1. +22 −1 spec/table_matcher_spec.rb
@@ -58,7 +58,9 @@
describe 'with negative failure' do
it 'should raise ExpectationNotMetError' do
response = mock_model Object, :body => '<table id="my_id"><tr><td>c1</td><td>c2</td></tr></table>'
- lambda{response.should_not have_table('#my_id', [['c1', 'c2']])}.should raise_error(Spec::Expectations::ExpectationNotMetError,
+ lambda{
+ response.should_not have_table('#my_id', [['c1', 'c2']])
+ }.should raise_error(Spec::Expectations::ExpectationNotMetError,
"\nTable should not have matched: [[\"c1\", \"c2\"]]\n")
end
end
@@ -69,4 +71,23 @@
lambda{ response.should have_table('#my_id', nil)}.should raise_error(RuntimeError, 'Invalid "expected" argument')
end
end
+
+ describe "using non-id selectors" do
+ describe "class" do
+ it "matches with class" do
+ response = mock_model(Object, :body => '<table class="my_class"><tr><th>h1</th><th>h2</th></tr><tr><td>c1</td><td>c2</td></tr></table>')
+ response.should have_table('.my_class', [['h1', 'h2'], ['c1', 'c2']])
+ end
+ it "does not match when class do not match" do
+ response = mock_model(Object, :body => '<table class="my_class_2"><tr><th>h1</th><th>h2</th></tr><tr><td>c1</td><td>c2</td></tr></table>')
+ response.should_not have_table('.my_class', [['h1', 'h2'], ['c1', 'c2']])
+ end
+ it 'should raise ExpectationNotMetError with correct message' do
+ response = mock_model Object, :body => 'Some non-matching HTML'
+ lambda do
+ response.should have_table('.my_id', [['c1', 'c2']])
+ end.should raise_error(Spec::Expectations::ExpectationNotMetError, "\nWrong table contents.\nexpected: [[\"c1\", \"c2\"]]\n found: []\n\n")
+ end
+ end
+ end
end

0 comments on commit 6f54d94

Please sign in to comment.