Expose append and prepend as public for xpath

This commit is contained in:
Jonas Nicklas 2009-12-13 15:02:25 +01:00
parent 0509c87aa5
commit 72d01848da
2 changed files with 36 additions and 8 deletions

View File

@ -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

View File

@ -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')