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
1 changed files with 20 additions and 14 deletions

View File

@ -5,29 +5,35 @@ module Webrat
meths.each do |meth| meths.each do |meth|
self.class_eval <<-RUBY self.class_eval <<-RUBY
def #{meth}(*args, &blk) def #{meth}(*args, &blk)
with_session do |sess| webrat_session.#{meth}(*args, &blk)
sess.#{meth}(*args, &blk)
end
end end
RUBY RUBY
end end
end end
def with_session def self.delegate_to_session_returning_response(*meths)
@session ||= ::Webrat::Session.new meths.each do |meth|
yield @session self.class_eval <<-RUBY
@session.response 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 end
# all of these methods delegate to the @session, which should delegate_to_session :within, :header, :http_accept, :basic_auth,
# be created transparently.
delegate_to_session :visits, :within, :clicks_link_within,
:reload, :header, :http_accept, :basic_auth,
:save_and_open_page, :fill_in, :check, :save_and_open_page, :fill_in, :check,
:uncheck, :choose, :select, :attach_file, :uncheck, :choose, :select, :attach_file,
:click_area, :click_link, :click_button, :field_labeled, :cookies, :response, :current_page,
:field_labeled :current_url
delegate_to_session_returning_response :visits, :click_link, :click_area, :click_button, :reload, :clicks_link_within
alias reloads reload alias reloads reload
alias visit visits alias visit visits