1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00
teamcapybara--capybara/lib/capybara/dsl.rb

66 lines
1.4 KiB
Ruby
Raw Normal View History

2009-11-16 16:02:16 -05:00
module Capybara
2009-11-12 12:09:29 -05:00
class << self
2009-11-16 14:11:42 -05:00
attr_writer :default_driver, :current_driver, :javascript_driver
2009-11-12 11:51:31 -05:00
attr_accessor :app
2009-11-12 12:09:29 -05:00
def default_driver
@default_driver || :rack_test
end
2009-11-12 11:51:31 -05:00
2009-11-12 12:09:29 -05:00
def current_driver
@current_driver || default_driver
2009-11-12 12:09:29 -05:00
end
alias_method :mode, :current_driver
2009-11-16 14:11:42 -05:00
def javascript_driver
@javascript_driver || :selenium
end
2009-11-12 11:51:31 -05:00
2009-11-12 12:09:29 -05:00
def use_default_driver
@current_driver = nil
2009-11-12 12:09:29 -05:00
end
2009-11-12 11:51:31 -05:00
def current_session
session_pool["#{current_driver}#{app.object_id}"] ||= begin
2009-11-26 17:47:58 -05:00
Capybara::Session.new(current_driver, app)
end
end
def current_session?
session_pool.has_key?("#{current_driver}#{app.object_id}")
end
2009-11-15 17:20:37 -05:00
def reset_sessions!
@session_pool = nil
end
private
2009-11-12 12:09:29 -05:00
def session_pool
@session_pool ||= {}
end
2009-11-12 11:51:31 -05:00
end
2009-11-12 12:09:29 -05:00
extend(self)
def page
2009-11-16 16:02:16 -05:00
Capybara.current_session
end
2009-11-12 12:09:29 -05:00
2009-11-12 11:51:31 -05:00
SESSION_METHODS = [
2009-11-15 17:20:18 -05:00
:visit, :body, :click_link, :click_button, :fill_in, :choose, :has_xpath?, :has_css?,
2009-11-24 15:32:25 -05:00
:check, :uncheck, :attach_file, :select, :has_content?, :within, :within_fieldset,
2009-11-24 15:45:52 -05:00
:within_table, :save_and_open_page, :find_field, :find_link, :find_button,
:field_labeled
2009-11-12 11:51:31 -05:00
]
SESSION_METHODS.each do |method|
class_eval <<-RUBY, __FILE__, __LINE__+1
def #{method}(*args, &block)
page.#{method}(*args, &block)
2009-11-12 11:51:31 -05:00
end
RUBY
end
end