Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added span_text_matcher_spec.rb. [#4 state:resolved]
- Loading branch information
Stephen Anderson
committed
Sep 28, 2008
1 parent
3477200
commit 404391a
Showing
2 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | ||
|
||
describe 'span_text_matcher' do | ||
it 'should find matching span' do | ||
response = mock_model(Object, :body => '<p><span id="span_id">My Text</span></p>') | ||
response.should have_span_text('span_id', 'My Text') | ||
end | ||
|
||
describe 'passed wrong id' do | ||
it 'should not match' do | ||
response = mock_model(Object, :body => '<p><span id="span_id">My Text</span></p>') | ||
response.should_not have_span_text('wrong_id', 'My Text') | ||
end | ||
end | ||
|
||
describe 'with non-matching expected' do | ||
it 'should not match' do | ||
response = mock_model(Object, :body => '<p><span id="span_id">My Text</span></p>') | ||
response.should_not have_span_text('span_id', 'Some Other Text') | ||
end | ||
end | ||
|
||
describe 'with normal failure' do | ||
it 'should raise ExpectationNotMetError with correct message' do | ||
response = mock_model Object, :body => 'Some non-matching HTML' | ||
lambda do | ||
response.should have_span_text('span_id', 'My Text') | ||
end.should raise_error(Spec::Expectations::ExpectationNotMetError, "\nWrong span text contents.\nexpected: \"My Text\"\n found: nil\n\n") | ||
end | ||
end | ||
|
||
describe 'with negative failure' do | ||
it 'should raise ExpectationNotMetError' do | ||
response = mock_model Object, :body => '<p><span id="span_id">My Text</span></p>' | ||
lambda{response.should_not have_span_text('span_id', 'My Text')}.should raise_error(Spec::Expectations::ExpectationNotMetError, | ||
"\nShould not have matched span: span_id, with text: 'My Text'\n\n") | ||
end | ||
end | ||
end |