blazing 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +183 -0
  4. data/.travis.yml +8 -4
  5. data/CHANGELOG.md +7 -1
  6. data/Gemfile +1 -1
  7. data/Guardfile +6 -7
  8. data/README.md +30 -152
  9. data/Rakefile +5 -6
  10. data/bin/blazing +1 -2
  11. data/blazing.gemspec +17 -26
  12. data/lib/blazing.rb +2 -14
  13. data/lib/blazing/cli.rb +32 -39
  14. data/lib/blazing/commands.rb +18 -26
  15. data/lib/blazing/config.rb +21 -51
  16. data/lib/blazing/dsl.rb +37 -0
  17. data/lib/blazing/hook.rb +15 -11
  18. data/lib/blazing/logger.rb +13 -17
  19. data/lib/blazing/repository.rb +5 -1
  20. data/lib/blazing/shell.rb +5 -5
  21. data/lib/blazing/target.rb +3 -3
  22. data/lib/blazing/templates/config.erb +10 -45
  23. data/lib/blazing/templates/hook/base.erb +0 -3
  24. data/lib/blazing/templates/hook/bundler.erb +4 -3
  25. data/lib/blazing/templates/hook/env-scripts.erb +3 -3
  26. data/lib/blazing/templates/hook/rake.erb +0 -1
  27. data/lib/blazing/templates/hook/rvm.erb +3 -31
  28. data/lib/blazing/templates/hook/setup.erb +1 -1
  29. data/lib/blazing/version.rb +3 -0
  30. data/spec/blazing/cli_spec.rb +1 -11
  31. data/spec/blazing/commands_spec.rb +35 -65
  32. data/spec/blazing/config_spec.rb +22 -102
  33. data/spec/blazing/dsl_spec.rb +60 -0
  34. data/spec/blazing/hook_spec.rb +31 -82
  35. data/spec/blazing/integration/deployment_spec.rb +20 -22
  36. data/spec/blazing/integration/init_spec.rb +2 -4
  37. data/spec/blazing/integration/setup_spec.rb +30 -30
  38. data/spec/blazing/integration/update_spec.rb +35 -35
  39. data/spec/blazing/logger_spec.rb +0 -4
  40. data/spec/blazing/repository_spec.rb +8 -10
  41. data/spec/blazing/shell_spec.rb +2 -4
  42. data/spec/blazing/target_spec.rb +12 -13
  43. data/spec/spec_helper.rb +8 -12
  44. data/spec/support/dummy_config.rb +6 -0
  45. metadata +18 -35
  46. data/lib/blazing/dsl_setter.rb +0 -20
  47. data/lib/blazing/recipe.rb +0 -45
  48. data/lib/blazing/templates/hook/recipes.erb +0 -5
  49. data/spec/blazing/dsl_setter_spec.rb +0 -29
  50. data/spec/blazing/integration/list_spec.rb +0 -20
  51. data/spec/blazing/integration/recipes_spec.rb +0 -29
  52. data/spec/blazing/recipe_spec.rb +0 -42
@@ -1,129 +1,49 @@
1
1
  require 'spec_helper'
2
- require 'blazing/config'
2
+ require_relative '../../lib/blazing/config'
3
3
 
4
4
  describe Blazing::Config do
5
+ let(:config) { Blazing::Config.new }
5
6
 
6
7
  describe '#initialize' do
7
8
  it 'takes the path of the config file as an argument' do
8
9
  config = Blazing::Config.new('/some/where/config.rb')
9
- config.file.should == '/some/where/config.rb'
10
+ expect(config.file).to eq '/some/where/config.rb'
10
11
  end
11
12
 
12
13
  it 'takes the default config path if no path is specified' do
13
14
  config = Blazing::Config.new
14
- config.file.should == 'config/blazing.rb'
15
+ expect(config.file).to eq 'config/blazing.rb'
15
16
  end
16
17
  end
17
18
 
18
19
  describe '.parse' do
19
-
20
20
  it 'returns a config object' do
