Permalink
Browse files

Merge pull request #34 from selectport/master

Added support for thor tasks installer (just like rake) ...
  • Loading branch information...
2 parents cdc8295 + b9eefc6 commit 55c7078d6db2b5cd5f21db1c05a4b7b923db714a @crafterm committed Sep 9, 2011
Showing with 70 additions and 0 deletions.
  1. +37 −0 lib/sprinkle/installers/thor.rb
  2. +4 −0 lib/sprinkle/package.rb
  3. +29 −0 spec/sprinkle/installers/thor_spec.rb
@@ -0,0 +1,37 @@
+module Sprinkle
+ module Installers
+ # = Thor Installer
+ #
+ # This installer runs a thor command.
+ #
+ # == Example Usage
+ #
+ # The following example runs the command "thor spec" on
+ # the remote server.
+ #
+ # package :spec do
+ # thor 'spec'
+ # end
+ #
+ # Specify a Thorfile with the :thorfile option.
+ #
+ # package :spec, :thorfile => "/var/setup/Thorfile" do
+ # thor 'spec'
+ # end
+
+ class Thor < Installer
+ def initialize(parent, commands, options = {}, &block) #:nodoc:
+ super parent, options, &block
+ @commands = commands
+ end
+
+ protected
+
+ def install_commands #:nodoc:
+ file = @options[:thorfile] ? "-f #{@options[:thorfile]} " : ""
+ "thor #{file}#{@commands}"
+ end
+
+ end
+ end
+end
View
@@ -187,6 +187,10 @@ def rake(name, options = {}, &block)
@installers << Sprinkle::Installers::Rake.new(self, name, options, &block)
end
+ def thor(name, options = {}, &block)
+ @installers << Sprinkle::Installers::Thor.new(self, name, options, &block)
+ end
+
def noop(&block)
@installers << Sprinkle::Installers::Noop.new(self, name, options, &block)
end
@@ -0,0 +1,29 @@
+require File.expand_path("../../spec_helper", File.dirname(__FILE__))
+
+describe Sprinkle::Installers::Thor do
+
+ before do
+ @package = mock(Sprinkle::Package, :name => 'spec')
+ end
+
+ def create_thor(names, options = {}, &block)
+ Sprinkle::Installers::Thor.new(@package, names, options, &block)
+ end
+
+ describe 'during installation' do
+
+ it 'should invoke the thor executer for all specified tasks' do
+ @installer = create_thor 'spec'
+ @install_commands = @installer.send :install_commands
+ @install_commands.should =~ /thor spec/
+ end
+
+ it 'should invoke the thor executer for all specified tasks' do
+ @installer = create_thor 'spec', :thorfile => '/some/Thorfile'
+ @install_commands = @installer.send :install_commands
+ @install_commands.should == "thor -f /some/Thorfile spec"
+ end
+
+ end
+
+end

0 comments on commit 55c7078

Please sign in to comment.