Work on specs
This commit is contained in:
parent
3b73ea77b7
commit
c4ddb29fc6
@ -32,6 +32,11 @@ module Guard
|
||||
|
||||
Dsl.evaluate_guardfile(options)
|
||||
|
||||
listener.on_change do |files|
|
||||
Dsl.reevaluate_guardfile if Watcher.match_guardfile?(files)
|
||||
listener.changed_files += files if Watcher.match_files?(guards, files)
|
||||
end
|
||||
|
||||
UI.info "Guard is now watching at '#{listener.directory}'"
|
||||
guards.each { |guard| supervised_task(guard, :start) }
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
module Guard
|
||||
class Interactor
|
||||
|
||||
attr_reader :locked
|
||||
|
||||
def initialize
|
||||
@locked = false
|
||||
end
|
||||
|
@ -11,6 +11,7 @@ module Guard
|
||||
class Listener
|
||||
|
||||
DefaultIgnorePaths = %w[. .. .bundle .git log tmp vendor]
|
||||
attr_accessor :changed_files
|
||||
attr_reader :directory, :ignore_paths, :locked
|
||||
|
||||
def self.select_and_init(*a)
|
||||
@ -32,8 +33,9 @@ module Guard
|
||||
@relativize_paths = options.fetch(:relativize_paths, true)
|
||||
@changed_files = []
|
||||
@locked = false
|
||||
@ignore_paths = options[:ignore_paths] || DefaultIgnorePaths
|
||||
|
||||
@ignore_paths = DefaultIgnorePaths
|
||||
@ignore_paths |= options[:ignore_paths] if options[:ignore_paths]
|
||||
|
||||
update_last_event
|
||||
start_reactor
|
||||
end
|
||||
@ -53,14 +55,6 @@ module Guard
|
||||
end
|
||||
|
||||
def start
|
||||
on_change do |files|
|
||||
if Watcher.match_guardfile?(files)
|
||||
Dsl.reevaluate_guardfile
|
||||
end
|
||||
if Watcher.match_files?(::Guard.guards, files)
|
||||
@changed_files += files
|
||||
end
|
||||
end
|
||||
watch(@directory)
|
||||
end
|
||||
|
||||
@ -117,7 +111,7 @@ module Guard
|
||||
def relativize_paths?
|
||||
!!@relativize_paths
|
||||
end
|
||||
|
||||
|
||||
# return children of the passed dirs that are not in the ignore_paths list
|
||||
def exclude_ignored_paths(dirs, ignore_paths = self.ignore_paths)
|
||||
Dir.glob(dirs.map { |d| "#{d.sub(%r{/+$}, '')}/*" }, File::FNM_DOTMATCH).reject do |path|
|
||||
@ -129,7 +123,7 @@ module Guard
|
||||
|
||||
def potentially_modified_files(dirs, options={})
|
||||
paths = exclude_ignored_paths(dirs)
|
||||
|
||||
|
||||
if options[:all]
|
||||
paths.inject([]) do |array, path|
|
||||
if File.file?(path)
|
||||
|
@ -1,34 +1,26 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Guard::Interactor do
|
||||
subject { Guard::Interactor }
|
||||
subject { Guard::Interactor.new }
|
||||
|
||||
let(:guard) { mock "guard" }
|
||||
|
||||
before :each do
|
||||
Guard.stub!(:guards).and_return([guard])
|
||||
Guard.stub!(:options).and_return({})
|
||||
Guard.stub!(:listener).and_return(mock(:start => nil, :stop => nil))
|
||||
end
|
||||
|
||||
describe ".run_all" do
|
||||
it "sends :run_all to all guards" do
|
||||
guard.should_receive(:run_all)
|
||||
subject.run_all
|
||||
describe "#initialize" do
|
||||
it "un-lock by default" do
|
||||
subject.locked.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe ".stop" do
|
||||
it "sends :stop to all guards" do
|
||||
guard.should_receive(:stop)
|
||||
lambda { subject.stop }.should raise_error(SystemExit)
|
||||
describe "#lock" do
|
||||
it "locks" do
|
||||
subject.lock
|
||||
subject.locked.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe ".reload" do
|
||||
it "sends :reload to all guards" do
|
||||
guard.should_receive(:reload)
|
||||
subject.reload
|
||||
describe "#unlock" do
|
||||
it "unlocks" do
|
||||
subject.unlock
|
||||
subject.locked.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user