From fbcd5090973919e7e68d878ba65d1d8bd835901e Mon Sep 17 00:00:00 2001 From: Mike Gaffney Date: Sat, 27 Dec 2008 16:44:54 -0600 Subject: [PATCH] added code, working on specs --- lib/webrat/core/matchers/have_content.rb | 12 +++++++ spec/api/matchers_spec.rb | 43 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/lib/webrat/core/matchers/have_content.rb b/lib/webrat/core/matchers/have_content.rb index 9a2c6a0..11f9092 100644 --- a/lib/webrat/core/matchers/have_content.rb +++ b/lib/webrat/core/matchers/have_content.rb @@ -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 \ No newline at end of file diff --git a/spec/api/matchers_spec.rb b/spec/api/matchers_spec.rb index af885b3..3c40f98 100644 --- a/spec/api/matchers_spec.rb +++ b/spec/api/matchers_spec.rb @@ -155,8 +155,51 @@ describe Webrat::Matchers do @body.should contain(/hello, world/) 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)