Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add kumade:pre_deploy rake hook

  • Loading branch information...
commit 8bd28248dbff28d83be596d42000e1500f2e52f5 1 parent 769e80d
Joshua Clayton authored January 09, 2012
21  features/rake_task_pre_deploy.feature
... ...
@@ -0,0 +1,21 @@
  1
+@slow
  2
+Feature: Rake task that always runs during pre deploy
  3
+  As a user
  4
+  I want a Rake task that runs before deployment
  5
+  So that I can hook into the deployment process
  6
+
  7
+  Scenario: Pre-deploy task runs during deployment
  8
+    Given a new Rails application with Kumade and Jammit
  9
+    When I create a Heroku remote named "pretend-staging"
  10
+    And I add a pre-deploy rake task that prints "Hi!"
  11
+    And I run kumade with "pretend-staging"
  12
+    Then the output should contain "kumade:pre_deploy"
  13
+    And the output should contain "Hi!"
  14
+
  15
+  Scenario: Pre-deploy task does not run when pretending
  16
+    Given a new Rails application with Kumade and Jammit
  17
+    When I create a Heroku remote named "pretend-staging"
  18
+    And I add a pre-deploy rake task that prints "Hi!"
  19
+    And I run kumade with "pretend-staging -p"
  20
+    Then the output should contain "kumade:pre_deploy"
  21
+    But the output should not contain "Hi!"
12  features/step_definitions/rake_steps.rb
@@ -36,3 +36,15 @@
36 36
 
37 37
   commit_everything_in_repo
38 38
 end
  39
+
  40
+When /^I add a pre-deploy rake task that prints "Hi!"$/ do
  41
+  append_to_file("Rakefile", <<-CUSTOM_TASK)
  42
+      namespace :kumade do
  43
+        task :pre_deploy do
  44
+          puts 'Hi!'
  45
+        end
  46
+      end
  47
+  CUSTOM_TASK
  48
+
  49
+  commit_everything_in_repo
  50
+end
7  lib/kumade/deployer.rb
@@ -28,6 +28,7 @@ def deploy
28 28
 
29 29
     def pre_deploy
30 30
       ensure_clean_git
  31
+      run_predeploy_task
31 32
       package_assets
32 33
       sync_origin
33 34
     end
@@ -59,5 +60,11 @@ def ensure_heroku_remote_exists
59 60
         Kumade.configuration.outputter.error(%{Cannot deploy: "#{Kumade.configuration.environment}" remote does not exist})
60 61
       end
61 62
     end
  63
+
  64
+    private
  65
+
  66
+    def run_predeploy_task
  67
+      RakeTaskRunner.new("kumade:pre_deploy").invoke
  68
+    end
62 69
   end
63 70
 end
16  spec/kumade/deployer_spec.rb
... ...
@@ -1,7 +1,14 @@
1 1
 require 'spec_helper'
2 2
 
3 3
 describe Kumade::Deployer, "#pre_deploy", :with_mock_outputter do
4  
-  let(:git) { subject.git }
  4
+  let(:git)              { subject.git }
  5
+  let(:rake_task_runner) { stub("RakeTaskRunner", :invoke => true) }
  6
+  let(:packager)         { stub("packager", :run => true) }
  7
+
  8
+  before do
  9
+    Kumade::Packager.stubs(:new => packager)
  10
+    Kumade::RakeTaskRunner.stubs(:new).with("kumade:pre_deploy").returns(rake_task_runner)
  11
+  end
5 12
 
6 13
   it "calls the correct methods" do
7 14
     git.expects(:ensure_clean_git)
@@ -10,6 +17,13 @@
10 17
 
11 18
     subject.pre_deploy
12 19
   end
  20
+
  21
+  it "invokes the kumade:pre_deploy task" do
  22
+    subject.pre_deploy
  23
+
  24
+    Kumade::RakeTaskRunner.should have_received(:new).with("kumade:pre_deploy")
  25
+    rake_task_runner.should have_received(:invoke)
  26
+  end
13 27
 end
14 28
 
15 29
 describe Kumade::Deployer, "#deploy", :with_mock_outputter do

0 notes on commit 8bd2824

Please sign in to comment.
Something went wrong with that request. Please try again.