From c01778b0d330bd29e800f3cb7d6590281415c198 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Tue, 4 Nov 2008 10:38:12 -0500 Subject: [PATCH] More work on Webrat::Methods (not currently used for anything just yet) --- lib/webrat/core/methods.rb | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/webrat/core/methods.rb b/lib/webrat/core/methods.rb index 264aeea..c327be8 100644 --- a/lib/webrat/core/methods.rb +++ b/lib/webrat/core/methods.rb @@ -5,29 +5,35 @@ module Webrat meths.each do |meth| self.class_eval <<-RUBY def #{meth}(*args, &blk) - with_session do |sess| - sess.#{meth}(*args, &blk) - end + webrat_session.#{meth}(*args, &blk) end RUBY end end - - def with_session - @session ||= ::Webrat::Session.new - yield @session - @session.response + + def self.delegate_to_session_returning_response(*meths) + meths.each do |meth| + self.class_eval <<-RUBY + def #{meth}(*args, &blk) + webrat_session.#{meth}(*args, &blk) + return webrat_session.response + end + RUBY + end + end + + def webrat_session + @webrat_session ||= ::Webrat::Session.new end - # all of these methods delegate to the @session, which should - # be created transparently. - delegate_to_session :visits, :within, :clicks_link_within, - :reload, :header, :http_accept, :basic_auth, + delegate_to_session :within, :header, :http_accept, :basic_auth, :save_and_open_page, :fill_in, :check, :uncheck, :choose, :select, :attach_file, - :click_area, :click_link, :click_button, - :field_labeled + :field_labeled, :cookies, :response, :current_page, + :current_url + delegate_to_session_returning_response :visits, :click_link, :click_area, :click_button, :reload, :clicks_link_within + alias reloads reload alias visit visits