Cleaning up the Rails session code. Extract scoped_html method in Scope

This commit is contained in:
Bryan Helmkamp 2008-09-14 14:37:24 -04:00
parent fb5b663590
commit 44db244a76
3 changed files with 17 additions and 19 deletions

View File

@ -165,19 +165,21 @@ module Webrat
alias_method :click_button, :clicks_button
def dom # :nodoc:
return @dom if defined?(@dom) && @dom
@dom = Hpricot(@html)
if @selector
html = (@dom / @selector).first.to_html
@dom = Hpricot(html)
end
return @dom
@dom ||= Hpricot(scoped_html)
end
protected
def scoped_html
@scoped_html ||= begin
if @selector
(Hpricot(@html) / @selector).first.to_html
else
@html
end
end
end
def find_select_option(option_text, id_or_name_or_label)
if id_or_name_or_label
field = find_field(id_or_name_or_label, SelectField)

View File

@ -109,6 +109,11 @@ module Webrat
yield Scope.new(self, response_body, selector)
end
# Issues a GET request for a page, follows any redirects, and verifies the final page
# load was successful.
#
# Example:
# visits "/"
def visits(url = nil, http_method = :get, data = {})
request_page(url, http_method, data)
end
@ -136,6 +141,5 @@ module Webrat
def_delegators :current_scope, :click_post_link, :clicks_post_link
def_delegators :current_scope, :click_put_link, :clicks_put_link
def_delegators :current_scope, :click_button, :clicks_button
end
end

View File

@ -6,15 +6,6 @@ module ActionController
include Webrat::RedirectActions
end
# Issues a GET request for a page, follows any redirects, and verifies the final page
# load was successful.
#
# Example:
# visits "/"
def visits(*args)
webrat_session.visits(*args)
end
def respond_to?(name)
super || webrat_session.respond_to?(name)
end
@ -32,6 +23,7 @@ module ActionController
def webrat_session
@webrat_session ||= Webrat::RailsSession.new(self)
end
end
end
end