capistrano-fanfare 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ gemspec
6
6
  group :test do
7
7
  gem 'rake', '~> 0.9'
8
8
  gem 'foreman'
9
+ gem 'capistrano-campfire'
9
10
  end
10
11
 
11
12
  platforms :jruby do
@@ -0,0 +1,103 @@
1
+ require 'capistrano'
2
+
3
+ module Capistrano::Fanfare::Campfire
4
+ def self.load_into(configuration)
5
+ configuration.load do
6
+ begin
7
+ require 'capistrano/campfire'
8
+
9
+ rescue LoadError => error
10
+ raise "capistrano-campfire gem could not be loaded: (#{error.message}). " +
11
+ "Please ensure it is in your Gemfile."
12
+ end
13
+
14
+ set(:campfire_pre_msg) do
15
+ [ ENV['USER'],
16
+ %{is starting a deploy of},
17
+ application,
18
+ %{from},
19
+ branch,
20
+ %{to},
21
+ deploy_env
22
+ ].join(' ')
23
+ end
24
+
25
+ set(:campfire_success_msg) do
26
+ "Deployment started by #{ENV['USER']} succeeded."
27
+ end
28
+
29
+ set(:campfire_fail_msg) do
30
+ "Deployment started by #{ENV['USER']} failed, so attempting to roll back."
31
+ end
32
+
33
+ set :campfire_success_play, "pushit"
34
+ set :campfire_fail_play, "trombone"
35
+
36
+
37
+ # ========================================================================
38
+ # These are helper methods that will be available to your recipes.
39
+ # ========================================================================
40
+
41
+ def deploy_env_formatted
42
+ if deploy_env.to_s.downcase.start_with? 'prod'
43
+ "**#{deploy_env.to_s.upcase}**"
44
+ else
45
+ deploy_env.to_s.downcase
46
+ end
47
+ end
48
+
49
+ def speak(msg)
50
+ if dry_run
51
+ puts "[campfire.speak]: #{msg}"
52
+ else
53
+ campfire_room.speak msg
54
+ end
55
+ end
56
+
57
+ def play(clip)
58
+ if dry_run
59
+ puts "[campfire.play]: #{clip}"
60
+ else
61
+ campfire_room.play clip
62
+ end
63
+ end
64
+
65
+
66
+ # ========================================================================
67
+ # These are the tasks that are available to help with deploying web apps.
68
+ # You can have cap give you a summary of them with `cap -T'.
69
+ # ========================================================================
70
+
71
+ namespace :campfire do
72
+ task :pre_deploy do
73
+ @deploy_start_time = Time.now
74
+ speak fetch(:campfire_pre_msg)
75
+ end
76
+
77
+ task :successful_deploy do
78
+ elapsed = @deploy_start_time ? Time.now - @deploy_start_time : 0
79
+
80
+ speak "#{fetch(:campfire_success_msg)} (#{elapsed} seconds)"
81
+ play fetch(:campfire_success_play)
82
+ end
83
+
84
+ task :rollback_deploy do
85
+ speak fetch(:campfire_fail_msg)
86
+ play fetch(:campfire_fail_play)
87
+ end
88
+ end
89
+
90
+ unless ENV['QUIET'].to_i > 0
91
+ before "deploy", "campfire:pre_deploy"
92
+ after "deploy", "campfire:successful_deploy"
93
+ after "deploy:migrations", "campfire:successful_deploy"
94
+ end
95
+
96
+ before 'deploy:rollback', 'campfire:rollback_deploy'
97
+ end
98
+ end
99
+ end
100
+
101
+ if Capistrano::Configuration.instance
102
+ Capistrano::Fanfare::Campfire.load_into(Capistrano::Configuration.instance)
103
+ end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Fanfare
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
@@ -0,0 +1,192 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/capistrano'
3
+ require 'capistrano/fanfare'
4
+ require 'capistrano/fanfare/campfire'
5
+
6
+ class MockRoom
7
+ attr_reader :speaks, :plays
8
+
9
+ def speak(msg)
10
+ @speaks ||= []
11
+ @speaks << msg
12
+ end
13
+
14
+ def play(clip)
15
+ @plays ||= []
16
+ @plays << clip
17
+ end
18
+ end
19
+
20
+ describe Capistrano::Fanfare::Campfire do
21
+ before do
22
+ @config = Capistrano::Configuration.new
23
+ Capistrano::Fanfare::Campfire.load_into(@config)
24
+ @config.extend(MiniTest::Capistrano::ConfigurationExtension)
25
+
26
+ ENV['_SPEC_USER'] = ENV['USER']
27
+ ENV['USER'] = 'filbert'
28
+
29
+ @config.load do
30
+ def puts(msg)
31
+ @outputs ||= []
32
+ @outputs << msg
33
+ end
34
+
35
+ def outputs ; @outputs ; end
36
+
37
+ def campfire_room
38
+ @room ||= MockRoom.new
39
+ end
40
+ end
41
+ end
42
+
43
+ after do
44
+ ENV['USER'] = ENV.delete('_SPEC_USER')
45
+ end
46
+
47
+ describe "for variables" do
48
+ it "sets :campfire_pre_msg to a known default" do
49
+ @config.set :application, 'wazup'
50
+ @config.set :deploy_env, 'staging'
51
+ @config.set :branch, "master"
52
+
53
+ @config.fetch(:campfire_pre_msg).must_equal(
54
+ "filbert is starting a deploy of wazup from master to staging")
55
+ end
56
+
57
+ it "sets :campfire_success_msg to a known default" do
58
+ @config.fetch(:campfire_success_msg).must_equal(
59
+ "Deployment started by filbert succeeded.")
60
+ end
61
+
62
+ it "sets :campfire_fail_msg to a known default" do
63
+ @config.fetch(:campfire_fail_msg).must_equal(
64
+ "Deployment started by filbert failed, so attempting to roll back.")
65
+ end
66
+
67
+ it "sets :campfire_success_play to 'pushit'" do
68
+ @config.fetch(:campfire_success_play).must_equal "pushit"
69
+ end
70
+
71
+ it "sets :campfire_fail_play to 'trombone'" do
72
+ @config.fetch(:campfire_fail_play).must_equal "trombone"
73
+ end
74
+ end
75
+
76
+ describe "for methods" do
77
+ describe "#deploy_env_formatted" do
78
+ it "returns the :deploy_env if it is not production" do
79
+ @config.set :deploy_env, "load_testing"
80
+
81
+ @config.deploy_env_formatted.must_equal "load_testing"
82
+ end
83
+
84
+ it "can handle :deploy_env as a symbol" do
85
+ @config.set :deploy_env, :staging
86
+
87
+ @config.deploy_env_formatted.must_equal "staging"
88
+ end
89
+
90
+ it "downcases the :deploy_env" do
91
+ @config.set :deploy_env, "THEKINGSTAGE"
92
+
93
+ @config.deploy_env_formatted.must_equal "thekingstage"
94
+ end
95
+
96
+ it "surrounds :deploy_env with stars and upcase when it starts with 'prod'" do
97
+ @config.set :deploy_env, "produc"
98
+
99
+ @config.deploy_env_formatted.must_equal "**PRODUC**"
100
+ end
101
+ end
102
+
103
+ describe "#speak" do
104
+ it "speaks in a campfire room" do
105
+ @config.speak("yo")
106
+
107
+ @config.campfire_room.speaks.first.must_equal "yo"
108
+ end
109
+
110
+ it "prints out a message if in dry run" do
111
+ @config.dry_run = true
112
+ @config.speak("yo")
113
+
114
+ @config.outputs.first.must_equal "[campfire.speak]: yo"
115
+ end
116
+ end
117
+
118
+ describe "#play" do
119
+ it "plays a clip in a campfire room" do
120
+ @config.play("tada")
121
+
122
+ @config.campfire_room.plays.first.must_equal "tada"
123
+ end
124
+
125
+ it "prints out a message if in dry run" do
126
+ @config.dry_run = true
127
+ @config.play("live")
128
+
129
+ @config.outputs.first.must_equal "[campfire.play]: live"
130
+ end
131
+ end
132
+ end
133
+
134
+ describe "for namespace :campfire" do
135
+ describe "task :pre_deploy" do
136
+ it "prints a message in campfire" do
137
+ @config.set :campfire_pre_msg, "giddy up, yo"
138
+ @config.find_and_execute_task("campfire:pre_deploy")
139
+
140
+ @config.campfire_room.speaks.first.must_equal "giddy up, yo"
141
+ end
142
+
143
+ it "gets called before deploy task" do
144
+ @config.must_have_callback_before "deploy", "campfire:pre_deploy"
145
+ end
146
+ end
147
+
148
+ describe "task :successful_deploy" do
149
+ it "print a message in campfire" do
150
+ @config.set :campfire_success_msg, "you did it bro"
151
+ @config.find_and_execute_task("campfire:successful_deploy")
152
+
153
+ @config.campfire_room.speaks.first.must_equal "you did it bro (0 seconds)"
154
+ end
155
+
156
+ it "play a sound in campfire" do
157
+ @config.set :campfire_success_play, "blahblah"
158
+ @config.find_and_execute_task("campfire:successful_deploy")
159
+
160
+ @config.campfire_room.plays.first.must_equal "blahblah"
161
+ end
162
+
163
+ it "gets called after deploy task" do
164
+ @config.must_have_callback_after "deploy", "campfire:successful_deploy"
165
+ end
166
+
167
+ it "gets called after deploy:migrations task" do
168
+ @config.must_have_callback_after "deploy:migrations", "campfire:successful_deploy"
169
+ end
170
+ end
171
+
172
+ describe "task :rollback_deploy" do
173
+ it "prints a message in campfire" do
174
+ @config.set :campfire_fail_msg, "you = fail dude"
175
+ @config.find_and_execute_task("campfire:rollback_deploy")
176
+
177
+ @config.campfire_room.speaks.first.must_equal "you = fail dude"
178
+ end
179
+
180
+ it "play a sound in campfire" do
181
+ @config.set :campfire_fail_play, "whawha"
182
+ @config.find_and_execute_task("campfire:rollback_deploy")
183
+
184
+ @config.campfire_room.plays.first.must_equal "whawha"
185
+ end
186
+
187
+ it "gets called before deploy:rollback task" do
188
+ @config.must_have_callback_before "deploy:rollback", "campfire:rollback_deploy"
189
+ end
190
+ end
191
+ end
192
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-fanfare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &70302340120260 !ruby/object:Gem::Requirement
16
+ requirement: &70106299506720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.10.0.pre
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70302340120260
24
+ version_requirements: *70106299506720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: capistrano_colors
27
- requirement: &70302340119600 !ruby/object:Gem::Requirement
27
+ requirement: &70106299506160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.5'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70302340119600
35
+ version_requirements: *70106299506160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sushi
38
- requirement: &70302340118980 !ruby/object:Gem::Requirement
38
+ requirement: &70106299505620 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.0.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70302340118980
46
+ version_requirements: *70106299505620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: minitest
49
- requirement: &70302340118220 !ruby/object:Gem::Requirement
49
+ requirement: &70106299505060 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.10.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70302340118220
57
+ version_requirements: *70106299505060
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: minitest-capistrano
60
- requirement: &70302340117580 !ruby/object:Gem::Requirement
60
+ requirement: &70106299504560 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0.0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70302340117580
68
+ version_requirements: *70106299504560
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: timecop
71
- requirement: &70302340116940 !ruby/object:Gem::Requirement
71
+ requirement: &70106299503980 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0.3'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70302340116940
79
+ version_requirements: *70106299503980
80
80
  description: Capistrano recipes (with full test suite) for fanfare application deployment
