vendorificator 0.5.git.v0.4.0.17.g26d50d8 → 0.5.git.v0.4.0.60.g9c35209

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,10 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  module Vendorificator
4
4
  describe Environment do
5
+ let(:environment) do
6
+ Environment.new Thor::Shell::Basic.new, :quiet, nil do
7
+ vendor 'name', :option => 'value'
8
+ vendor 'other_name', :option => 'other_value'
9
+ end
10
+ end
11
+
5
12
  before do
6
- MiniGit.any_instance.stubs(:fetch)
13
+ environment.git.capturing.stubs(:remote).returns("origin\n")
7
14
  end
8
- let(:environment){ Environment.new 'spec/vendorificator/fixtures/vendorfiles/vendor.rb' }
9
15
 
10
16
  describe '#clean' do
11
17
  it 'returns false for dirty repo' do
@@ -41,31 +47,69 @@ module Vendorificator
41
47
  end
42
48
 
43
49
  describe '#pull' do
50
+ let(:environment){ Environment.new(Thor::Shell::Basic.new, :quiet, nil){} }
51
+
52
+ before do
53
+ environment.git.expects(:fetch).with('origin')
54
+ environment.git.expects(:fetch).with({:tags => true}, 'origin')
55
+ @git_fetch_notes = environment.git.expects(:fetch).with('origin', 'refs/notes/vendor:refs/notes/vendor')
56
+ environment.git.capturing.stubs(:show_ref).returns("602315 refs/remotes/origin/vendor/test\n")
57
+ end
58
+
44
59
  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)]
60
+ environment.vendor_instances << stub(
61
+ :branch_name => 'vendor/test', :head => nil,
62
+ :compute_dependencies! => nil
63
+ )
49
64
 
50
65
  environment.git.expects(:branch).with({:track => true}, 'vendor/test', '602315')
66
+
51
67
  environment.pull('origin')
52
68
  end
53
69
 
54
70
  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
-
71
+ environment.vendor_instances << stub(
72
+ :branch_name => 'vendor/test', :head => '123456', :in_branch => true,
73
+ :name => 'test', :compute_dependencies! => nil
74
+ )
62
75
  environment.expects(:fast_forwardable?).returns(true)
76
+
63
77
  environment.pull('origin')
64
78
  end
79
+
80
+ it "handles git error on fetching empty notes" do
81
+ @git_fetch_notes.raises(MiniGit::GitError)
82
+
83
+ environment.pull('origin')
84
+ end
85
+ end
86
+
87
+ describe '#push' do
88
+ let(:environment){ Environment.new(Thor::Shell::Basic.new, :quiet, nil){} }
89
+
90
+ it "handles git error on pushing empty notes" do
91
+ environment.stubs(:ensure_clean!)
92
+
93
+ environment.git.capturing.expects(:rev_parse).with({:quiet => true, :verify => true}, 'refs/notes/vendor').raises(MiniGit::GitError)
94
+ environment.git.expects(:push).with('origin', [])
95
+ environment.git.stubs(:push).with('origin', :tags => true)
96
+
97
+ environment.push(:remote => 'origin')
98
+ end
99
+
100
+ it "pushes note when they exist" do
101
+ environment.stubs(:ensure_clean!)
102
+
103
+ environment.git.capturing.expects(:rev_parse).with({:quiet => true, :verify => true}, 'refs/notes/vendor').returns('abcdef')
104
+ environment.git.expects(:push).with('origin', ['refs/notes/vendor'])
105
+ environment.git.stubs(:push).with('origin', :tags => true)
106
+
107
+ environment.push(:remote => 'origin')
108
+ end
65
109
  end
66
110
 
67
111
  describe '#vendor_instances' do
68
- let(:environment){ Environment.new 'spec/vendorificator/fixtures/vendorfiles/empty_vendor.rb' }
112
+ let(:environment){ Environment.new Thor::Shell::Basic.new, :default, nil }
69
113
 
70
114
  it 'is initialized on a new environment' do
71
115
  assert { environment.vendor_instances == [] }
@@ -98,5 +142,6 @@ module Vendorificator
98
142
  assert { @metadata[:git_describe] == 'git description' }
99
143
  end
100
144
  end
145
+
101
146
  end
102
147
  end
@@ -1,10 +1,10 @@
1
1
  # Note that due to git operations involved, most of the Vendor class is tested
2
2
  # with cucumber features instead.
3
- require 'spec_helper'
3
+ require_relative '../spec_helper'
4
4
 
5
5
  module Vendorificator
6
6
  class Vendor::Categorized < Vendor
7
- @category = :test
7
+ @group = :test
8
8
  end
9
9
 
10
10
  class Vendor::Custom < Vendor
@@ -12,34 +12,34 @@ module Vendorificator
12
12
  end
13
13
 
14
14
  describe Vendor do
15
- describe '.category' do
15
+ describe '.group' do
16
16
  it 'defaults to nil' do
