Merge branch 'lh_86_assert_contains' of git@github.com:gaffo/webrat into lh_86_assert_contains

This commit is contained in:
Mike 2009-01-05 13:06:53 -06:00
commit 7bfa4c55c0
4 changed files with 28 additions and 28 deletions

View File

@ -36,14 +36,14 @@ module Webrat
# Asserts that the body of the response contains # Asserts that the body of the response contains
# the supplied selector # the supplied selector
def assert_selector(expected) def assert_have_selector(expected)
hs = HaveSelector.new(expected) hs = HaveSelector.new(expected)
raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response_body) raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.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_no_selector(expected) def assert_have_no_selector(expected)
hs = HaveSelector.new(expected) hs = HaveSelector.new(expected)
raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response_body) raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response_body)
end end

View File

@ -55,14 +55,14 @@ module Webrat
# Asserts that the body of the response contains # Asserts that the body of the response contains
# the supplied tag with the associated selectors # the supplied tag with the associated selectors
def assert_tag(name, attributes = {}) def assert_have_tag(name, attributes = {})
ht = HaveTag.new([name, attributes]) ht = HaveTag.new([name, attributes])
raise Test::Unit::AssertionFailedError.new(ht.failure_message) unless ht.matches?(response_body) raise Test::Unit::AssertionFailedError.new(ht.failure_message) unless ht.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_no_tag(name, attributes = {}) def assert_have_no_tag(name, attributes = {})
ht = HaveTag.new([name, attributes]) ht = HaveTag.new([name, attributes])
raise Test::Unit::AssertionFailedError.new(ht.negative_failure_message) if ht.matches?(response_body) raise Test::Unit::AssertionFailedError.new(ht.negative_failure_message) if ht.matches?(response_body)
end end

View File

@ -79,12 +79,12 @@ module Webrat
end end
alias_method :match_xpath, :have_xpath alias_method :match_xpath, :have_xpath
def assert_xpath(expected, &block) def assert_have_xpath(expected, &block)
hs = HaveXpath.new(expected, &block) hs = HaveXpath.new(expected, &block)
raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response_body) raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response_body)
end end
def assert_no_xpath(expected, &block) def assert_have_no_xpath(expected, &block)
hs = HaveXpath.new(expected, &block) hs = HaveXpath.new(expected, &block)
raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response_body) raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response_body)
end end

View File

@ -59,24 +59,24 @@ describe Webrat::Matchers do
should_receive(:response_body).and_return @body should_receive(:response_body).and_return @body
require 'test/unit' require 'test/unit'
end end
describe "assert_xpath" do describe "assert_have_xpath" do
it "should pass when body contains the selection" do it "should pass when body contains the selection" do
assert_xpath("//div") assert_have_xpath("//div")
end end
it "should throw an exception when the body doesnt have matching xpath" do it "should throw an exception when the body doesnt have matching xpath" do
lambda {assert_xpath("//p")}.should raise_error(Test::Unit::AssertionFailedError) lambda {assert_have_xpath("//p")}.should raise_error(Test::Unit::AssertionFailedError)
end end
end end
describe "assert_no_xpath" do describe "assert_have_no_xpath" do
it "should pass when the body doesn't contan the xpath" do it "should pass when the body doesn't contan the xpath" do
assert_no_xpath("//p") assert_have_no_xpath("//p")
end end
it "should throw an exception when the body does contain the xpath" do it "should throw an exception when the body does contain the xpath" do
lambda {assert_no_xpath("//div")}.should raise_error(Test::Unit::AssertionFailedError) lambda {assert_have_no_xpath("//div")}.should raise_error(Test::Unit::AssertionFailedError)
end end
end end
end end
@ -118,24 +118,24 @@ describe Webrat::Matchers do
should_receive(:response_body).and_return @body should_receive(:response_body).and_return @body
require 'test/unit' require 'test/unit'
end end
describe "assert_selector" do describe "assert_have_selector" do
it "should pass when body contains the selection" do it "should pass when body contains the selection" do
assert_selector("div") assert_have_selector("div")
end end
it "should throw an exception when the body doesnt have matching selection" do it "should throw an exception when the body doesnt have matching selection" do
lambda {assert_selector("p")}.should raise_error(Test::Unit::AssertionFailedError) lambda {assert_have_selector("p")}.should raise_error(Test::Unit::AssertionFailedError)
end end
end end
describe "assert_not_selector" do describe "assert_have_not_selector" do
it "should pass when the body doesn't contan the selection" do it "should pass when the body doesn't contan the selection" do
assert_no_selector("p") assert_have_no_selector("p")
end end
it "should throw an exception when the body does contain the selection" do it "should throw an exception when the body does contain the selection" do
lambda {assert_no_selector("div")}.should raise_error(Test::Unit::AssertionFailedError) lambda {assert_have_no_selector("div")}.should raise_error(Test::Unit::AssertionFailedError)
end end
end end
end end
@ -192,40 +192,40 @@ describe Webrat::Matchers do
should_receive(:response_body).and_return @body should_receive(:response_body).and_return @body
require 'test/unit' require 'test/unit'
end end
describe "assert_tag" do describe "assert_have_tag" do
it "should pass when body contains the tag" do it "should pass when body contains the tag" do
assert_tag("div") assert_have_tag("div")
end end
it "should pass when finding with additional selectors" do it "should pass when finding with additional selectors" do
assert_tag("div", :class => "inner") assert_have_tag("div", :class => "inner")
end end
it "should throw an exception when the body doesnt have matching tag" do it "should throw an exception when the body doesnt have matching tag" do
lambda {assert_tag("p")}.should raise_error(Test::Unit::AssertionFailedError) lambda {assert_have_tag("p")}.should raise_error(Test::Unit::AssertionFailedError)
end end
it "should throw an exception when the body doens't have a tag matching the additional selector" do it "should throw an exception when the body doens't have a tag matching the additional selector" do
lambda {assert_tag("div", :class => "nope")}.should raise_error(Test::Unit::AssertionFailedError) lambda {assert_have_tag("div", :class => "nope")}.should raise_error(Test::Unit::AssertionFailedError)
end end
end end
describe "assert_no_tag" do describe "assert_have_no_tag" do
it "should pass when the body doesn't contan the tag" do it "should pass when the body doesn't contan the tag" do
assert_no_tag("p") assert_have_no_tag("p")
end end
it "should pass when the body doesn't contain the tag due to additional selectors missing" do it "should pass when the body doesn't contain the tag due to additional selectors missing" do
assert_no_tag("div", :class => "nope") assert_have_no_tag("div", :class => "nope")
end end
it "should throw an exception when the body does contain the tag" do it "should throw an exception when the body does contain the tag" do
lambda {assert_no_tag("div")}.should raise_error(Test::Unit::AssertionFailedError) lambda {assert_have_no_tag("div")}.should raise_error(Test::Unit::AssertionFailedError)
end end
it "should throw an exception when the body contains the tag with additional selectors" do it "should throw an exception when the body contains the tag with additional selectors" do
lambda {assert_no_tag("div", :class => "inner")}.should raise_error(Test::Unit::AssertionFailedError) lambda {assert_have_no_tag("div", :class => "inner")}.should raise_error(Test::Unit::AssertionFailedError)
end end
end end
end end