lib/capybara_selenium.rb in capybara-selenium-0.0.3 vs lib/capybara_selenium.rb in capybara-selenium-0.0.4
- old
+ new
@@ -12,46 +12,51 @@
# Class for configuring capybara and selenium in order to instance the
# desired driver.
class Configurator
include AppServer
include SeleniumServer
- attr_reader :driver
+ attr_reader :driver, :app_server, :selenium_server
- def initialize(&block)
- define_singleton_method(:dispatch, block) if block_given?
+ # @param [Hash] opts The options for configuring servers
+ # @option opts [String] :app_server The application server type. Default
+ # :rack
+ # @option opts [String] :selenium_server The selenium server type. Default
+ # :remote
+ def initialize(opts = {}, &block)
+ @app_server = configurator :app_server, app_server_type(opts)
+ @selenium_server = configurator :selenium_server, selenium_server_type(opts)
+ define_singleton_method :configure do
+ block.call(app_server, selenium_server)
+ app_server.apply
+ selenium_server.apply
+ end
end
- def apply
- @app_server.apply
- @driver = @selenium_server.apply
+ private
+
+ # @param [Hash] opts The options for app server
+ # @option opts [Symbol] :app_server The app server type
+ # @return [String] The application server type
+ def app_server_type(opts)
+ opts[:app_server] || :rack
end
- def method_missing(method, *args, &block)
- if method =~ /(.*)_app_server/
- @app_server ||= configurator :app_server, $1
- elsif method =~ /(.*)_selenium_server/
- @selenium_server ||= configurator :selenium_server, $1
- else
- raise
- end
+ # @param [Hash] opts The options for selenium server
+ # @option opts [Symbol] :selenium_server The selenium server type
+ # @return [String] The selenium server type
+ def selenium_server_type(opts)
+ opts[:selenium_server] || :remote
end
- private
-
def configurator(server_type, configurator_type, &block)
- klass = self.class
- server_module = klass.classify(server_type)
- configurator_klass = klass.classify(configurator_type)
+ server_module = server_type.to_s.classify
+ configurator_klass = configurator_type.to_s.classify
"CapybaraSelenium::#{server_module}::#{configurator_klass}Configurator"
.constantize.new(configuration(server_module, configurator_klass))
end
def configuration(server_module, klass)
"CapybaraSelenium::#{server_module}::#{klass}Configuration"
.constantize.new
- end
-
- def self.classify(type)
- ActiveSupport::Inflector.classify(type)
end
end
end