# # File 'clean_spec.rb' created on 19 feb 2008 at 19:30:45. # See 'dokkit.rb' or +LICENSE+ for licence information. # # (c)2008 Andrea Fazzi (and contributors). # # To execute this spec run: # # spec spec/clean_spec.rb # $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__),'../lib'))) require 'rubygems' require 'spec' require 'dokkit' require 'dokkit/rendertask' require 'dokkit/cleantask' require File.dirname(__FILE__) + '/spec_helper.rb' describe Dokkit::CleanTask do include SpecPathHelper before(:all) do @initial_dir = Dir.pwd Dir.chdir(File.join(File.dirname(__FILE__), SpecPathHelper::DATA_TEST_DIR)) end before do Rake.application.clear model = mock('model') model.should_receive(:config).and_return(Dokkit::TaskConfig.new) @cleantask = Dokkit::CleanTask.new(model, 'clean') do |task| task.config.output_dir = output_path end mkdir_p output_path mkdir_p cache_path end after do rmdir output_path if File.exists?(output_path) rmdir cache_path if File.exists?(cache_path) end after(:all) do Dir.chdir(@initial_dir) end it 'should be initialized with the output directory' do @cleantask.config.output_dir.should == output_path end describe ' when clean:output is invoked' do it 'should remove output directory' do task('clean:output').invoke File.exists?(@cleantask.config.output_dir).should be_false end end describe ' when clean:cache is invoked' do before do Rake.application.clear model = mock('model') cache = mock('cache') cache.should_receive(:cache_dir).and_return(cache_path) cache.should_receive(:clean) model.should_receive(:config).and_return(Dokkit::TaskConfig.new) model.should_receive(:cache).twice.and_return(cache) @cleantask = Dokkit::CleanTask.new(model, 'clean') do |task| task.config.output_dir = output_path end end it 'should call CacheManager#clean method to remove cache' do task('clean:cache').invoke end end end