# # File 'dokkitlib_spec.rb' created on 18 feb 2008 at 17:49:23. # See 'dokkit.rb' or +LICENSE+ for licence information. # # (c)2008 Andrea Fazzi (and contributors). # # To execute this spec run: # # spec spec/dokkitlib_spec.rb # $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__),'../lib'))) require 'rubygems' require 'spec' require 'dokkit' require 'dokkit/dokkitlib' require File.dirname(__FILE__) + '/spec_helper.rb' describe Dokkit::DokkitLib, ' when initialized' do include SpecPathHelper before do class Dokkit::DokkitLib private def define_dokkit_task dokkit_task 'test' => 'dep' end def pre_block_configuration @config.another_test_option = 'default value' end def post_block_configuration @config.yet_another_test_option = @config.test_option end end model = mock('model') model.should_receive(:config).and_return(OpenStruct.new) @dokkittask = Dokkit::DokkitLib.new(model, 'dokkit') do |task| task.config.test_dir = 'test_dir/' task.config.test_option = 'test_option' end end it 'should define a namespace for its tasks' do @dokkittask.ns.should_not be_empty end it 'should be initialized with a configuration hash' do @dokkittask.config.test_dir.should == 'test_dir/' @dokkittask.config.test_option.should == 'test_option' end it 'should do pre configuration' do @dokkittask.config.another_test_option.should == 'default value' end it 'should do post configuration' do @dokkittask.config.yet_another_test_option.should == @dokkittask.config.test_option end it 'should encapsulate the tasks defined in its namespace' do task('dokkit:test').prerequisites.should == ['dep'] end it 'should define the same task only once' do @dokkittask.dokkit_task('test' => 'dep').should be_nil end end