17
- assert { Vendor.category == nil }
17
+ assert { Vendor.group == nil }
18
18
  end
19
19
 
20
20
  it 'can be overridden in a subclass' do
21
- assert { Vendor::Categorized.category == :test }
21
+ assert { Vendor::Categorized.group == :test }
22
22
  end
23
23
  end
24
24
 
25
- describe '#category' do
25
+ describe '#group' do
26
26
  it 'defaults to class attribute' do
27
- assert { Vendor.new(basic_environment, 'test').category == nil }
28
- assert { Vendor::Categorized.new(basic_environment, 'test').category == :test }
27
+ assert { Vendor.new(basic_environment, 'test').group == nil }
28
+ assert { Vendor::Categorized.new(basic_environment, 'test').group == :test }
29
29
  end
30
30
 
31
31
  it 'can be overriden by option' do
32
- assert { Vendor.new(basic_environment, 'test', :category => :foo).category == :foo }
33
- assert { Vendor::Categorized.new(basic_environment, 'test', :category => :foo).category == :foo }
32
+ assert { Vendor.new(basic_environment, 'test', :group => :foo).group == :foo }
33
+ assert { Vendor::Categorized.new(basic_environment, 'test', :group => :foo).group == :foo }
34
34
  end
35
35
 
36
36
  it 'can be reset to nil by option' do
37
- assert { Vendor::Categorized.new(basic_environment, 'test', :category => nil).category == nil }
37
+ assert { Vendor::Categorized.new(basic_environment, 'test', :group => nil).group == nil }
38
38
  end
39
39
 
40
40
  it 'is inserted into paths and other names' do
41
41
  uncategorized = Vendor.new(basic_environment, 'test')
42
- categorized = Vendor.new(basic_environment, 'test', :category => :cat)
42
+ categorized = Vendor.new(basic_environment, 'test', :group => :cat)
43
43
 
44
44
  deny { uncategorized.branch_name.include? 'cat' }
45
45
  assert { categorized.branch_name.include? 'cat' }
@@ -52,12 +52,18 @@ module Vendorificator
52
52
  deny { uncategorized.tag_name.include? 'cat' }
53
53
  assert { categorized.tag_name.include? 'cat' }
54
54
  end
55
+
56
+ it 'accepts a deprecated :category option' do
57
+ vendor = Vendor.new(basic_environment, 'test', :category => 'foo')
58
+
59
+ assert { vendor.group == 'foo' }
60
+ end
55
61
  end
56
62
 
57
63
  describe '#metadata' do
58
64
  before do
59
65
  @vendor = Vendor.new(basic_environment, 'name_test',
60
- :category => 'cat_test', :test_arg => 'test_value'
66
+ :group => 'cat_test', :test_arg => 'test_value'
61
67
  )
62
68
  @vendor.stubs(:version).returns('0.23')
63
69
  end
@@ -66,8 +72,8 @@ module Vendorificator
66
72
  assert { @vendor.metadata[:module_version] == '0.23' }
67
73
  end
68
74
 
69
- it 'contains the category' do
70
- assert { @vendor.metadata[:module_category] == 'cat_test' }
75
+ it 'contains the group' do
76
+ assert { @vendor.metadata[:module_group] == 'cat_test' }
71
77
  end
72
78
 
73
79
  it 'contains the name' do
@@ -79,7 +85,7 @@ module Vendorificator
79
85
  end
80
86
 
81
87
  it 'contains the unparsed arguments' do
82
- assert { @vendor.metadata[:unparsed_args].keys.include? :category }
88
+ assert { @vendor.metadata[:unparsed_args].keys.include? :group }
83
89
  end
84
90
  end
85
91
 
@@ -108,30 +114,65 @@ e4646a83e6d24322958e1d7a2ed922dae034accd refs/tags/vendor/cookbooks/nginx/1.2.0
108
114
  fa0293b914420f59f8eb4c347fb628dcb953aad3 refs/tags/vendor/cookbooks/nginx/1.3.0
109
115
  680dee5e56a0d49ba2ae299bb82189b6f2660c9b refs/tags/vendor/cookbooks/nginx_simplecgi/0.1.0
110
116
  EOF
117
+ environment.load_vendorfile
111
118
  end
112
119
 
113
120
  let(:environment) do
114
- Environment.new do
115
- vendor :nginx, :category => :cookbooks
116
- vendor :nginx_simplecgi, :category => :cookbooks
121
+ Environment.new(Thor::Shell::Basic.new) do
122
+ vendor :nginx, :group => :cookbooks
123
+ vendor :nginx_simplecgi, :group => :cookbooks
117
124
  end
118
125
  end
119
126
 
120
127
  it 'includes all own refs' do
121
128
  refs = environment['nginx'].pushable_refs
