More work on Webrat::Methods (not currently used for anything just yet)

This commit is contained in:
Bryan Helmkamp 2008-11-04 10:38:12 -05:00
parent 4a898b4223
commit c01778b0d3

View File

@ -5,28 +5,34 @@ 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
# 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,
def webrat_session
@webrat_session ||= ::Webrat::Session.new
end
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