Refactor the watch_all_modifications specs.
- Just test a single expectation per it block - Better separation of fixture setup/teardown
This commit is contained in:
parent
40e033ce0f
commit
db949bf9e4
@ -148,18 +148,34 @@ describe Guard::Listener do
|
|||||||
subject.instance_variable_get(:@watch_all_modifications).should eql false
|
subject.instance_variable_get(:@watch_all_modifications).should eql false
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'it should not track deleted files' do
|
context 'for a deleted file' do
|
||||||
|
after { FileUtils.touch(file3) }
|
||||||
|
|
||||||
|
it 'does not catch the deletion' do
|
||||||
|
File.exists?(file3).should be_true
|
||||||
|
|
||||||
watch do
|
watch do
|
||||||
FileUtils.touch([file1, file2, file3])
|
FileUtils.remove_file(file3)
|
||||||
subject.modified_files([fixture('folder1')], {}).should =~
|
end
|
||||||
['spec/fixtures/folder1/deletedfile1.txt', 'spec/fixtures/folder1/file1.txt']
|
|
||||||
|
|
||||||
subject.update_last_event
|
|
||||||
|
|
||||||
FileUtils.rm(file3)
|
|
||||||
subject.modified_files([fixture('folder1')], {}).should =~ []
|
subject.modified_files([fixture('folder1')], {}).should =~ []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'for a moved file' do
|
||||||
|
after { FileUtils.move(file4, file1) }
|
||||||
|
|
||||||
|
it 'does not catch the move' do
|
||||||
|
File.exists?(file1).should be_true
|
||||||
|
File.exists?(file4).should be_false
|
||||||
|
|
||||||
|
watch do
|
||||||
|
FileUtils.move(file1, file4)
|
||||||
|
end
|
||||||
|
|
||||||
|
subject.modified_files([@fixture_path.join('folder1')], {}).should =~ []
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with the :watch_all_modifications option' do
|
context 'with the :watch_all_modifications option' do
|
||||||
@ -170,71 +186,38 @@ describe Guard::Listener do
|
|||||||
subject.update_last_event
|
subject.update_last_event
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
|
||||||
FileUtils.touch([file1, file2, file3])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should be true when set' do
|
it 'should be true when set' do
|
||||||
subject.instance_variable_get(:@watch_all_modifications).should eql true
|
subject.instance_variable_get(:@watch_all_modifications).should eql true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should track deleted files' do
|
context 'for a deleted file' do
|
||||||
|
after { FileUtils.touch(file3) }
|
||||||
|
|
||||||
|
it 'catches the deletion' do
|
||||||
|
File.exists?(file3).should be_true
|
||||||
|
|
||||||
watch do
|
watch do
|
||||||
FileUtils.touch([file1, file3])
|
|
||||||
subject.modified_files([fixture('folder1')], { }).should =~
|
|
||||||
['spec/fixtures/folder1/deletedfile1.txt', 'spec/fixtures/folder1/file1.txt']
|
|
||||||
|
|
||||||
subject.update_last_event
|
|
||||||
|
|
||||||
FileUtils.remove_file(file3)
|
FileUtils.remove_file(file3)
|
||||||
|
end
|
||||||
|
|
||||||
subject.modified_files([fixture('folder1')], {}).should =~
|
subject.modified_files([fixture('folder1')], {}).should =~
|
||||||
['!spec/fixtures/folder1/deletedfile1.txt']
|
['!spec/fixtures/folder1/deletedfile1.txt']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should track moved files' do
|
context 'for a moved file' do
|
||||||
|
after { FileUtils.move(file4, file1) }
|
||||||
|
|
||||||
|
it 'catches the move' do
|
||||||
|
File.exists?(file1).should be_true
|
||||||
|
File.exists?(file4).should be_false
|
||||||
|
|
||||||
watch do
|
watch do
|
||||||
FileUtils.touch([file1, file3])
|
|
||||||
subject.modified_files([fixture('folder1')], { }).should =~
|
|
||||||
['spec/fixtures/folder1/deletedfile1.txt', 'spec/fixtures/folder1/file1.txt']
|
|
||||||
|
|
||||||
subject.update_last_event
|
|
||||||
|
|
||||||
FileUtils.move(file1, file4)
|
FileUtils.move(file1, file4)
|
||||||
|
end
|
||||||
|
|
||||||
subject.modified_files([@fixture_path.join('folder1')], {}).should =~
|
subject.modified_files([@fixture_path.join('folder1')], {}).should =~
|
||||||
['!spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/movedfile1.txt']
|
['!spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/movedfile1.txt']
|
||||||
|
|
||||||
FileUtils.move(file4, file1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should track deleted files with all option' do
|
|
||||||
watch do
|
|
||||||
FileUtils.touch([file1, file2])
|
|
||||||
subject.modified_files([fixture('folder1')], { :all => true }).should =~
|
|
||||||
['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
|
|
||||||
|
|
||||||
subject.update_last_event
|
|
||||||
|
|
||||||
FileUtils.remove_file(file2)
|
|
||||||
subject.modified_files([fixture('folder1')], { :all => true }).should =~
|
|
||||||
['!spec/fixtures/folder1/folder2/file2.txt']
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should track moved files with all option' do
|
|
||||||
watch do
|
|
||||||
FileUtils.touch([file1, file2])
|
|
||||||
subject.modified_files([fixture('folder1')], { :all => true }).should =~
|
|
||||||
['spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/file2.txt']
|
|
||||||
|
|
||||||
subject.update_last_event
|
|
||||||
|
|
||||||
FileUtils.move(file1, file5)
|
|
||||||
subject.modified_files([fixture('folder1')], { :all => true }).should =~
|
|
||||||
['!spec/fixtures/folder1/file1.txt', 'spec/fixtures/folder1/folder2/movedfile1.txt']
|
|
||||||
|
|
||||||
FileUtils.move(file5, file1)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user