Accept do/end blocks in matchers. [#157 state:resolved]
This commit is contained in:
parent
7fe667da73
commit
24eab77ecd
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
* 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)
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user