From d4fb7bbd0a369636a82c345e9d00004bbe84d20b Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 3 Nov 2008 20:00:20 -0500 Subject: [PATCH] Adding Webrat::Methods module in a WIP effort to cleanup framework integration --- lib/webrat/core.rb | 1 + lib/webrat/core/methods.rb | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 lib/webrat/core/methods.rb diff --git a/lib/webrat/core.rb b/lib/webrat/core.rb index b7aaf4f..53c33e6 100644 --- a/lib/webrat/core.rb +++ b/lib/webrat/core.rb @@ -7,3 +7,4 @@ require "webrat/core/area" require "webrat/core/label" require "webrat/core/select_option" require "webrat/core/session" +require "webrat/core/methods" diff --git a/lib/webrat/core/methods.rb b/lib/webrat/core/methods.rb new file mode 100644 index 0000000..264aeea --- /dev/null +++ b/lib/webrat/core/methods.rb @@ -0,0 +1,35 @@ +module Webrat + module Methods + + def self.delegate_to_session(*meths) + meths.each do |meth| + self.class_eval <<-RUBY + def #{meth}(*args, &blk) + with_session do |sess| + sess.#{meth}(*args, &blk) + end + end + RUBY + end + end + + def with_session + @session ||= ::Webrat::Session.new + yield @session + @session.response + 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, + :save_and_open_page, :fill_in, :check, + :uncheck, :choose, :select, :attach_file, + :click_area, :click_link, :click_button, + :field_labeled + + alias reloads reload + alias visit visits + + end +end \ No newline at end of file