class Guard::Konacha::Runner
Constants
- DEFAULT_OPTIONS
Attributes
formatter[R]
options[R]
Public Class Methods
new(options={})
click to toggle source
# File lib/guard/konacha/runner.rb, line 13 def initialize(options={}) @options = DEFAULT_OPTIONS.merge(options) # Require project's rails environment file to load Konacha # configuration require_rails_environment raise "Konacha not loaded" unless defined? ::Konacha # Custom formatter to handle multiple runs @formatter = Formatter.new ::Konacha.config.formatters = [@formatter] # Reusable session to increase performance @session = Capybara::Session.new(::Konacha.driver, Server.new) ::Konacha.mode = :runner UI.info "Guard::Konacha Initialized" end
Public Instance Methods
run(paths = [''])
click to toggle source
# File lib/guard/konacha/runner.rb, line 37 def run(paths = ['']) formatter.reset paths.each do |path| if path.empty? or File.exists? real_path path runner.run konacha_path(path) end end formatter.write_summary notify rescue => e UI.error(e) end
start()
click to toggle source
# File lib/guard/konacha/runner.rb, line 33 def start run if options[:run_all_on_start] end
Private Instance Methods
konacha_path(path)
click to toggle source
# File lib/guard/konacha/runner.rb, line 76 def konacha_path(path) '/' + path.gsub(/^#{::Konacha.config[:spec_dir]}\/?/, '').gsub(/\.coffee$/, '').gsub(/\.js$/, '') end
notify()
click to toggle source
# File lib/guard/konacha/runner.rb, line 88 def notify if options[:notification] image = @formatter.success? ? :success : :failed ::Guard::Notifier.notify(@formatter.summary_line, :title => "Konacha Specs", :image => image) end end
real_path(path)
click to toggle source
# File lib/guard/konacha/runner.rb, line 80 def real_path(path) ::Rails.root.join(::Konacha.config[:spec_dir] + konacha_path(path) + (path[/\.js(\.coffee)?$/] || '')).to_s end
require_rails_environment()
click to toggle source
# File lib/guard/konacha/runner.rb, line 56 def require_rails_environment if @options[:rails_environment_file] require @options[:rails_environment_file] else dir = '.' while File.expand_path(dir) != '/' do env_file = File.join(dir, 'config/environment.rb') if File.exist?(env_file) require File.expand_path(env_file) break end dir = File.join(dir, '..') end end end
runner()
click to toggle source
# File lib/guard/konacha/runner.rb, line 72 def runner ::Konacha::Runner.new(@session) end
unique_id()
click to toggle source
# File lib/guard/konacha/runner.rb, line 84 def unique_id "#{Time.now.to_i}#{rand(100)}" end