Work on specs

This commit is contained in:
Thibaud Guillaume-Gentil 2011-09-01 23:24:45 +02:00
parent 3b73ea77b7
commit c4ddb29fc6
4 changed files with 26 additions and 33 deletions

View File

@ -32,6 +32,11 @@ module Guard
Dsl.evaluate_guardfile(options) 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}'" UI.info "Guard is now watching at '#{listener.directory}'"
guards.each { |guard| supervised_task(guard, :start) } guards.each { |guard| supervised_task(guard, :start) }

View File

@ -1,6 +1,8 @@
module Guard module Guard
class Interactor class Interactor
attr_reader :locked
def initialize def initialize
@locked = false @locked = false
end end

View File

@ -11,6 +11,7 @@ module Guard
class Listener class Listener
DefaultIgnorePaths = %w[. .. .bundle .git log tmp vendor] DefaultIgnorePaths = %w[. .. .bundle .git log tmp vendor]
attr_accessor :changed_files
attr_reader :directory, :ignore_paths, :locked attr_reader :directory, :ignore_paths, :locked
def self.select_and_init(*a) def self.select_and_init(*a)
@ -32,8 +33,9 @@ module Guard
@relativize_paths = options.fetch(:relativize_paths, true) @relativize_paths = options.fetch(:relativize_paths, true)
@changed_files = [] @changed_files = []
@locked = false @locked = false
@ignore_paths = options[:ignore_paths] || DefaultIgnorePaths @ignore_paths = DefaultIgnorePaths
@ignore_paths |= options[:ignore_paths] if options[:ignore_paths]
update_last_event update_last_event
start_reactor start_reactor
end end
@ -53,14 +55,6 @@ module Guard
end end
def start 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) watch(@directory)
end end
@ -117,7 +111,7 @@ module Guard
def relativize_paths? def relativize_paths?
!!@relativize_paths !!@relativize_paths
end end
# return children of the passed dirs that are not in the ignore_paths list # return children of the passed dirs that are not in the ignore_paths list
def exclude_ignored_paths(dirs, ignore_paths = self.ignore_paths) def exclude_ignored_paths(dirs, ignore_paths = self.ignore_paths)
Dir.glob(dirs.map { |d| "#{d.sub(%r{/+$}, '')}/*" }, File::FNM_DOTMATCH).reject do |path| 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={}) def potentially_modified_files(dirs, options={})
paths = exclude_ignored_paths(dirs) paths = exclude_ignored_paths(dirs)
if options[:all] if options[:all]
paths.inject([]) do |array, path| paths.inject([]) do |array, path|
if File.file?(path) if File.file?(path)

View File

@ -1,34 +1,26 @@
require 'spec_helper' require 'spec_helper'
describe Guard::Interactor do describe Guard::Interactor do
subject { Guard::Interactor } subject { Guard::Interactor.new }
let(:guard) { mock "guard" } describe "#initialize" do
it "un-lock by default" do
before :each do subject.locked.should be_false
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
end end
end end
describe ".stop" do describe "#lock" do
it "sends :stop to all guards" do it "locks" do
guard.should_receive(:stop) subject.lock
lambda { subject.stop }.should raise_error(SystemExit) subject.locked.should be_true
end end
end end
describe ".reload" do describe "#unlock" do
it "sends :reload to all guards" do it "unlocks" do
guard.should_receive(:reload) subject.unlock
subject.reload subject.locked.should be_false
end end
end end
end end