From 72d01848daa036c4f78aa32fe19b21de8f4689cf Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Sun, 13 Dec 2009 15:02:25 +0100 Subject: [PATCH] Expose append and prepend as public for xpath --- lib/capybara/xpath.rb | 16 ++++++++-------- spec/xpath_spec.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lib/capybara/xpath.rb b/lib/capybara/xpath.rb index 031cc33e..d8f20794 100644 --- a/lib/capybara/xpath.rb +++ b/lib/capybara/xpath.rb @@ -91,6 +91,14 @@ module Capybara def to_s @paths.join(' | ') end + + def append(path) + XPath.new(*[@paths, XPath.wrap(path).paths].flatten) + end + + def prepend(path) + XPath.new(*[XPath.wrap(path).paths, @paths].flatten) + end protected @@ -111,14 +119,6 @@ module Capybara "'#{string}'" end end - - def prepend(path) - XPath.new(*[path, @paths].flatten) - end - - def append(path) - XPath.new(*[@paths, path].flatten) - end end end diff --git a/spec/xpath_spec.rb b/spec/xpath_spec.rb index f0f39aff..2afe9a90 100644 --- a/spec/xpath_spec.rb +++ b/spec/xpath_spec.rb @@ -29,6 +29,34 @@ describe Capybara::XPath do end end + describe '#append' do + it "should append an XPath's paths" do + @xpath = Capybara::XPath.wrap('//test') + @xpath = @xpath.append(Capybara::XPath.wrap('//foo/bar')) + @xpath.paths.should == ['//test', '//foo/bar'] + end + + it "should append an String as a new path" do + @xpath = Capybara::XPath.wrap('//test') + @xpath = @xpath.append('//foo/bar') + @xpath.paths.should == ['//test', '//foo/bar'] + end + end + + describe '#prepend' do + it "should prepend an XPath's paths" do + @xpath = Capybara::XPath.wrap('//test') + @xpath = @xpath.prepend(Capybara::XPath.wrap('//foo/bar')) + @xpath.paths.should == ['//foo/bar', '//test'] + end + + it "should prepend an String as a new path" do + @xpath = Capybara::XPath.wrap('//test') + @xpath = @xpath.prepend('//foo/bar') + @xpath.paths.should == ['//foo/bar', '//test'] + end + end + describe '#scope' do it "should prepend the given scope to all paths" do @xpath = Capybara::XPath.new('//foo/bar', '//test[@blah=foo]').scope('//quox')