21
- Blazing::Config.parse('spec/support/empty_config.rb').should be_a Blazing::Config
22
- end
23
-
24
- end
25
-
26
- describe '#default_target' do
27
-
28
- it 'returns a target object if only one is present' do
29
- config = Blazing::Config.new
30
- config.target :sometarget, 'somewhere'
31
- config.default_target.name.should be :sometarget
32
- end
33
-
34
- end
35
-
36
- describe 'DSL' do
37
-
38
- before :each do
39
- @config = Blazing::Config.new
40
- end
41
-
42
- describe 'target' do
43
-
44
- it 'creates a target object for each target call' do
45
- @config.target :somename, 'someuser@somehost:/path/to/deploy/to'
46
- @config.target :someothername, 'someuser@somehost:/path/to/deploy/to'
47
-
48
- @config.targets.each { |t| t.should be_a Blazing::Target }
49
- @config.targets.size.should be 2
50
- end
51
-
52
- it 'does not allow the creation of two targets with the same name' do
53
- @config.target :somename, 'someuser@somehost:/path/to/deploy/to'
54
- lambda { @config.target :somename, 'someuser@somehost:/path/to/deploy/to' }.should raise_error
55
- end
21
+ expect(Blazing::Config.parse('spec/support/empty_config.rb')).to be_a Blazing::Config
56
22
  end
57
23
 
58
- describe 'recipe' do
59
-
60
- before :each do
61
- class Blazing::Recipe::Dummy < Blazing::Recipe
62
- end
63
- end
64
-
65
- it 'is an empty array if nothing was set' do
66
- @config.recipes.should be_a Array
67
- end
68
-
69
- it 'accepts a single recipe as argument' do
70
- @config.recipe :dummy
71
- @config.recipes.first.should be_a Blazing::Recipe::Dummy
72
- end
73
-
74
- it 'allows multiple recipes to be defined' do
75
- @config.recipe :dummy
76
- @config.recipe :dummy
77
- @config.recipes.size.should be 2
78
- @config.recipes.each { |r| r.should be_a Blazing::Recipe::Dummy }
79
- end
80
-
81
- it 'passes the options to the recipe initializer' do
82
- @config.recipe :dummy, :something => 'blah'
83
- @config.recipes.first.options[:something].should == 'blah'
84
- end
24
+ it 'creates a new DSL object and instance_evals the config file' do
25
+ dsl_double = double('dsl double')
26
+ expect(Blazing::DSL).to receive(:new).and_return(dsl_double)
27
+ expect(dsl_double).to receive(:instance_eval)
28
+ Blazing::Config.parse('spec/support/empty_config.rb')
85
29
  end
86
30
 
87
- describe 'rake' do
88
-
89
- it 'takes the name of the rake task as argument' do
90
- @config.rake :post_deploy
91
- @config.instance_variable_get('@rake').should == { :task => :post_deploy }
92
- end
93
-
94
- it 'accepts environment variables to pass along to rake' do
95
- @config.rake :post_deploy, 'RAILS_ENV=production'
96
- @config.instance_variable_get('@rake').should == { :task => :post_deploy, :env => 'RAILS_ENV=production' }
97
- end
98
-
31
+ it 'loads the actual data from the config file' do
32
+ config = Blazing::Config.parse('spec/support/dummy_config.rb')
33
+ expect(config.targets.size).to be 1
34
+ expect(config.target(:staging)).to be_a Blazing::Target
99
35
  end
36
+ end
100
37
 
101
- describe 'rvm' do
102
-
103
- it 'takes an rvm string as argument' do
104
- @config.rvm 'ruby-1.9.2@rails31'
105
- @config.instance_variable_get('@rvm').should == 'ruby-1.9.2@rails31'
106
- end
107
-
108
- it 'returns the rvm string if no argument given' do
109
- @config.rvm 'ruby-1.9.2@rails31'
110
- @config.rvm.should == 'ruby-1.9.2@rails31'
111
- end
112
-
38
+ describe 'target' do
39
+ it 'returns a target object if the target exists in config' do
40
+ target = double('dummy_target', name: 'foo')
41
+ config.targets << target
42
+ expect(config.target('foo')).to be target
113
43
  end
114
44
 
