diff --git a/lib/webrat/core/page.rb b/lib/webrat/core/page.rb index fedc518..9cac8ec 100644 --- a/lib/webrat/core/page.rb +++ b/lib/webrat/core/page.rb @@ -24,28 +24,13 @@ module Webrat session.current_page = self end - # Reloads the last page requested. Note that this will resubmit forms - # and their data. - # - # Example: - # reloads - def reloads - load_page + def http_method + @method end - - alias_method :reload, :reloads - # Works like clicks_link, but only looks for the link text within a given selector - # - # Example: - # clicks_link_within "#user_12", "Vote" - def clicks_link_within(selector, link_text) - session.within(selector) do |scope| - scope.clicks_link(link_text) - end + def data + @data end - - alias_method :click_link_within, :clicks_link_within def_delegators :scope, :fill_in, :fills_in def_delegators :scope, :check, :checks @@ -59,6 +44,10 @@ module Webrat def_delegators :scope, :click_post_link, :clicks_post_link def_delegators :scope, :click_put_link, :clicks_put_link def_delegators :scope, :click_button, :clicks_button + + def scope + @scope ||= Scope.new(self, session.response_body) + end protected @@ -71,9 +60,7 @@ module Webrat @scope = nil end - def scope - @scope ||= Scope.new(self, session.response_body) - end + end end \ No newline at end of file diff --git a/lib/webrat/core/scope.rb b/lib/webrat/core/scope.rb index bd2c6f8..e26e270 100644 --- a/lib/webrat/core/scope.rb +++ b/lib/webrat/core/scope.rb @@ -1,5 +1,6 @@ module Webrat class Scope + include Logging include Flunk def initialize(page, html, selector = nil) diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index e63259f..0f2066a 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -46,10 +46,38 @@ module Webrat @current_page ||= Page.new(self) end + def current_scope + current_page.scope + end + def current_page=(new_page) @current_page = new_page end + # Reloads the last page requested. Note that this will resubmit forms + # and their data. + # + # Example: + # reloads + def reloads + request_page(@current_page.url, current_page.http_method, current_page.data) + end + + alias_method :reload, :reloads + + + # Works like clicks_link, but only looks for the link text within a given selector + # + # Example: + # clicks_link_within "#user_12", "Vote" + def clicks_link_within(selector, link_text) + within(selector) do |scope| + scope.clicks_link(link_text) + end + end + + alias_method :click_link_within, :clicks_link_within + def within(selector) yield Scope.new(current_page, response_body, selector) end @@ -75,7 +103,7 @@ module Webrat def method_missing(name, *args, &block) if current_page.respond_to?(name) - current_page.send(name, *args, &block) + current_scope.send(name, *args, &block) else super end