Skip to content
Browse files

Test rake task

  • Loading branch information...
1 parent 3be2425 commit 0b1a17f09408c74f1045ef86394ab0ac0b9c4bb1 @josh josh committed Dec 13, 2011
Showing with 66 additions and 5 deletions.
  1. +4 −2 lib/rake/sprocketstask.rb
  2. +10 −1 lib/sprockets/manifest.rb
  3. +2 −2 test/test_performance.rb
  4. +50 −0 test/test_rake_task.rb
View
6 lib/rake/sprocketstask.rb
@@ -48,7 +48,7 @@ def initialize(name = :bundle)
def init(name)
@name = name
- @environment = Sprockets::Environment.new(Dir.pwd)
+ @environment = Sprockets::Environment.new(Dir.pwd)
@logger = Logger.new($stderr)
@logger.level = Logger::WARN
end
@@ -71,7 +71,9 @@ def define
desc name == :bundle ? "Remove all asset bundles" : "Remove all #{name} bundles"
task "clobber_#{name}" do
- rm_r bundle_dir if File.exist?(bundle_dir)
+ with_logger do
+ manifest.clobber
+ end
end
task :clobber => ["clobber_#{name}"]
View
11 lib/sprockets/manifest.rb
@@ -98,7 +98,6 @@ def compile(logical_path)
# manifest.remove("application-2e8e9a7c6b0aafa0c9bdeec90ea30213.js")
#
def remove(filename)
- logger.warn "Remove #{filename}"
path = File.join(dir, filename)
logical_path = files[filename]['logical_path']
@@ -110,6 +109,9 @@ def remove(filename)
FileUtils.rm(path) if File.exist?(path)
save
+
+ logger.warn "Removed #{filename}"
+
nil
end
@@ -128,6 +130,13 @@ def clean(keep = 2)
end
end
+ # Wipe directive
+ def clobber
+ FileUtils.rm_r(@dir) if File.exist?(@dir)
+ logger.warn "Removed #{@dir}"
+ nil
+ end
+
protected
# Finds all the backup assets for a logical path. The latest
# version is always excluded. The return array is sorted by the
View
4 test/test_performance.rb
@@ -20,7 +20,7 @@ def stat(filename)
$dir_entires_calls = nil
class << Dir
alias_method :original_entries, :entries
- def entries(dirname)
+ def entries(dirname, *args)
if $dir_entires_calls
$dir_entires_calls[dirname.to_s] ||= 0
$dir_entires_calls[dirname.to_s] += 1
@@ -30,7 +30,7 @@ def entries(dirname)
warn caller.join("\n")
end
end
- original_entries(dirname)
+ original_entries(dirname, *args)
end
end
View
50 test/test_rake_task.rb
@@ -0,0 +1,50 @@
+require 'sprockets_test'
+
+require 'rake/sprocketstask'
+require 'rake'
+
+class TestRakeTask < Sprockets::TestCase
+ def setup
+ @rake = Rake::Application.new
+ Rake.application = @rake
+
+ @env = Sprockets::Environment.new(".") do |env|
+ env.append_path(fixture_path('default'))
+ end
+
+ @dir = File.join(Dir::tmpdir, 'sprockets/manifest')
+
+ Rake::SprocketsTask.new do |t|
+ t.environment = @env
+ t.bundle_dir = @dir
+ t.bundles = ['application.js']
+ t.log_level = :fatal
+ end
+ end
+
+ def teardown
+ Rake.application = nil
+
+ # FileUtils.rm_rf(@dir)
+ # wtf, dunno
+ system "rm -rf #{@dir}"
+ assert Dir["#{@dir}/*"].empty?
+ end
+
+ test "bundle" do
+ assert !File.exist?("#{@dir}/application-2e8e9a7c6b0aafa0c9bdeec90ea30213.js")
+
+ @rake[:bundle].invoke
+
+ assert File.exist?("#{@dir}/manifest.json")
+ assert File.exist?("#{@dir}/application-2e8e9a7c6b0aafa0c9bdeec90ea30213.js")
+ end
+
+ test "clobber" do
+ @rake[:bundle].invoke
+ assert File.exist?("#{@dir}/application-2e8e9a7c6b0aafa0c9bdeec90ea30213.js")
+
+ @rake[:clobber_bundle].invoke
+ assert !File.exist?("#{@dir}/application-2e8e9a7c6b0aafa0c9bdeec90ea30213.js")
+ end
+end

0 comments on commit 0b1a17f

Please sign in to comment.
Something went wrong with that request. Please try again.