From cc0422238420e8f3e3d098eb3ef7e5797656ab33 Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Tue, 31 Jan 2012 17:24:34 +0100 Subject: [PATCH] Send in node when initializing query --- lib/capybara/node/finders.rb | 8 ++++++-- lib/capybara/node/matchers.rb | 4 ++-- lib/capybara/query.rb | 2 +- lib/capybara/rspec/matchers.rb | 2 +- lib/capybara/session.rb | 2 +- spec/rspec/matchers_spec.rb | 4 +++- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/capybara/node/finders.rb b/lib/capybara/node/finders.rb index 32fef789..9941aa66 100644 --- a/lib/capybara/node/finders.rb +++ b/lib/capybara/node/finders.rb @@ -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 diff --git a/lib/capybara/node/matchers.rb b/lib/capybara/node/matchers.rb index f6a2e3c7..e0d7141a 100644 --- a/lib/capybara/node/matchers.rb +++ b/lib/capybara/node/matchers.rb @@ -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 diff --git a/lib/capybara/query.rb b/lib/capybara/query.rb index 238727cd..b8b39f52 100644 --- a/lib/capybara/query.rb +++ b/lib/capybara/query.rb @@ -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 diff --git a/lib/capybara/rspec/matchers.rb b/lib/capybara/rspec/matchers.rb index 9a293534..73cc4da1 100644 --- a/lib/capybara/rspec/matchers.rb +++ b/lib/capybara/rspec/matchers.rb @@ -36,7 +36,7 @@ module Capybara end def query - @query ||= Capybara::Query.new(*@args) + @query ||= @actual.query(*@args) end end diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index a9dfb82e..f5b8b451 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -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, diff --git a/spec/rspec/matchers_spec.rb b/spec/rspec/matchers_spec.rb index 822702f1..ccc0acea 100644 --- a/spec/rspec/matchers_spec.rb +++ b/spec/rspec/matchers_spec.rb @@ -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') + "

Text

".should matcher + matcher.description.should == "has xpath \"//h1\"" end context "on a string" do