Linux support work fine now, don't loop more one time on same test.
This commit is contained in:
parent
4daae46444
commit
dd04914657
@ -3,6 +3,8 @@ module Guard
|
||||
attr_reader :inotify, :files, :latency, :callback
|
||||
|
||||
def initialize
|
||||
super
|
||||
|
||||
@inotify = INotify::Notifier.new
|
||||
@files = []
|
||||
@latency = 0.5
|
||||
@ -20,12 +22,12 @@ module Guard
|
||||
|
||||
def start
|
||||
@stop = false
|
||||
watch_change
|
||||
watch_change unless @watch_change
|
||||
end
|
||||
|
||||
def stop
|
||||
@stop = true
|
||||
inotify.stop
|
||||
sleep latency
|
||||
end
|
||||
|
||||
def self.usable?
|
||||
@ -44,18 +46,24 @@ module Guard
|
||||
private
|
||||
|
||||
def watch_change
|
||||
@watch_change = true
|
||||
while !@stop
|
||||
if Config::CONFIG['build'] =~ /java/ || IO.select([inotify.to_io], [], [], latency)
|
||||
break if @stop
|
||||
|
||||
inotify.process
|
||||
update_last_event
|
||||
|
||||
unless files.empty?
|
||||
files.map! { |file| file.gsub("#{Dir.pwd}/", '') }
|
||||
callback.call(files)
|
||||
callback.call(files.dup)
|
||||
files.clear
|
||||
end
|
||||
|
||||
sleep latency unless @stop
|
||||
end
|
||||
end
|
||||
@watch_change = false
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -15,6 +15,25 @@ describe Guard::Linux do
|
||||
subject.should be_usable
|
||||
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
|
||||
before(:each) do
|
||||
@results = []
|
||||
@ -54,6 +73,15 @@ describe Guard::Linux do
|
||||
stop
|
||||
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user