Send in node when initializing query

This commit is contained in:
Jonas Nicklas 2012-01-31 17:24:34 +01:00
parent d7c9330849
commit cc04222384
6 changed files with 14 additions and 8 deletions

View File

@ -113,7 +113,7 @@ module Capybara
# @return [Array[Capybara::Element]] The found elements
#
def all(*args)
query = Capybara::Query.new(*args)
query = query(*args)
find_in_base(query).select { |node| query.matches_filters?(node) }
end
@ -132,10 +132,14 @@ module Capybara
all(*args).first
end
def query(*args)
Capybara::Query.new(self, *args)
end
protected
def raise_find_error(*args)
query = Capybara::Query.new(*args)
query = query(*args)
raise Capybara::ElementNotFound, query.failure_message(:find, self)
end

View File

@ -36,7 +36,7 @@ module Capybara
options = if args.last.is_a?(Hash) then args.last else {} end
wait_until do
results = all(*args)
Query.new(*args).matches_count?(results) or raise Capybara::ExpectationNotMet
query(*args).matches_count?(results) or raise Capybara::ExpectationNotMet
results
end
rescue Capybara::ExpectationNotMet
@ -55,7 +55,7 @@ module Capybara
options = if args.last.is_a?(Hash) then args.last else {} end
wait_until do
results = all(*args)
Query.new(*args).matches_count?(results) and raise Capybara::ExpectationNotMet
query(*args).matches_count?(results) and raise Capybara::ExpectationNotMet
results
end
rescue Capybara::ExpectationNotMet

View File

@ -2,7 +2,7 @@ module Capybara
class Query
attr_accessor :selector, :locator, :options, :xpath
def initialize(*args)
def initialize(node, *args)
@options = if args.last.is_a?(Hash) then args.pop.dup else {} end
unless options.has_key?(:visible)
@options[:visible] = Capybara.ignore_hidden_elements

View File

@ -36,7 +36,7 @@ module Capybara
end
def query
@query ||= Capybara::Query.new(*@args)
@query ||= @actual.query(*@args)
end
end

View File

@ -36,7 +36,7 @@ module Capybara
:has_no_button?, :has_field?, :has_no_field?, :has_checked_field?,
:has_unchecked_field?, :has_no_table?, :has_table?, :unselect,
:has_select?, :has_no_select?, :has_selector?, :has_no_selector?,
:click_on, :has_no_checked_field?, :has_no_unchecked_field?
:click_on, :has_no_checked_field?, :has_no_unchecked_field?, :query
]
SESSION_METHODS = [
:body, :html, :current_url, :current_host, :evaluate_script, :source,

View File

@ -152,7 +152,9 @@ describe Capybara::RSpecMatchers do
describe "have_selector matcher" do
it "gives proper description" do
have_selector('//h1').description.should == "has xpath \"//h1\""
matcher = have_selector('//h1')
"<h1>Text</h1>".should matcher
matcher.description.should == "has xpath \"//h1\""
end
context "on a string" do