assert_contain and assert_not_contain fully functional

This commit is contained in:
Amos King 2008-12-31 17:01:46 -06:00
parent f864bbde52
commit b3d6c9d89b
2 changed files with 11 additions and 11 deletions

View File

@ -55,14 +55,14 @@ module Webrat
# the supplied string or regexp # the supplied string or regexp
def assert_contain(content) def assert_contain(content)
hc = HasContent.new(content) hc = HasContent.new(content)
assert(hc.matches?(content), hc.failure_message) raise Test::Unit::AssertionFailedError.new(hc.failure_message) unless hc.matches?(response_body)
end end
# Asserts that the body of the response # Asserts that the body of the response
# does not contain the supplied string or regepx # does not contain the supplied string or regepx
def assert_not_contain(content) def assert_not_contain(content)
hc = HasContent.new(content) hc = HasContent.new(content)
assert(!hc.matches?(content), hc.negative_failure_message) raise Test::Unit::AssertionFailedError.new(hc.negative_failure_message) if hc.matches?(response_body)
end end
end end

View File

@ -157,6 +157,10 @@ describe Webrat::Matchers do
end end
describe "asserts for contains," do describe "asserts for contains," do
before(:each) do
should_receive(:response_body).and_return @body
require 'test/unit'
end
describe "assert_contain" do describe "assert_contain" do
it "should pass when containing the text" do it "should pass when containing the text" do
assert_contain("hello, world") assert_contain("hello, world")
@ -167,19 +171,17 @@ describe Webrat::Matchers do
end end
it "should throw an exception when the body doesnt contain the text" do it "should throw an exception when the body doesnt contain the text" do
require 'test/unit' lambda {assert_contain("monkeys")}.should raise_error(Test::Unit::AssertionFailedError)
lambda {assert_contain("monkeys")}.should raise_error(Test::Unit::AssertionFailure)
end end
it "should throw an exception when the body doesnt contain the regexp" do it "should throw an exception when the body doesnt contain the regexp" do
require 'test/unit' lambda {assert_contain(/monkeys/)}.should raise_error(Test::Unit::AssertionFailedError)
lambda {assert_contain(/monkeys/)}.should raise_error(Test::Unit::AssertionFailure)
end end
end end
describe "assert_not_contain" do describe "assert_not_contain" do
it "should pass when not containing the text" do it "should pass when not containing the text" do
assert_not_contain("hello, world") assert_not_contain("monkeys")
end end
it "should pass when not containing the regexp" do it "should pass when not containing the regexp" do
@ -187,13 +189,11 @@ describe Webrat::Matchers do
end end
it "should throw an exception when the body does contain the text" do it "should throw an exception when the body does contain the text" do
require 'test/unit' lambda {assert_not_contain("hello, world")}.should raise_error(Test::Unit::AssertionFailedError)
lambda {assert_not_contain("hello, world")}.should raise_error(Test::Unit::AssertionFailure)
end end
it "should throw an exception when the body does contain the regexp" do it "should throw an exception when the body does contain the regexp" do
require 'test/unit' lambda {assert_not_contain(/hello, world/)}.should raise_error(Test::Unit::AssertionFailedError)
lambda {assert_not_contain(/hello, world/)}.should raise_error(Test::Unit::AssertionFailure)
end end
end end
end end