115
- describe 'rvm_scripts' do
116
-
117
- it 'takes an string as argument' do
118
- @config.rvm_scripts '/opt/rvm/scripts'
119
- @config.instance_variable_get('@env_scripts').should == '/opt/rvm/scripts'
120
- end
121
-
122
- it 'returns the string if no argument given' do
123
- @config.rvm_scripts '/opt/rvm/scripts'
124
- @config.rvm_scripts.should == '/opt/rvm/scripts'
125
- end
126
-
45
+ it 'returns nil if the target does not exist in config' do
46
+ expect(config.target('foo')).to be nil
127
47
  end
128
48
  end
129
49
  end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'blazing/dsl'
3
+
4
+ module Blazing
5
+ describe DSL do
6
+ let(:dsl) { Blazing::DSL.new(config) }
7
+ let(:config) { double('config') }
8
+
9
+ describe 'target' do
10
+ let(:config) { double('config', targets: []) }
11
+
12
+ it 'adds a target to the config object' do
13
+ dsl.target :somename, 'someuser@somehost:/path/to/deploy/to'
14
+ dsl.target :someothername, 'someuser@somehost:/path/to/deploy/to'
15
+ expect(config.targets.size).to be 2
16
+ end
17
+
18
+ it 'does not allow the creation of two targets with the same name' do
19
+ dsl.target :somename, 'someuser@somehost:/path/to/deploy/to'
20
+ expect { dsl.target :somename, 'someuser@somehost:/path/to/deploy/to' }.to raise_error(RuntimeError, 'Name already taken')
21
+ expect(config.targets.size).to be 1
22
+ end
23
+ end
24
+
25
+ describe 'rake' do
26
+ it 'sets the rake task to the given name' do
27
+ expect(config).to receive(:rake_task=).with('some_task')
28
+ dsl.rake 'some_task'
29
+ end
30
+ end
31
+
32
+ describe 'env_script' do
33
+ it 'sets the env script to the given path' do
34
+ expect(config).to receive(:env_script=).with('/path/to/script')
35
+ dsl.env_script '/path/to/script'
36
+ end
37
+ end
38
+
39
+ describe 'rvm_scripts' do
40
+ it 'is deprecated and outputs a warning' do
41
+ expect(dsl).to receive(:warn)
42
+ dsl.rvm_scripts '/path/to/script'
43
+ end
44
+ end
45
+
46
+ describe 'rvm' do
47
+ it 'is deprecated and outputs a warning' do
48
+ expect(dsl).to receive(:warn)
49
+ dsl.rvm '/path/to/script'
50
+ end
51
+ end
52
+
53
+ describe 'recipes' do
54
+ it 'is deprecated and outputs a warning' do
55
+ expect(dsl).to receive(:warn)
56
+ dsl.recipes '/path/to/script'
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,148 +1,97 @@
1
1
  require 'spec_helper'
2
+ require 'blazing/hook'
3
+ require 'blazing/config'
2
4
 
3
5
  module Blazing
4
-
5
- class Recipe::Dummy < Blazing::Recipe
6
- end
7
-
8
6
  describe Hook do
9
-
10
- let(:config) { Config.new }
7
+ let(:config) { Blazing::Config.new }
11
8
 
12
9
  describe '#rake_command' do
13
- it 'prepends the environment variables specified in the rake call' do
14
- config.rake :deploy, 'SOMEFUNKYVARIABLE=foobar'
15
- target = Blazing::Target.new(:sometarget, '/path', config)
10
+ it 'prepends the RAILS_ENV specified as :rails_env option to the target call' do
11
+ config.rake_task = :deploy
12
+ target = Blazing::Target.new(:sometarget, '/path', config, rails_env: 'production')
16
13
  hook = Hook.new(target)
17
- hook.rake_command.should == 'SOMEFUNKYVARIABLE=foobar bundle exec rake deploy'
14
+ expect(hook.rake_command).to eq('RAILS_ENV=production bundle exec rake deploy')
18
15
  end
19
16
 
20
- it 'appends the RAILS_ENV specified as :rails_env option to the target call' do
21
- config.rake :deploy
22
- target = Blazing::Target.new(:sometarget, '/path', config, :rails_env => 'production')
17
+ it 'prepends the any other option specified specified in the target call' do
18
+ config.rake_task = :deploy
19
+ target = Blazing::Target.new(:sometarget, '/path', config, rails_env: 'production', foo: 'bar')
23
20
  hook = Hook.new(target)
