spec/sprinkle/package_spec.rb in sprinkle-0.3.6 vs spec/sprinkle/package_spec.rb in sprinkle-0.4.0

- old
+ new

@@ -6,11 +6,11 @@ before do @name = :package_name @empty = Proc.new { } @opts = { } end - + # Kind of a messy way to do this but it works and DRYs out # the specs. Checks to make sure an installer is receiving # the block passed to it throught the package block. def check_block_forwarding_on(installer) eval(<<CODE) @@ -19,16 +19,16 @@ pkg = package @name do #{installer} 'archive' do pre :install, 'preOp' end end - + pre_count = pkg.installers.first.instance_variable_get(:@pre)[:install].length }.should change { pre_count }.by(1) CODE end - + # More of Mitchell's meta-programming to dry up specs. def create_package_with_blank_verify(n = 1) eval(<<CODE) @pkg = package @name do gem 'gem' @@ -140,18 +140,46 @@ end pkg.should respond_to(:gem) pkg.installers.first.class.should == Sprinkle::Installers::Gem end + it 'should optionally accept a noop installer' do + pkg = package @name do + noop do + end + end + pkg.should respond_to(:noop) + pkg.installers.first.class.should == Sprinkle::Installers::Runner + @installer = pkg.installers.first + @install_commands = @installer.send :install_commands + @install_commands.should == 'echo noop' + end + + it 'should optionally accept an group installer' do + pkg = package @name do + add_group 'bob' + end + pkg.should respond_to(:add_group) + pkg.installers.first.class.should == Sprinkle::Installers::Group + end + it 'should optionally accept a source installer' do pkg = package @name do source 'archive' end pkg.should respond_to(:source) pkg.installers.first.class.should == Sprinkle::Installers::Source end + it 'should optionally accept an user installer' do + pkg = package @name do + add_user 'bob' + end + pkg.should respond_to(:add_user) + pkg.installers.first.class.should == Sprinkle::Installers::User + end + it 'should allow multiple installer steps to be defined and respect order' do pkg = package @name do source 'archive' gem 'momoney' end @@ -177,11 +205,11 @@ source 'archive' do; end end pkg.should respond_to(:source) pkg.installers.first.class.should == Sprinkle::Installers::Source end - + it 'should forward block to installer superclass' do check_block_forwarding_on(:source) end it 'should automatically add a build essential recommendation' do @@ -190,17 +218,17 @@ end pkg.recommends.should include(:build_essential) end end - + describe 'with an apt installer' do it 'should forward block to installer superclass' do check_block_forwarding_on(:apt) end end - + describe 'with an rpm installer' do it 'should forward block to installer superclass' do check_block_forwarding_on(:rpm) end end @@ -211,11 +239,11 @@ pkg = package @name do gem 'gem' end pkg.recommends.should include(:rubygems) end - + it 'should forward block to installer superclass' do check_block_forwarding_on(:gem) end end @@ -254,69 +282,69 @@ @installer.should_not_receive(:process) @package.process(@deployment, @roles) end end - + describe 'with verifications' do before do @pkg = create_package_with_blank_verify(3) @pkg.installers = [ @installer ] @installer.stub!(:defaults) @installer.stub!(:process) end - + describe 'with forcing' do before do # Being explicit Sprinkle::OPTIONS[:force] = true end - + it 'should process verifications only once' do @pkg.should_receive(:process_verifications).once @pkg.process(@deployment, @roles) end - + after do # Being explicit Sprinkle::OPTIONS[:force] = false end end - + describe 'without forcing' do before do # Being explicit Sprinkle::OPTIONS[:force] = false end - + it 'should process verifications twice' do @pkg.should_receive(:process_verifications).once.with(@deployment, @roles, true).and_raise(Sprinkle::VerificationFailed.new(@pkg, '')) @pkg.should_receive(:process_verifications).once.with(@deployment, @roles).and_raise(Sprinkle::VerificationFailed.new(@pkg, '')) end - + it 'should continue with installation if pre-verification fails' do @pkg.should_receive(:process_verifications).twice.and_raise(Sprinkle::VerificationFailed.new(@pkg, '')) @installer.should_receive(:defaults) @installer.should_receive(:process) end - + it 'should only process verifications once and should not process installer if verifications succeed' do @pkg.should_receive(:process_verifications).once.and_return(nil) @installer.should_not_receive(:defaults) @installer.should_not_receive(:process) end - + after do begin @pkg.process(@deployment, @roles) rescue Sprinkle::VerificationFailed => e; end end end end end - + describe 'when processing verifications' do before do @deployment = mock(Sprinkle::Deployment) @roles = [ :app, :db ] @installer = mock(Sprinkle::Installers::Installer, :defaults => true, :process => true) @@ -325,11 +353,11 @@ @installer.stub!(:defaults) @installer.stub!(:process) @logger = mock(ActiveSupport::BufferedLogger, :debug => true, :debug? => true) @logger.stub!(:info) end - + it 'should request _each_ verification to configure itself against the deployment context' do @pkg.verifications.each do |v| v.should_receive(:defaults).with(@deployment).once v.stub!(:process) end @@ -339,20 +367,20 @@ @pkg.verifications.each do |v| v.stub!(:defaults) v.should_receive(:process).with(@roles).once end end - + it 'should enter a log info event to notify user whats happening' do @pkg.verifications.each do |v| v.stub!(:defaults) v.stub!(:process) end - + @pkg.should_receive(:logger).once.and_return(@logger) end - + after do @pkg.process_verifications(@deployment, @roles) end end @@ -417,11 +445,11 @@ before do @a = package :a do; requires :virtual ; end @v1 = package :v1, :provides => :virtual do; end @v2 = package :v2, :provides => :virtual do; end end - + it 'should select package for an array' do @a.should_receive(:select_package).with(:virtual, [@v1,@v2]).and_return(@v1) @a.tree do; end end end @@ -438,34 +466,34 @@ it 'should raise an error if a package is missing' do lambda { @pkg.tree }.should raise_error end end - - describe 'with verifications' do + + describe 'with verifications' do it 'should create a Sprinkle::Verification object for the verify block' do Sprinkle::Verify.should_receive(:new).once - + create_package_with_blank_verify end - + it 'should create multiple Sprinkle::Verification objects for multiple verify blocks' do Sprinkle::Verify.should_receive(:new).twice - + create_package_with_blank_verify(2) end - + it 'should add each Sprinkle::Verificaton object to the @verifications array' do @pkg = create_package_with_blank_verify(3) @pkg.verifications.length.should eql(3) end - + it 'should initialize Sprinkle::Verification with the package name, description, and block' do Sprinkle::Verify.should_receive(:new) do |pkg, desc| pkg.name.should eql(@name) desc.should eql('stuff happens') end - + # We do a should_not raise_error because if a block was NOT passed, an error # is raised. This is specced in verification_spec.rb lambda { create_package_with_blank_verify }.should_not raise_error end end