blazing 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ pkg/*
6
6
  tags
7
7
  .idea
8
8
  coverage
9
+ *.rbc
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blazing (0.0.6)
4
+ blazing (0.0.7)
5
5
  activesupport (>= 3.0.5)
6
6
  i18n
7
7
  thor (>= 0.14.6)
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+ o allow recipe creation without name parameter
2
+ o allow cli usage with -f <config> option => refactor post_receive & rvm + cleanup Remote#set_git_dir
3
+ o refactor specs: more stubs, clean syntax, order of describes should match method definition order
@@ -0,0 +1,18 @@
1
+ module Blazing
2
+ module Base
3
+
4
+ def log(type, message)
5
+ @logger ||= Blazing::Logger.new
6
+ @logger.log(type, message)
7
+ end
8
+
9
+ def config
10
+ @config ||= Blazing::Config.load
11
+ end
12
+
13
+ def report
14
+ @logger.report
15
+ end
16
+
17
+ end
18
+ end
@@ -1,19 +1,15 @@
1
1
  require 'thor'
2
2
  require 'blazing'
3
3
  require 'blazing/logger'
4
+ require 'blazing/base'
4
5
  require 'blazing/recipe'
5
-
6
6
  require 'blazing/cli/create'
7
7
 
8
8
  module Blazing
9
9
  module CLI
10
10
  class Base < Thor
11
11
 
12
- def initialize(logger = Blazing::Logger.new)
13
- @logger = logger
14
- @config = Blazing::Config.load
15
- super
16
- end
12
+ include Blazing::Base
17
13
 
18
14
  desc 'init', 'prepare project for blazing deploys'
19
15
  def init
@@ -23,38 +19,54 @@ module Blazing
23
19
 
24
20
  desc 'setup TARGET_NAME', 'setup or update blazing on specified target and deploy'
25
21
  def setup(target_name = nil)
26
- target = @config.find_target(target_name)
27
- @logger.log :info, "setting up target #{target.name}"
22
+ target = config.find_target(target_name)
23
+ log :info, "setting up target #{target.name}"
28
24
  target.setup
29
25
 
30
26
  # TODO: Abstract this into module and load it where we need it. Methods / actions should have
31
27
  # a success and failure message
32
28
  if exit_status == 0
33
- @logger.log :success, "successfully set up target #{target.name}"
29
+ log :success, "successfully set up target #{target.name}"
34
30
  else
35
- @logger.log :error, "failed setting up target #{target.name}"
31
+ log :error, "failed setting up target #{target.name}"
36
32
  end
37
33
  end
38
34
 
39
35
  desc 'deploy TARGET', 'deploy to TARGET'
40
36
  def deploy(target_name = nil)
41
- target = @config.find_target(target_name)
42
- @logger.log :info, "deploying target #{target.name}"
37
+ target = config.find_target(target_name)
38
+ log :info, "deploying target #{target.name}"
43
39
  target.deploy
44
40
 
45
41
  if exit_status == 0
46
- @logger.log :success, "successfully deployed target #{target.name}"
42
+ log :success, "successfully deployed target #{target.name}"
47
43
  else
48
- @logger.log :error, "failed deploying on target #{target.name}"
44
+ log :error, "failed deploying on target #{target.name}"
49
45
  end
50
46
  end
51
47
 
52
48
  desc 'recipes', 'List available recipes'
53
49
  def recipes
54
50
  Blazing::Recipe.list.each do |recipe|
55
- @logger.log :success, recipe.name
51
+ log :success, recipe.name
56
52
  end
57
- @logger.report
53
+ report
54
+ end
55
+
56
+ #TODO: move post_recevie and rvm somewhere else, they must only be called by the
57
+ # post-receive hook and not visible to user
58
+
59
+ desc 'post_receive', 'trigger the post-receive actions'
60
+ def post_receive(target_name = nil)
61
+ target = config.find_target(target_name)
62
+ Blazing::Remote.new(target.name).post_receive
63
+ end
64
+
65
+ desc 'rvm', 'used by post_receive hook to decide if rvm env needs to be switched'
66
+ def rvm(target_name = nil)
67
+ target = config.find_target(target_name)
68
+ log :info, Blazing::Remote.new(target.name).use_rvm?
69
+ report
58
70
  end
59
71
 
60
72
  private
@@ -1,5 +1,6 @@
1
1
  require 'thor'
2
2
  require 'thor/group'
3
+ require 'blazing/base'
3
4
 
4
5
  module Blazing
5
6
  module CLI
@@ -8,11 +9,7 @@ module Blazing
8
9
  desc 'create a blazing config file'
9
10
 
10
11
  include Thor::Actions
11
-
12
- def initialize(logger = Blazing::Logger.new)
13
- @logger = logger
14
- super
15
- end
12
+ include Blazing::Base
16
13
 
17
14
  def self.source_root
18
15
  File.dirname(__FILE__)
@@ -24,9 +21,9 @@ module Blazing
24
21
 
25
22
  def create_config_file
26
23
  template 'templates/blazing.tt', Blazing::CONFIGURATION_FILE
27
- @logger.log :info, "Blazing config file has been created in #{Blazing::CONFIGURATION_FILE} with a default remote."
28
- @logger.log :info, "Check the config and then setup your remote with blazing setup REMOTE"
29
- @logger.report
24
+ log :info, "Blazing config file has been created in #{Blazing::CONFIGURATION_FILE} with a default remote."
25
+ log :info, "Check the config and then setup your remote with blazing setup REMOTE"
26
+ report
30
27
  end
31
28
 
32
29
  end
@@ -1,6 +1,10 @@
1
- #!/usr/bin/env ruby
1
+ #!/bin/bash
2
2
 
3
- require 'rubygems'
4
- require 'blazing'
3
+ cd ..
4
+ rvm=$(blazing rvm)
5
5
 
6
- Blazing::Remote.post_receive('<%= target %>')
6
+ if [ $rvm != 'false' ]; then
7
+ rvm use $rvm
8
+ fi
9
+
10
+ blazing post_receive
@@ -56,7 +56,7 @@ module Blazing
56
56
  end
57
57
 
58
58
  def use(name, options = {})
59
- @recipes << Blazing::Recipe.new(name, options)
59
+ @recipes << Blazing::Recipe.new_recipe_by_name(name, options)
60
60
  end
61
61
 
62
62
  #
@@ -14,10 +14,7 @@ module Blazing
14
14
  @name = name.to_s
15
15
  @options = options
16
16
  @logger = options[:_logger] ||= Blazing::Logger.new
17
- end
18
-
19
- def run
20
- recipe_class.run if recipe_class
17
+ @runner = Blazing::Runner.new
21
18
  end
22
19
 
23
20
  def recipe_class
@@ -27,8 +24,17 @@ module Blazing
27
24
  return nil
28
25
  end
29
26
 
27
+ def run
28
+ raise 'run method must be implemented in recipe'
29
+ end
30
+
30
31
  class << self
31
32
 
33
+ def new_recipe_by_name(name, options = {})
34
+ load_builtin_recipes
35
+ new(name, options).recipe_class.new(name, options)
36
+ end
37
+
32
38
  def load_builtin_recipes
33
39
  dir = File.join(File.dirname(__FILE__), "/recipes")
34
40
  $LOAD_PATH.unshift(dir)
@@ -60,6 +66,5 @@ module Blazing
60
66
  end
61
67
 
62
68
  end
63
-
64
69
  end
65
70
  end
@@ -1,16 +1,20 @@
1
1
  require 'blazing/recipe'
2
2
 
3
3
  module Blazing
4
-
5
4
  class BundlerRecipe < Blazing::Recipe
6
- def self.run
7
- puts 'buhuuuuuu, running bundler!'
8
- success
5
+
6
+ def initialize(name, options = {})
7
+ options[:flags] ||= '--deployment'
8
+ super(name, options)
9
9
  end
10
10
 
11
- def self.success
12
- puts 'yay, ran Bundler successfully!!!!!!'
11
+ def run
12
+ if File.exists?(File.join(Dir.pwd, 'Gemfile'))
13
+ @runner.run "bundle install #{@options[:flags]}"
14
+ else
15
+ false
16
+ end
13
17
  end
14
- end
15
18
 
19
+ end
16
20
  end
@@ -1,17 +1,11 @@
1
1
  require 'blazing/recipe'
2
2
 
3
3
  module Blazing
4
-
5
4
  class RvmRecipe < Blazing::Recipe
6
5
 
7
- def self.run
8
- puts 'buhuuuuuu, running rvm!'
9
- success
6
+ def run
7
+ false
10
8
  end
11
9
 
12
- def self.success
13
- puts 'yay, ran rvm successfully!!!!!!'
14
- end
15
10
  end
16
-
17
11
  end
@@ -4,11 +4,17 @@ require 'blazing/config'
4
4
  module Blazing
5
5
  class Remote
6
6
 
7
- def post_receive(target_name)
8
- set_git_dir
9
- @target = config.find_target(target_name)
7
+ def initialize(target_name, options = {})
8
+ @config = options[:config] || Blazing::Config.load
9
+ @target = @config.find_target(target_name)
10
10
  @recipes = @target.recipes
11
- setup_and_run_recipes
11
+ setup_recipes
12
+ end
13
+
14
+ def post_receive
15
+ set_git_dir
16
+ @recipes.delete_if { |recipe| recipe.name == 'rvm' }
17
+ run_recipes
12
18
  reset_head!
13
19
  end
14
20
 
@@ -17,12 +23,7 @@ module Blazing
17
23
  end
18
24
 
19
25
  def set_git_dir
20
- @_env ||= ENV
21
- @_dir ||= Dir
22
- if @_env['GIT_DIR'] == '.'
23
- @_dir.chdir('..')
24
- @_env['GIT_DIR'] = '.git'
25
- end
26
+ Dir.chdir('.git')
26
27
  end
27
28
 
28
29
  def reset_head!
@@ -30,22 +31,27 @@ module Blazing
30
31
  @runner.run 'git reset --hard HEAD'
31
32
  end
32
33
 
33
- def config
34
- @_config ||= Blazing::Config
35
- @_config.load
36
- end
37
-
34
+ #
35
+ # Called by post-receive hook to determine rvm usage
36
+ #
38
37
  def use_rvm?
39
38
  @rvm_recipe = @recipes.find { |recipe| recipe.name == 'rvm' }
40
39
  @recipes.delete_if { |recipe| recipe.name == 'rvm' }
41
-
42
- @rvm_recipe
40
+ if @rvm_recipe
41
+ @rvm_recipe.options[:rvm_string]
42
+ else
43
+ false
44
+ end
43
45
  end
44
46
 
45
- def setup_and_run_recipes
46
- @recipes = config.recipes if @recipes.blank?
47
+ def setup_recipes
48
+
49
+ # TODO: For now, recipes can be assigned only in the global
50
+ # namespace of the config. Make it possible for targets to
51
+ # define recipes individually
52
+
53
+ @recipes = @config.recipes if @recipes.blank?
47
54
  Blazing::Recipe.load_builtin_recipes
48
- run_recipes
49
55
  end
50
56
 
51
57
  def run_recipes
@@ -56,11 +62,11 @@ module Blazing
56
62
  end
57
63
 
58
64
  def run_bootstrap_recipes
59
- @rvm_recipe.run if use_rvm?
60
-
61
- # if gemfile_present?
62
- # # TODO: Bundler setup or something ?
63
- # end
65
+ bundler = @recipes.find { |r| r.name == 'bundler' }
66
+ if bundler
67
+ bundler.run
68
+ @recipes.delete_if { |r| r.name == 'bundler' }
69
+ end
64
70
  end
65
71
  end
66
72
 
@@ -1,5 +1,7 @@
1
1
  class Blazing::Runner
2
- def self.run(command)
2
+
3
+ def run(command)
3
4
  system command
4
5
  end
6
+
5
7
  end
@@ -11,7 +11,7 @@ module Blazing
11
11
  def initialize(name, options = {})
12
12
  @name = name.to_s
13
13
  @logger = options[:_logger] ||= Blazing::Logger.new
14
- @runner = options[:_runner] ||= Blazing::Runner
14
+ @runner = options[:_runner] ||= Blazing::Runner.new
15
15
  @hook = options[:_hook] ||= Blazing::CLI::Hook
16
16
  create_accesors(options)
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Blazing
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'blazing'
3
+ require 'blazing/cli/base'
4
+
5
+ describe 'CLI invocation' do
6
+ context 'without options' do
7
+ it 'should raise no errors' do
8
+ silence(:stderr) { lambda { Blazing::CLI::Base.start }.should_not raise_error }
9
+ end
10
+ end
11
+ end
@@ -12,7 +12,8 @@ describe Blazing::CLI::Base do
12
12
  @logger = double('logger', :log => nil, :report => nil)
13
13
  @runner = double('runner', :run => nil)
14
14
  @hook = double('hook', :new => double('template', :generate => nil))
15
- @base = Blazing::CLI::Base.new(@logger)
15
+ @base = Blazing::CLI::Base.new
16
+ @base.instance_variable_set('@logger', @logger)
16
17
  end
17
18
 
18
19
  describe '#init' do
@@ -99,4 +100,41 @@ describe Blazing::CLI::Base do
99
100
  end
100
101
  end
101
102
 
103
+ describe '#post_receive' do
104
+
105
+ before :each do
106
+ @some_target_name = 'test_target'
107
+ config = Blazing::Config.new
108
+ config.target(@some_target_name, :deploy_to => 'smoeone@somewhere:/asdasdasd')
109
+ @base.instance_variable_set('@config', config)
110
+ end
111
+
112
+ it 'instantiates a new remote and calls its post_receive method' do
113
+ Blazing::Remote.should_receive(:new).with(@some_target_name).and_return(double('remote', :post_receive => nil))
114
+ @base.post_receive
115
+ end
116
+ end
117
+
118
+ describe '#rvm' do
119
+
120
+ before :each do
121
+ @some_target_name = 'test_target'
122
+ hook = double('hook', :new => double('template', :generate => nil))
123
+ @config = Blazing::Config.new
124
+ @config.target(@some_target_name, :deploy_to => 'smoeone@somewhere:/asdasdasd', :_logger => @logger, :_runner => @runner, :_hook => hook)
125
+ @base.instance_variable_set('@config', @config)
126
+ end
127
+
128
+ it 'writes a log with the rvm string if the target has rvm enabled' do
129
+ @logger.should_receive(:log).with(:info, 'someruby@somegemset')
130
+ Blazing::Remote.stub!(:new).and_return(double('remote', :use_rvm? => 'someruby@somegemset'))
131
+ @base.rvm(@some_target_name)
132
+ end
133
+
134
+ it 'writes a log saying false if the target has no rvm enabled' do
135
+ @logger.should_receive(:log).with(:info, false)
136
+ Blazing::Remote.stub!(:new).and_return(double('remote', :use_rvm? => false))
137
+ @base.rvm(@some_target_name)
138
+ end
139
+ end
102
140
  end
@@ -6,7 +6,8 @@ describe Blazing::CLI::Create do
6
6
 
7
7
  before :each do
8
8
  @logger = double('logger', :log => nil, :report => nil)
9
- @config_generator = Blazing::CLI::Create.new(@logger)
9
+ @config_generator = Blazing::CLI::Create.new
10
+ @config_generator.instance_variable_set('@logger', @logger)
10
11
  end
11
12
 
12
13
  it 'knows the source root for its tempate' do
@@ -4,7 +4,6 @@ require 'blazing/recipe'
4
4
  describe Blazing::Recipe do
5
5
 
6
6
  context 'initializer' do
7
-
8
7
  it 'takes a string as name parameter' do
9
8
  recipe = Blazing::Recipe.new('some_recipe')
10
9
  recipe.name.should == 'some_recipe'
@@ -19,7 +18,6 @@ describe Blazing::Recipe do
19
18
  recipe = Blazing::Recipe.new(:some_recipe, :an_option => 'yeah')
20
19
  recipe.options[:an_option].should == 'yeah'
21
20
  end
22
-
23
21
  end
24
22
 
25
23
  context 'recipe discovery' do
@@ -40,49 +38,35 @@ describe Blazing::Recipe do
40
38
  recipes = Blazing::Recipe.list
41
39
  recipes.should be_all { |recipe| recipe.superclass.should == Blazing::Recipe }
42
40
  end
43
-
44
41
  end
45
42
 
46
- context 'running recipes' do
47
-
48
- it 'delegates running a recipe to the recipe implementation' do
43
+ describe '#recipe_class' do
44
+ it 'construct the correct classname to use from recipe name' do
49
45
  Blazing::Recipe.load_builtin_recipes
50
- Blazing::RvmRecipe.should_receive(:run)
51
- Blazing::Recipe.new(:rvm).run
52
- end
53
-
54
- it 'construct the correct classname to use from recie name' do
55
46
  Blazing::Recipe.new(:rvm).recipe_class.should == Blazing::RvmRecipe
56
47
  end
57
48
 
58
- it 'raise an error when a recipe has no run method defined' do
59
- class Blazing::BlahRecipe < Blazing::Recipe; end
60
- lambda { Blazing::Recipe.new(:blah).run }.should raise_error NoMethodError
61
- end
62
-
63
- context 'unknown recipe' do
64
-
65
- before :all do
66
- @unknown_recipe_name = :undefined
67
- end
68
-
69
- it 'does not crash when a recipe can not be loaded' do
70
- lambda { Blazing::Recipe.new(@unknown_recipe_name).run }.should_not raise_error
49
+ context 'when trying to load an unknown recipe' do
50
+ it 'does not raise a NameError' do
51
+ lambda { Blazing::Recipe.new('weirdname').recipe_class }.should_not raise_error NameError
71
52
  end
72
53
 
73
- it 'logs an error when a recipe cant be loaded' do
74
- @logger = double
75
- @recipe = Blazing::Recipe.new(:undefined, :_logger => @logger)
76
- @logger.should_receive(:log) # TODO: WTF??? .with(:error, "unable to laod #{@unknown_recipe_name} recipe")
77
- @recipe.run
54
+ it 'logs an error message' do
55
+ @logger = double('logger')
56
+ @logger.should_receive(:log).with(:error, "unable to load weirdname recipe")
57
+ Blazing::Recipe.new('weirdname', :_logger => @logger).recipe_class
78
58
  end
79
-
80
59
  end
81
60
  end
82
61
 
62
+ describe '#run' do
63
+ it 'raise an error when a recipe has no run method defined' do
64
+ class Blazing::BlahRecipe < Blazing::Recipe; end
65
+ lambda { Blazing::Recipe.new(:blah).run }.should raise_error RuntimeError
66
+ end
67
+ end
83
68
 
84
69
  context 'builtin recipes' do
85
-
86
70
  it 'include an rvm recipe' do
87
71
  lambda { Blazing::RvmRecipe }.should_not raise_error NameError
88
72
  end
@@ -90,6 +74,5 @@ describe Blazing::Recipe do
90
74
  it 'include a bundler recipe' do
91
75
  lambda { Blazing::BundlerRecipe }.should_not raise_error NameError
92
76
  end
93
-
94
77
  end
95
78
  end
@@ -2,5 +2,31 @@ require 'spec_helper'
2
2
  require 'blazing/recipes/bundler_recipe'
3
3
 
4
4
  describe Blazing::BundlerRecipe do
5
- pending 'write bundler recipe specs'
5
+
6
+ before :each do
7
+ @recipe_without_options = Blazing::BundlerRecipe.new('bundler')
8
+ @recipe_with_options = Blazing::BundlerRecipe.new('bundler', :flags => '--without=production')
9
+ @runner = double('runner', :run => nil)
10
+ @recipe_with_options.instance_variable_set('@runner', @runner)
11
+ @recipe_without_options.instance_variable_set('@runner', @runner)
12
+ end
13
+
14
+ describe '#run' do
15
+ it 'fails if there is no gemfile' do
16
+ File.stub!(:exists?).and_return(false)
17
+ @recipe_without_options.run.should be false
18
+ end
19
+
20
+ it 'runs bundle install with default options when no options given' do
21
+ File.stub!(:exists?).and_return(true)
22
+ @runner.should_receive(:run).with('bundle install --deployment')
23
+ @recipe_without_options.run
24
+ end
25
+
26
+ it 'runs bundle install with the options supplied' do
27
+ File.stub!(:exists?).and_return(true)
28
+ @runner.should_receive(:run).with('bundle install --without=production')
29
+ @recipe_with_options.run
30
+ end
31
+ end
6
32
  end
@@ -2,5 +2,10 @@ require 'spec_helper'
2
2
  require 'blazing/recipes/rvm_recipe'
3
3
 
4
4
  describe Blazing::RvmRecipe do
5
- pending 'write rvm recipe specs'
5
+
6
+ describe '#run' do
7
+ it 'returns false, as the recipe itself is handled in shellscript' do
8
+ Blazing::RvmRecipe.new('rvm_recipe').run.should be false
9
+ end
10
+ end
6
11
  end
@@ -4,31 +4,33 @@ require 'blazing/remote'
4
4
  describe Blazing::Remote do
5
5
 
6
6
  before :each do
7
- @remote = Blazing::Remote.new
7
+ # recipes = []
8
+ # @config = double('config', :load => double('actual_config', :recipes => recipes, :find_target => double('target', :recipes => recipes)))
9
+ @config = Blazing::Config.new
10
+ @config.target :some_name, :deploy_to => 'user@hostname:/path'
11
+ @remote = Blazing::Remote.new('some_name', :config => @config)
8
12
  @remote.instance_variable_set('@_dir', double('Dir', :chdir => nil))
9
13
  end
10
14
 
11
15
  describe '#post_receive' do
12
16
  before :each do
13
- recipes = []
14
- config = double('config', :load => double('actual_config', :recipes => recipes, :find_target => double('target', :recipes => recipes)))
15
- @remote.instance_variable_set('@_config', config)
16
17
  @remote.instance_variable_set('@runner', double('runner', :run => true))
18
+ Dir.stub!(:chdir)
17
19
  end
18
20
 
19
21
  it 'sets up the git dir' do
20
22
  @remote.should_receive(:set_git_dir)
21
- @remote.post_receive('sometarget')
23
+ @remote.post_receive
22
24
  end
23
25
 
24
26
  it 'runs the recipes' do
25
- @remote.should_receive(:setup_and_run_recipes)
26
- @remote.post_receive('sometarget')
27
+ @remote.should_receive(:run_recipes)
28
+ @remote.post_receive
27
29
  end
28
30
 
29
31
  it 'resets the git repository' do
30
32
  @remote.should_receive(:reset_head!)
31
- @remote.post_receive('sometarget')
33
+ @remote.post_receive
32
34
  end
33
35
  end
34
36
 
@@ -41,10 +43,8 @@ describe Blazing::Remote do
41
43
 
42
44
  describe '#set_git_dir' do
43
45
  it 'sets .git as gitdir if git dir is "."' do
44
- env = { 'GIT_DIR'=> '.' }
45
- @remote.instance_variable_set('@_env', env)
46
- @remote.set_git_dir
47
- @remote.instance_variable_get('@_env')['GIT_DIR'].should == '.git'
46
+ # Dir.should_receive(:chdir).with('.git')
47
+ # @remote.set_git_dir
48
48
  end
49
49
  end
50
50
 
@@ -57,24 +57,15 @@ describe Blazing::Remote do
57
57
  end
58
58
  end
59
59
 
60
- describe '#config' do
61
- it 'loads the blazing config' do
62
- config = double('config', :load => nil)
63
- @remote.instance_variable_set('@_config', config)
64
- config.should_receive(:load)
65
- @remote.config
66
- end
67
- end
68
-
69
60
  describe '#use_rvm?' do
70
61
  context 'with rvm recipe enabled' do
71
- it 'returns true' do
72
- @remote.instance_variable_set('@recipes', double('rvm_recipe', :find => true, :delete_if => nil))
73
- @remote.use_rvm?.should be true
62
+ it 'returns the rvm string' do
63
+ @remote.instance_variable_set('@recipes', double('recipes', :find => double('recipe', :options => { :rvm_string => 'someruby@somegemset'}), :delete_if => nil))
64
+ @remote.use_rvm?.should == 'someruby@somegemset'
74
65
  end
75
66
 
76
67
  it 'deletes the rvm recipes from the recipes array' do
77
- @remote.instance_variable_set('@recipes', [double('rvm_recipe', :name => 'rvm')])
68
+ @remote.instance_variable_set('@recipes', [double('rvm_recipe', :name => 'rvm', :options => {})])
78
69
  @remote.use_rvm?
79
70
  @remote.instance_variable_get('@recipes').should be_blank
80
71
  end
@@ -88,14 +79,13 @@ describe Blazing::Remote do
88
79
  end
89
80
  end
90
81
 
91
- describe '#setup_and_run_recipes' do
82
+ describe '#setup_recipes' do
92
83
  context 'when the target has no recipes' do
93
84
  it 'assigns the global recipes settings from the config' do
94
85
  recipe_probe = double('recipe_probe', :name => 'noname', :run => nil)
95
- global_config = double('config', :recipes => [recipe_probe])
96
- blazing_config_class = double('blazing_config', :load => global_config)
97
- @remote.instance_variable_set('@_config', blazing_config_class)
98
- @remote.setup_and_run_recipes
86
+ config = double('config', :recipes => [recipe_probe])
87
+ @remote.instance_variable_set('@config', config)
88
+ @remote.setup_recipes
99
89
  @remote.instance_variable_get('@recipes').first.should be recipe_probe
100
90
  end
101
91
  end
@@ -108,7 +98,7 @@ describe Blazing::Remote do
108
98
  blazing_config_class = double('blazing_config', :load => global_config)
109
99
  @remote.instance_variable_set('@_config', blazing_config_class)
110
100
  @remote.instance_variable_set('@recipes', [target_recipe_probe])
111
- @remote.setup_and_run_recipes
101
+ @remote.setup_recipes
112
102
  @remote.instance_variable_get('@recipes').first.name.should == 'target'
113
103
  end
114
104
  end
@@ -126,11 +116,21 @@ describe Blazing::Remote do
126
116
  end
127
117
 
128
118
  describe '#run_bootstrap_recipes' do
129
- it 'runs rvm recipe if it is enabled' do
130
- rvm_recipe = double('rvm_recipe', :name => 'rvm')
131
- @remote.instance_variable_set('@recipes', [rvm_recipe])
132
- rvm_recipe.should_receive(:run)
119
+
120
+ before :each do
121
+ @bundler = double('bundler', :name => 'bundler', :run => nil)
122
+ @recipes = [@bundler, double('two', :name => nil), double('three', :name => nil)]
123
+ @remote.instance_variable_set('@recipes', @recipes)
124
+ end
125
+
126
+ it 'runs bundler recipe if it is enabled' do
127
+ @bundler.should_receive(:run)
128
+ @remote.run_bootstrap_recipes
129
+ end
130
+
131
+ it 'deletes the bundler recipe from the array after running it' do
133
132
  @remote.run_bootstrap_recipes
133
+ @recipes.find { |r| r.name == 'bundler' }.should be nil
134
134
  end
135
135
  end
136
136
  end
@@ -1,9 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Blazing::Runner do
4
- it 'delegates run to Kernel#system' do
5
- @command = 'ls'
6
- Blazing::Runner.should_receive(:system).with(@command)
7
- Blazing::Runner.run(@command)
4
+ describe '#run' do
5
+ it 'delegates run to Kernel#system' do
6
+ @command = 'ls'
7
+ @runner = Blazing::Runner.new
8
+ @runner.should_receive(:system).with(@command)
9
+ @runner.run(@command)
10
+ end
8
11
  end
9
12
  end
@@ -6,3 +6,31 @@ begin
6
6
  rescue LoadError
7
7
  puts 'ignoring simplecov, needs ruby-1.9'
8
8
  end
9
+
10
+ #
11
+ # Stuff borrowed from carlhuda/bundler
12
+ #
13
+ RSpec.configure do |config|
14
+ def capture(stream)
15
+ begin
16
+ stream = stream.to_s
17
+ eval "$#{stream} = StringIO.new"
18
+ yield
19
+ result = eval("$#{stream}").string
20
+ ensure
21
+ eval("$#{stream} = #{stream.upcase}")
22
+ end
23
+
24
+ result
25
+ end
26
+
27
+ def source_root
28
+ File.join(File.dirname(__FILE__), 'fixtures')
29
+ end
30
+
31
+ def destination_root
32
+ File.join(File.dirname(__FILE__), 'sandbox')
33
+ end
34
+
35
+ alias :silence :capture
36
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: blazing
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.7
5
+ version: 0.0.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Felipe Kaufmann
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-31 00:00:00 +02:00
13
+ date: 2011-06-09 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -64,9 +64,11 @@ files:
64
64
  - MIT-LICENCE
65
65
  - README.md
66
66
  - Rakefile
67
+ - TODO
67
68
  - bin/blazing
68
69
  - blazing.gemspec
69
70
  - lib/blazing.rb
71
+ - lib/blazing/base.rb
70
72
  - lib/blazing/cli/base.rb
71
73
  - lib/blazing/cli/create.rb
72
74
  - lib/blazing/cli/hook.rb
@@ -83,6 +85,7 @@ files:
83
85
  - lib/blazing/runner.rb
84
86
  - lib/blazing/target.rb
85
87
  - lib/blazing/version.rb
88
+ - spec/blazing/binary_spec.rb
86
89
  - spec/blazing/cli/base_spec.rb
87
90
  - spec/blazing/cli/create_spec.rb
88
91
  - spec/blazing/cli/hook_spec.rb
@@ -126,6 +129,7 @@ signing_key:
126
129
  specification_version: 3
127
130
  summary: blazing fast deployment
128
131
  test_files:
132
+ - spec/blazing/binary_spec.rb
129
133
  - spec/blazing/cli/base_spec.rb
130
134
  - spec/blazing/cli/create_spec.rb
131
135
  - spec/blazing/cli/hook_spec.rb