Accept do/end blocks in matchers. [#157 state:resolved]

This commit is contained in:
Peter Jaros 2009-02-08 19:02:24 -05:00 committed by Bryan Helmkamp
parent 7fe667da73
commit 24eab77ecd
3 changed files with 24 additions and 9 deletions

View File

@ -6,6 +6,7 @@
* Bug fixes
* Accept do/end blocks in matchers. [#157] (Peter Jaros)
* Quote --chdir option to mongrel_rails to support RAILS_ROOTs with spaces
(T.J. VanSlyke)

View File

@ -10,7 +10,9 @@ module Webrat
@block = block
end
def matches?(stringlike)
def matches?(stringlike, &block)
@block ||= block
if Webrat.configuration.parse_with_nokogiri?
matches_nokogiri?(stringlike)
else

View File

@ -26,12 +26,16 @@ describe Webrat::Matchers do
end
it "should be able to loop over all the matched elements" do
@body.should have_xpath("//div") { |node| node.first.name.should == "div" }
@body.should have_xpath("//div") do |node|
node.first.name.should == "div"
end
end
it "should not match of any of the matchers in the block fail" do
it "should not match if any of the matchers in the block fail" do
lambda {
@body.should have_xpath("//div") { |node| node.first.name.should == "p" }
@body.should have_xpath("//div") do |node|
node.first.name.should == "p"
end
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
end
@ -90,12 +94,16 @@ describe Webrat::Matchers do
end
it "should be able to loop over all the matched elements" do
@body.should have_selector("div") { |node| node.first.name.should == "div" }
@body.should have_selector("div") do |node|
node.first.name.should == "div"
end
end
it "should not match of any of the matchers in the block fail" do
lambda {
@body.should have_selector("div") { |node| node.first.name.should == "p" }
@body.should have_selector("div") do |node|
node.first.name.should == "p"
end
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
end
@ -158,12 +166,16 @@ describe Webrat::Matchers do
end
it "should be able to loop over all the matched elements" do
@body.should have_tag("div") { |node| node.first.name.should == "div" }
@body.should have_tag("div") do |node|
node.first.name.should == "div"
end
end
it "should not match of any of the matchers in the block fail" do
lambda {
@body.should have_tag("div") { |node| node.first.name.should == "p" }
@body.should have_tag("div") do |node|
node.first.name.should == "p"
end
}.should raise_error(Spec::Expectations::ExpectationNotMetError)
end