vendorificator 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/CHANGELOG.md +40 -0
- data/Gemfile +2 -2
- data/README.md +18 -17
- data/Rakefile +15 -1
- data/features/edgecases.feature +34 -0
- data/features/environment.feature +17 -0
- data/features/fixtures/git/testrepo/objects/53/ac1a96882e666cee31504179abc21eac522f8d +2 -0
- data/features/fixtures/git/testrepo/refs/tags/email-v0 +1 -0
- data/features/git.feature +19 -1
- data/features/status.feature +1 -1
- data/features/step_definitions/basic.rb +11 -0
- data/features/step_definitions/git.rb +12 -0
- data/features/support/env.rb +3 -4
- data/features/support/minigit.rb +4 -0
- data/lib/vendorificator/cli.rb +32 -44
- data/lib/vendorificator/config.rb +63 -15
- data/lib/vendorificator/environment.rb +123 -16
- data/lib/vendorificator/errors.rb +3 -0
- data/lib/vendorificator/hooks/chef_cookbook.rb +1 -1
- data/lib/vendorificator/vendor/archive.rb +69 -65
- data/lib/vendorificator/vendor/chef_cookbook.rb +45 -39
- data/lib/vendorificator/vendor/download.rb +30 -26
- data/lib/vendorificator/vendor/git.rb +43 -32
- data/lib/vendorificator/vendor.rb +83 -91
- data/lib/vendorificator/version.rb +1 -1
- data/lib/vendorificator.rb +1 -0
- data/spec/spec_helper.rb +20 -22
- data/spec/vendorificator/config_spec.rb +64 -0
- data/spec/vendorificator/environment_spec.rb +81 -0
- data/spec/vendorificator/fixtures/vendorfiles/empty_vendor.rb +1 -0
- data/spec/vendorificator/fixtures/vendorfiles/vendor.rb +15 -0
- data/spec/vendorificator/vendor/chef_cookbook_spec.rb +13 -0
- data/spec/vendorificator/vendor_spec.rb +29 -33
- data/vendorificator.gemspec +3 -3
- metadata +45 -30
@@ -10,17 +10,6 @@ module Vendorificator
|
|
10
10
|
class << self
|
11
11
|
attr_accessor :category, :method_name
|
12
12
|
|
13
|
-
# Define a method on Vendorificator::Config to add the
|
14
|
-
# vendor module to the module definition list.
|
15
|
-
def install!
|
16
|
-
@method_name ||= self.name.split('::').last.downcase.to_sym
|
17
|
-
_cls = self # for self is obscured in define_method block's body
|
18
|
-
( class << Vendorificator::Config ; self ; end ).
|
19
|
-
send(:define_method, @method_name ) do |name, *args, &block|
|
20
|
-
_cls.new(self.environment, name.to_s, *args, &block)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
13
|
def arg_reader(*names)
|
25
14
|
names.each do |name|
|
26
15
|
define_method(name) do
|
@@ -28,44 +17,6 @@ module Vendorificator
|
|
28
17
|
end
|
29
18
|
end
|
30
19
|
end
|
31
|
-
|
32
|
-
def [](*key)
|
33
|
-
return key.map { |k| self[k] }.flatten if key.length > 1
|
34
|
-
|
35
|
-
key = key.first
|
36
|
-
|
37
|
-
if key.is_a?(Fixnum)
|
38
|
-
self.instances[key]
|
39
|
-
else
|
40
|
-
instances.select { |i| i === key }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def each(*modules)
|
45
|
-
modpaths = modules.map { |m| File.expand_path(m) }
|
46
|
-
|
47
|
-
# We don't use instances.each here, because Vendor#run! is
|
48
|
-
# explicitly allowed to append to instantiate new
|
49
|
-
# dependencies, and #each fails to catch up on some Ruby
|
50
|
-
# implementations.
|
51
|
-
i = 0
|
52
|
-
while true
|
53
|
-
break if i >= instances.length
|
54
|
-
mod = instances[i]
|
55
|
-
yield mod if modules.empty? ||
|
56
|
-
modules.include?(mod.name) ||
|
57
|
-
modpaths.include?(mod.work_dir)
|
58
|
-
i += 1
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def instances
|
63
|
-
Vendorificator::Vendor.instance_eval { @instances ||= [] }
|
64
|
-
end
|
65
|
-
|
66
|
-
def compute_dependencies!
|
67
|
-
self.instances.each(&:compute_dependencies!)
|
68
|
-
end
|
69
20
|
end
|
70
21
|
|
71
22
|
attr_reader :environment, :name, :args, :block
|
@@ -75,11 +26,18 @@ module Vendorificator
|
|
75
26
|
@environment = environment
|
76
27
|
@category = args.delete(:category) if args.key?(:category)
|
77
28
|
|
29
|
+
unless (hooks = Array(args.delete(:hooks))).empty?
|
30
|
+
hooks.each do |hook|
|
31
|
+
hook_module = hook.is_a?(Module) ? hook : ::Vendorificator::Hooks.const_get(hook)
|
32
|
+
klass = class << self; self; end;
|
33
|
+
klass.send :include, hook_module
|
34
|
+
end
|
35
|
+
end
|
78
36
|
@name = name
|
79
37
|
@args = args
|
80
38
|
@block = block
|
81
39
|
|
82
|
-
|
40
|
+
@environment.vendor_instances << self
|
83
41
|
end
|
84
42
|
|
85
43
|
def ===(other)
|
@@ -91,20 +49,15 @@ module Vendorificator
|
|
91
49
|
end
|
92
50
|
|
93
51
|
def shell
|
94
|
-
@shell ||=
|
95
|
-
environment.config[:shell] || Thor::Shell::Basic.new
|
52
|
+
@shell ||= config[:shell] || Thor::Shell::Basic.new
|
96
53
|
end
|
97
54
|
|
98
55
|
def category
|
99
|
-
|
100
|
-
@category
|
101
|
-
else
|
102
|
-
self.class.category
|
103
|
-
end
|
56
|
+
defined?(@category) ? @category : self.class.category
|
104
57
|
end
|
105
58
|
|
106
59
|
def branch_name
|
107
|
-
_join(
|
60
|
+
_join(config[:branch_prefix], category, name)
|
108
61
|
end
|
109
62
|
|
110
63
|
def to_s
|
@@ -116,21 +69,15 @@ module Vendorificator
|
|
116
69
|
end
|
117
70
|
|
118
71
|
def work_subdir
|
119
|
-
_join(
|
72
|
+
_join(config[:basedir], path)
|
120
73
|
end
|
121
74
|
|
122
75
|
def work_dir
|
123
|
-
_join(
|
76
|
+
_join(config[:root_dir], work_subdir)
|
124
77
|
end
|
125
78
|
|
126
79
|
def head
|
127
|
-
|
128
|
-
rescue MiniGit::GitError
|
129
|
-
nil
|
130
|
-
end
|
131
|
-
|
132
|
-
def tagged_sha1
|
133
|
-
@tagged_sha1 ||= environment.git.capturing.rev_parse({:verify => true}, "refs/tags/#{tag_name}^{commit}").strip
|
80
|
+
git.capturing.rev_parse({:verify => true, :quiet => true}, "refs/heads/#{branch_name}").strip
|
134
81
|
rescue MiniGit::GitError
|
135
82
|
nil
|
136
83
|
end
|
@@ -138,7 +85,7 @@ module Vendorificator
|
|
138
85
|
def merged
|
139
86
|
unless @_has_merged
|
140
87
|
if ( head = self.head )
|
141
|
-
merged =
|
88
|
+
merged = git.capturing.merge_base(head, 'HEAD').strip
|
142
89
|
@merged = merged unless merged.empty?
|
143
90
|
end
|
144
91
|
@_has_merged = true
|
@@ -149,7 +96,7 @@ module Vendorificator
|
|
149
96
|
def merged_tag
|
150
97
|
unless @_has_merged_tag
|
151
98
|
if merged
|
152
|
-
tag =
|
99
|
+
tag = git.capturing.describe( {
|
153
100
|
:exact_match => true,
|
154
101
|
:match => _join(tag_name_base, '*') },
|
155
102
|
merged).strip
|
@@ -165,7 +112,7 @@ module Vendorificator
|
|
165
112
|
end
|
166
113
|
|
167
114
|
def version
|
168
|
-
@args[:version] || (!
|
115
|
+
@args[:version] || (!config[:use_upstream_version] && merged_version) || upstream_version
|
169
116
|
end
|
170
117
|
|
171
118
|
def upstream_version
|
@@ -176,7 +123,7 @@ module Vendorificator
|
|
176
123
|
return nil if self.status == :up_to_date
|
177
124
|
return false if !head
|
178
125
|
return false if head && merged == head
|
179
|
-
|
126
|
+
git.describe({:abbrev => 0, :always => true}, branch_name)
|
180
127
|
end
|
181
128
|
|
182
129
|
def status
|
@@ -205,25 +152,44 @@ module Vendorificator
|
|
205
152
|
|
206
153
|
def in_branch(options={}, &block)
|
207
154
|
orig_branch = environment.current_branch
|
155
|
+
stash_message = "vendorificator-#{git.capturing.rev_parse('HEAD').strip}-#{branch_name}-#{Time.now.to_i}"
|
208
156
|
|
209
157
|
# We want to be in repository's root now, as we may need to
|
210
158
|
# remove stuff and don't want to have removed directory as cwd.
|
211
|
-
Dir::chdir
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
159
|
+
Dir::chdir git.git_work_tree do
|
160
|
+
begin
|
161
|
+
# Stash all local changes
|
162
|
+
git.stash :save, {:all => true, :quiet => true}, stash_message
|
163
|
+
|
164
|
+
# If our branch exists, check it out; otherwise, create a new
|
165
|
+
# orphaned branch.
|
166
|
+
if self.head
|
167
|
+
git.checkout branch_name
|
168
|
+
git.rm( { :r => true, :f => true, :q => true, :ignore_unmatch => true }, '.') if options[:clean]
|
169
|
+
else
|
170
|
+
git.checkout( { :orphan => true }, branch_name )
|
171
|
+
git.rm( { :r => true, :f => true, :q => true, :ignore_unmatch => true }, '.')
|
172
|
+
end
|
173
|
+
|
174
|
+
yield
|
175
|
+
ensure
|
176
|
+
# We should try to ensure we're back on original branch and
|
177
|
+
# local changes have been applied
|
178
|
+
begin
|
179
|
+
git.checkout orig_branch
|
180
|
+
stash = git.capturing.
|
181
|
+
stash(:list, {:grep => stash_message, :fixed_strings => true}).lines.map(&:strip)
|
182
|
+
if stash.length > 1
|
183
|
+
shell.say_status 'WARNING', "more than one stash matches #{stash_message}, it's weird", :yellow
|
184
|
+
stash.each { |ln| shell.say_status '-', ln, :yellow }
|
185
|
+
end
|
186
|
+
git.stash :pop, {:quiet => true}, stash.first.sub(/:.*/, '') unless stash.empty?
|
187
|
+
rescue => e
|
188
|
+
shell.say_status 'ERROR', "Cannot revert branch from #{self.head} back to #{orig_branch}: #{e}", :red
|
189
|
+
raise
|
190
|
+
end
|
220
191
|
end
|
221
192
|
end
|
222
|
-
|
223
|
-
yield
|
224
|
-
ensure
|
225
|
-
# We should try to ensure we're back on original branch
|
226
|
-
environment.git.checkout orig_branch if defined?(orig_branch) rescue nil
|
227
193
|
end
|
228
194
|
|
229
195
|
def run!
|
@@ -234,7 +200,7 @@ module Vendorificator
|
|
234
200
|
|
235
201
|
when :unpulled, :unmerged
|
236
202
|
shell.say_status 'merging', self.to_s, :yellow
|
237
|
-
|
203
|
+
git.merge({:no_edit => true, :no_ff => true}, tagged_sha1)
|
238
204
|
compute_dependencies!
|
239
205
|
|
240
206
|
when :outdated, :new
|
@@ -259,13 +225,13 @@ module Vendorificator
|
|
259
225
|
|
260
226
|
|
261
227
|
# Commit and tag the conjured module
|
262
|
-
|
263
|
-
|
264
|
-
|
228
|
+
git.add work_dir
|
229
|
+
git.commit :m => conjure_commit_message
|
230
|
+
git.tag( { :a => true, :m => tag_message }, tag_name )
|
265
231
|
shell.say_status :tag, tag_name
|
266
232
|
end
|
267
233
|
# Merge back to the original branch
|
268
|
-
|
234
|
+
git.merge( {:no_edit => true, :no_ff => true}, branch_name )
|
269
235
|
compute_dependencies!
|
270
236
|
ensure
|
271
237
|
shell.padding -= 1
|
@@ -298,8 +264,33 @@ module Vendorificator
|
|
298
264
|
|
299
265
|
def compute_dependencies! ; end
|
300
266
|
|
267
|
+
def pushable_refs
|
268
|
+
branch = "+refs/heads/#{branch_name}"
|
269
|
+
tags = created_tags.map{ |tag| '+' + tag }
|
270
|
+
[branch, tags].flatten
|
271
|
+
end
|
272
|
+
|
301
273
|
private
|
302
274
|
|
275
|
+
def tagged_sha1
|
276
|
+
@tagged_sha1 ||= git.capturing.rev_parse({:verify => true, :quiet => true}, "refs/tags/#{tag_name}^{commit}").strip
|
277
|
+
rescue MiniGit::GitError
|
278
|
+
nil
|
279
|
+
end
|
280
|
+
|
281
|
+
def created_tags
|
282
|
+
git.capturing.show_ref.split("\n").map{ |line| line.split(' ')[1] }.
|
283
|
+
select{ |ref| ref =~ /\Arefs\/tags\/#{tag_name_base}/ }
|
284
|
+
end
|
285
|
+
|
286
|
+
def git
|
287
|
+
environment.git
|
288
|
+
end
|
289
|
+
|
290
|
+
def config
|
291
|
+
environment.config
|
292
|
+
end
|
293
|
+
|
303
294
|
def _join(*parts)
|
304
295
|
parts.compact.map(&:to_s).join('/')
|
305
296
|
end
|
@@ -318,6 +309,7 @@ module Vendorificator
|
|
318
309
|
Dir.chdir(curdir.to_s) if curdir.exist?
|
319
310
|
end
|
320
311
|
|
321
|
-
install!
|
322
312
|
end
|
313
|
+
|
314
|
+
Config.register_module :vendor, Vendor
|
323
315
|
end
|
data/lib/vendorificator.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -16,6 +16,16 @@ else
|
|
16
16
|
MiniTest::ANSI.use! if STDOUT.tty?
|
17
17
|
end
|
18
18
|
|
19
|
+
if ENV['COVERAGE']
|
20
|
+
require 'simplecov'
|
21
|
+
SimpleCov.start do
|
22
|
+
add_filter '/spec/'
|
23
|
+
add_group 'Vendors', 'lib/vendorificator/vendor'
|
24
|
+
use_merging
|
25
|
+
end
|
26
|
+
SimpleCov.command_name 'rake spec'
|
27
|
+
end
|
28
|
+
|
19
29
|
require 'vendorificator'
|
20
30
|
|
21
31
|
VCR.configure do |config|
|
@@ -24,34 +34,22 @@ VCR.configure do |config|
|
|
24
34
|
config.hook_into :webmock
|
25
35
|
end
|
26
36
|
|
27
|
-
Vendorificator::Config[:root_dir] = Pathname.new(__FILE__).dirname
|
28
|
-
|
29
37
|
class MiniTest::Spec
|
30
|
-
|
31
|
-
Vendorificator::
|
38
|
+
before do
|
39
|
+
Vendorificator::Environment.any_instance.stubs(:git).returns(stub)
|
32
40
|
end
|
33
41
|
|
34
|
-
|
35
|
-
@
|
36
|
-
@saved_methods = conf.methods
|
42
|
+
def conf
|
43
|
+
@conf ||= Vendorificator::Config.new
|
37
44
|
end
|
38
45
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
class << conf
|
44
|
-
Vendorificator::Config[:methods_to_remove!].each do |method_to_remove|
|
45
|
-
remove_method method_to_remove
|
46
|
-
end
|
47
|
-
end
|
48
|
-
assert { conf.methods.sort == @saved_methods.sort }
|
49
|
-
|
50
|
-
# Restore saved configuration
|
51
|
-
conf.configuration = @saved_configuration
|
46
|
+
def basic_environment
|
47
|
+
@basic_environment ||= Vendorificator::Environment.new(
|
48
|
+
'spec/vendorificator/fixtures/vendorfiles/empty_vendor.rb'
|
49
|
+
)
|
52
50
|
end
|
53
51
|
|
54
|
-
def
|
55
|
-
|
52
|
+
def includes_method?(obj, method)
|
53
|
+
(obj.methods.include? method.to_sym) || (obj.methods.include? method.to_s)
|
56
54
|
end
|
57
55
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
module Vendorificator
|
4
|
+
describe Config do
|
5
|
+
let(:config){ Config.new }
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it' creates a Config object' do
|
9
|
+
assert { config.is_a? Config }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'allows to overwrite the default configuration' do
|
13
|
+
config = Config.new(:basedir => 'different/basedir')
|
14
|
+
assert { config[:basedir] == 'different/basedir' }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'allows to set and get values' do
|
19
|
+
assert { config[:new_value] == nil }
|
20
|
+
config[:new_value] = 'new value'
|
21
|
+
|
22
|
+
assert { config[:new_value] == 'new value' }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'extensions' do
|
26
|
+
before do
|
27
|
+
class Config
|
28
|
+
option :custom_option, :default_value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'allows to define custom options' do
|
33
|
+
assert { includes_method? Config.new, :custom_option }
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'allows to get custom_option value via method' do
|
37
|
+
assert { Config.new.custom_option == :default_value }
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'allows to set custom_option via method' do
|
41
|
+
config.custom_option :custom_value
|
42
|
+
assert { config[:custom_option] == :custom_value }
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'sets a default value for custom option' do
|
46
|
+
assert { Config.new[:custom_option] == :default_value }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'options' do
|
51
|
+
it 'have default values' do
|
52
|
+
assert { config[:basedir] == 'vendor' }
|
53
|
+
assert { config[:branch_prefix] == 'vendor' }
|
54
|
+
assert { config[:remotes] == %w(origin) }
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'can be set' do
|
58
|
+
assert { includes_method? config, :basedir }
|
59
|
+
assert { includes_method? config, :branch_prefix }
|
60
|
+
assert { includes_method? config, :remotes }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Vendorificator
|
4
|
+
describe Environment do
|
5
|
+
before do
|
6
|
+
MiniGit.any_instance.stubs(:fetch)
|
7
|
+
end
|
8
|
+
let(:environment){ Environment.new 'spec/vendorificator/fixtures/vendorfiles/vendor.rb' }
|
9
|
+
|
10
|
+
describe '#clean' do
|
11
|
+
it 'returns false for dirty repo' do
|
12
|
+
git_error = MiniGit::GitError.new(['command'], 'status')
|
13
|
+
environment.git.expects(:update_index).raises(git_error)
|
14
|
+
|
15
|
+
assert { environment.clean? == false }
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns true for a clean repo' do
|
19
|
+
environment.git.expects(:update_index)
|
20
|
+
environment.git.expects(:diff_files)
|
21
|
+
environment.git.expects(:diff_index)
|
22
|
+
|
23
|
+
assert { environment.clean? == true }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#pull_all' do
|
28
|
+
it 'aborts on a dirty repo' do
|
29
|
+
environment.expects(:clean?).returns(false)
|
30
|
+
|
31
|
+
assert { rescuing { environment.pull_all }.is_a? DirtyRepoError }
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'pulls multiple remotes if specified' do
|
35
|
+
environment.stubs(:clean?).returns(true)
|
36
|
+
environment.expects(:pull).with('origin_1', anything)
|
37
|
+
environment.expects(:pull).with('origin_2', anything)
|
38
|
+
|
39
|
+
environment.pull_all(:remote => 'origin_1,origin_2')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#pull' do
|
44
|
+
it "creates a branch if it doesn't exist" do
|
45
|
+
Environment.any_instance.unstub(:git)
|
46
|
+
environment.git.capturing.stubs(:show_ref).
|
47
|
+
returns("602315 refs/remotes/origin/vendor/test")
|
48
|
+
environment.vendor_instances = [ stub(:branch_name => 'vendor/test', :head => nil)]
|
49
|
+
|
50
|
+
environment.git.expects(:branch).with({:track => true}, 'vendor/test', '602315')
|
51
|
+
environment.pull('origin')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "handles fast forwardable branches" do
|
55
|
+
Environment.any_instance.unstub(:git)
|
56
|
+
environment.git.capturing.stubs(:show_ref).
|
57
|
+
returns("602315 refs/remotes/origin/vendor/test")
|
58
|
+
environment.vendor_instances = [stub(
|
59
|
+
:branch_name => 'vendor/test', :head => '123456', :in_branch => true, :name => 'test'
|
60
|
+
)]
|
61
|
+
|
62
|
+
environment.expects(:fast_forwardable?).returns(true)
|
63
|
+
environment.pull('origin')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#vendor_instances' do
|
68
|
+
let(:environment){ Environment.new 'spec/vendorificator/fixtures/vendorfiles/empty_vendor.rb' }
|
69
|
+
|
70
|
+
it 'is initialized on a new environment' do
|
71
|
+
assert { environment.vendor_instances == [] }
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'allows to add/read instances' do
|
75
|
+
environment.vendor_instances << :foo
|
76
|
+
assert { environment.vendor_instances == [:foo] }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Empty vendor file, just for stubbing purposes.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Just an example config
|
2
|
+
|
3
|
+
vendor 'name', :option => 'value' do
|
4
|
+
# here in the block you code what needs to be done
|
5
|
+
# to get ("conjure") the module. You're already in
|
6
|
+
# the right directory, branch, etc, and what you add to the
|
7
|
+
# current directory will be committed and tagged.
|
8
|
+
end
|
9
|
+
|
10
|
+
vendor 'other_name', :option => 'other_value' do
|
11
|
+
# here in the block you code what needs to be done
|
12
|
+
# to get ("conjure") the module. You're already in
|
13
|
+
# the right directory, branch, etc, and what you add to the
|
14
|
+
# current directory will be committed and tagged.
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path("../../../spec_helper", __FILE__)
|
2
|
+
|
3
|
+
module Vendorificator
|
4
|
+
describe Vendor::ChefCookbook do
|
5
|
+
describe 'config extensions' do
|
6
|
+
describe 'options' do
|
7
|
+
it 'registers chef_cookbook_ignore_dependencies' do
|
8
|
+
assert { includes_method? Config.new, :chef_cookbook_ignore_dependencies }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# Note that due to git operations involved, most of the Vendor class is tested
|
2
|
+
# with cucumber features instead.
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Vendorificator
|
@@ -20,50 +22,24 @@ module Vendorificator
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
describe '.install!' do
|
24
|
-
it "creates a method inside Vendorificator::Config" do
|
25
|
-
deny { conf.respond_to?(:categorized) }
|
26
|
-
|
27
|
-
Vendor::Categorized.install!
|
28
|
-
assert { conf.respond_to?(:categorized) }
|
29
|
-
end
|
30
|
-
|
31
|
-
it "uses @method_name for method's name if set" do
|
32
|
-
deny { conf.respond_to?(:custom) }
|
33
|
-
deny { conf.respond_to?(:whatever) }
|
34
|
-
|
35
|
-
Vendor::Custom.install!
|
36
|
-
deny { conf.respond_to?(:custom) }
|
37
|
-
assert { conf.respond_to?(:whatever) }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
25
|
describe '#category' do
|
42
26
|
it 'defaults to class attribute' do
|
43
|
-
assert { Vendor.new(
|
44
|
-
assert { Vendor::Categorized.new(
|
27
|
+
assert { Vendor.new(basic_environment, 'test').category == nil }
|
28
|
+
assert { Vendor::Categorized.new(basic_environment, 'test').category == :test }
|
45
29
|
end
|
46
30
|
|
47
31
|
it 'can be overriden by option' do
|
48
|
-
assert { Vendor.new(
|
49
|
-
assert { Vendor::Categorized.new(
|
32
|
+
assert { Vendor.new(basic_environment, 'test', :category => :foo).category == :foo }
|
33
|
+
assert { Vendor::Categorized.new(basic_environment, 'test', :category => :foo).category == :foo }
|
50
34
|
end
|
51
35
|
|
52
36
|
it 'can be reset to nil by option' do
|
53
|
-
assert { Vendor::Categorized.new(
|
37
|
+
assert { Vendor::Categorized.new(basic_environment, 'test', :category => nil).category == nil }
|
54
38
|
end
|
55
39
|
|
56
40
|
it 'is inserted into paths and other names' do
|
57
|
-
|
58
|
-
|
59
|
-
:capturing => stub(
|
60
|
-
:rev_parse => 'cafe',
|
61
|
-
:merge_base => 'cafe',
|
62
|
-
:describe => '')),
|
63
|
-
:config => Vendorificator::Config)
|
64
|
-
|
65
|
-
uncategorized = Vendor.new(env, 'test')
|
66
|
-
categorized = Vendor.new(env, 'test', :category => :cat)
|
41
|
+
uncategorized = Vendor.new(basic_environment, 'test')
|
42
|
+
categorized = Vendor.new(basic_environment, 'test', :category => :cat)
|
67
43
|
|
68
44
|
deny { uncategorized.branch_name.include? 'cat' }
|
69
45
|
assert { categorized.branch_name.include? 'cat' }
|
@@ -71,9 +47,29 @@ module Vendorificator
|
|
71
47
|
deny { uncategorized.path.include? 'cat' }
|
72
48
|
assert { categorized.path.include? 'cat' }
|
73
49
|
|
50
|
+
uncategorized.stubs(:version).returns(:foo)
|
51
|
+
categorized.stubs(:version).returns(:foo)
|
74
52
|
deny { uncategorized.tag_name.include? 'cat' }
|
75
53
|
assert { categorized.tag_name.include? 'cat' }
|
76
54
|
end
|
77
55
|
end
|
56
|
+
|
57
|
+
describe '#initialize' do
|
58
|
+
it 'adds hooks when you pass a module option' do
|
59
|
+
vendor = Vendor.new(basic_environment, 'test', {:hooks => Hooks::FooHook})
|
60
|
+
assert { includes_method? vendor, :foo_hooked_method }
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'adds hooks via the String option shortcut' do
|
64
|
+
vendor = Vendor.new(basic_environment, 'test', {:hooks => 'FooHook'})
|
65
|
+
assert { includes_method? vendor, :foo_hooked_method }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
module Hooks
|
71
|
+
module FooHook
|
72
|
+
def foo_hooked_method; end
|
73
|
+
end
|
78
74
|
end
|
79
75
|
end
|
data/vendorificator.gemspec
CHANGED
@@ -16,11 +16,10 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = Vendorificator::VERSION
|
17
17
|
|
18
18
|
gem.add_dependency 'escape'
|
19
|
-
gem.add_dependency 'thor', '>= 0.
|
20
|
-
gem.add_dependency 'mixlib-config'
|
19
|
+
gem.add_dependency 'thor', '>= 0.18.1'
|
21
20
|
gem.add_dependency 'minigit', '>= 0.0.3'
|
22
21
|
|
23
|
-
gem.add_development_dependency 'aruba'
|
22
|
+
gem.add_development_dependency 'aruba', '0.5.1'
|
24
23
|
gem.add_development_dependency 'cucumber'
|
25
24
|
gem.add_development_dependency 'mocha'
|
26
25
|
gem.add_development_dependency 'chef', '>= 10.16.0' unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
@@ -28,4 +27,5 @@ Gem::Specification.new do |gem|
|
|
28
27
|
gem.add_development_dependency 'webmock'
|
29
28
|
gem.add_development_dependency 'wrong', '>= 0.7.0'
|
30
29
|
gem.add_development_dependency 'rake'
|
30
|
+
gem.add_development_dependency 'simplecov'
|
31
31
|
end
|