capnotify 0.1.0pre

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,256 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capnotify::Plugin do
4
+
5
+ # a proxy object to call methods on to detect what gets called in the plugin
6
+ class ProxyObject
7
+ class << self
8
+ @instance = nil
9
+ end
10
+
11
+ def self.instance
12
+ @instance ||= ProxyObject.new
13
+ end
14
+
15
+ def call_init; end
16
+ def call_unload; end
17
+ end
18
+
19
+ # a plugin for testing with
20
+ # wires up init and unload to the ProxyObject
21
+ module MyPlugin
22
+ def init
23
+ ProxyObject.instance.call_init
24
+ end
25
+
26
+ def unload
27
+ ProxyObject.instance.call_unload
28
+ end
29
+ end
30
+
31
+ let(:config) do
32
+ Capistrano::Configuration.new
33
+ end
34
+
35
+ before do
36
+ Capnotify.load_into(config)
37
+ end
38
+
39
+ after do
40
+ Capistrano::EXTENSIONS.keys.each do |ex|
41
+ Capistrano.remove_plugin(ex)
42
+ end
43
+ end
44
+
45
+ let(:capnotify) { config.capnotify }
46
+
47
+ context "#appname" do
48
+
49
+ context "when capnotify_appname is missing" do
50
+
51
+ before do
52
+ config.load do
53
+ unset :capnotify_appname
54
+ end
55
+ end
56
+
57
+ it "should return an empty string" do
58
+ capnotify.appname.should == ''
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ context "#load_plugin" do
65
+
66
+ it "should load the plugin into capistrano" do
67
+ config.load do
68
+ capnotify.load_plugin :my_plugin, MyPlugin
69
+ end
70
+
71
+ Capistrano::EXTENSIONS.keys.should include(:my_plugin)
72
+ end
73
+
74
+ it "should call init on the plugin" do
75
+ ProxyObject.instance.should_receive :call_init
76
+
77
+ config.load do
78
+ capnotify.load_plugin :my_plugin, MyPlugin
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
85
+ context "#unload_plugin" do
86
+
87
+ before do
88
+ config.load do
89
+ capnotify.load_plugin :my_plugin, MyPlugin
90
+ end
91
+ end
92
+
93
+ it "should call unload on the plugin if the plugin handles it" do
94
+ ProxyObject.instance.should_receive(:call_unload)
95
+
96
+ config.load do
97
+ capnotify.unload_plugin :my_plugin
98
+ end
99
+ end
100
+
101
+ it "should not blow up if the plugin does not handle #unload" do
102
+ MyPlugin.send(:undef_method, :unload)
103
+
104
+ lambda do
105
+ config.load do
106
+ capnotify.unload_plugin :my_plugin
107
+ end
108
+ end.should_not raise_error
109
+ end
110
+
111
+ end
112
+
113
+ context "#get_plugin" do
114
+
115
+ context "when plugin exists" do
116
+ before do
117
+ config.load do
118
+ capnotify.load_plugin :my_plugin, MyPlugin
119
+ end
120
+ end
121
+
122
+ it "should return the plugin" do
123
+ capnotify.send(:get_plugin, :my_plugin).should_not be_nil
124
+ end
125
+
126
+ it "should not raise an error" do
127
+ lambda { capnotify.send(:get_plugin, :my_plugin) }.should_not raise_error
128
+ end
129
+
130
+ end
131
+
132
+ context "when the plugin does not exist" do
133
+
134
+ it "should raise an error" do
135
+ lambda { capnotify.send(:get_plugin, :does_not_exist) }.should raise_error
136
+ end
137
+
138
+ end
139
+
140
+ end
141
+
142
+ context "#build_template" do
143
+
144
+ it "should not error when using a built-in html template" do
145
+ lambda { capnotify.build_template( capnotify.built_in_template_for('default_notification.html.erb') ) }.should_not raise_error
146
+ end
147
+
148
+ it "should not error when using a built-in text template" do
149
+ lambda { capnotify.build_template( capnotify.built_in_template_for('default_notification.txt.erb') ) }.should_not raise_error
150
+ end
151
+
152
+ end
153
+
154
+ context "#components" do
155
+ it "should return the components" do
156
+ capnotify.components.should === config.fetch(:capnotify_component_list)
157
+ end
158
+ end
159
+
160
+ context "#component" do
161
+ let!(:component) { Capnotify::Component.new(:test_component) }
162
+
163
+ before do
164
+ 4.times do |i|
165
+ capnotify.components << Capnotify::Component.new("component_#{ i }")
166
+ end
167
+
168
+ capnotify.components << component
169
+ end
170
+
171
+ it "should return the component with the given name" do
172
+ capnotify.component(:test_component).should === component
173
+ end
174
+
175
+ it "should return nil if the requested component does not exist" do
176
+ capnotify.component(:fake_component).should be_nil
177
+ end
178
+ end
179
+
180
+ context "inserting components" do
181
+ let!(:component) { Capnotify::Component.new(:test_component) }
182
+
183
+ before do
184
+ capnotify.components.clear
185
+
186
+ # add components 0 - 3
187
+ 4.times do |i|
188
+ capnotify.components << Capnotify::Component.new("component_#{ i }")
189
+ end
190
+ end
191
+
192
+ context "before" do
193
+
194
+ it "should insert the given component" do
195
+ expect { capnotify.insert_component_before(:component_2, component) }.to change { capnotify.components.count }.by(1)
196
+ end
197
+
198
+ it "should insert the given component in the correct place" do
199
+ capnotify.insert_component_before(:component_2, component)
200
+
201
+ capnotify.components.map(&:name)[2].should == component.name
202
+ end
203
+
204
+ it "should insert the component at the end if no component with given name exists" do
205
+ capnotify.insert_component_before(:this_component_does_not_exist, component)
206
+
207
+ capnotify.components.last.name.should == component.name
208
+ end
209
+
210
+ end
211
+
212
+ context "after" do
213
+
214
+ it "should insert the given component" do
215
+ expect { capnotify.insert_component_after(:component_2, component) }.to change { capnotify.components.count }.by(1)
216
+ end
217
+
218
+ it "should insert the given component in the correct place" do
219
+ capnotify.insert_component_after(:component_2, component)
220
+
221
+ capnotify.components.map(&:name)[3].should == component.name
222
+ end
223
+
224
+ it "should insert the component at the end if no component with given name exists" do
225
+ capnotify.insert_component_after(:this_component_does_not_exist, component)
226
+
227
+ capnotify.components.last.name.should == component.name
228
+ end
229
+ end
230
+
231
+ end
232
+
233
+ context "#delete_component" do
234
+ let!(:component) { Capnotify::Component.new(:test_component) }
235
+
236
+ before do
237
+ 4.times do |i|
238
+ capnotify.components << Capnotify::Component.new("component_#{ i }")
239
+ end
240
+
241
+ capnotify.components << component
242
+ end
243
+
244
+ it "should not error out if you delete a non-existent component" do
245
+ lambda { capnotify.delete_component(:fake_component) }.should_not raise_error
246
+ end
247
+
248
+ it "should delete the given component" do
249
+ expect { capnotify.delete_component(:test_component) }.to change { capnotify.components.length }.by(-1)
250
+ end
251
+
252
+ it "should return the given deleted component" do
253
+ capnotify.delete_component(:test_component).should === capnotify.components
254
+ end
255
+ end
256
+ end
@@ -0,0 +1,196 @@
1
+ require 'spec_helper'
2
+
3
+ describe Capnotify do
4
+
5
+ let(:config) do
6
+ Capistrano::Configuration.new
7
+ end
8
+
9
+ before do
10
+ Capnotify.load_into(config)
11
+ end
12
+
13
+ after do
14
+ Capistrano::EXTENSIONS.keys.each do |ex|
15
+ Capistrano.remove_plugin(ex)
16
+ end
17
+ end
18
+
19
+ let(:capnotify) { config.capnotify }
20
+
21
+ context "loading" do
22
+ it "should initialize capnotify.components" do
23
+ capnotify.components.should_not be_nil
24
+ end
25
+ end
26
+
27
+ context "built-in callbacks" do
28
+
29
+ before do
30
+ # there has to be a better way of doing this...
31
+ # create a MockObject to handle the callbacks
32
+ class MockObject
33
+ end
34
+ MockObject.stub!(:deploy_start => true)
35
+ MockObject.stub!(:deploy_complete => true)
36
+ MockObject.stub!(:migrate_start => true)
37
+ MockObject.stub!(:migrate_complete => true)
38
+ MockObject.stub!(:maintenance_page_up => true)
39
+ MockObject.stub!(:maintenance_page_down => true)
40
+
41
+ config.load do
42
+ # these don't get triggered unless something is defined.
43
+ on(:deploy_start) { MockObject.deploy_start }
44
+ on(:deploy_complete) { MockObject.deploy_complete }
45
+ on(:migrate_start) { MockObject.migrate_start }
46
+ on(:migrate_complete) { MockObject.migrate_complete }
47
+ on(:maintenance_page_up) { MockObject.maintenance_page_up }
48
+ on(:maintenance_page_down) { MockObject.maintenance_page_down }
49
+
50
+ # stub some tasks
51
+ namespace :deploy do
52
+ task(:default) {}
53
+ task(:migrate) {}
54
+ namespace :web do
55
+ task(:enable) {}
56
+ task(:disable) {}
57
+ end
58
+ end
59
+ end
60
+
61
+ config.trigger(:load)
62
+ end
63
+
64
+ context "deploy callbacks" do
65
+ it "should trigger :deploy_start before deploy" do
66
+ MockObject.should_receive(:deploy_start)
67
+ config.find_and_execute_task('deploy')
68
+ end
69
+
70
+ it "should trigger :deploy_complete after deploy" do
71
+ MockObject.should_receive(:deploy_complete)
72
+ config.find_and_execute_task('deploy')
73
+ end
74
+ end
75
+
76
+ context "migration callbacks" do
77
+ it "should trigger :migrate_start before deploy:migrate" do
78
+ MockObject.should_receive(:migrate_start)
79
+ config.find_and_execute_task('deploy:migrate')
80
+ end
81
+
82
+ it "should trigger :migrate_complete after deploy:migrate" do
83
+ MockObject.should_receive(:migrate_complete)
84
+ config.find_and_execute_task('deploy:migrate')
85
+ end
86
+ end
87
+
88
+ context "maintenance page callbacks" do
89
+ it "should trigger :maintenance_page_up before deploy:web:disable" do
90
+ MockObject.should_receive(:maintenance_page_up)
91
+ config.find_and_execute_task('deploy:web:disable')
92
+ end
93
+
94
+ it "should trigger :maintenance_page_down after deploy:web:enable" do
95
+ MockObject.should_receive(:maintenance_page_down)
96
+ config.find_and_execute_task('deploy:web:enable')
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+ context "built-in messages" do
103
+
104
+ context "when application is not specified" do
105
+
106
+ before do
107
+ config.load do
108
+ set :stage, 'production'
109
+ end
110
+ end
111
+
112
+ it "should not raise an error" do
113
+ lambda { config.capnotify_appname }.should_not raise_error
114
+ end
115
+
116
+ end
117
+
118
+ context "when stage is not specified" do
119
+
120
+ before do
121
+ config.load do
122
+ set :application, 'MyApp'
123
+ end
124
+ end
125
+
126
+ it "should not raise an error" do
127
+ lambda { config.capnotify_appname }.should_not raise_error
128
+ end
129
+
130
+ end
131
+
132
+ context "when the user wants to override capnotify_appname" do
133
+ before do
134
+ config.load do
135
+ set :capnotify_appname, 'SimpleApp'
136
+ end
137
+ end
138
+
139
+ it "should return what the user overrode with" do
140
+ config.capnotify_appname.should == 'SimpleApp'
141
+ end
142
+
143
+ end
144
+
145
+ context "when both application and stage are specified" do
146
+
147
+ before do
148
+ config.load do
149
+ set :application, 'SimpleApp'
150
+ set :stage, 'production'
151
+ end
152
+ end
153
+
154
+ it "should not raise an error" do
155
+ lambda { config.capnotify_appname }.should_not raise_error
156
+ end
157
+
158
+ it "should include the application name" do
159
+ config.capnotify_appname.should match('SimpleApp')
160
+ end
161
+
162
+ it "should include the stage name" do
163
+ config.capnotify_appname.should match('production')
164
+ end
165
+
166
+ end
167
+
168
+ end
169
+
170
+ context "capnotify_disable_default_components" do
171
+
172
+ context "when it is set to true" do
173
+
174
+ before do
175
+ config.load do
176
+ set :capnotify_disable_default_components, true
177
+ end
178
+ end
179
+
180
+ it "should not have any plugins loaded by default" do
181
+ config.trigger(:load)
182
+ Capistrano::EXTENSIONS.keys.map(&:to_s).grep(/^capnotify_/).count.should == 0
183
+ end
184
+
185
+ end
186
+
187
+ context "when it is not set" do
188
+
189
+ it "should have defauilt plugins loaded by default" do
190
+ config.trigger(:load)
191
+ Capistrano::EXTENSIONS.keys.map(&:to_s).grep(/^capnotify_/).count.should > 0
192
+ end
193
+ end
194
+ end
195
+
196
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'awesome_print'
5
+
6
+ $: << File.dirname(__FILE__) + '/../lib'
7
+
8
+ require 'capistrano'
9
+ require 'capnotify'
10
+ require 'pry'
11
+
12
+ def fixture_path(filename)
13
+ File.join( File.dirname(__FILE__), 'fixtures', filename )
14
+ end
15
+
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capnotify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0pre
5
+ prerelease: 5
6
+ platform: ruby
7
+ authors:
8
+ - Spike Grobstein
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: awesome_print
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: capistrano
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 2.14.2
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 2.14.2
110
+ description: Extensible Capistrano notification system with helpers and sensible default
111
+ values for common notification tasks.
112
+ email:
113
+ - me@spike.cx
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .travis.yml
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - capnotify.gemspec
126
+ - lib/capnotify.rb
127
+ - lib/capnotify/component.rb
128
+ - lib/capnotify/plugin.rb
129
+ - lib/capnotify/plugin/details.rb
130
+ - lib/capnotify/plugin/overview.rb
131
+ - lib/capnotify/templates/_component.html.erb
132
+ - lib/capnotify/templates/_component.txt.erb
133
+ - lib/capnotify/templates/default_notification.html.erb
134
+ - lib/capnotify/templates/default_notification.txt.erb
135
+ - lib/capnotify/version.rb
136
+ - spec/capnotify/component_spec.rb
137
+ - spec/capnotify/plugin_spec.rb
138
+ - spec/capnotify_spec.rb
139
+ - spec/spec_helper.rb
140
+ homepage: https://github.com/spikegrobstein/capnotify
141
+ licenses:
142
+ - MIT
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>'
157
+ - !ruby/object:Gem::Version
158
+ version: 1.3.1
159
+ requirements: []
160
+ rubyforge_project:
161
+ rubygems_version: 1.8.24
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: Extensible Capistrano notification system.
165
+ test_files:
166
+ - spec/capnotify/component_spec.rb
167
+ - spec/capnotify/plugin_spec.rb
168
+ - spec/capnotify_spec.rb
169
+ - spec/spec_helper.rb
170
+ has_rdoc: