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,9 +6,10 @@
* Bug fixes * Bug fixes
* Accept do/end blocks in matchers. [#157] (Peter Jaros)
* Quote --chdir option to mongrel_rails to support RAILS_ROOTs with spaces * Quote --chdir option to mongrel_rails to support RAILS_ROOTs with spaces
(T.J. VanSlyke) (T.J. VanSlyke)
== 0.4.1 / 2009-01-31 == 0.4.1 / 2009-01-31
* Minor enhancements * Minor enhancements

View File

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

View File

@ -26,12 +26,16 @@ describe Webrat::Matchers do
end end
it "should be able to loop over all the matched elements" do 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 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 { 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) }.should raise_error(Spec::Expectations::ExpectationNotMetError)
end end
@ -90,12 +94,16 @@ describe Webrat::Matchers do
end end
it "should be able to loop over all the matched elements" do 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 end
it "should not match of any of the matchers in the block fail" do it "should not match of any of the matchers in the block fail" do
lambda { 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) }.should raise_error(Spec::Expectations::ExpectationNotMetError)
end end
@ -158,12 +166,16 @@ describe Webrat::Matchers do
end end
it "should be able to loop over all the matched elements" do 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 end
it "should not match of any of the matchers in the block fail" do it "should not match of any of the matchers in the block fail" do
lambda { 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) }.should raise_error(Spec::Expectations::ExpectationNotMetError)
end end