class Guard::JRubyRSpec

Public Class Methods

new(watchers = [], options = {}) click to toggle source
Calls superclass method
# File lib/guard/jruby-rspec.rb, line 11
def initialize(watchers = [], options = {})
  @options = {
    :all_after_pass   => true,
    :all_on_start     => true,
    :keep_failed      => true,
    :spec_paths       => ["spec"],
    :spec_file_suffix => "_spec.rb",
    :run_all          => {},
    :monitor_file     => ".guard-jruby-rspec",
    :custom_reloaders => []
  }.merge(options)
  @last_failed  = false
  @failed_paths = []

  default_watchers = [Watcher.new(@monitor)]
  if @custom_watchers.nil? or @custom_watchers.empty?
    default_watchers <<
        Watcher.new(%r{^(.+)\.rb$}) <<
        Watcher.new(%r{^(.+)\.(erb|haml)$})
  else
    watchers.each do |w|
      default_watchers << Watcher.new(w.pattern)
    end
  end

  @custom_watchers = watchers

  # touch the monitor file (lets the gjrspec know we're here)
  #File.open(@monitor, "w") {}

  # ideally we would bypass the Guard::RSpec initializer
  super(default_watchers, @options)

  @inspector = Inspector.new(@options)
  @runner = Runner.new(@options)
  @reloaders = set_up_reloaders(@options)
end

Public Instance Methods

reload_factory_girl(*) click to toggle source
# File lib/guard/jruby-rspec.rb, line 87
def reload_factory_girl(*)
  FactoryGirl.reload if defined? ::FactoryGirl
end
reload_paths(paths) click to toggle source
# File lib/guard/jruby-rspec.rb, line 91
def reload_paths(paths)
  paths.reject {|p| p.end_with?(@options[:spec_file_suffix])}.each do |p|
    if File.exists?(p)
      if p == @options[:monitor_file]
        # begin
        #   pidfile = open(@options[:monitor_file], "r+")
        #   pid = pidfile.read

        #   run_all

        #   system("kill #{pid}") if (pid and !pid.empty?)
        # ensure
        #   @runner.cleanup
        # end
      else
        # reload the file
        Containment.new.protect do
          load p
        end
      end
    end
  end
end
reload_rails(*) click to toggle source
# File lib/guard/jruby-rspec.rb, line 80
def reload_rails(*)
  if defined? ::ActionDispatch::Reloader
    ActionDispatch::Reloader.cleanup!
    ActionDispatch::Reloader.prepare!
  end
end
run_all() click to toggle source
Calls superclass method
# File lib/guard/jruby-rspec.rb, line 55
def run_all
  unload_previous_examples
  super
end
run_on_change(raw_paths)
Alias for: run_on_changes
run_on_changes(raw_paths) click to toggle source
Calls superclass method
# File lib/guard/jruby-rspec.rb, line 60
def run_on_changes(raw_paths)
  unload_previous_examples
  @reloaders.reload(raw_paths)

  unless @custom_watchers.nil? or @custom_watchers.empty?
    paths = []

    raw_paths.each do |p|
      @custom_watchers.each do |w|
        if (m = w.match(p))
          paths << (w.action.nil? ? p : w.call_action(m))
        end
      end
    end
    super(paths.flatten)
  end
end
Also aliased as: run_on_change
start() click to toggle source

Call once when guard starts

# File lib/guard/jruby-rspec.rb, line 50
def start
  UI.info "Guard::JRuby::RSpec is running, with RSpec!"
  run_all if @options[:all_on_start]
end

Private Instance Methods

set_up_reloaders(options) click to toggle source
# File lib/guard/jruby-rspec.rb, line 117
def set_up_reloaders(options)
  reloaders = Reloaders.new
  reloader_methods = [:reload_rails, :reload_paths, :reload_factory_girl]
  reloader_procs = reloader_methods.map { |name| method(name) }
  reloader_procs += options[:custom_reloaders]
  reloader_procs.each { |reloader| reloaders.register &reloader }

  reloaders
end
unload_previous_examples() click to toggle source
# File lib/guard/jruby-rspec.rb, line 127
def unload_previous_examples
  ::RSpec.configuration.reset
  ::RSpec.world.reset
end