captain_hoog 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +195 -0
- data/captain_hoog.gemspec +1 -0
- data/changelog.md +7 -0
- data/features/support/env.rb +9 -3
- data/features/support/steps/hooks_steps.rb +33 -0
- data/features/support/world.rb +15 -0
- data/features/testing.feature +107 -0
- data/lib/captain_hoog/pre_git.rb +9 -3
- data/lib/captain_hoog/test/all.rb +4 -0
- data/lib/captain_hoog/test/rspec.rb +36 -0
- data/lib/captain_hoog/test/sandbox.rb +102 -0
- data/lib/captain_hoog/test/strategies.rb +48 -0
- data/lib/captain_hoog/test.rb +2 -0
- data/lib/captain_hoog/version.rb +1 -1
- data/spec/fixtures/plugins/test_plugins/divide.rb +13 -0
- data/spec/fixtures/plugins/test_plugins/passing/pure/{foo.rb → foo/foo.rb} +0 -0
- data/spec/fixtures/plugins/test_plugins/passing/{simple.rb → simple/simple.rb} +0 -0
- data/spec/lib/captain_hoog/test/rspec_spec.rb +61 -0
- data/spec/lib/captain_hoog/test/sandbox_spec.rb +157 -0
- data/spec/spec_helper.rb +1 -0
- metadata +34 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 003b25531cde9e6c8e8b6fcd4f0e6ae9956ad1d7
|
4
|
+
data.tar.gz: f245586235d2c992aed724c4f20cbdc300dce90f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0fae4a66d9489e669fc0e1446219575b76a8ca17a1cf8f585f79651c9fbb22c7855310fee831ec7350a971f951f8d59fac23b1642918b641edcadb85fdd3df9
|
7
|
+
data.tar.gz: c8092c92675e0750297c5d0d47d896bc95dfc631edfc83ae8d9ff529fe1d1223eb4b3af2e193c7024fd06762655cd51eb0e77a6616aabff8184d2209281d1b33
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -165,6 +165,16 @@ end
|
|
165
165
|
|
166
166
|
```
|
167
167
|
|
168
|
+
**Plugin file structure**
|
169
|
+
|
170
|
+
A common way to organize plugins is:
|
171
|
+
|
172
|
+
```
|
173
|
+
<plugin_name>/
|
174
|
+
- <plugin_name>.rb
|
175
|
+
- test/
|
176
|
+
- <plugin_name>_[spec|test].rb
|
177
|
+
```
|
168
178
|
|
169
179
|
**Plugin specific configurations**
|
170
180
|
|
@@ -185,6 +195,191 @@ git.describe 'clear logs' do |pre|
|
|
185
195
|
end
|
186
196
|
```
|
187
197
|
|
198
|
+
## Test Support
|
199
|
+
|
200
|
+
### Sandbox
|
201
|
+
|
202
|
+
For testing purposes, Captain Hoog uses some kind of sandboxing. You're able to use the sandbox directly (you have to do this by now for any other test frameworks than RSpec).
|
203
|
+
|
204
|
+
Using the sandbox is easy:
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
sandbox = CaptainHoog::Test::Sandbox.new(plugin_code, cfg)
|
208
|
+
sandbox.run
|
209
|
+
# then have full access to the plugin by using sandbox.plugin
|
210
|
+
```
|
211
|
+
|
212
|
+
You have to pass the plugin as String or File object and a configuration hash to the sandbox.
|
213
|
+
The configuration hash might consist of a global (the ```env```) and a plugin specific configuration (marked by using the plugins name as key).
|
214
|
+
|
215
|
+
Example:
|
216
|
+
|
217
|
+
```rb
|
218
|
+
plugin_code = <<-PLUGIN
|
219
|
+
git.describe 'foo' do |hook|
|
220
|
+
hook.helper :foo_helper do
|
221
|
+
config.number
|
222
|
+
end
|
223
|
+
|
224
|
+
hook.test do
|
225
|
+
foo_helper
|
226
|
+
true
|
227
|
+
end
|
228
|
+
|
229
|
+
hook.message do
|
230
|
+
'Fun'
|
231
|
+
end
|
232
|
+
end
|
233
|
+
PLUGIN
|
234
|
+
|
235
|
+
cfg = {
|
236
|
+
env: {
|
237
|
+
suppress_headline: true
|
238
|
+
},
|
239
|
+
plugin: {
|
240
|
+
foo: {
|
241
|
+
number: 12
|
242
|
+
}
|
243
|
+
}
|
244
|
+
}
|
245
|
+
sandbox = CaptainHoog::Test::Sandbox.new(plugin_code, cfg)
|
246
|
+
sandbox.run
|
247
|
+
sandbox.plugin.result[:test] # => true
|
248
|
+
sandbox.plugin.foo_helper # => 12
|
249
|
+
sandbox.plugin.result[:message] # => Fun
|
250
|
+
```
|
251
|
+
|
252
|
+
**Note** that the sandbox will not provide you some fake file system.
|
253
|
+
|
254
|
+
### Frameworks
|
255
|
+
|
256
|
+
Captain Hoog provides some small DSL for testing plugins if you're using RSpec. For the use of MiniTest (or any other testing framework, see the section below.)
|
257
|
+
|
258
|
+
### RSpec
|
259
|
+
|
260
|
+
Require test support by using
|
261
|
+
|
262
|
+
```rb
|
263
|
+
require 'captain_hoog/test'
|
264
|
+
```
|
265
|
+
|
266
|
+
There is no configuration needed, Captain Hoog will detect if you're using Rspec.
|
267
|
+
|
268
|
+
Then - as usual - add a ```describe``` block. Within this block you have access to a block helper:
|
269
|
+
|
270
|
+
```rb
|
271
|
+
with_plugin :<PLUGIN_NAME>, config: <HASH>, silence: <true|false> do
|
272
|
+
# ....
|
273
|
+
end
|
274
|
+
```
|
275
|
+
|
276
|
+
|Argument| Description|
|
277
|
+
|:-------|:-----------|
|
278
|
+
|PLUGIN_NAME | Plugin - as String or File object (given as a ```let``` or method) |
|
279
|
+
|config | plugin configuration, see **Sandbox** section for details. |
|
280
|
+
|silence | Truthy or falsy value, silences the plugin output |
|
281
|
+
|
282
|
+
With ```with_plugin``` you have full access to the Captain Hoog plugin by using ```plugin```.
|
283
|
+
|
284
|
+
A full example:
|
285
|
+
|
286
|
+
```rb
|
287
|
+
require 'rspec'
|
288
|
+
require 'captain_hoog/test'
|
289
|
+
|
290
|
+
describe 'Test for hook' do
|
291
|
+
let(:divide) do
|
292
|
+
path = File.expand_path(File.join(File.dirname(__FILE__),
|
293
|
+
'..',
|
294
|
+
'fixtures',
|
295
|
+
'plugins',
|
296
|
+
'test_plugins',
|
297
|
+
'divide.rb'))
|
298
|
+
File.new(path)
|
299
|
+
end
|
300
|
+
|
301
|
+
let(:config) do
|
302
|
+
{
|
303
|
+
plugin: {
|
304
|
+
divide: {
|
305
|
+
divider: 12,
|
306
|
+
compare_value: 1
|
307
|
+
}
|
308
|
+
}
|
309
|
+
}
|
310
|
+
end
|
311
|
+
|
312
|
+
with_plugin :divide, config: :config, silence: true do
|
313
|
+
describe 'helpers' do
|
314
|
+
describe '#divider' do
|
315
|
+
it 'returns 12 as Fixnum' do
|
316
|
+
expect(plugin.divider).to eq 12
|
317
|
+
expect(plugin.divider).to be_instance_of Fixnum
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
describe '#check_equal' do
|
322
|
+
it 'returns 1' do
|
323
|
+
expect(plugin.check_equal).to be 1
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
it 'exits with true' do
|
329
|
+
expect(plugin.result[:test]).to be true
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
```
|
334
|
+
|
335
|
+
### Other Test Frameworks (MiniTest, TestUnit ...)
|
336
|
+
|
337
|
+
You have to use the sandbox directly. See an example using MiniTest below.
|
338
|
+
|
339
|
+
```rb
|
340
|
+
gem 'minitest'
|
341
|
+
require 'minitest/autorun'
|
342
|
+
require 'minitest/unit'
|
343
|
+
require 'captain_hoog'
|
344
|
+
require 'captain_hoog/test'
|
345
|
+
|
346
|
+
class DividePluginTest < Minitest::Test
|
347
|
+
def setup
|
348
|
+
config = {
|
349
|
+
env: {
|
350
|
+
suppress_headline: true
|
351
|
+
},
|
352
|
+
plugin: {
|
353
|
+
divide: {
|
354
|
+
divider: 12,
|
355
|
+
compare_value: 1
|
356
|
+
}
|
357
|
+
}
|
358
|
+
}
|
359
|
+
path = File.expand_path(File.join(File.dirname(__FILE__),
|
360
|
+
'..',
|
361
|
+
'fixtures',
|
362
|
+
'plugins',
|
363
|
+
'test_plugins',
|
364
|
+
'divide.rb'))
|
365
|
+
sandbox = ::CaptainHoog::Test::Sandbox.new(File.new(path), config)
|
366
|
+
sandbox.run
|
367
|
+
@plugin = sandbox.plugin
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_helper_divider
|
371
|
+
assert_equal @plugin.divider, 12
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_helper_divider_class
|
375
|
+
assert_instance_of Fixnum, @plugin.divider
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_result
|
379
|
+
assert_equal plugin.result[:test], true
|
380
|
+
end
|
381
|
+
end
|
382
|
+
```
|
188
383
|
|
189
384
|
## Last stuff
|
190
385
|
|
data/captain_hoog.gemspec
CHANGED
data/changelog.md
CHANGED
data/features/support/env.rb
CHANGED
@@ -3,11 +3,13 @@ require 'aruba/cucumber'
|
|
3
3
|
|
4
4
|
require 'rspec/expectations'
|
5
5
|
|
6
|
-
|
6
|
+
SPEC_PATH = File.expand_path(File.join(File.dirname(__FILE__),
|
7
7
|
"..",
|
8
8
|
"..",
|
9
|
-
"spec"
|
10
|
-
|
9
|
+
"spec"))
|
10
|
+
|
11
|
+
FIXTURES_PATH = File.join(SPEC_PATH, "fixtures")
|
12
|
+
HOOK_SPEC_PATH = File.join(SPEC_PATH, "hooks")
|
11
13
|
|
12
14
|
Before do
|
13
15
|
$git_fixture_dir_exists ||= false
|
@@ -21,6 +23,9 @@ Before do
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
$git_fixture_dir_exists = true
|
26
|
+
unless File.exists?(HOOK_SPEC_PATH)
|
27
|
+
FileUtils.mkdir(HOOK_SPEC_PATH)
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
|
@@ -39,5 +44,6 @@ After do
|
|
39
44
|
".git",
|
40
45
|
"hooks",
|
41
46
|
hook_type))
|
47
|
+
#FileUtils.rm_rf(HOOK_SPEC_PATH)
|
42
48
|
end
|
43
49
|
end
|
@@ -69,3 +69,36 @@ Then(/^the config file includes the "(.*?)" directory$/) do |config_path|
|
|
69
69
|
expect(config).to have_key("#{config_path}_dir")
|
70
70
|
expect(config["#{config_path}_dir"]).to include @dir
|
71
71
|
end
|
72
|
+
|
73
|
+
Given(/^I wrote a spec "([^"]*)" containing:$/) do |name, content|
|
74
|
+
write_spec(name, content)
|
75
|
+
end
|
76
|
+
|
77
|
+
Given(/^I wrote a test "([^"]*)" containing:$/) do |name, content|
|
78
|
+
write_spec(name, content)
|
79
|
+
end
|
80
|
+
|
81
|
+
When(/^I run the spec "([^"]*)"$/) do |spec_name|
|
82
|
+
path = File.join(HOOK_SPEC_PATH, "#{spec_name}.rb")
|
83
|
+
cmd = "bundle exec rspec #{path}"
|
84
|
+
@spec_executed = true
|
85
|
+
run_simple(unescape(cmd), false)
|
86
|
+
end
|
87
|
+
|
88
|
+
When(/^I run the test "([^"]*)"$/) do |test_name|
|
89
|
+
path = File.join(HOOK_SPEC_PATH, "#{test_name}.rb")
|
90
|
+
@cmd = "ruby #{path}"
|
91
|
+
@test_executed = true
|
92
|
+
run_simple(unescape(@cmd), false)
|
93
|
+
end
|
94
|
+
|
95
|
+
Then(/^I should see the test is passing with "([^"]*)" example and "([^"]*)" failures$/) do |success_count, failure_count|
|
96
|
+
if @spec_executed
|
97
|
+
result = all_stdout.split(/\n/).last
|
98
|
+
expect(result).to match(/#{success_count} (example|examples), #{failure_count} failures/)
|
99
|
+
end
|
100
|
+
if @test_executed
|
101
|
+
output = output_from(@cmd).split(/\n/).last
|
102
|
+
expect(output).to match(/\d+ runs, #{success_count} assertions, #{failure_count} failures/)
|
103
|
+
end
|
104
|
+
end
|
data/features/support/world.rb
CHANGED
@@ -27,6 +27,21 @@ module FileWorld
|
|
27
27
|
def hook_config_file_path
|
28
28
|
git_project_path.join('hoogfile.yml')
|
29
29
|
end
|
30
|
+
|
31
|
+
def write_file(path, file_content)
|
32
|
+
File.open(path, 'w') { |file| file.write(file_content) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def write_spec(name, file_content)
|
36
|
+
spec_name = File.expand_path(File.join(File.dirname(__FILE__),
|
37
|
+
'..',
|
38
|
+
'..',
|
39
|
+
'spec',
|
40
|
+
'hooks',
|
41
|
+
"#{name}.rb"))
|
42
|
+
write_file(spec_name, file_content)
|
43
|
+
end
|
44
|
+
|
30
45
|
end
|
31
46
|
|
32
47
|
World(FileWorld)
|
@@ -0,0 +1,107 @@
|
|
1
|
+
Feature: Testing a hook plugin
|
2
|
+
In order to have tested hook plugins
|
3
|
+
As developer that want to write tests
|
4
|
+
I want to have the possibility to test my hook plugins
|
5
|
+
|
6
|
+
Scenario: Testing a hook plugin with RSpec
|
7
|
+
Given I wrote a spec "divide_spec" containing:
|
8
|
+
"""
|
9
|
+
require 'rspec'
|
10
|
+
require 'captain_hoog/test'
|
11
|
+
|
12
|
+
describe 'Test for hook' do
|
13
|
+
let(:divide) do
|
14
|
+
path = File.expand_path(File.join(File.dirname(__FILE__),
|
15
|
+
'..',
|
16
|
+
'fixtures',
|
17
|
+
'plugins',
|
18
|
+
'test_plugins',
|
19
|
+
'divide.rb'))
|
20
|
+
File.new(path)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:config) do
|
24
|
+
{
|
25
|
+
plugin: {
|
26
|
+
divide: {
|
27
|
+
divider: 12,
|
28
|
+
compare_value: 1
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
with_plugin :divide, config: :config, silence: true do
|
35
|
+
describe 'helpers' do
|
36
|
+
describe '#divider' do
|
37
|
+
it 'returns 12 as Fixnum' do
|
38
|
+
expect(plugin.divider).to eq 12
|
39
|
+
expect(plugin.divider).to be_instance_of Fixnum
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#check_equal' do
|
44
|
+
it 'returns 1' do
|
45
|
+
expect(plugin.check_equal).to be 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'exits with true' do
|
51
|
+
expect(plugin.result[:test]).to be true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
"""
|
57
|
+
When I run the spec "divide_spec"
|
58
|
+
Then I should see the test is passing with "3" example and "0" failures
|
59
|
+
|
60
|
+
Scenario: Testing a hook plugin with Minitest
|
61
|
+
Given I wrote a test "divide_test" containing:
|
62
|
+
"""
|
63
|
+
gem 'minitest'
|
64
|
+
require 'minitest/autorun'
|
65
|
+
require 'minitest/unit'
|
66
|
+
require 'captain_hoog'
|
67
|
+
require 'captain_hoog/test'
|
68
|
+
|
69
|
+
class DividePluginTest < Minitest::Test
|
70
|
+
def setup
|
71
|
+
config = {
|
72
|
+
env: {
|
73
|
+
suppress_headline: true
|
74
|
+
},
|
75
|
+
plugin: {
|
76
|
+
divide: {
|
77
|
+
divider: 12,
|
78
|
+
compare_value: 1
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
path = File.expand_path(File.join(File.dirname(__FILE__),
|
83
|
+
'..',
|
84
|
+
'fixtures',
|
85
|
+
'plugins',
|
86
|
+
'test_plugins',
|
87
|
+
'divide.rb'))
|
88
|
+
sandbox = ::CaptainHoog::Test::Sandbox.new(File.new(path), config)
|
89
|
+
sandbox.run
|
90
|
+
@plugin = sandbox.plugin
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_helper_divider
|
94
|
+
assert_equal @plugin.divider, 12
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_helper_divider_class
|
98
|
+
assert_instance_of Fixnum, @plugin.divider
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_result
|
102
|
+
assert_equal plugin.result[:test], true
|
103
|
+
end
|
104
|
+
end
|
105
|
+
"""
|
106
|
+
When I run the test "divide_test"
|
107
|
+
Then I should see the test is passing with "2" example and "0" failures
|
data/lib/captain_hoog/pre_git.rb
CHANGED
@@ -110,9 +110,15 @@ module CaptainHoog
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def read_plugins_from_dir(dir, env)
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
unless File.basename(dir).match(/test/)
|
114
|
+
Dir["#{dir}/**"].each do |file|
|
115
|
+
if File.directory?(file)
|
116
|
+
read_plugins_from_dir(file, env)
|
117
|
+
else
|
118
|
+
code = File.read(file)
|
119
|
+
@plugins << Plugin.new(code,env)
|
120
|
+
end
|
121
|
+
end
|
116
122
|
end
|
117
123
|
end
|
118
124
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module CaptainHoog
|
2
|
+
module Test
|
3
|
+
module RSpec
|
4
|
+
module TestCase
|
5
|
+
|
6
|
+
attr_reader :plugin
|
7
|
+
|
8
|
+
def with_plugin(plugin_name, config: nil, silence: false)
|
9
|
+
before do
|
10
|
+
cfg = config ? self.send(config) : {}
|
11
|
+
cfg.merge!(env: { suppress_headline: silence }) if silence
|
12
|
+
build_sandbox(plugin_name, cfg)
|
13
|
+
end
|
14
|
+
context "with plugin #{plugin_name}" do
|
15
|
+
yield if block_given?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def build_sandbox(plugin_name, cfg)
|
22
|
+
plugin_code = self.send(plugin_name)
|
23
|
+
sandbox = CaptainHoog::Test::Sandbox.new(plugin_code, cfg)
|
24
|
+
sandbox.run
|
25
|
+
@plugin = sandbox.plugin
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
RSpec.configure do |config|
|
34
|
+
config.include CaptainHoog::Test::RSpec::TestCase
|
35
|
+
config.extend CaptainHoog::Test::RSpec::TestCase
|
36
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require_relative './strategies'
|
2
|
+
|
3
|
+
module CaptainHoog
|
4
|
+
module Test
|
5
|
+
class Sandbox
|
6
|
+
attr_reader :configuration,
|
7
|
+
:plugin
|
8
|
+
|
9
|
+
module FakePlugin
|
10
|
+
|
11
|
+
attr_reader :fake_plugin
|
12
|
+
|
13
|
+
def fake(with_plugin: nil, config: {}, eval_plugin: :false)
|
14
|
+
setup_env(config)
|
15
|
+
self.instance_variable_set(:@raw_plugin, with_plugin)
|
16
|
+
self.class.send(:define_method, :available_plugins, fake_code)
|
17
|
+
self.plugins_eval if eval_plugin
|
18
|
+
end
|
19
|
+
|
20
|
+
module_function
|
21
|
+
|
22
|
+
def fake_code
|
23
|
+
proc do
|
24
|
+
env = prepare_env
|
25
|
+
@fake_plugin = CaptainHoog::Plugin.new(@raw_plugin, env)
|
26
|
+
@fake_plugin.eval_plugin
|
27
|
+
[@fake_plugin]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def setup_env(configuration)
|
32
|
+
configuration.keys.each do |key|
|
33
|
+
self.send("#{key}_configuration", configuration)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def env_configuration(configuration)
|
38
|
+
suppress_headline = configuration[:env].fetch(:suppress_headline, false)
|
39
|
+
self.class.suppress_headline = suppress_headline
|
40
|
+
end
|
41
|
+
|
42
|
+
def plugin_configuration(configuration)
|
43
|
+
self.class.plugins_conf = CaptainHoog::Struct.new(configuration[:plugin])
|
44
|
+
end
|
45
|
+
|
46
|
+
def headline_on_success_configuration(configuration)
|
47
|
+
headline = configuration[:env].fetch(:headline_on_success)
|
48
|
+
self.class.headline_on_success = headline
|
49
|
+
end
|
50
|
+
|
51
|
+
def headline_on_failure_configuration(configuration)
|
52
|
+
headline = configuration[:env].fetch(:headline_on_failure)
|
53
|
+
self.class.headline_on_failure = headline
|
54
|
+
end
|
55
|
+
|
56
|
+
def method_missing(meth_name, *args, &block)
|
57
|
+
super unless meth_name.include?('_configuration')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def initialize(raw_plugin, config = {})
|
62
|
+
@raw_plugin = guess_plugin(raw_plugin)
|
63
|
+
@configuration = config
|
64
|
+
init_plugin
|
65
|
+
end
|
66
|
+
|
67
|
+
def run
|
68
|
+
@plugin = @pre_git.fake_plugin
|
69
|
+
mod = Module.new do
|
70
|
+
def result
|
71
|
+
eigenplugin = self.send(:eigenplugin)
|
72
|
+
git = eigenplugin.instance_variable_get(:@git)
|
73
|
+
{
|
74
|
+
test: git.instance_variable_get(:@test_result),
|
75
|
+
message: git.instance_variable_get(:@message)
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
@plugin.extend(mod)
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def init_plugin
|
85
|
+
@pre_git = CaptainHoog::PreGit.new
|
86
|
+
@pre_git.extend(CaptainHoog::Test::Sandbox::FakePlugin)
|
87
|
+
@pre_git.fake(with_plugin: @raw_plugin, config: configuration)
|
88
|
+
@pre_git.plugins_eval
|
89
|
+
end
|
90
|
+
|
91
|
+
def guess_plugin(plugin_code)
|
92
|
+
prefix = 'CaptainHoog::Test::PluginStrategies'
|
93
|
+
types = %w(File String NullObject)
|
94
|
+
strategies = types.inject([]) do |result, strategy|
|
95
|
+
result << Module.const_get("#{prefix}::#{strategy}").new(plugin_code)
|
96
|
+
result
|
97
|
+
end
|
98
|
+
strategies.detect(&:match?).to_s
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module CaptainHoog
|
2
|
+
module Test
|
3
|
+
module PluginStrategies
|
4
|
+
module Initializer
|
5
|
+
def initialize(plugin)
|
6
|
+
@plugin = plugin
|
7
|
+
end
|
8
|
+
|
9
|
+
def match?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
@plugin
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class File
|
19
|
+
include Initializer
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
::File.read(@plugin)
|
23
|
+
end
|
24
|
+
|
25
|
+
def match?
|
26
|
+
@plugin.is_a?(::File)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class String
|
31
|
+
include Initializer
|
32
|
+
|
33
|
+
def match?
|
34
|
+
@plugin.is_a?(String)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class NullObject
|
43
|
+
include Initializer
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/captain_hoog/version.rb
CHANGED
File without changes
|
File without changes
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Rspec support' do
|
4
|
+
let(:foo) do
|
5
|
+
<<-PLUGIN
|
6
|
+
git.describe 'foo' do |hook|
|
7
|
+
hook.helper :foo_helper do
|
8
|
+
config.number
|
9
|
+
end
|
10
|
+
|
11
|
+
hook.test do
|
12
|
+
foo_helper
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
hook.message do
|
17
|
+
'Fun'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
PLUGIN
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:config) do
|
24
|
+
{
|
25
|
+
env: {
|
26
|
+
suppress_headline: true
|
27
|
+
},
|
28
|
+
plugin: {
|
29
|
+
foo: {
|
30
|
+
number: 12
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
with_plugin :foo, config: :config, silence: true do
|
37
|
+
describe 'helpers' do
|
38
|
+
it 'plugin has helper :foo_helper' do
|
39
|
+
expect(plugin).to respond_to(:foo_helper)
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ':foo_helper' do
|
43
|
+
it 'returns configured number' do
|
44
|
+
expect(plugin.foo_helper).to eq config[:plugin][:foo][:number]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'plugin test' do
|
50
|
+
it 'is true' do
|
51
|
+
expect(plugin.result[:test]).to be true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'success message' do
|
56
|
+
it 'prints out "Fun"' do
|
57
|
+
expect(plugin.result[:message]).to eq 'Fun'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CaptainHoog::Test::Sandbox do
|
4
|
+
let(:config) do
|
5
|
+
{
|
6
|
+
env: {
|
7
|
+
suppress_headline: true
|
8
|
+
}
|
9
|
+
}
|
10
|
+
end
|
11
|
+
describe 'methods' do
|
12
|
+
let(:null_plugin) do
|
13
|
+
<<-PLUGIN
|
14
|
+
git.describe 'null' do |hook|
|
15
|
+
hook.run {}
|
16
|
+
end
|
17
|
+
PLUGIN
|
18
|
+
end
|
19
|
+
|
20
|
+
subject do
|
21
|
+
described_class.new(null_plugin, config)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'provides #run' do
|
25
|
+
expect(subject).to respond_to(:run)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'provides #configuration' do
|
29
|
+
expect(subject).to respond_to(:configuration)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'provides #plugin' do
|
33
|
+
expect(subject).to respond_to(:plugin)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#run' do
|
38
|
+
context 'a plugin given as String' do
|
39
|
+
|
40
|
+
let(:plugin) do
|
41
|
+
<<-PLUGIN
|
42
|
+
git.describe 'foo' do |hook|
|
43
|
+
hook.helper :foo_helper do
|
44
|
+
config.number
|
45
|
+
end
|
46
|
+
|
47
|
+
hook.test do
|
48
|
+
foo_helper
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
hook.message do
|
53
|
+
'Fun'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
PLUGIN
|
57
|
+
end
|
58
|
+
|
59
|
+
let(:sandbox) do
|
60
|
+
plugins_config = {
|
61
|
+
plugin: {
|
62
|
+
foo: {
|
63
|
+
number: 12
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
cfg = config.merge(plugins_config)
|
68
|
+
CaptainHoog::Test::Sandbox.new(plugin, cfg)
|
69
|
+
end
|
70
|
+
|
71
|
+
before do
|
72
|
+
sandbox.run
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'assigns evaluated plugin to #plugin' do
|
76
|
+
expect(sandbox.plugin).to_not be nil
|
77
|
+
expect(sandbox.plugin).to respond_to(:foo_helper)
|
78
|
+
expect(sandbox.plugin.foo_helper).to eq 12
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#plugin" do
|
82
|
+
it 'provides #result' do
|
83
|
+
expect(sandbox.plugin).to respond_to(:result)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'provides access to helper' do
|
87
|
+
expect(sandbox.plugin.foo_helper).to eq 12
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#result' do
|
91
|
+
it 'has :test key' do
|
92
|
+
expect(sandbox.plugin.result).to have_key(:test)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'has :message key' do
|
96
|
+
expect(sandbox.plugin.result).to have_key(:message)
|
97
|
+
expect(sandbox.plugin.result[:message]).to eq 'Fun'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'a plugin given as file path' do
|
104
|
+
let(:path) do
|
105
|
+
File.expand_path(File.join(File.dirname(__FILE__),
|
106
|
+
"..",
|
107
|
+
"..",
|
108
|
+
"..",
|
109
|
+
"..",
|
110
|
+
"spec",
|
111
|
+
"fixtures",
|
112
|
+
"plugins",
|
113
|
+
"test_plugins",
|
114
|
+
"passing",
|
115
|
+
"simple",
|
116
|
+
"simple.rb"))
|
117
|
+
end
|
118
|
+
let(:sandbox) do
|
119
|
+
plugin_config = {
|
120
|
+
plugin: {
|
121
|
+
simple: {
|
122
|
+
runtime_count: 19.6
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
CaptainHoog::Test::Sandbox.new(File.new(path, 'r'),
|
127
|
+
config.merge(plugin_config))
|
128
|
+
end
|
129
|
+
|
130
|
+
before do
|
131
|
+
sandbox.run
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'assigns evaluated plugin to #plugin' do
|
135
|
+
expect(sandbox.plugin).to_not be nil
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "#plugin" do
|
139
|
+
it 'provides #result' do
|
140
|
+
expect(sandbox.plugin).to respond_to(:result)
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#result' do
|
144
|
+
it 'has :test key' do
|
145
|
+
expect(sandbox.plugin.result).to have_key(:test)
|
146
|
+
expect(sandbox.plugin.result[:test]).to be false
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'has :message key' do
|
150
|
+
expect(sandbox.plugin.result).to have_key(:message)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: captain_hoog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schmidt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -134,6 +134,20 @@ dependencies:
|
|
134
134
|
- - ">="
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: minitest
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
137
151
|
description:
|
138
152
|
email:
|
139
153
|
- daniel.schmidt@gateprotect.com
|
@@ -159,6 +173,7 @@ files:
|
|
159
173
|
- features/support/env.rb
|
160
174
|
- features/support/steps/hooks_steps.rb
|
161
175
|
- features/support/world.rb
|
176
|
+
- features/testing.feature
|
162
177
|
- features/version.feature
|
163
178
|
- lib/captain_hoog.rb
|
164
179
|
- lib/captain_hoog/config/hook_types.yml
|
@@ -178,14 +193,20 @@ files:
|
|
178
193
|
- lib/captain_hoog/struct/hoog_struct.rb
|
179
194
|
- lib/captain_hoog/templates/hoogfile.erb
|
180
195
|
- lib/captain_hoog/templates/install.erb
|
196
|
+
- lib/captain_hoog/test.rb
|
197
|
+
- lib/captain_hoog/test/all.rb
|
198
|
+
- lib/captain_hoog/test/rspec.rb
|
199
|
+
- lib/captain_hoog/test/sandbox.rb
|
200
|
+
- lib/captain_hoog/test/strategies.rb
|
181
201
|
- lib/captain_hoog/version.rb
|
182
202
|
- spec/fixtures/code/helper.rb
|
183
203
|
- spec/fixtures/config/cucumber/hoogfile.yml
|
184
204
|
- spec/fixtures/config/spec/hoogfile.yml
|
185
205
|
- spec/fixtures/plugins/shared/passing/simple_shared.rb
|
206
|
+
- spec/fixtures/plugins/test_plugins/divide.rb
|
186
207
|
- spec/fixtures/plugins/test_plugins/failing/simple.rb
|
187
|
-
- spec/fixtures/plugins/test_plugins/passing/pure/foo.rb
|
188
|
-
- spec/fixtures/plugins/test_plugins/passing/simple.rb
|
208
|
+
- spec/fixtures/plugins/test_plugins/passing/pure/foo/foo.rb
|
209
|
+
- spec/fixtures/plugins/test_plugins/passing/simple/simple.rb
|
189
210
|
- spec/fixtures/pre-commit-fail
|
190
211
|
- spec/fixtures/pre-commit-pass
|
191
212
|
- spec/lib/captain_hoog/env_spec.rb
|
@@ -194,6 +215,8 @@ files:
|
|
194
215
|
- spec/lib/captain_hoog/plugin_list_spec.rb
|
195
216
|
- spec/lib/captain_hoog/plugin_spec.rb
|
196
217
|
- spec/lib/captain_hoog/pre_git_spec.rb
|
218
|
+
- spec/lib/captain_hoog/test/rspec_spec.rb
|
219
|
+
- spec/lib/captain_hoog/test/sandbox_spec.rb
|
197
220
|
- spec/spec_helper.rb
|
198
221
|
- spec/support/matchers/be_subclass_of.rb
|
199
222
|
homepage: ''
|
@@ -219,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
242
|
version: '0'
|
220
243
|
requirements: []
|
221
244
|
rubyforge_project:
|
222
|
-
rubygems_version: 2.4.
|
245
|
+
rubygems_version: 2.4.6
|
223
246
|
signing_key:
|
224
247
|
specification_version: 4
|
225
248
|
summary: Plugin based git-pre hook.
|
@@ -232,14 +255,16 @@ test_files:
|
|
232
255
|
- features/support/env.rb
|
233
256
|
- features/support/steps/hooks_steps.rb
|
234
257
|
- features/support/world.rb
|
258
|
+
- features/testing.feature
|
235
259
|
- features/version.feature
|
236
260
|
- spec/fixtures/code/helper.rb
|
237
261
|
- spec/fixtures/config/cucumber/hoogfile.yml
|
238
262
|
- spec/fixtures/config/spec/hoogfile.yml
|
239
263
|
- spec/fixtures/plugins/shared/passing/simple_shared.rb
|
264
|
+
- spec/fixtures/plugins/test_plugins/divide.rb
|
240
265
|
- spec/fixtures/plugins/test_plugins/failing/simple.rb
|
241
|
-
- spec/fixtures/plugins/test_plugins/passing/pure/foo.rb
|
242
|
-
- spec/fixtures/plugins/test_plugins/passing/simple.rb
|
266
|
+
- spec/fixtures/plugins/test_plugins/passing/pure/foo/foo.rb
|
267
|
+
- spec/fixtures/plugins/test_plugins/passing/simple/simple.rb
|
243
268
|
- spec/fixtures/pre-commit-fail
|
244
269
|
- spec/fixtures/pre-commit-pass
|
245
270
|
- spec/lib/captain_hoog/env_spec.rb
|
@@ -248,6 +273,8 @@ test_files:
|
|
248
273
|
- spec/lib/captain_hoog/plugin_list_spec.rb
|
249
274
|
- spec/lib/captain_hoog/plugin_spec.rb
|
250
275
|
- spec/lib/captain_hoog/pre_git_spec.rb
|
276
|
+
- spec/lib/captain_hoog/test/rspec_spec.rb
|
277
|
+
- spec/lib/captain_hoog/test/sandbox_spec.rb
|
251
278
|
- spec/spec_helper.rb
|
252
279
|
- spec/support/matchers/be_subclass_of.rb
|
253
280
|
has_rdoc:
|