lib/page_magic.rb in page_magic-1.0.0.alpha2 vs lib/page_magic.rb in page_magic-1.0.0.alpha3
- old
+ new
@@ -1,43 +1,35 @@
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
require 'capybara'
require 'page_magic/exceptions'
-require 'page_magic/browser'
require 'page_magic/session'
require 'page_magic/elements'
require 'page_magic/element_context'
require 'page_magic/element'
require 'page_magic/page_magic'
+require 'page_magic/drivers'
module PageMagic
+ class UnspportedBrowserException < Exception;end
+
class << self
- def session browser=nil, options = {}
- if browser.is_a?(Symbol)
- application = options.delete(:application)
- Capybara.register_driver browser do |app|
- options[:browser] = browser
- case browser
- when :poltergeist
- require 'capybara/poltergeist'
- Capybara::Poltergeist::Driver.new(app)
- when :rack_test
- Capybara::RackTest::Driver.new(app, options)
- else
- require 'watir-webdriver'
- Capybara::Selenium::Driver.new(app, options)
- end
+ def drivers
+ @drivers ||= Drivers.new.tap do |drivers|
+ drivers.load
+ end
+ end
- end
+ def session(application: nil, browser: :rack_test, options: {})
+ driver = drivers.find(browser)
+ raise UnspportedBrowserException unless driver
- Session.new(Capybara::Session.new(browser, application))
- else
- Capybara.reset!
- Capybara.app = browser[:application] if browser.is_a?(Hash) && browser[:application]
- Session.new(Capybara.current_session)
- end
+ Capybara.register_driver browser do |app|
+ driver.build(app, browser: browser, options: options)
+ end
+ Session.new(Capybara::Session.new(browser, application))
end
def included clazz
clazz.extend Elements
pages << clazz if clazz.is_a? Class
@@ -51,13 +43,12 @@
def inherited clazz
clazz.element_definitions.merge!(element_definitions)
PageMagic.pages << clazz
end
end
-
end
def pages
@pages||=[]
end
end
-end
\ No newline at end of file
+end