spec/lib/sweeper_spec.rb in stowaway-0.0.4 vs spec/lib/sweeper_spec.rb in stowaway-0.0.6

- old
+ new

@@ -2,36 +2,44 @@ require 'lib/stowaway/file' require 'lib/stowaway/sweeper' describe Stowaway::Sweeper do + def sweeper(ignore = nil) + ig = ignore || [/^\./] + @sweeper ||= Stowaway::Sweeper.new(@files, @status_mock, ig) + end + before(:each) do @f1 = Stowaway::FileObj.new('/fake/file1.jpg') @f2 = Stowaway::FileObj.new('/fake/file2.gif') @f3 = Stowaway::FileObj.new('/fake/file3.js') @f4 = Stowaway::FileObj.new('/fake/also/file3.js') @files = [@f1, @f2, @f3, @f4] - @sweeper = Stowaway::Sweeper.new(@files) + @status_mock = mock('status_mock', :null_object => true) end - it "should sweep through directory structure looking for matches" do - @sweeper.sweep('.') + it "should sweep through directory looking for matches" do + sweeper.sweep('.') @files.should be_empty end - it "should not examine ignored file types" do - @sweeper = Stowaway::Sweeper.new(@files, ["^\\.", ".rb", "testfile1"]) - @sweeper.sweep('.').length.should == 2 + it "should not sweep through ignored file types" do + sweeper([/^\.|\.rb$|testfile1/]).sweep('spec/data').length.should == 2 end + + it "should output a message when sweeping through a file" do + @status_mock.should_receive(:out).with("Sweeping: spec/data/testfile1.txt").once + sweeper([/^\.|\.rb$|testfile2/]).sweep('spec/data') + end - it "should read through the file looking for matches" do - @sweeper.inspect_file('spec/data/testfile1.txt') - @files.should == [@f3, @f4] + it "should flush the output after sweeping through a file" do + @status_mock.should_receive(:flush).once + sweeper([/^\.|\.rb$|testfile2/]).sweep('spec/data') end - - it "should remove matches from the list of files to find" do - line = 'file2.gif, file3.js' - @sweeper.remove_match line - @files.should == [@f1] + + it "should remove matches and leave files that were not found" do + sweeper([/^\.|\.rb$|testfile1/]).sweep('spec/data') + @files.should == [@f1, @f2] end -end \ No newline at end of file +end