mina-hooks 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +8 -0
- data/lib/mina/hooks/plugin.rb +11 -4
- data/lib/mina/hooks/version.rb +1 -1
- data/test/deploy.rb +1 -1
- data/test/helper.rb +39 -7
- data/test/hooks/plugin_test.rb +55 -39
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aae82afddf542410261fdad75a76f401aee5bc17
|
4
|
+
data.tar.gz: 68eff9f5ad53598ea8b5bb54feb5ed9538f306be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83e7bb03e8e5ef0e207cce2a9015194cbc97b8838e387d8a04979060ee131ad33b40e85f3f6a954fe2dd46bfeea2962b3802793fef068901a822800ab0576741
|
7
|
+
data.tar.gz: 88979cc6c52b5b848dfa37dfe2f3a15abb14c853e5d225e103fba206b31cf8f22dd5633c39954f13d991f509f8b2edf79da43ab9fa9692e2b77e1600539f0cf9
|
data/ChangeLog.md
CHANGED
data/lib/mina/hooks/plugin.rb
CHANGED
@@ -23,17 +23,21 @@ module Mina
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def invoke_before_mina_tasks
|
26
|
+
return unless deploying?
|
27
|
+
|
26
28
|
print_local_status "Invoke before mina tasks"
|
27
|
-
print_task_list self.before_mina_tasks if verbose_mode?
|
29
|
+
print_task_list self.before_mina_tasks if self.verbose_mode?
|
28
30
|
|
29
|
-
self.before_mina_tasks.each { |task_name| invoke task_name }
|
31
|
+
self.before_mina_tasks.each { |task_name| self.invoke task_name }
|
30
32
|
end
|
31
33
|
|
32
34
|
def invoke_after_mina_tasks
|
35
|
+
return unless deploying?
|
36
|
+
|
33
37
|
print_local_status "Invoke after mina tasks"
|
34
|
-
print_task_list self.after_mina_tasks if verbose_mode?
|
38
|
+
print_task_list self.after_mina_tasks if self.verbose_mode?
|
35
39
|
|
36
|
-
self.after_mina_tasks.each { |task_name| invoke task_name }
|
40
|
+
self.after_mina_tasks.each { |task_name| self.invoke task_name }
|
37
41
|
end
|
38
42
|
|
39
43
|
def mina_cleanup!
|
@@ -53,6 +57,9 @@ module Mina
|
|
53
57
|
puts "#{color('<-----', 32)} #{msg}"
|
54
58
|
end
|
55
59
|
|
60
|
+
def deploying?
|
61
|
+
@deploying ||= ARGV.include? "deploy"
|
62
|
+
end
|
56
63
|
end
|
57
64
|
end
|
58
65
|
end
|
data/lib/mina/hooks/version.rb
CHANGED
data/test/deploy.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "rubygems"
|
2
|
+
require "securerandom"
|
2
3
|
|
3
4
|
begin
|
4
5
|
require "bundler"
|
@@ -20,7 +21,7 @@ require "mina"
|
|
20
21
|
|
21
22
|
# create a regular class scope to test methods
|
22
23
|
class MinaClass
|
23
|
-
require "mina/hooks"
|
24
|
+
require "mina/hooks/plugin"
|
24
25
|
extend Mina::Hooks::Plugin
|
25
26
|
end
|
26
27
|
|
@@ -29,7 +30,9 @@ def mina_app
|
|
29
30
|
Rake.application.instance_eval do
|
30
31
|
init "mina"
|
31
32
|
require "mina/rake"
|
32
|
-
|
33
|
+
|
34
|
+
@rakefiles = ["test/deploy.rb"]
|
35
|
+
load_rakefile
|
33
36
|
|
34
37
|
# list of tasks that were "invoked"
|
35
38
|
@invoked_tasks = []
|
@@ -54,7 +57,38 @@ def mina_app
|
|
54
57
|
|
55
58
|
# fake mina_cleanup! command for testing
|
56
59
|
def mina_cleanup!
|
57
|
-
|
60
|
+
super
|
61
|
+
@cleanup_called = true
|
62
|
+
end
|
63
|
+
|
64
|
+
@deploying = true
|
65
|
+
|
66
|
+
# set not deploying!
|
67
|
+
def not_deploying!
|
68
|
+
@deploying = false
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_task(task_name = random_task_name, &block)
|
72
|
+
task = define_task(Rake::Task, task_name) do |t|
|
73
|
+
extend Mina::Helpers
|
74
|
+
extend Mina::Hooks::Plugin # simulates a rakefile env
|
75
|
+
block.call(self)
|
76
|
+
end
|
77
|
+
task.invoke
|
78
|
+
task
|
79
|
+
end
|
80
|
+
|
81
|
+
# to avoid rake task enhancing and correct invocation
|
82
|
+
def random_task_name
|
83
|
+
"test_task_#{SecureRandom.hex}"
|
84
|
+
end
|
85
|
+
|
86
|
+
def reset!
|
87
|
+
@before_mina_tasks = []
|
88
|
+
@after_mina_tasks = []
|
89
|
+
@invoked_tasks = []
|
90
|
+
@cleanup_called = false
|
91
|
+
@deploying = true
|
58
92
|
end
|
59
93
|
|
60
94
|
return self
|
@@ -62,10 +96,8 @@ def mina_app
|
|
62
96
|
end
|
63
97
|
|
64
98
|
# create a task in the scope of the mina app
|
65
|
-
def task(
|
66
|
-
mina_app.
|
67
|
-
define_task Rake::Task, name, &block
|
68
|
-
end
|
99
|
+
def task(&block)
|
100
|
+
mina_app.test_task(&block)
|
69
101
|
end
|
70
102
|
|
71
103
|
require "minitest/autorun"
|
data/test/hooks/plugin_test.rb
CHANGED
@@ -42,90 +42,106 @@ describe Mina::Hooks::Plugin do
|
|
42
42
|
|
43
43
|
describe "default task lists" do
|
44
44
|
it "before tasks" do
|
45
|
-
assert_equal klass.before_mina_tasks
|
45
|
+
assert_equal [], klass.before_mina_tasks
|
46
46
|
end
|
47
47
|
|
48
48
|
it "after tasks" do
|
49
|
-
assert_equal klass.after_mina_tasks
|
49
|
+
assert_equal [], klass.after_mina_tasks
|
50
50
|
end
|
51
51
|
end # default task lists
|
52
52
|
end # class scope
|
53
53
|
|
54
54
|
describe "rake/mina scope" do
|
55
|
+
before do
|
56
|
+
mina_app.reset!
|
57
|
+
end
|
58
|
+
|
55
59
|
describe "before mina" do
|
56
60
|
let(:task_list) { ["some:task", "some:other:task"] }
|
57
61
|
|
58
|
-
it "defines before_mina" do
|
59
|
-
task do
|
60
|
-
assert_respond_to self, :before_mina
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
62
|
it "adds tasks to the task list" do
|
65
|
-
task do
|
66
|
-
before_mina *task_list
|
67
|
-
assert_equal before_mina_tasks, task_list
|
63
|
+
task do |t|
|
64
|
+
t.before_mina *task_list
|
68
65
|
end
|
66
|
+
assert_equal task_list, mina_app.before_mina_tasks
|
69
67
|
end
|
70
68
|
|
71
69
|
it "adds more tasks to the list" do
|
72
|
-
task do
|
73
|
-
before_mina *task_list
|
74
|
-
before_mina "another:task"
|
75
|
-
assert_equal before_mina_tasks, (task_list + ["another:task"])
|
70
|
+
task do |t|
|
71
|
+
t.before_mina *task_list
|
72
|
+
t.before_mina "another:task"
|
76
73
|
end
|
74
|
+
assert_equal (task_list + ["another:task"]), mina_app.before_mina_tasks
|
77
75
|
end
|
78
76
|
end # before mina
|
79
77
|
|
80
78
|
describe "after mina" do
|
81
79
|
let(:task_list) { ["after:task"] }
|
82
80
|
|
83
|
-
it "defines after_mina" do
|
84
|
-
task do
|
85
|
-
assert_respond_to self, :after_mina
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
81
|
it "adds tasks to the task list" do
|
90
|
-
task do
|
91
|
-
after_mina *task_list
|
92
|
-
assert_equal after_mina_tasks, task_list
|
82
|
+
task do |t|
|
83
|
+
t.after_mina *task_list
|
93
84
|
end
|
85
|
+
assert_equal task_list, mina_app.after_mina_tasks
|
94
86
|
end
|
95
87
|
end # after mina
|
96
88
|
|
97
89
|
describe "invoke tasks" do
|
90
|
+
let(:mina) { mina_app }
|
98
91
|
let(:task_list) { ["first:task", "second:task", "third:task"]}
|
99
92
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
93
|
+
describe "when deploying" do
|
94
|
+
it "invokes before mina in order" do
|
95
|
+
mina.test_task do |t|
|
96
|
+
t.before_mina *task_list
|
97
|
+
t.invoke_before_mina_tasks
|
98
|
+
end
|
99
|
+
assert_equal task_list, mina.invoked_tasks
|
105
100
|
end
|
106
101
|
end
|
107
102
|
|
108
103
|
it "invokes after mina in order" do
|
109
|
-
|
110
|
-
after_mina *task_list
|
111
|
-
invoke_after_mina_tasks
|
112
|
-
|
104
|
+
mina.test_task do |t|
|
105
|
+
t.after_mina *task_list
|
106
|
+
t.invoke_after_mina_tasks
|
107
|
+
end
|
108
|
+
assert_equal task_list, mina.invoked_tasks
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "when not deploying" do
|
112
|
+
it "invokes before mina in order" do
|
113
|
+
mina.test_task do |t|
|
114
|
+
t.not_deploying!
|
115
|
+
t.before_mina *task_list
|
116
|
+
t.invoke_before_mina_tasks
|
117
|
+
end
|
118
|
+
refute_equal task_list, mina.invoked_tasks
|
119
|
+
end
|
120
|
+
|
121
|
+
it "invokes after mina in order" do
|
122
|
+
mina.test_task do |t|
|
123
|
+
t.not_deploying!
|
124
|
+
t.after_mina *task_list
|
125
|
+
t.invoke_after_mina_tasks
|
126
|
+
end
|
127
|
+
refute_equal task_list, mina.invoked_tasks
|
113
128
|
end
|
114
129
|
end
|
115
130
|
end # invoke tasks
|
116
131
|
|
117
132
|
describe "mina cleanup" do
|
133
|
+
let(:mina) { mina_app }
|
118
134
|
let(:before_task_list) { ["before:task:one", "before:task:two"] }
|
119
135
|
let(:after_task_list) { ["after:task:one", "after:task:two"] }
|
120
136
|
|
121
137
|
it "invokes all tasks" do
|
122
|
-
|
123
|
-
before_mina *before_task_list
|
124
|
-
after_mina *after_task_list
|
125
|
-
mina_cleanup!
|
126
|
-
assert cleanup_called
|
127
|
-
assert_equal invoked_tasks, (before_task_list + after_task_list)
|
138
|
+
mina.test_task do |t|
|
139
|
+
t.before_mina *before_task_list
|
140
|
+
t.after_mina *after_task_list
|
141
|
+
t.mina_cleanup!
|
128
142
|
end
|
143
|
+
assert mina.cleanup_called, "cleanup_called must be true."
|
144
|
+
assert_equal (before_task_list + after_task_list), mina.invoked_tasks
|
129
145
|
end
|
130
146
|
end # mina cleanup
|
131
147
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mina-hooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Don Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mina
|