Skip to content

Commit

Permalink
added openbsd pkg installer
Browse files Browse the repository at this point in the history
  • Loading branch information
doke committed Jan 14, 2009
1 parent 21237f2 commit 115a154
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/sprinkle/installers/bsd_port.rb
@@ -1,15 +1,15 @@
module Sprinkle
module Installers
# = FreeBSD Port Installer
# = OpenBSD and FreeBSD Port Installer
#
# The Port installer installs FreeBSD ports.
# The Port installer installs OpenBSD and FreeBSD ports.
#
# == Example Usage
#
# Installing the magic_beans port.
#
# package :magic_beans do
# port 'magic/magic_beans'
# bsd_port 'magic/magic_beans'
# end
#
class BsdPort < Installer
Expand Down
37 changes: 37 additions & 0 deletions lib/sprinkle/installers/openbsd_pkg.rb
@@ -0,0 +1,37 @@
module Sprinkle
module Installers
# = OpenBSD Package Installer
#
# The Pkg package installer installs OpenBSD packages.
#
# == Example Usage
#
# Installing the magic_beans package.
#
# package :magic_beans do
# openbsd_pkg 'magic_beans'
# end
#
# You may also specify multiple packages as an array:
#
# package :magic_beans do
# openbsd_pkg %w(magic_beans magic_sauce)
# end
class OpenbsdPkg < Installer
attr_accessor :packages #:nodoc:

def initialize(parent, packages, &block) #:nodoc:
super parent, &block
packages = [packages] unless packages.is_a? Array
@packages = packages
end

protected

def install_commands #:nodoc:
"pkg_add #{@packages.join(' ')}"
end

end
end
end
4 changes: 4 additions & 0 deletions lib/sprinkle/package.rb
Expand Up @@ -124,6 +124,10 @@ def freebsd_pkg(*names, &block)
@installer = Sprinkle::Installers::FreebsdPkg.new(self, *names, &block)
end

def openbsd_pkg(*names, &block)
@installer = Sprinkle::Installers::OpenbsdPkg.new(self, *names, &block)
end

def bsd_port(port, &block)
@installer = Sprinkle::Installers::BsdPort.new(self, port, &block)
end
Expand Down
49 changes: 49 additions & 0 deletions spec/sprinkle/installers/openbsd_pkg_spec.rb
@@ -0,0 +1,49 @@
require File.dirname(__FILE__) + '/../../spec_helper'

describe Sprinkle::Installers::OpenbsdPkg do

before do
@package = mock(Sprinkle::Package, :name => 'package')
end

def create_pkg(pkgs, &block)
Sprinkle::Installers::OpenbsdPkg.new(@package, pkgs, &block)
end

describe 'when created' do

it 'should accept a single package to install' do
@installer = create_pkg 'ruby'
@installer.packages.should == [ 'ruby' ]
end

it 'should accept an array of packages to install' do
@installer = create_pkg %w( gcc gdb g++ )
@installer.packages.should == ['gcc', 'gdb', 'g++']
end

end

describe 'during installation' do

before do
@installer = create_pkg 'ruby' do
pre :install, 'op1'
post :install, 'op2'
end
@install_commands = @installer.send :install_commands
end

it 'should invoke the freebsd_pkg installer for all specified packages' do
@install_commands.should =~ /pkg_add ruby/
end

it 'should automatically insert pre/post commands for the specified package' do
@installer.send(:install_sequence).should == [ 'op1', 'pkg_add ruby', 'op2' ]
end

it 'should install a specific version if defined'

end

end

0 comments on commit 115a154

Please sign in to comment.