minitest-capistrano 0.0.2 → 0.0.3

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.
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .rvmrc
19
+ .rbx/
data/.travis.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - jruby
4
5
  - 1.9.2
6
+ - ruby-head
5
7
  - 1.8.7
8
+ - rbx-18mode
9
+ - ree
data/Gemfile CHANGED
@@ -6,3 +6,7 @@ gemspec
6
6
  group :test do
7
7
  gem 'rake', '~> 0.9'
8
8
  end
9
+
10
+ platforms :jruby do
11
+ gem 'jruby-openssl'
12
+ end
@@ -1,5 +1,5 @@
1
1
  module MiniTest
2
2
  module Capistrano
3
- VERSION = "0.0.2" # :nodoc:
3
+ VERSION = "0.0.3" # :nodoc:
4
4
  end
5
5
  end
@@ -23,6 +23,84 @@ module MiniTest
23
23
  msg = message(msg) { "Expected configuration to not run #{cmd}, but did" }
24
24
  assert_nil configuration.runs[cmd], msg
25
25
  end
26
+
27
+ ##
28
+ # Fails unless +configuration+ has not run anything.
29
+ #
30
+ # assert_have_run_something configuration
31
+
32
+ def assert_have_run_something(configuration, msg = nil)
33
+ msg = message(msg) { "Expected configuration to have run something, but did not" }
34
+ refute_empty configuration.runs, msg
35
+ end
36
+
37
+ ##
38
+ # Fails if +configuration+ has run any commands.
39
+ #
40
+ # refute_have_run_something configuration
41
+
42
+ def refute_have_run_something(configuration, msg = nil)
43
+ msg = message(msg) { "Expected configuration to have run nothing, but did" }
44
+ assert_empty configuration.runs, msg
45
+ end
46
+
47
+ ##
48
+ # Fails unless +configuration+ has a callback of +before_task_name+ before
49
+ # +task_name+.
50
+ #
51
+ # assert_callback_before configuration, :stop, :finalize
52
+
53
+ def assert_callback_before(configuration, task_name, before_task_name, msg = nil)
54
+ msg = message(msg) { "Expected configuration to callback #{task_name.inspect} before #{before_task_name.inspect} but did not" }
55
+ test_callback_on(true, configuration, task_name, :before, before_task_name, msg)
56
+ end
57
+
58
+ ##
59
+ # Fails if +configuration+ has a callback of +before_task_name+ before
60
+ # +task_name+.
61
+ #
62
+ # refute_callback_before configuration, :stop, :start
63
+
64
+ def refute_callback_before(configuration, task_name, before_task_name, msg = nil)
65
+ msg = message(msg) { "Expected configuration to not have a callback #{task_name.inspect} before #{before_task_name.inspect} but did" }
66
+ test_callback_on(false, configuration, task_name, :before, before_task_name, msg)
67
+ end
68
+
69
+ ##
70
+ # Fails unless +configuration+ has a callback of +after_task_name+ after
71
+ # +task_name+.
72
+ #
73
+ # assert_callback_after configuration, :reload, :log_event
74
+
75
+ def assert_callback_after(configuration, task_name, after_task_name, msg = nil)
76
+ msg = message(msg) { "Expected configuration to callback #{task_name.inspect} after #{after_task_name.inspect} but did not" }
77
+ test_callback_on(true, configuration, task_name, :after, after_task_name, msg)
78
+ end
79
+
80
+ ##
81
+ # Fails if +configuration+ has a callback of +after_task_name+ after
82
+ # +task_name+.
83
+ #
84
+ # refute_callback_after configuration, :start, :stop
85
+
86
+ def refute_callback_after(configuration, task_name, after_task_name, msg = nil)
87
+ msg = message(msg) { "Expected configuration to not have a callback #{task_name.inspect} after #{after_task_name.inspect} but did" }
88
+ test_callback_on(false, configuration, task_name, :after, after_task_name, msg)
89
+ end
90
+
91
+ private
92
+
93
+ def test_callback_on(positive, configuration, task_name, on, other_task_name, msg)
94
+ task = configuration.find_task(task_name)
95
+ callbacks = configuration.find_callback(on, task)
96
+
97
+ if callbacks
98
+ method = positive ? :refute_empty : :assert_empty
99
+ send method, callbacks.select { |c| c.source == other_task_name }, msg
100
+ else
101
+ flunk msg
102
+ end
103
+ end
26
104
  end
27
105
 
28
106
  ##
@@ -46,6 +124,60 @@ module MiniTest
46
124
  # :method: wont_have_run
47
125
 
48
126
  infect_an_assertion :refute_have_run, :wont_have_run
