Skip to content

Commit

Permalink
assert_contain and assert_not_contain fully functional
Browse files Browse the repository at this point in the history
  • Loading branch information
adkron committed Dec 31, 2008
1 parent f864bbd commit b3d6c9d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/webrat/core/matchers/have_content.rb
Expand Up @@ -55,14 +55,14 @@ def contain(content)
# the supplied string or regexp
def assert_contain(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

# Asserts that the body of the response
# does not contain the supplied string or regepx
def assert_not_contain(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
Expand Down
18 changes: 9 additions & 9 deletions spec/api/matchers_spec.rb
Expand Up @@ -157,6 +157,10 @@
end

describe "asserts for contains," do
before(:each) do
should_receive(:response_body).and_return @body
require 'test/unit'
end
describe "assert_contain" do
it "should pass when containing the text" do
assert_contain("hello, world")
Expand All @@ -167,33 +171,29 @@
end

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::AssertionFailure)
lambda {assert_contain("monkeys")}.should raise_error(Test::Unit::AssertionFailedError)
end

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::AssertionFailure)
lambda {assert_contain(/monkeys/)}.should raise_error(Test::Unit::AssertionFailedError)
end
end

describe "assert_not_contain" do
it "should pass when not containing the text" do
assert_not_contain("hello, world")
assert_not_contain("monkeys")
end

it "should pass when not containing the regexp" do
assert_not_contain(/monkeys/)
end

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::AssertionFailure)
lambda {assert_not_contain("hello, world")}.should raise_error(Test::Unit::AssertionFailedError)
end

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::AssertionFailure)
lambda {assert_not_contain(/hello, world/)}.should raise_error(Test::Unit::AssertionFailedError)
end
end
end
Expand Down

0 comments on commit b3d6c9d

Please sign in to comment.