122
- assert { refs.include? '+refs/heads/vendor/cookbooks/nginx' }
123
- assert { refs.include? '+refs/tags/vendor/cookbooks/nginx/1.2.0' }
124
- assert { refs.include? '+refs/tags/vendor/cookbooks/nginx/1.3.0' }
129
+ assert { refs.include? 'refs/heads/vendor/cookbooks/nginx' }
130
+ assert { refs.include? 'refs/tags/vendor/cookbooks/nginx/1.2.0' }
131
+ assert { refs.include? 'refs/tags/vendor/cookbooks/nginx/1.3.0' }
125
132
 
126
133
  refs = environment['nginx_simplecgi'].pushable_refs
127
- assert { refs.include? '+refs/heads/vendor/cookbooks/nginx_simplecgi' }
128
- assert { refs.include? '+refs/tags/vendor/cookbooks/nginx_simplecgi/0.1.0' }
134
+ assert { refs.include? 'refs/heads/vendor/cookbooks/nginx_simplecgi' }
135
+ assert { refs.include? 'refs/tags/vendor/cookbooks/nginx_simplecgi/0.1.0' }
129
136
  end
130
137
 
131
138
  it "doesn't include other modules' refs" do
132
139
  refs = environment['nginx'].pushable_refs
133
- deny { refs.include? '+refs/tags/vendor/cookbooks/nginx_simplecgi/0.1.0' }
140
+ deny { refs.include? 'refs/tags/vendor/cookbooks/nginx_simplecgi/0.1.0' }
141
+ end
142
+ end
143
+
144
+ describe '#included_in_list?' do
145
+ let(:vendor) { Vendor.new(basic_environment, 'test_name', :group => 'test_group') }
146
+
147
+ it 'finds a module by name' do
148
+ assert { vendor.included_in_list?(['test_name']) }
134
149
  end
150
+
151
+ it 'finds a module by qualified name' do
152
+ assert { vendor.included_in_list?(['test_group/test_name']) }
153
+ end
154
+
155
+ it 'finds a module by path' do
156
+ vendor.stubs(:work_dir).returns('./vendor/test_group/test_name')
157
+
158
+ assert { vendor.included_in_list?(['./vendor/test_group/test_name']) }
159
+ end
160
+
161
+ it 'finds a module by merge commit' do
162
+ vendor.stubs(:merged).returns('foobar')
163
+ vendor.stubs(:work_dir).returns('abc/def')
164
+
165
+ assert { vendor.included_in_list?(['foobar']) }
166
+ end
167
+
168
+ it 'finds a module by branch name' do
169
+ vendor.stubs(:merged).returns('abcdef')
170
+ vendor.stubs(:work_dir).returns('abc/def')
171
+
172
+ vendor.stubs(:branch_name).returns('foo/bar')
173
+ assert { vendor.included_in_list?(['foo/bar']) }
174
+ end
175
+
135
176
  end
136
177
  end
137
178
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vendorificator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.git.v0.4.0.17.g26d50d8
4
+ version: 0.5.git.v0.4.0.60.g9c35209
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Pasternacki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-17 00:00:00.000000000 Z
11
+ date: 2013-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: escape
@@ -310,6 +310,7 @@ files:
310
310
  - lib/vendorificator/environment.rb
311
311
  - lib/vendorificator/errors.rb
312
312
  - lib/vendorificator/hooks/chef_cookbook.rb
313
+ - lib/vendorificator/io_proxy.rb
313
314
  - lib/vendorificator/vendor.rb
314
315
  - lib/vendorificator/vendor/archive.rb
315
316
  - lib/vendorificator/vendor/chef_cookbook.rb
@@ -321,8 +322,6 @@ files:
321
322
  - spec/spec_helper.rb
322
323
  - spec/vendorificator/config_spec.rb
323
324
  - spec/vendorificator/environment_spec.rb
324
- - spec/vendorificator/fixtures/vendorfiles/empty_vendor.rb
325
- - spec/vendorificator/fixtures/vendorfiles/vendor.rb
326
325
  - spec/vendorificator/vendor/chef_cookbook_spec.rb
327
326
  - spec/vendorificator/vendor/git_spec.rb
328
327
  - spec/vendorificator/vendor_spec.rb
@@ -418,8 +417,6 @@ test_files:
418
417
  - spec/spec_helper.rb
419
418
  - spec/vendorificator/config_spec.rb
420
419
  - spec/vendorificator/environment_spec.rb
421
- - spec/vendorificator/fixtures/vendorfiles/empty_vendor.rb
422
- - spec/vendorificator/fixtures/vendorfiles/vendor.rb
423
420
  - spec/vendorificator/vendor/chef_cookbook_spec.rb
424
421
  - spec/vendorificator/vendor/git_spec.rb
425
422
  - spec/vendorificator/vendor_spec.rb
@@ -1 +0,0 @@
1
- # Empty vendor file, just for stubbing purposes.
@@ -1,15 +0,0 @@
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