127
+
128
+ ##
129
+ # See MiniTest::Assertions#assert_have_run_something
130
+ #
131
+ # config.must_have_run_something
132
+ #
133
+ # :method: must_have_run_something
134
+
135
+ infect_an_assertion :assert_have_run_something, :must_have_run_something, true
136
+
137
+ ##
138
+ # See MiniTest::Assertions#refute_have_run_something
139
+ #
140
+ # config.wont_have_run_anything
141
+ #
142
+ # :method: wont_have_run_anything
143
+
144
+ infect_an_assertion :refute_have_run_something, :wont_have_run_anything, true
145
+
146
+ ##
147
+ # See MiniTest::Assertions#assert_callback_before
148
+ #
149
+ # config.must_have_callback_before :stop, :warn_people
150
+ #
151
+ # :method: must_have_callback_before
152
+
153
+ infect_an_assertion :assert_callback_before, :must_have_callback_before, true
154
+
155
+ ##
156
+ # See MiniTest::Assertions#refute_callback_before
157
+ #
158
+ # config.wont_have_callback_before :stop, :begin_long_job
159
+ #
160
+ # :method: wont_have_callback_before
161
+
162
+ infect_an_assertion :refute_callback_before, :wont_have_callback_before, true
163
+
164
+ ##
165
+ # See MiniTest::Assertions#assert_callback_after
166
+ #
167
+ # config.must_have_callback_after :reload, :log_event
168
+ #
169
+ # :method: must_have_callback_after
170
+
171
+ infect_an_assertion :assert_callback_after, :must_have_callback_after, true
172
+
173
+ ##
174
+ # See MiniTest::Assertions#refute_callback_after
175
+ #
176
+ # config.wont_have_callback_after :stop, :do_taxes
177
+ #
178
+ # :method: wont_have_callback_after
179
+
180
+ infect_an_assertion :refute_callback_after, :wont_have_callback_after, true
49
181
  end
50
182
 
51
183
  module Capistrano
@@ -91,6 +223,15 @@ module MiniTest
91
223
  def captures_responses
92
224
  @captures_responses ||= {}
93
225
  end
226
+
227
+ def find_callback(on, task)
228
+ task = find_task(task) if task.kind_of?(String)
229
+
230
+ Array(callbacks[on]).select do |task_callback|
231
+ task_callback.applies_to?(task) ||
232
+ task_callback.source == task.fully_qualified_name
233
+ end
234
+ end
94
235
  end
95
236
  end
96
237
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
6
6
  gem.email = ["fnichol@nichol.ca"]
7
7
  gem.description = %q{MiniTest assertions and expectations for testing Capistrano recipes}
8
8
  gem.summary = %q{MiniTest assertions and expectations for testing Capistrano recipes}
9
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/fnichol/minitest-capistrano"
10
10
 
11
11
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
12
  gem.files = `git ls-files`.split("\n")
@@ -1,6 +1,7 @@
1
1
  gem 'minitest'
2
2
  require 'minitest/autorun'
3
3
  require 'minitest/capistrano'
4
+ require 'capistrano'
4
5
 
5
6
  describe MiniTest::Capistrano::ConfigurationExtension do
6
7
  before do
@@ -69,6 +70,26 @@ describe MiniTest::Capistrano::ConfigurationExtension do
69
70
  @config.capture("cat /tmp/file").must_equal "blah bleh"
70
71
  end
71
72
  end
73
+
74
+ describe "#find_callback" do
75
+ before do
76
+ @config = Capistrano::Configuration.new
77
+ @config.extend(MiniTest::Capistrano::ConfigurationExtension)
78
+ @config.task(:startup) { run "rails server" }
79
+ @config.task(:announce_startup) { run "echo starting up"}
80
+ end
81
+
82
+ it "returns an empty array when no callbacks are found" do
83
+ @config.find_callback(:before, @config.find_task("startup")).must_equal []
84
+ end
85
+
86
+ it "returns an array of callbacks that apply to the task" do
87
+ @config.before :startup, :announce_startup
88
+
89
+ @config.find_callback(:before, @config.find_task("startup")).
90
+ first.source.must_equal :announce_startup
91
+ end
92
+ end
72
93
  end
73
94
 
74
95
  describe MiniTest::Assertions do
@@ -88,6 +109,44 @@ describe MiniTest::Assertions do
88
109
  @config.run "nothing"
89
110
  subject.refute_have_run "yoyodyne", @config
90
111
  end
112
+
113
+ it "asserts any command has run" do
114
+ @config.run "yo"
115
+ subject.assert_have_run_something @config
116
+ end
117
+
118
+ it "refute any command has run" do
119
+ subject.refute_have_run_something @config
120
+ end
121
+
122
+ describe "callbacks" do
123
+ before do
124
+ @config = Capistrano::Configuration.new
125
+ @config.extend(MiniTest::Capistrano::ConfigurationExtension)
126
+ @config.task(:startup) { run "rails server" }
127
+ @config.task(:announce_startup) { run "echo starting up"}
128
+ end
129
+
130
+ it "asserts a callback exists for one task before another" do
131
+ @config.before :startup, :announce_startup
132
+
133
+ subject.assert_callback_before @config, :startup, :announce_startup
134
+ end
135
+
136
+ it "refutes a callback exists for one task before another" do
137
+ subject.refute_callback_before @config, :startup, :nadda
138
+ end
139
+
140
+ it "asserts a callback exists for one task after another" do
141
+ @config.after :start, :intialize
142
+
143
+ subject.assert_callback_after @config, :start, :intialize
144
+ end
145
+
146
+ it "refutes a callback exists for one task after another" do
147
+ subject.refute_callback_after @config, :clone, :nadda
148
+ end
149
+ end
91
150
  end
