From f032a8de73d25899f149ba6c0740c0fecac3f10e Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sat, 29 Nov 2008 00:11:40 -0500 Subject: [PATCH] Refactoring CSS searching for building Links, Areas and Forms --- lib/webrat/core/area.rb | 4 ++++ lib/webrat/core/form.rb | 4 ++++ lib/webrat/core/link.rb | 4 ++++ lib/webrat/core/scope.rb | 13 +++++-------- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/webrat/core/area.rb b/lib/webrat/core/area.rb index 5c9dedf..fd38183 100644 --- a/lib/webrat/core/area.rb +++ b/lib/webrat/core/area.rb @@ -1,6 +1,10 @@ module Webrat class Area #:nodoc: + def self.css_search + "area" + end + def initialize(session, element) @session = session @element = element diff --git a/lib/webrat/core/form.rb b/lib/webrat/core/form.rb index c29a69b..56507df 100644 --- a/lib/webrat/core/form.rb +++ b/lib/webrat/core/form.rb @@ -5,6 +5,10 @@ module Webrat class Form #:nodoc: attr_reader :element + def self.css_search + "form" + end + def initialize(session, element) @session = session @element = element diff --git a/lib/webrat/core/link.rb b/lib/webrat/core/link.rb index 81653bc..ccdd9d2 100644 --- a/lib/webrat/core/link.rb +++ b/lib/webrat/core/link.rb @@ -3,6 +3,10 @@ require "webrat/core_extensions/blank" module Webrat class Link #:nodoc: + def self.css_search + "a[@href]" + end + def initialize(session, element) @session = session @element = element diff --git a/lib/webrat/core/scope.rb b/lib/webrat/core/scope.rb index 3a25d3d..e04f4d4 100644 --- a/lib/webrat/core/scope.rb +++ b/lib/webrat/core/scope.rb @@ -289,9 +289,6 @@ module Webrat end def scoped_dom #:nodoc: - # if @selector == "#form2" - # require "rubygems"; require "ruby-debug"; Debugger.start; debugger - # end Webrat::XML.document("" + Webrat::XML.to_html(Webrat::XML.css_search(@scope.dom, @selector).first) + "") end @@ -309,22 +306,22 @@ module Webrat end def areas #:nodoc: - Webrat::XML.css_search(dom, "area").map do |element| + Webrat::XML.css_search(dom, Area.css_search).map do |element| Area.new(@session, element) end end def links #:nodoc: - Webrat::XML.css_search(dom, "a[@href]").map do |link_element| - Link.new(@session, link_element) + Webrat::XML.css_search(dom, Link.css_search).map do |element| + Link.new(@session, element) end end def forms #:nodoc: return @forms if @forms - @forms = Webrat::XML.css_search(dom, "form").map do |form_element| - Form.new(@session, form_element) + @forms = Webrat::XML.css_search(dom, Form.css_search).map do |element| + Form.new(@session, element) end end