added assert_selector
This commit is contained in:
parent
cf1589823d
commit
fece459f5f
@ -33,5 +33,20 @@ module Webrat
|
|||||||
end
|
end
|
||||||
alias_method :match_selector, :have_selector
|
alias_method :match_selector, :have_selector
|
||||||
|
|
||||||
|
|
||||||
|
# Asserts that the body of the response contains
|
||||||
|
# the supplied selector
|
||||||
|
def assert_selector(expected)
|
||||||
|
hs = HaveSelector.new(expected)
|
||||||
|
raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response_body)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Asserts that the body of the response
|
||||||
|
# does not contain the supplied string or regepx
|
||||||
|
def assert_no_selector(expected)
|
||||||
|
hs = HaveSelector.new(expected)
|
||||||
|
raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response_body)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -86,6 +86,33 @@ describe Webrat::Matchers do
|
|||||||
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "asserts for selector," do
|
||||||
|
before(:each) do
|
||||||
|
should_receive(:response_body).and_return @body
|
||||||
|
require 'test/unit'
|
||||||
|
end
|
||||||
|
describe "assert_selector" do
|
||||||
|
it "should pass when body contains the selection" do
|
||||||
|
assert_selector("div")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should throw an exception when the body doesnt have matching selection" do
|
||||||
|
lambda {assert_selector("p")}.should raise_error(Test::Unit::AssertionFailedError)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "assert_not_selector" do
|
||||||
|
it "should pass when the body doesn't contan the selection" do
|
||||||
|
assert_no_selector("p")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should throw an exception when the body does contain the selection" do
|
||||||
|
lambda {assert_no_selector("div")}.should raise_error(Test::Unit::AssertionFailedError)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#have_tag" do
|
describe "#have_tag" do
|
||||||
|
Loading…
Reference in New Issue
Block a user