more specs on linux listener
This commit is contained in:
parent
0bff5e86d8
commit
7bae189eba
@ -10,6 +10,16 @@ module Guard
|
|||||||
@latency = 0.5
|
@latency = 0.5
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def start
|
||||||
|
@stop = false
|
||||||
|
watch_change unless watch_change?
|
||||||
|
end
|
||||||
|
|
||||||
|
def stop
|
||||||
|
@stop = true
|
||||||
|
sleep latency
|
||||||
|
end
|
||||||
|
|
||||||
def on_change(&callback)
|
def on_change(&callback)
|
||||||
@callback = callback
|
@callback = callback
|
||||||
inotify.watch(Dir.pwd, :recursive, :modify, :create, :delete, :move) do |event|
|
inotify.watch(Dir.pwd, :recursive, :modify, :create, :delete, :move) do |event|
|
||||||
@ -20,16 +30,6 @@ module Guard
|
|||||||
rescue Interrupt
|
rescue Interrupt
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
|
||||||
@stop = false
|
|
||||||
watch_change unless @watch_change
|
|
||||||
end
|
|
||||||
|
|
||||||
def stop
|
|
||||||
@stop = true
|
|
||||||
sleep latency
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.usable?
|
def self.usable?
|
||||||
require 'rb-inotify'
|
require 'rb-inotify'
|
||||||
if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.5.1')
|
if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.5.1')
|
||||||
@ -43,6 +43,10 @@ module Guard
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def watch_change?
|
||||||
|
!!@watch_change
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def watch_change
|
def watch_change
|
||||||
|
0
spec/fixtures/folder1/deletedfile1.txt
vendored
Normal file
0
spec/fixtures/folder1/deletedfile1.txt
vendored
Normal file
@ -1,4 +1,5 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
require 'fileutils'
|
||||||
require 'guard/listeners/linux'
|
require 'guard/listeners/linux'
|
||||||
|
|
||||||
describe Guard::Linux do
|
describe Guard::Linux do
|
||||||
@ -20,16 +21,21 @@ describe Guard::Linux do
|
|||||||
@listener = Guard::Linux.new
|
@listener = Guard::Linux.new
|
||||||
end
|
end
|
||||||
|
|
||||||
it "call watch_change" do
|
it "should call watch_change if first start" do
|
||||||
@listener.should_receive(:watch_change)
|
@listener.should_receive(:watch_change)
|
||||||
start
|
start
|
||||||
end
|
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
|
start
|
||||||
stop
|
stop
|
||||||
|
@listener.should be_watch_change
|
||||||
@listener.should_not_receive(:watch_change)
|
@listener.should_not_receive(:watch_change)
|
||||||
start
|
start
|
||||||
|
@listener.unstub!(:stop)
|
||||||
|
stop
|
||||||
|
@listener.should_not be_watch_change
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -73,6 +79,28 @@ 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 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
|
it "should not process change if stopped" do
|
||||||
file = @fixture_path.join("folder1/file1.txt")
|
file = @fixture_path.join("folder1/file1.txt")
|
||||||
|
Loading…
Reference in New Issue
Block a user