24
- hook.rake_command.should == ' RAILS_ENV=production bundle exec rake deploy'
21
+ expect(hook.rake_command).to include('RAILS_ENV=production')
22
+ expect(hook.rake_command).to include('FOO=bar')
23
+ expect(hook.rake_command).to include('bundle exec rake deploy')
25
24
  end
26
25
 
27
26
  it 'returns nil when no rake task was specified in config' do
28
- target = Blazing::Target.new(:sometarget, '/path', config, :rails_env => 'production')
27
+ target = Blazing::Target.new(:sometarget, '/path', config, rails_env: 'production')
29
28
  hook = Hook.new(target)
30
- hook.rake_command.should be nil
29
+ expect(hook.rake_command).to be nil
31
30
  end
32
31
  end
33
32
 
34
33
  describe 'Generated Hook' do
35
-
36
- let(:target) { Blazing::Target.new(:sometarget, '/path', config, :rails_env => 'production') }
34
+ let(:target) { Blazing::Target.new(:sometarget, '/path', config, rails_env: 'production') }
37
35
  let(:hook_file) { Hook.new(target).send(:generate_hook) }
38
36
 
39
37
  context 'Always' do
40
38
  it 'logs the header with the target name' do
41
- hook_file.should include("ENTERING POST RECEIVE HOOK FOR: sometarget")
39
+ expect(hook_file).to include('ENTERING POST RECEIVE HOOK FOR: sometarget')
42
40
  end
43
41
 
44
42
  it 'goes one directory up' do
45
- hook_file.should include('cd ..')
43
+ expect(hook_file).to include('cd ..')
46
44
  end
47
45
 
48
46
  it 'sets the GIT_DIR variable to .git' do
49
- hook_file.should include("GIT_DIR='.git'")
47
+ expect(hook_file).to include("GIT_DIR='.git'")
50
48
  end
51
49
 
52
50
  it 'does a hard reset' do
53
- hook_file.should include("git reset --hard HEAD")
51
+ expect(hook_file).to include('git reset --hard HEAD')
54
52
  end
55
53
 
56
54
  it 'checks out the pushed branch' do
57
- hook_file.should include("git checkout $refname")
55
+ expect(hook_file).to include('git checkout $refname')
58
56
  end
59
57
 
60
58
  it 'resets the GIT_DIR variable' do
61
- hook_file.should include("unset GIT_DIR")
59
+ expect(hook_file).to include('unset GIT_DIR')
62
60
  end
63
61
 
64
62
  it 'resets the GIT_WORK_TREE variable' do
65
- hook_file.should include("unset GIT_WORK_TREE")
63
+ expect(hook_file).to include('unset GIT_WORK_TREE')
66
64
  end
67
65
 
68
66
  it 'runs bundler with the correct options' do
69
- hook_file.should include("bundle --deployment --quiet --without development test")
70
- end
71
- end
72
-
73
- context 'RVM Setup' do
74
- context 'when rvm is enabled' do
75
- context 'loading rvm' do
76
- it 'uses the load mechanism suggested by rvm' do
77
- config.rvm 'someruby@somegemset'
78
- hook_file.should include("source \"$HOME/.rvm/scripts/rvm\"")
79
- hook_file.should include("source \"/usr/local/rvm/scripts/rvm\"")
80
- end
81
-
82
- it 'sources the rvm_scripts directory when rvm_scripts is specified' do
83
- config.rvm 'someruby@somegemset'
84
- config.rvm_scripts '/location/of/rvm/scripts'
85
- hook_file.should include("source /location/of/rvm/scripts")
86
- end
87
- end
88
-
89
- context 'loading the rvm ruby and gemset' do
90
- it 'sources the rvmrc to load the env' do
91
- config.rvm 'someruby@somegemset'
92
- hook_file.should include("rvm use someruby@somegemset")
93
- end
94
-
95
- it 'uses rvm use to load the env when an rvm string was specified' do
96
- config.rvm :rvmrc
97
- hook_file.should include("source .rvmrc")
98
- end
99
- end
100
- end
101
-
102
- context 'when rvm is disabled' do
103
- it 'does not include any rvm handling' do
104
- hook_file.should_not include("Loading rvm")
105
- end
67
+ expect(hook_file).to include('bundle --deployment --quiet --without development test')
106
68
  end