81
81
  framework
82
82
  email:
@@ -95,6 +95,7 @@ files:
95
95
  - lib/capistrano/fanfare.rb
96
96
  - lib/capistrano/fanfare/assets.rb
97
97
  - lib/capistrano/fanfare/bundler.rb
98
+ - lib/capistrano/fanfare/campfire.rb
98
99
  - lib/capistrano/fanfare/colors.rb
99
100
  - lib/capistrano/fanfare/database_yaml.rb
100
101
  - lib/capistrano/fanfare/defaults.rb
@@ -109,6 +110,7 @@ files:
109
110
  - lib/capistrano/recipes/deploy/strategy/git_style.rb
110
111
  - spec/assets_spec.rb
111
112
  - spec/bundler_spec.rb
113
+ - spec/campfire_spec.rb
112
114
  - spec/colors_spec.rb
113
115
  - spec/database_yaml_spec.rb
114
116
  - spec/defaults_spec.rb
@@ -136,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
138
  version: '0'
137
139
  segments:
138
140
  - 0
139
- hash: 564881561557686212
141
+ hash: 1649157397655448049
140
142
  required_rubygems_version: !ruby/object:Gem::Requirement
141
143
  none: false
142
144
  requirements:
@@ -145,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
147
  version: '0'
146
148
  segments:
147
149
  - 0
148
- hash: 564881561557686212
150
+ hash: 1649157397655448049
149
151
  requirements: []
150
152
  rubyforge_project:
151
153
  rubygems_version: 1.8.10
@@ -156,6 +158,7 @@ summary: Capistrano recipes (with full test suite) for fanfare application deplo
156
158
  test_files:
157
159
  - spec/assets_spec.rb
158
160
  - spec/bundler_spec.rb
161
+ - spec/campfire_spec.rb
159
162
  - spec/colors_spec.rb
160
163
  - spec/database_yaml_spec.rb
161
164
  - spec/defaults_spec.rb