diff --git a/History.txt b/History.txt index 218841a..55de196 100644 --- a/History.txt +++ b/History.txt @@ -6,9 +6,10 @@ * 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) - + == 0.4.1 / 2009-01-31 * Minor enhancements diff --git a/lib/webrat/core/matchers/have_xpath.rb b/lib/webrat/core/matchers/have_xpath.rb index 6f242b1..bd3618f 100644 --- a/lib/webrat/core/matchers/have_xpath.rb +++ b/lib/webrat/core/matchers/have_xpath.rb @@ -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 diff --git a/spec/public/matchers_spec.rb b/spec/public/matchers_spec.rb index f2eb337..554708c 100644 --- a/spec/public/matchers_spec.rb +++ b/spec/public/matchers_spec.rb @@ -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