blazing 0.0.6 → 0.0.7

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.
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'blazing/logger'
3
+ require 'blazing/object'
4
+
5
+ describe Blazing::Logger do
6
+
7
+ before :each do
8
+ @output = double
9
+ @logger = Blazing::Logger.new(@output)
10
+ end
11
+
12
+ context 'message logger' do
13
+ it 'saves the message within the logging class' do
14
+ @logger.log :info, 'something'
15
+ @logger.instance_variable_get('@messages').should_not be_blank
16
+ end
17
+
18
+ it 'keeps track what log level a message has' do
19
+ @logger.log :info, 'something'
20
+ @logger.instance_variable_get('@messages').first[:type].should be :info
21
+ end
22
+
23
+ it 'fails if the log level is unknown' do
24
+ lambda { @logger.log(:meh, 'something') }.should raise_error
25
+ end
26
+ end
27
+
28
+ context 'message reporter' do
29
+ it 'prints the messages from the messages hash' do
30
+ @logger.log :info, 'just a message'
31
+ @output.should_receive(:puts).with('just a message')
32
+ @logger.report
33
+ end
34
+
35
+ it 'prints all messages when no type given' do
36
+ @logger.log :info, 'an info message'
37
+ @logger.log :warn, 'a warn message'
38
+ @output.should_receive(:puts).exactly(2).times
39
+ @logger.report
40
+ end
41
+
42
+ it 'prints only the message of the given type when a type is supplied' do
43
+ @logger.log :info, 'an info message'
44
+ @logger.log :info, 'another info message'
45
+ @logger.log :warn, 'a warn message'
46
+ @output.should_receive(:puts).exactly(2).times
47
+ @logger.report(:info)
48
+ end
49
+ end
50
+ end
@@ -24,6 +24,14 @@ describe Blazing::Recipe do
24
24
 
25
25
  context 'recipe discovery' do
26
26
 
27
+ around :each do |example|
28
+ # Make sure specs dont interfere with recipe discovery mechanism
29
+ recipes = Blazing::Recipe.list
30
+ recipes.each { |r| Blazing.send(:remove_const, r.name.to_s.gsub(/^.*::/, '')) rescue NameError }
31
+ example.run
32
+ recipes.each { |r| Blazing.send(:remove_const, r.name.to_s.gsub(/^.*::/, '')) rescue NameError }
33
+ end
34
+
27
35
  it 'before loading them, no recipes are known' do
28
36
  lambda { Blazing::RvmRecipe }.should raise_error NameError
29
37
  end
@@ -31,18 +39,13 @@ describe Blazing::Recipe do
31
39
  it 'can discover available recipes' do
32
40
  recipes = Blazing::Recipe.list
33
41
  recipes.should be_all { |recipe| recipe.superclass.should == Blazing::Recipe }
34
- recipes.each { |r| Blazing.send(:remove_const, r.name.to_s.gsub(/^.*::/, '')) }
35
42
  end
36
43
 
37
44
  end
38
45
 
39
46
  context 'running recipes' do
40
47
 
41
- # before :each do
42
- # @logger = double('logger').as_null_object
43
- # end
44
-
45
- it 'delegate running a recipe to the recipe implementation' do
48
+ it 'delegates running a recipe to the recipe implementation' do
46
49
  Blazing::Recipe.load_builtin_recipes
47
50
  Blazing::RvmRecipe.should_receive(:run)
48
51
  Blazing::Recipe.new(:rvm).run
@@ -68,8 +71,10 @@ describe Blazing::Recipe do
68
71
  end
69
72
 
70
73
  it 'logs an error when a recipe cant be loaded' do
71
- Blazing::LOGGER.should_receive(:error) # TODO: how should one do this?? .with("unable to laod #{@unknown_recipe_name} recipe")
72
- Blazing::Recipe.new(:undefined).run
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
73
78
  end
74
79
 
75
80
  end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+ require 'blazing/recipes/bundler_recipe'
