Adding Webrat::Methods module in a WIP effort to cleanup framework integration

This commit is contained in:
Bryan Helmkamp 2008-11-03 20:00:20 -05:00
parent 87f549b3af
commit d4fb7bbd0a
2 changed files with 36 additions and 0 deletions

View File

@ -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"

View File

@ -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