lib/simulacrum.rb in simulacrum-0.1.1 vs lib/simulacrum.rb in simulacrum-0.3.0
- old
+ new
@@ -1,37 +1,96 @@
+# encoding: UTF-8
+require 'yaml'
require 'ostruct'
require 'capybara'
-require_relative './simulacrum/methods'
-require_relative './simulacrum/matchers'
-require_relative './simulacrum/configuration'
+require 'logger'
+require 'simulacrum/configuration'
+require 'simulacrum/runner'
# Gem module
module Simulacrum
- @browsers = {}
+ CONFIG_FILE = './.simulacrum.yml'
+
@components = {}
@current_browser = nil
@configuration = Simulacrum::Configuration.new
+ @logger = Logger.new($stdout)
- def self.components
+ def logger
+ @logger
+ end
+ module_function :logger
+
+ def components
@components
end
+ module_function :components
- def self.configuration
+ def configuration
@configuration
end
+ module_function :configuration
- def self.configure(&block)
- options = OpenStruct.new(defaults: OpenStruct.new)
+ def runner_options
+ @runner_options
+ end
+ module_function :runner_options
+
+ def root
+ File.expand_path('../..', __FILE__)
+ end
+ module_function :root
+
+ def run(options)
+ @runner_options = options
+ configure_logger
+ configure_runner.run
+ end
+ module_function :run
+
+ def configure(&block)
+ options = OpenStruct.new(component: OpenStruct.new)
yield options
- @configuration.configure(options.to_h)
+ configuration.configure(options.to_h)
end
+ module_function :configure
- def self.included(receiver, &block)
- receiver.extend Simulacrum::Methods
- receiver.send :include, Simulacrum::Matchers
+ def config_file
+ YAML.load_file(Simulacrum.config_file_path)
+ end
+ module_function :config_file
- if defined?(Rails)
- receiver.send :include, Rails.application.routes.url_helpers
- receiver.send :include, Rails.application.routes.mounted_helpers
+ def config_file?
+ File.exist?(Simulacrum.config_file_path)
+ end
+ module_function :config_file?
+
+ def config_file_path
+ if defined? Rails
+ Rails.root.join(CONFIG_FILE)
+ else
+ CONFIG_FILE
end
+ end
+ module_function :config_file_path
+
+ def self.configure_runner
+ case Simulacrum.runner_options.runner
+ when nil
+ Simulacrum::Runner.new
+ when :browserstack
+ use_browserstack_runner
+ end
+ end
+
+ def self.use_browserstack_runner
+ gem 'simulacrum-browserstack', '>= 0.0.1'
+ require 'simulacrum-browserstack'
+ Simulacrum::Browserstack::Runner.new
+ rescue Gem::LoadError
+ raise
+ end
+
+ def self.configure_logger
+ @logger.level = @runner_options.verbose ? Logger::DEBUG : Logger::INFO
end
end