3
+
4
+ describe Blazing::BundlerRecipe do
5
+ pending 'write bundler recipe specs'
6
+ end
@@ -0,0 +1,6 @@
1
+ # require 'spec_helper'
2
+ # require 'blazing/recipe/rvm'
3
+
4
+ # describe Blazing::RvmRecipe do
5
+ # pending 'write rvm recipe specs'
6
+ # end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+ require 'blazing/recipes/rvm_recipe'
3
+
4
+ describe Blazing::RvmRecipe do
5
+ pending 'write rvm recipe specs'
6
+ end
@@ -3,11 +3,134 @@ require 'blazing/remote'
3
3
 
4
4
  describe Blazing::Remote do
5
5
 
6
- context 'post_receive method' do
7
- it 'set the gid dir to .git if it is not already' do
8
- pending 'dont know how to spec this yet'
6
+ before :each do
7
+ @remote = Blazing::Remote.new
8
+ @remote.instance_variable_set('@_dir', double('Dir', :chdir => nil))
9
+ end
10
+
11
+ describe '#post_receive' do
12
+ 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
+ @remote.instance_variable_set('@runner', double('runner', :run => true))
17
+ end
18
+
19
+ it 'sets up the git dir' do
20
+ @remote.should_receive(:set_git_dir)
21
+ @remote.post_receive('sometarget')
22
+ end
23
+
24
+ it 'runs the recipes' do
25
+ @remote.should_receive(:setup_and_run_recipes)
26
+ @remote.post_receive('sometarget')
27
+ end
28
+
29
+ it 'resets the git repository' do
30
+ @remote.should_receive(:reset_head!)
31
+ @remote.post_receive('sometarget')
32
+ end
33
+ end
34
+
35
+ describe '#gemfile_present?' do
36
+ it 'checks if a Gemfile is in the cwd' do
37
+ File.should_receive(:exists?).with('Gemfile')
38
+ @remote.gemfile_present?
9
39
  end
40
+ end
10
41
 
42
+ describe '#set_git_dir' do
43
+ 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'
48
+ end
11
49
  end
12
50
 
