more specs on linux listener

This commit is contained in:
Yann Lugrin 2010-10-25 11:16:56 +02:00
parent 0bff5e86d8
commit 7bae189eba
3 changed files with 44 additions and 12 deletions

View File

@ -10,6 +10,16 @@ module Guard
@latency = 0.5
end
def start
@stop = false
watch_change unless watch_change?
end
def stop
@stop = true
sleep latency
end
def on_change(&callback)
@callback = callback
inotify.watch(Dir.pwd, :recursive, :modify, :create, :delete, :move) do |event|
@ -20,16 +30,6 @@ module Guard
rescue Interrupt
end
def start
@stop = false
watch_change unless @watch_change
end
def stop
@stop = true
sleep latency
end
def self.usable?
require 'rb-inotify'
if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.5.1')
@ -43,6 +43,10 @@ module Guard
false
end
def watch_change?
!!@watch_change
end
private
def watch_change

View File

View File

@ -1,4 +1,5 @@
require 'spec_helper'
require 'fileutils'
require 'guard/listeners/linux'
describe Guard::Linux do
@ -20,16 +21,21 @@ describe Guard::Linux do
@listener = Guard::Linux.new
end
it "call watch_change" do
it "should call watch_change if first start" do
@listener.should_receive(:watch_change)
start
end
it "don't call watch_change if re start after stop" do
it "should not call watch_change if start after stop" do
@listener.stub!(:stop)
start
stop
@listener.should be_watch_change
@listener.should_not_receive(:watch_change)
start
@listener.unstub!(:stop)
stop
@listener.should_not be_watch_change
end
end
@ -73,6 +79,28 @@ describe Guard::Linux do
stop
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
end
it "should catch deleted file" do
file = @fixture_path.join("folder1/file1.txt")
File.exists?(file).should be_true
start
File.delete file
stop
FileUtils.touch file
@results.should == ['spec/fixtures/folder1/file1.txt']
end
it "should catch moved file" do
file1 = @fixture_path.join("folder1/file1.txt")
file2 = @fixture_path.join("folder1/movedfile1.txt")
File.exists?(file1).should be_true
File.exists?(file2).should be_false
start
FileUtils.mv file1, file2
stop
FileUtils.mv file2, file1
@results.should == ['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/movedfile1.txt']
end
it "should not process change if stopped" do
file = @fixture_path.join("folder1/file1.txt")