mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Moved has_*? back to session from searchable
This commit is contained in:
parent
810fe3bc74
commit
4a69fbd6f5
4 changed files with 30 additions and 108 deletions
|
@ -1,35 +1,5 @@
|
|||
module Capybara
|
||||
module Searchable
|
||||
def has_content?(content)
|
||||
has_xpath?(XPath.content(content).to_s)
|
||||
end
|
||||
|
||||
def has_no_content?(content)
|
||||
!has_content?(content)
|
||||
end
|
||||
|
||||
def has_xpath?(path, options={})
|
||||
results = all(path, options)
|
||||
|
||||
if options[:count]
|
||||
results.size == options[:count]
|
||||
else
|
||||
results.size > 0
|
||||
end
|
||||
end
|
||||
|
||||
def has_no_xpath?(path, options={})
|
||||
!has_xpath?(path, options)
|
||||
end
|
||||
|
||||
def has_css?(path, options={})
|
||||
has_xpath?(XPath.from_css(path), options)
|
||||
end
|
||||
|
||||
def has_no_css?(path, options={})
|
||||
!has_css?(path, options)
|
||||
end
|
||||
|
||||
def find(locator, options = {})
|
||||
all(locator, options).first
|
||||
end
|
||||
|
|
|
@ -113,6 +113,36 @@ module Capybara
|
|||
yield
|
||||
end
|
||||
end
|
||||
|
||||
def has_content?(content)
|
||||
has_xpath?(XPath.content(content).to_s)
|
||||
end
|
||||
|
||||
def has_no_content?(content)
|
||||
!has_content?(content)
|
||||
end
|
||||
|
||||
def has_xpath?(path, options={})
|
||||
results = all(path, options)
|
||||
|
||||
if options[:count]
|
||||
results.size == options[:count]
|
||||
else
|
||||
results.size > 0
|
||||
end
|
||||
end
|
||||
|
||||
def has_no_xpath?(path, options={})
|
||||
!has_xpath?(path, options)
|
||||
end
|
||||
|
||||
def has_css?(path, options={})
|
||||
has_xpath?(XPath.from_css(path), options)
|
||||
end
|
||||
|
||||
def has_no_css?(path, options={})
|
||||
!has_css?(path, options)
|
||||
end
|
||||
|
||||
def save_and_open_page
|
||||
require 'capybara/save_and_open_page'
|
||||
|
|
|
@ -117,8 +117,6 @@ shared_examples_for "driver with node path support" do
|
|||
it "should be able to navigate/search child nodes" do
|
||||
@node.all('//table').size.should == 3
|
||||
@node.find('//form').all('//table').size.should == 1
|
||||
@node.has_xpath?('//table', :count => 3).should be_true
|
||||
@node.find('//form').has_xpath?('//table', :count => 1).should be_true
|
||||
@node.find('//form').find('//table//caption').text.should == 'Agent'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,82 +56,6 @@ module Capybara
|
|||
end
|
||||
|
||||
end #all
|
||||
|
||||
describe "#has_xpath?" do
|
||||
def new_node(values = {})
|
||||
stub(Node, values)
|
||||
end
|
||||
|
||||
before do
|
||||
@searchable = Klass.new
|
||||
end
|
||||
|
||||
it "should start with unfiltered matches for locator" do
|
||||
@searchable.should_receive(:all_unfiltered).with('//x').and_return([])
|
||||
@searchable.has_xpath?('//x')
|
||||
end
|
||||
|
||||
it "should be true if the given selector is on the page" do
|
||||
@searchable.stub(:all_unfiltered).and_return([new_node])
|
||||
@searchable.should have_xpath("//x")
|
||||
end
|
||||
|
||||
it "should be false if the given selector is not on the page" do
|
||||
@searchable.should_receive(:all_unfiltered).and_return([])
|
||||
@searchable.should_not have_xpath("//abbr")
|
||||
end
|
||||
|
||||
context "with count" do
|
||||
|
||||
it "should be true if the content is on the page the given number of times" do
|
||||
@searchable.stub(:all_unfiltered).and_return([new_node, new_node])
|
||||
@searchable.should have_xpath("//x", :count => 2)
|
||||
end
|
||||
|
||||
it "should be false if the content is not on the page the given number of times" do
|
||||
@searchable.stub(:all_unfiltered).and_return([new_node, new_node])
|
||||
@searchable.should_not have_xpath("//x", :count => 6)
|
||||
end
|
||||
|
||||
it "should be false if the content isn't on the page at all" do
|
||||
@searchable.stub(:all_unfiltered).and_return([])
|
||||
@searchable.should_not have_xpath("//x", :count => 2)
|
||||
@searchable.should_not have_xpath("//x", :count => 1)
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
before do
|
||||
@searchable.stub(:all_unfiltered).and_return([new_node(:text => "node one"), new_node(:text => 'node two')])
|
||||
end
|
||||
|
||||
it "should discard all matches where the given string is not contained" do
|
||||
@searchable.should have_xpath("//x", :text => "node one", :count => 1)
|
||||
@searchable.should have_xpath('//x', :text => 'node two', :count => 1)
|
||||
@searchable.should have_xpath('//x', :text => 'node', :count => 2)
|
||||
@searchable.should_not have_xpath("//x", :text => "Doesnotexist")
|
||||
end
|
||||
|
||||
it "should discard all matches where the given regexp is not matched" do
|
||||
@searchable.should have_xpath("//x", :text => /Node\sone/i, :count => 1)
|
||||
@searchable.should_not have_xpath("//x", :text => /Nope$/)
|
||||
end
|
||||
end
|
||||
|
||||
context "with visible" do
|
||||
before do
|
||||
node1_visible = new_node(:text => "node one", :visible? => true)
|
||||
node2_hidden = new_node(:text => "node two", :visible? => false)
|
||||
@searchable.stub(:all_unfiltered).and_return([node1_visible, node2_hidden])
|
||||
end
|
||||
|
||||
it "should discard hidden matches" do
|
||||
@searchable.should have_xpath('//x', :visible => true, :count => 1)
|
||||
end
|
||||
end
|
||||
|
||||
end #has_xpath?
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Reference in a new issue