51
+ describe '#reset_head!' do
52
+ it 'does a git reset --hard HEAD' do
53
+ runner = double('runner', :run => nil)
54
+ @remote.instance_variable_set('@runner', runner)
55
+ runner.should_receive(:run).with('git reset --hard HEAD')
56
+ @remote.reset_head!
57
+ end
58
+ end
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
+ describe '#use_rvm?' do
70
+ 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
74
+ end
75
+
76
+ it 'deletes the rvm recipes from the recipes array' do
77
+ @remote.instance_variable_set('@recipes', [double('rvm_recipe', :name => 'rvm')])
78
+ @remote.use_rvm?
79
+ @remote.instance_variable_get('@recipes').should be_blank
80
+ end
81
+ end
82
+
83
+ context 'without rvm_recipe' do
84
+ it 'returns false' do
85
+ @remote.instance_variable_set('@recipes', double('rvm_recipe', :find => false, :delete_if => nil))
86
+ @remote.use_rvm?.should be false
87
+ end
88
+ end
89
+ end
90
+
91
+ describe '#setup_and_run_recipes' do
92
+ context 'when the target has no recipes' do
93
+ it 'assigns the global recipes settings from the config' do
94
+ 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
99
+ @remote.instance_variable_get('@recipes').first.should be recipe_probe
100
+ end
101
+ end
102
+
103
+ context 'when the target has recipes' do
104
+ it 'does not touch the target recipes' do
105
+ target_recipe_probe = double('target_recipe_probe', :name => 'target', :run => nil)
106
+ global_recipe_probe = double('global_recipe_probe', :name => 'global', :run => nil)
107
+ global_config = double('config', :recipes => [global_recipe_probe])
108
+ blazing_config_class = double('blazing_config', :load => global_config)
109
+ @remote.instance_variable_set('@_config', blazing_config_class)
110
+ @remote.instance_variable_set('@recipes', [target_recipe_probe])
111
+ @remote.setup_and_run_recipes
112
+ @remote.instance_variable_get('@recipes').first.name.should == 'target'
113
+ end
114
+ end
115
+ end
116
+
117
+ describe '#run_recipes' do
118
+ it 'runs all recipes' do
119
+ recipes = [double('one', :name => nil), double('two', :name => nil), double('three', :name => nil)]
120
+ @remote.instance_variable_set('@recipes', recipes)
121
+ recipes.each do |recipe|
122
+ recipe.should_receive(:run)
123
+ end
124
+ @remote.run_recipes
125
+ end
126
+ end
127
+
128
+ 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)
133
+ @remote.run_bootstrap_recipes
134
+ end
135
+ end
13
136
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
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)
8
+ end
9
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+ require 'blazing/target'
3
+
4
+ describe Blazing::Target do
5
+
6
+ before :each do
7
+ @logger = double('logger')
8
+ @runner = double('runner', :run => nil)
9
+ @hook = double('hook', :new => double('template', :generate => nil))
10
+ @options = { :deploy_to => 'someone@somehost:/some/path', :_hook => @hook, :_runner => @runner, :_logger => @logger }
11
+ end
12
+
13
+ describe '#initialize' do
14
+ context 'with deploy_to option' do
15
+ it 'sets the configuration options accordingly and creates an accessor' do
16
+ @target = Blazing::Target.new('somename', @options)
17
+ @target.deploy_to.should == @options[:deploy_to]
18
+ end
19
+
20
+ it 'extracts the hostname from the deploy_to option' do
21
+ @target = Blazing::Target.new('somename', @options)
22
+ @target.host.should == 'somehost'
23
+ end
24
+
25
+ it 'extracts the username from the deploy_to option' do
26
+ @target = Blazing::Target.new('somename', @options)
27
+ @target.user.should == 'someone'
28
+ end
29
+
30
+ it 'extracts the path from the deploy_to option' do
31
+ @target = Blazing::Target.new('somename', @options)
32
+ @target.path.should == '/some/path'
33
+ end
34
+
35
+ it 'overrides the hostname that was set explicitly' do
36
+ @target = Blazing::Target.new('somename', @options.merge({ :host => 'anotherhost' }))
37
+ @target.host.should == 'somehost'
38
+ end
39
+
40
+ it 'overrides the username that was set explicitly' do
41
+ @target = Blazing::Target.new('somename', @options.merge({ :user => 'anotheruser' }))
42
+ @target.user.should == 'someone'
43
+ end
44
+
45
+ it 'overrides the path that was set explicitly' do
46
+ @target = Blazing::Target.new('somename', @options.merge({ :path => 'anotherpath' }))
47
+ @target.path.should == '/some/path'
48
+ end
49
+ end
50
+
51
+ context 'with missing options' do
52
+ it 'raises an error if the path option is missing' do
53
+ @options = { :host => 'somehost', :user => 'someuser' }
54
+ lambda { Blazing::Target.new('somename', @options) }.should raise_error
55
+ end
56
+
57
+ it 'raises an error if the host option is missing' do
58
+ @options = { :user => 'someuser', :path => 'somepath' }
59
+ lambda { Blazing::Target.new('somename', @options) }.should raise_error
60
+ end
61
+
62
+ it 'raises an error if the user option is missing' do
63
+ @options = { :host => 'somehost', :path => 'somepath' }
64
+ lambda { Blazing::Target.new('somename', @options) }.should raise_error
65
+ end
66
+ end
67
+ end
68
+
69
+ describe '#config' do
70
+ it 'delegates to Blazing::Config.load' do
71
+ blazing_config = double
72
+ target = Blazing::Target.new('somename', @options)
73
+ target.instance_variable_set("@_config", blazing_config)
74
+ blazing_config.should_receive(:load)
75
+ target.config
76
+ end
77
+ end
78
+
79
+
80
+ describe '#deploy' do
81
+ it 'uses git push to deploy to the target' do
82
+ target = Blazing::Target.new('somename', @options)
83
+ @runner.should_receive(:run).with(/git push somename/)
84
+ target.deploy
85
+ end
86
+ end
87
+
88
+ describe '#setup' do
89
+ before :each do
90
+ blazing_config = double('config', :load => Blazing::Config.new)
91
+ @target = Blazing::Target.new('somename', @options)
92
+ @target.instance_variable_set("@_config", blazing_config)
93
+ end
94
+
95
+ it 'clones the repository on the target location' do
96
+ @target.should_receive(:clone_repository)
97
+ @target.setup
98
+ end
99
+
100
+ it 'adds the target as a git remote' do
101
+ @target.should_receive(:add_target_as_remote)
102
+ @target.setup
103
+ end
104
+
105
+ it 'sets up the post-receive hook' do
106
+ @target.should_receive(:setup_post_receive_hook)
107
+ @target.setup
108
+ end
109
+ end
110
+ end
@@ -1,4 +1,8 @@
1
- require 'simplecov'
2
- SimpleCov.start do
3
- add_filter "/spec/"
1
+ begin
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ end
6
+ rescue LoadError
7
+ puts 'ignoring simplecov, needs ruby-1.9'
4
8
  end
