Added assert_xpath and assert_no_xpath for Test::Unit support.
This commit is contained in:
parent
fece459f5f
commit
4e0845c8db
|
@ -79,5 +79,15 @@ module Webrat
|
|||
end
|
||||
alias_method :match_xpath, :have_xpath
|
||||
|
||||
def assert_xpath(expected, &block)
|
||||
hs = HaveXpath.new(expected, &block)
|
||||
raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response_body)
|
||||
end
|
||||
|
||||
def assert_no_xpath(expected, &block)
|
||||
hs = HaveXpath.new(expected, &block)
|
||||
raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response_body)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -54,6 +54,33 @@ describe Webrat::Matchers do
|
|||
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
||||
end
|
||||
|
||||
describe 'asserts for xpath' do
|
||||
before(:each) do
|
||||
should_receive(:response_body).and_return @body
|
||||
require 'test/unit'
|
||||
end
|
||||
describe "assert_xpath" do
|
||||
it "should pass when body contains the selection" do
|
||||
assert_xpath("//div")
|
||||
end
|
||||
|
||||
it "should throw an exception when the body doesnt have matching xpath" do
|
||||
lambda {assert_xpath("//p")}.should raise_error(Test::Unit::AssertionFailedError)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "assert_no_xpath" do
|
||||
it "should pass when the body doesn't contan the xpath" do
|
||||
assert_no_xpath("//p")
|
||||
end
|
||||
|
||||
it "should throw an exception when the body does contain the xpath" do
|
||||
lambda {assert_no_xpath("//div")}.should raise_error(Test::Unit::AssertionFailedError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#have_selector" do
|
||||
|
|
Loading…
Reference in New Issue