Linux support work fine now, don't loop more one time on same test.

This commit is contained in:
Yann Lugrin 2010-10-23 21:38:46 +08:00 committed by Thibaud Guillaume-Gentil
parent 4daae46444
commit dd04914657
2 changed files with 39 additions and 3 deletions

View File

@ -3,6 +3,8 @@ module Guard
attr_reader :inotify, :files, :latency, :callback attr_reader :inotify, :files, :latency, :callback
def initialize def initialize
super
@inotify = INotify::Notifier.new @inotify = INotify::Notifier.new
@files = [] @files = []
@latency = 0.5 @latency = 0.5
@ -20,12 +22,12 @@ module Guard
def start def start
@stop = false @stop = false
watch_change watch_change unless @watch_change
end end
def stop def stop
@stop = true @stop = true
inotify.stop sleep latency
end end
def self.usable? def self.usable?
@ -44,18 +46,24 @@ module Guard
private private
def watch_change def watch_change
@watch_change = true
while !@stop while !@stop
if Config::CONFIG['build'] =~ /java/ || IO.select([inotify.to_io], [], [], latency) if Config::CONFIG['build'] =~ /java/ || IO.select([inotify.to_io], [], [], latency)
break if @stop
inotify.process inotify.process
update_last_event
unless files.empty? unless files.empty?
files.map! { |file| file.gsub("#{Dir.pwd}/", '') } files.map! { |file| file.gsub("#{Dir.pwd}/", '') }
callback.call(files) callback.call(files.dup)
files.clear files.clear
end end
sleep latency unless @stop sleep latency unless @stop
end end
end end
@watch_change = false
end end
end end

View File

@ -15,6 +15,25 @@ describe Guard::Linux do
subject.should be_usable subject.should be_usable
end end
describe "start" do
before(:each) do
@listener = Guard::Linux.new
end
it "call watch_change" do
@listener.should_receive(:watch_change)
start
end
it "don't call watch_change if re start after stop" do
start
stop
@listener.should_not_receive(:watch_change)
start
end
end
describe "watch" do describe "watch" do
before(:each) do before(:each) do
@results = [] @results = []
@ -54,6 +73,15 @@ describe Guard::Linux do
stop stop
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt'] @results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
end end
it "should not process change if stopped" do
file = @fixture_path.join("folder1/file1.txt")
File.exists?(file).should be_true
start
@listener.inotify.should_not_receive(:process)
stop
File.open(file, 'w') {|f| f.write('') }
end
end end
end end