File without changes
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: blazing
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.7
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-04-12 00:00:00 +02:00
13
+ date: 2011-05-31 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -66,7 +66,6 @@ files:
66
66
  - Rakefile
67
67
  - bin/blazing
68
68
  - blazing.gemspec
69
- - index.html
70
69
  - lib/blazing.rb
71
70
  - lib/blazing/cli/base.rb
72
71
  - lib/blazing/cli/create.rb
@@ -81,11 +80,23 @@ files:
81
80
  - lib/blazing/recipes/bundler_recipe.rb
82
81
  - lib/blazing/recipes/rvm_recipe.rb
83
82
  - lib/blazing/remote.rb
83
+ - lib/blazing/runner.rb
84
84
  - lib/blazing/target.rb
85
85
  - lib/blazing/version.rb
86
+ - spec/blazing/cli/base_spec.rb
87
+ - spec/blazing/cli/create_spec.rb
88
+ - spec/blazing/cli/hook_spec.rb
89
+ - spec/blazing/config_spec.rb
90
+ - spec/blazing/logger_spec.rb
86
91
  - spec/blazing/recipe_spec.rb
92
+ - spec/blazing/recipes/bundler_recipe_spec.rb
93
+ - spec/blazing/recipes/passenger_recipe_spec.rb
94
+ - spec/blazing/recipes/rvm_recipe_spec.rb
87
95
  - spec/blazing/remote_spec.rb
96
+ - spec/blazing/runner_spec.rb
97
+ - spec/blazing/target_spec.rb
88
98
  - spec/spec_helper.rb
99
+ - spec/support/config.rb
89
100
  has_rdoc: true
90
101
  homepage: https://github.com/effkay/blazing
91
102
  licenses: []
@@ -115,6 +126,17 @@ signing_key:
115
126
  specification_version: 3
116
127
  summary: blazing fast deployment
117
128
  test_files:
129
+ - spec/blazing/cli/base_spec.rb
130
+ - spec/blazing/cli/create_spec.rb
131
+ - spec/blazing/cli/hook_spec.rb
132
+ - spec/blazing/config_spec.rb
133
+ - spec/blazing/logger_spec.rb
118
134
  - spec/blazing/recipe_spec.rb
135
+ - spec/blazing/recipes/bundler_recipe_spec.rb
136
+ - spec/blazing/recipes/passenger_recipe_spec.rb
137
+ - spec/blazing/recipes/rvm_recipe_spec.rb
119
138
  - spec/blazing/remote_spec.rb
139
+ - spec/blazing/runner_spec.rb
140
+ - spec/blazing/target_spec.rb
120
141
  - spec/spec_helper.rb
142
+ - spec/support/config.rb