Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add should_see and should_not_see assertions
- Loading branch information
Showing
6 changed files
with
177 additions
and
1 deletion.
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,27 @@ | ||
module Webrat | ||
module Assertions | ||
|
||
def should_see(text_or_regexp) | ||
case text_or_regexp | ||
when Regexp | ||
return if scoped_html.match(text_or_regexp) | ||
else | ||
return if scoped_html.include?(text_or_regexp) | ||
end | ||
|
||
flunk("Should see #{text_or_regexp.inspect} but didn't") | ||
end | ||
|
||
def should_not_see(text_or_regexp) | ||
case text_or_regexp | ||
when Regexp | ||
return unless scoped_html.match(text_or_regexp) | ||
else | ||
return unless scoped_html.include?(text_or_regexp) | ||
end | ||
|
||
flunk("Should not see #{text_or_regexp.inspect} but did") | ||
end | ||
|
||
end | ||
end |
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
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,73 @@ | ||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") | ||
|
||
describe "should_not_see" do | ||
before do | ||
@session = Webrat::TestSession.new | ||
end | ||
|
||
it "should fail if the string is in the HTML" do | ||
@session.response_body = <<-EOS | ||
<a href="/page2">Link</a> | ||
EOS | ||
|
||
lambda { | ||
@session.should_not_see "Link" | ||
}.should raise_error | ||
end | ||
|
||
it "should fail if the regexp is in the HTML" do | ||
@session.response_body = <<-EOS | ||
<a href="/page2">Link</a> | ||
EOS | ||
|
||
lambda { | ||
@session.should_not_see /Li(n)[ck]/ | ||
}.should raise_error | ||
end | ||
|
||
it "should fail if the string is in the HTML scope" do | ||
@session.response_body = <<-EOS | ||
<div id="first"> | ||
<a href="/page2">Link</a> | ||
</div> | ||
<div id="second"> | ||
</div> | ||
EOS | ||
|
||
lambda { | ||
@session.within "#first" do |scope| | ||
scope.should_not_see "Link" | ||
end | ||
}.should raise_error | ||
end | ||
|
||
it "should pass if the string is not in the HTML scope" do | ||
@session.response_body = <<-EOS | ||
<div id="first"> | ||
<a href="/page2">Link</a> | ||
</div> | ||
<div id="second"> | ||
</div> | ||
EOS | ||
|
||
@session.within "#second" do |scope| | ||
scope.should_not_see "Link" | ||
end | ||
end | ||
|
||
it "should pass if the string is not in the HTML" do | ||
@session.response_body = <<-EOS | ||
<a href="/page2">Link</a> | ||
EOS | ||
|
||
@session.should_not_see "Missing" | ||
end | ||
|
||
it "should pass if the regexp is not in the HTML" do | ||
@session.response_body = <<-EOS | ||
<a href="/page2">Different</a> | ||
EOS | ||
|
||
@session.should_not_see /Li(n)[ck]/ | ||
end | ||
end |
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,73 @@ | ||
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") | ||
|
||
describe "should_see" do | ||
before do | ||
@session = Webrat::TestSession.new | ||
end | ||
|
||
it "should pass if the string is in the HTML" do | ||
@session.response_body = <<-EOS | ||
<a href="/page2">Link</a> | ||
EOS | ||
|
||
@session.should_see "Link" | ||
end | ||
|
||
it "should pass if the regexp is in the HTML" do | ||
@session.response_body = <<-EOS | ||
<a href="/page2">Link</a> | ||
EOS | ||
|
||
@session.should_see /Li(n)[ck]/ | ||
end | ||
|
||
it "should pass if the string is in the HTML scope" do | ||
@session.response_body = <<-EOS | ||
<div id="first"> | ||
<a href="/page2">Link</a> | ||
</div> | ||
<div id="second"> | ||
</div> | ||
EOS | ||
|
||
@session.within "#first" do |scope| | ||
scope.should_see "Link" | ||
end | ||
end | ||
|
||
it "should fail if the string is not in the HTML scope" do | ||
@session.response_body = <<-EOS | ||
<div id="first"> | ||
<a href="/page2">Link</a> | ||
</div> | ||
<div id="second"> | ||
</div> | ||
EOS | ||
|
||
lambda { | ||
@session.within "#second" do |scope| | ||
scope.should_see "Link" | ||
end | ||
}.should raise_error | ||
end | ||
|
||
it "should fail if the string is not in the HTML" do | ||
@session.response_body = <<-EOS | ||
<a href="/page2">Link</a> | ||
EOS | ||
|
||
lambda { | ||
@session.should_see "Missing" | ||
}.should raise_error | ||
end | ||
|
||
it "should fail if the regexp is not in the HTML" do | ||
@session.response_body = <<-EOS | ||
<a href="/page2">Different</a> | ||
EOS | ||
|
||
lambda { | ||
@session.should_see /Li(n)[ck]/ | ||
}.should raise_error | ||
end | ||
end |