spec/lib/sweeper_spec.rb in stowaway-0.1.6 vs spec/lib/sweeper_spec.rb in stowaway-0.1.8
- old
+ new
@@ -1,98 +1,37 @@
require "spec/spec_helper"
require "lib/stowaway/file"
require "lib/stowaway/sweeper"
+require "lib/stowaway/matcher"
describe Stowaway::Sweeper do
def sweeper(ignore = nil)
- ig = ignore || [/^\./]
- @sweeper ||= Stowaway::Sweeper.new(@files, @status_mock, ig)
+ @sweeper ||= Stowaway::Sweeper.new(@files, @status_mock, Stowaway::Matcher.new, ignore)
end
before(:each) do
@files = []
@status_mock = mock("status_mock", :null_object => true)
end
- it "should match images referenced in a src attribute" do
+ it "should remove files when a reference to the file is found in source" do
@files << Stowaway::FileObj.new("/fake/path1/button.jpg")
sweeper.sweep("spec/data")
@files.should be_empty
end
-
- it "should match images referenced in an href attribute" do
- @files << Stowaway::FileObj.new("/fake/path/photo.jpg")
- sweeper.sweep("spec/data")
- @files.should be_empty
- end
- it "should match images referenced in a src attribute when files are stored in public folder" do
- @files << Stowaway::FileObj.new("/public/fake/path1/button.jpg")
- sweeper.sweep("spec/data")
- @files.should be_empty
+ it "should return an OpenStruct with the result of the sweeping" do
+ result = sweeper.sweep("spec/data")
+ result.files.should be_an_instance_of Array
+ result.name_only_matches.should be_an_instance_of Array
end
- it "should match images referenced in an haml href attribute" do
- @files << Stowaway::FileObj.new("/images/haml.jpg")
- sweeper.sweep("spec/data")
- @files.should be_empty
- end
-
- it "should match images referenced in a haml src attribute" do
- @files << Stowaway::FileObj.new("/images/file.jpg")
- sweeper.sweep("spec/data")
- @files.should be_empty
- end
-
- it "should match images referenced in a haml src attribute when files are stored in public folder" do
- @files << Stowaway::FileObj.new("/public/images/file.jpg")
- sweeper.sweep("spec/data")
- @files.should be_empty
- end
-
- it "should match scripts referenced in a src attribute" do
- @files << Stowaway::FileObj.new("/fake/path/file.js")
- sweeper.sweep("spec/data")
- @files.should be_empty
- end
-
- it "should match scripts referenced in a rails javascript_include_tag helper" do
- @files << Stowaway::FileObj.new("/public/javascripts/file.js")
- sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
- @files.should be_empty
- end
-
- it "should match scripts referenced in a rails javascript_include_tag helper when no extension is given" do
- @files << Stowaway::FileObj.new("/public/javascripts/application.js")
- sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
- @files.should be_empty
- end
-
- it "should match multiple scripts referenced in a rails javascript_include_tag helper" do
- @files << Stowaway::FileObj.new("/public/javascripts/jquery.js")
- @files << Stowaway::FileObj.new("/public/javascripts/home/index.js")
- sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
- @files.should be_empty
- end
-
- it "should match css files referenced in a rails stylesheet_link_tag helper" do
- @files << Stowaway::FileObj.new("/public/stylesheets/file.css")
- sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
- @files.should be_empty
- end
-
- it "should match multiple css files referenced in a rails stylesheet_link_tag helper" do
- @files << Stowaway::FileObj.new("/public/stylesheets/reset.css")
- @files << Stowaway::FileObj.new("/public/stylesheets/common.css")
- sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
- @files.should be_empty
- end
-
it "should not sweep through ignored file types" do
-# @files << Stowaway::FileObj.new("/public/stylesheets/reset.css")
-# sweeper([/^\.|\.rb$|testfile1/]).sweep("spec/data").length.should == 1
+ @files << Stowaway::FileObj.new("/fake/path1/button.jpg")
+ sweeper([/^\.|\.rb$|\.txt$/]).sweep("spec/data")
+ @files.length.should == 1
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")
@@ -101,20 +40,25 @@
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 find images of the same name but with different paths" do
+ it "should files of the same name but with different paths as last resort" do
@files << Stowaway::FileObj.new("/fake/path1/button.jpg")
@files << Stowaway::FileObj.new("/fake/path2/button.jpg")
sweeper([/^\.|\.rb$/]).sweep("spec/data")
@files.should be_empty
end
-# it "should remove matches and leave files that were not found" do
-# @files << Stowaway::FileObj.new("/a/stowaway/file.txt")
-# sweeper([/^\.|\.rb$/]).sweep("spec/data")
-# @files.should_not be_empty
-# @files.first.fullpath.should == "/a/stowaway/file.txt"
-# end
+ it "should add a file matched on name only to an array of partially matched files" do
+ @files << Stowaway::FileObj.new("/missing/button.jpg")
+ sweeper([/^\.|\.rb$/]).sweep("spec/data").should have(1).name_only_matches
+ end
+
+ it "should not remove files that were not found" do
+ @files << Stowaway::FileObj.new("/a/stowaway.txt")
+ sweeper([/^\.|\.rb$/]).sweep("spec/data")
+ @files.should_not be_empty
+ @files.first.fullpath.should == "/a/stowaway.txt"
+ end
end