107
69
  end
108
70
 
109
- context 'Recipes Handling' do
110
-
111
- context 'when there are no recipes configured' do
112
- it 'does not run blazing recipes' do
113
- hook_file.should_not include("bundle exec blazing recipes")
114
- end
115
- end
116
-
117
- context 'when there are recipes configured' do
118
- before :each do
119
- config.recipe :dummy
120
- end
121
-
122
- it 'runs the blazing recipes command with the correct target name' do
123
- hook_file.should include("bundle exec blazing recipes sometarget")
124
- end
71
+ context 'env script' do
72
+ it 'sources the specified directory when env_script is specified' do
73
+ config.env_script = '/location/of/script'
74
+ expect(hook_file).to include('source /location/of/script')
125
75
  end
126
76
  end
127
77
 
128
78
  context 'Rake Command Handling' do
129
79
  context 'when the rake_command is specified' do
130
80
  before :each do
131
- config.rake :deploy
81
+ config.rake_task = :deploy
132
82
  end
133
83
 
134
84
  it 'runs the rake command' do
135
- hook_file.should include(' RAILS_ENV=production bundle exec rake deploy')
85
+ expect(hook_file).to include(' RAILS_ENV=production bundle exec rake deploy')
136
86
  end
137
87
  end
138
88
 
139
89
  context 'when no rake_command is specified' do
140
90
  it 'does not run the rake_command' do
141
- hook_file.should_not include(" RAILS_ENV=production bundle exec rake")
91
+ expect(hook_file).not_to include(' RAILS_ENV=production bundle exec rake')
142
92
  end
143
93
  end
144
94
  end
145
95
  end
146
96
  end
147
97
  end
148
-
@@ -1,32 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'deployment with git push' do
4
+ before :each do
5
+ setup_sandbox
6
+ # @config = Blazing::Config.new
7
+ # @config.target :production, "#{@sandbox_directory}/target"
8
+ # @config.target :staging, "#{@sandbox_directory}/staging"
9
+ # @cli = Blazing::CLI.new
10
+ # Blazing::Config.stub(:parse).and_return @config
11
+ end
4
12
 
5
- before :each do
6
- setup_sandbox
7
- #@config = Blazing::Config.new
8
- #@config.target :production, "#{@sandbox_directory}/target"
9
- #@config.target :staging, "#{@sandbox_directory}/staging"
10
- #@cli = Blazing::CLI.new
11
- #Blazing::Config.stub(:parse).and_return @config
12
- end
13
+ after :each do
14
+ teardown_sandbox
15
+ end
13
16
 
14
- after :each do
15
- teardown_sandbox
16
- end
17
+ context 'git push <remote> <ref>' do
18
+ it 'deploys the pushed ref'
19
+ end
17
20
 
18
- context 'git push <remote> <ref>' do
21
+ context 'git push <remote>' do
22
+ context 'when one ref is pushed' do
19
23
  it 'deploys the pushed ref'
20
24
  end
21
25
 
22
- context 'git push <remote>' do
23
- context 'when one ref is pushed' do
24
- it 'deploys the pushed ref'
25
- end
26
-
27
- context 'when multiple refs are pushed' do
28
- it 'deploys the currently checked out ref'
29
- end
26
+ context 'when multiple refs are pushed' do
27
+ it 'deploys the currently checked out ref'
30
28
  end
31
- end
32
-
29
+ end
30
+ end
@@ -3,7 +3,6 @@ require 'blazing/config'
3
3
  require 'blazing/commands'
4
4
 
5
5
  describe '$ blazing init' do
6
-
7
6
  before :each do
8
7
  setup_sandbox
9
8
  Blazing::Commands.new.init
@@ -14,11 +13,10 @@ describe '$ blazing init' do
14
13
  end
15
14
 
16
15
  it 'creates a config directory if none exists yet' do
17
- File.exists?('config').should be true
16
+ expect(File.exist?('config')).to be true
18
17
  end
19
18
 
20
19
  it 'creates a config file in config/blazing.rb' do
21
- File.exists?('config/blazing.rb').should be true
20
+ expect(File.exist?('config/blazing.rb')).to be true
22
21
  end
23
22
  end
24
-