added code, working on specs

This commit is contained in:
Mike Gaffney 2008-12-27 16:44:54 -06:00
parent ee86067829
commit fbcd509097
2 changed files with 55 additions and 0 deletions

View File

@ -51,5 +51,17 @@ module Webrat
HasContent.new(content)
end
# Asserts that the body of the response contain
# the supplied string or regexp
def assert_contain(content)
assert(contain(content))
end
# Asserts that the body of the response
# does not contain the supplied string or regepx
def assert_not_contain(content)
assert(!contain(content))
end
end
end

View File

@ -156,7 +156,50 @@ describe Webrat::Matchers do
end
end
describe "asserts for contains," do
describe "assert_contain" do
it "should pass when containing the text" do
assert_contain("hello, world")
end
it "should pass when containing the regexp" do
assert_contain(/hello, world/)
end
it "should throw an exception when it the body doesnt contain the text" do
require 'test/unit'
lambda {assert_contain("monkeys")}.should raise_error(Test::Unit::AssertionFailure)
end
it "should throw an exception when it the body doesnt contain the regexp" do
require 'test/unit'
lambda {assert_contain(/monkeys/)}.should raise_error(Test::Unit::AssertionFailure)
end
end
describe "assert_not_contain" do
it "should pass when not containing the text" do
assert_not_contain("hello, world")
end
it "should pass when not containing the regexp" do
assert_not_contain(/monkeys/)
end
it "should throw an exception when it the body does contain the text" do
require 'test/unit'
lambda {assert_not_contain("hello, world")}.should raise_error(Test::Unit::AssertionFailure)
end
it "should throw an exception when it the body does contain the regexp" do
require 'test/unit'
lambda {assert_not_contain(/hello, world/)}.should raise_error(Test::Unit::AssertionFailure)
end
end
end
describe "#failure_message" do
it "should include the content string" do
hc = Webrat::Matchers::HasContent.new("hello, world!")
hc.matches?(@body)