92
151
 
93
152
  describe MiniTest::Expectations do
@@ -105,4 +164,42 @@ describe MiniTest::Expectations do
105
164
  @config.run "wot?"
106
165
  @config.wont_have_run "yabba dabba"
107
166
  end
167
+
168
+ it "needs to verify something has run" do
169
+ @config.run "woah"
170
+ @config.must_have_run_something
171
+ end
172
+
173
+ it "needs to verify no command has been run" do
174
+ @config.wont_have_run_anything
175
+ end
176
+
177
+ describe "callbacks" do
178
+ before do
179
+ @config = Capistrano::Configuration.new
180
+ @config.extend(MiniTest::Capistrano::ConfigurationExtension)
181
+ @config.task(:startup) { run "rails server" }
182
+ @config.task(:announce_startup) { run "echo starting up"}
183
+ end
184
+
185
+ it "needs to verify a callback exists for a task before another" do
186
+ @config.before :stop, :warn_people
187
+
188
+ @config.must_have_callback_before :stop, :warn_people
189
+ end
190
+
191
+ it "needs to verify no callback exists for a task before another" do
192
+ @config.wont_have_callback_before :reload, :stop
193
+ end
194
+
195
+ it "needs to verify a callback exists for a task after another" do
196
+ @config.after :start, :init_database
197
+
198
+ @config.must_have_callback_after :start, :init_database
199
+ end
200
+
201
+ it "needs to verify no callback exists for a task after another" do
202
+ @config.wont_have_callback_after :stop, :do_taxes
203
+ end
204
+ end
108
205
  end
metadata CHANGED
@@ -1,45 +1,64 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: minitest-capistrano
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 1889055196096400351
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Fletcher Nichol
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-01-08 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-01-11 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: minitest
16
- requirement: &70145221461000 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
17
25
  none: false
18
- requirements:
26
+ requirements:
19
27
  - - ~>
20
- - !ruby/object:Gem::Version
28
+ - !ruby/object:Gem::Version
29
+ hash: 4549645503570588592
30
+ segments:
31
+ - 2
32
+ - 10
33
+ - 0
21
34
  version: 2.10.0
22
35
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70145221461000
25
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
26
38
  name: capistrano
27
- requirement: &70145221459740 !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
28
41
  none: false
29
- requirements:
42
+ requirements:
30
43
  - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '2.9'
44
+ - !ruby/object:Gem::Version
45
+ hash: 424294802847615879
46
+ segments:
47
+ - 2
48
+ - 9
49
+ version: "2.9"
33
50
  type: :runtime
34
- prerelease: false
35
- version_requirements: *70145221459740
51
+ version_requirements: *id002
36
52
  description: MiniTest assertions and expectations for testing Capistrano recipes
37
- email:
53
+ email:
38
54
  - fnichol@nichol.ca
39
55
  executables: []
56
+
40
57
  extensions: []
58
+
41
59
  extra_rdoc_files: []
42
- files:
60
+
61
+ files:
43
62
  - .gitignore
44
63
  - .travis.yml
45
64
  - Gemfile
@@ -51,29 +70,39 @@ files:
51
70
  - lib/minitest/capistrano/version.rb
52
71
  - minitest-capistrano.gemspec
53
72
  - spec/minitest_capistrano_spec.rb
54
- homepage: ''
73
+ has_rdoc: true
74
+ homepage: https://github.com/fnichol/minitest-capistrano
55
75
  licenses: []
76
+
56
77
  post_install_message:
57
78
  rdoc_options: []
58
- require_paths:
79
+
80
+ require_paths:
59
81
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
82
+ required_ruby_version: !ruby/object:Gem::Requirement
61
83
  none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
- required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 2002549777813010636
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
92
  none: false
68
- requirements:
69
- - - ! '>='
70
- - !ruby/object:Gem::Version
71
- version: '0'
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 2002549777813010636
97
+ segments:
98
+ - 0
99
+ version: "0"
72
100
  requirements: []
101
+
73
102
  rubyforge_project:
74
- rubygems_version: 1.8.10
103
+ rubygems_version: 1.5.2
75
104
  signing_key:
76
105
  specification_version: 3
77
106
  summary: MiniTest assertions and expectations for testing Capistrano recipes
78
- test_files:
107
+ test_files:
79
108
  - spec/minitest_capistrano_spec.rb