spec/lib/sweeper_spec.rb in stowaway-0.0.6 vs spec/lib/sweeper_spec.rb in stowaway-0.1.1
- old
+ new
@@ -1,45 +1,96 @@
-require 'spec/spec_helper'
-require 'lib/stowaway/file'
-require 'lib/stowaway/sweeper'
+require "spec/spec_helper"
+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]
- @status_mock = mock('status_mock', :null_object => true)
+ @files = []
+ @status_mock = mock("status_mock", :null_object => true)
end
- it "should sweep through directory looking for matches" do
- sweeper.sweep('.')
+ it "should match images referened in a src attribute" do
+ @files << Stowaway::FileObj.new("/fake/path1/button.jpg")
+ sweeper.sweep("spec/data")
@files.should be_empty
end
+ it "should match images referened 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 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
- sweeper([/^\.|\.rb$|testfile1/]).sweep('spec/data').length.should == 2
+ @files << Stowaway::FileObj.new("/public/stylesheets/reset.css")
+ sweeper([/^\.|\.rb$|testfile1/]).sweep("spec/data").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')
+ sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
end
it "should flush the output after sweeping through a file" do
@status_mock.should_receive(:flush).once
- sweeper([/^\.|\.rb$|testfile2/]).sweep('spec/data')
+ sweeper([/^\.|\.rb$|testfile2/]).sweep("spec/data")
end
+ it "should find images of the same name but with different paths" 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
- sweeper([/^\.|\.rb$|testfile1/]).sweep('spec/data')
- @files.should == [@f1, @f2]
+ @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
end