berkshelf 2.0.18 → 3.0.0.beta1

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.
Files changed (128) hide show
  1. data/.ruby-version +1 -1
  2. data/.travis.yml +4 -1
  3. data/CHANGELOG.md +2 -26
  4. data/Gemfile +12 -2
  5. data/README.md +9 -1
  6. data/berkshelf.gemspec +9 -18
  7. data/bin/berks +3 -13
  8. data/features/apply_command.feature +11 -9
  9. data/features/berksfile.feature +8 -10
  10. data/features/config.feature +1 -2
  11. data/features/configure_command.feature +13 -14
  12. data/features/contingent_command.feature +13 -1
  13. data/features/cookbook_command.feature +2 -4
  14. data/features/groups_install.feature +10 -2
  15. data/features/help.feature +1 -1
  16. data/features/init_command.feature +5 -7
  17. data/features/install_command.feature +157 -228
  18. data/features/json_formatter.feature +27 -15
  19. data/features/licenses.feature +18 -12
  20. data/features/list_command.feature +6 -1
  21. data/features/lockfile.feature +116 -72
  22. data/features/outdated_command.feature +3 -47
  23. data/features/package_command.feature +10 -7
  24. data/features/shelf/show.feature +2 -2
  25. data/features/shelf/uninstall.feature +2 -2
  26. data/features/show_command.feature +10 -3
  27. data/features/step_definitions/chef/config_steps.rb +12 -0
  28. data/features/step_definitions/chef_server_steps.rb +16 -16
  29. data/features/step_definitions/cli_steps.rb +3 -79
  30. data/features/step_definitions/config_steps.rb +43 -0
  31. data/features/step_definitions/environment_steps.rb +7 -0
  32. data/features/step_definitions/filesystem_steps.rb +12 -57
  33. data/features/step_definitions/gem_steps.rb +1 -2
  34. data/features/step_definitions/json_steps.rb +3 -1
  35. data/features/step_definitions/lockfile_steps.rb +4 -0
  36. data/features/step_definitions/utility_steps.rb +0 -19
  37. data/features/support/aruba.rb +12 -0
  38. data/features/support/env.rb +52 -57
  39. data/features/update_command.feature +37 -23
  40. data/features/upload_command.feature +96 -160
  41. data/generator_files/Berksfile.erb +2 -1
  42. data/generator_files/Vagrantfile.erb +3 -0
  43. data/generator_files/default_test.rb.erb +1 -1
  44. data/generator_files/helpers.rb.erb +1 -1
  45. data/lib/berkshelf.rb +43 -24
  46. data/lib/berkshelf/api_client.rb +67 -0
  47. data/lib/berkshelf/api_client/remote_cookbook.rb +42 -0
  48. data/lib/berkshelf/berksfile.rb +232 -420
  49. data/lib/berkshelf/cached_cookbook.rb +22 -10
  50. data/lib/berkshelf/chef/config.rb +1 -0
  51. data/lib/berkshelf/cli.rb +66 -68
  52. data/lib/berkshelf/commands/shelf.rb +1 -1
  53. data/lib/berkshelf/community_rest.rb +10 -17
  54. data/lib/berkshelf/config.rb +23 -27
  55. data/lib/berkshelf/cookbook_generator.rb +3 -4
  56. data/lib/berkshelf/cookbook_store.rb +74 -17
  57. data/lib/berkshelf/core_ext/file.rb +2 -2
  58. data/lib/berkshelf/core_ext/pathname.rb +7 -5
  59. data/lib/berkshelf/{cookbook_source.rb → dependency.rb} +47 -67
  60. data/lib/berkshelf/downloader.rb +49 -106
  61. data/lib/berkshelf/errors.rb +64 -71
  62. data/lib/berkshelf/formatters.rb +11 -9
  63. data/lib/berkshelf/formatters/human_readable.rb +9 -9
  64. data/lib/berkshelf/formatters/json.rb +14 -4
  65. data/lib/berkshelf/init_generator.rb +3 -3
  66. data/lib/berkshelf/installer.rb +136 -0
  67. data/lib/berkshelf/location.rb +91 -131
  68. data/lib/berkshelf/locations/git_location.rb +9 -11
  69. data/lib/berkshelf/locations/github_location.rb +1 -1
  70. data/lib/berkshelf/locations/path_location.rb +10 -27
  71. data/lib/berkshelf/lockfile.rb +92 -70
  72. data/lib/berkshelf/logger.rb +4 -7
  73. data/lib/berkshelf/mixin/config.rb +21 -4
  74. data/lib/berkshelf/resolver.rb +60 -150
  75. data/lib/berkshelf/resolver/graph.rb +44 -0
  76. data/lib/berkshelf/source.rb +55 -0
  77. data/lib/berkshelf/source_uri.rb +38 -0
  78. data/lib/berkshelf/version.rb +1 -1
  79. data/spec/config/knife.rb +1 -1
  80. data/spec/fixtures/cassettes/Berkshelf_Resolver/_initialize/adds_the_dependencies_of_the_dependency_as_dependencies.yml +3694 -0
  81. data/spec/fixtures/cookbooks/example_cookbook/Berksfile.lock +1 -1
  82. data/spec/fixtures/lockfiles/default.lock +1 -1
  83. data/spec/spec_helper.rb +20 -121
  84. data/spec/support/chef_api.rb +3 -4
  85. data/spec/support/chef_server.rb +20 -11
  86. data/spec/support/git.rb +127 -0
  87. data/spec/support/kitchen.rb +12 -0
  88. data/spec/support/path_helpers.rb +69 -0
  89. data/spec/unit/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
  90. data/spec/unit/berkshelf/api_client_spec.rb +57 -0
  91. data/spec/unit/berkshelf/berksfile_spec.rb +206 -324
  92. data/spec/unit/berkshelf/cached_cookbook_spec.rb +73 -38
  93. data/spec/unit/berkshelf/community_rest_spec.rb +30 -71
  94. data/spec/unit/berkshelf/config_spec.rb +3 -14
  95. data/spec/unit/berkshelf/cookbook_generator_spec.rb +1 -2
  96. data/spec/unit/berkshelf/cookbook_store_spec.rb +12 -7
  97. data/spec/unit/berkshelf/dependency_spec.rb +285 -0
  98. data/spec/unit/berkshelf/downloader_spec.rb +4 -183
  99. data/spec/unit/berkshelf/formatters/null_spec.rb +1 -1
  100. data/spec/unit/berkshelf/formatters_spec.rb +4 -2
  101. data/spec/unit/berkshelf/git_spec.rb +15 -15
  102. data/spec/unit/berkshelf/installer_spec.rb +39 -0
  103. data/spec/unit/berkshelf/location_spec.rb +87 -114
  104. data/spec/unit/berkshelf/locations/git_location_spec.rb +41 -53
  105. data/spec/unit/berkshelf/locations/path_location_spec.rb +13 -23
  106. data/spec/unit/berkshelf/lockfile_spec.rb +38 -40
  107. data/spec/unit/berkshelf/resolver/graph_spec.rb +44 -0
  108. data/spec/unit/berkshelf/resolver_spec.rb +34 -83
  109. data/spec/unit/berkshelf/source_spec.rb +23 -0
  110. data/spec/unit/berkshelf/source_uri_spec.rb +29 -0
  111. metadata +149 -188
  112. checksums.yaml +0 -7
  113. data/features/default_locations.feature +0 -127
  114. data/features/step_definitions/berksfile_steps.rb +0 -8
  115. data/features/step_definitions/configure_cli_steps.rb +0 -19
  116. data/features/vendor_install.feature +0 -19
  117. data/lib/berkshelf/core_ext/openuri.rb +0 -36
  118. data/lib/berkshelf/core_ext/rbzip2.rb +0 -8
  119. data/lib/berkshelf/locations/chef_api_location.rb +0 -228
  120. data/lib/berkshelf/locations/site_location.rb +0 -92
  121. data/lib/berkshelf/test.rb +0 -35
  122. data/spec/knife.rb.sample +0 -12
  123. data/spec/support/test_generators.rb +0 -27
  124. data/spec/unit/berkshelf/cli_spec.rb +0 -16
  125. data/spec/unit/berkshelf/cookbook_source_spec.rb +0 -358
  126. data/spec/unit/berkshelf/core_ext/pathname_spec.rb +0 -46
  127. data/spec/unit/berkshelf/locations/chef_api_location_spec.rb +0 -139
  128. data/spec/unit/berkshelf/locations/site_location_spec.rb +0 -19
@@ -1,190 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Berkshelf::Downloader do
4
- let(:locations) do
5
- [
6
- {
7
- type: :chef_api,
8
- value: double('capi'),
9
- options: double('capi_opts')
10
- },
11
- {
12
- type: :chef_api,
13
- value: double('capi2'),
14
- options: double('capi_opts2')
15
- }
16
- ]
4
+ describe "#download" do
5
+ pending
17
6
  end
18
7
 
19
- describe '.initialize' do
20
- context 'when no value for locations is given' do
21
- it 'sets the @locations instance variable to a blank array' do
22
- downloader = Berkshelf::Downloader.new(double('store'))
23
- locations = downloader.instance_variable_get(:@locations)
24
-
25
- expect(locations).to be_a(Array)
26
- expect(locations).to be_empty
27
- end
28
- end
29
-
30
- context 'when an explicit value of locations is given' do
31
- it 'sets the @locations instance variable to the given locations' do
32
- downloader = Berkshelf::Downloader.new(double('store'), locations: locations)
33
- expect(downloader.instance_variable_get(:@locations)).to eq(locations)
34
- end
35
- end
36
- end
37
-
38
-
39
-
40
- let!(:cookbook_store) { Berkshelf::CookbookStore.new(tmp_path) }
41
- subject { Berkshelf::Downloader.new(cookbook_store) }
42
-
43
- describe '#download' do
44
- let(:source) { double('source', name: 'artifact', version_constraint: '= 0.10.0', locked_version: '0.10.0') }
45
- let(:location) { double('location') }
46
- let(:cached_cookbook) { double('cached') }
47
-
48
- context 'when the source has a location' do
49
- before do
50
- source.stub(:location).and_return(location)
51
- location.should_receive(:download).with(subject.storage_path).and_return(cached_cookbook)
52
- source.should_receive(:cached_cookbook=).with(cached_cookbook)
53
- end
54
-
55
- it "sends :download to the source's location and sets the source's cached_cookbook to the result" do
56
- expect(subject.download(source)).to be_true
57
- end
58
-
59
- it 'returns an Array containing the cached_cookbook and location used to download' do
60
- result = subject.download(source)
61
-
62
- expect(result).to be_a(Array)
63
- expect(result[0]).to eq(cached_cookbook)
64
- expect(result[1]).to eq(location)
65
- end
66
- end
67
-
68
- context 'when the source does not have a location' do
69
- before do
70
- source.stub(:location).and_return(nil)
71
- subject.stub(:locations).and_return([{ type: :chef_api, value: :config, options: {} }])
72
- end
73
-
74
- it 'sends the :download message to the default location' do
75
- Berkshelf::Location.should_receive(:init).with(source.name, source.version_constraint, chef_api: :config).and_return(location)
76
- location.should_receive(:download).with(subject.storage_path).and_return(cached_cookbook)
77
- source.should_receive(:cached_cookbook=).with(cached_cookbook)
78
-
79
- subject.download(source)
80
- end
81
- end
82
- end
83
-
84
- describe '#locations' do
85
- let(:type) { :site }
86
- let(:value) { double('value') }
87
- let(:options) { double('options') }
88
-
89
- it 'returns an array of Hashes representing locations' do
90
- subject.add_location(type, value, options)
91
-
92
- subject.locations.each do |location|
93
- expect(location).to be_a(Hash)
94
- end
95
- end
96
-
97
- context 'when no locations are explicitly added' do
98
- subject { Berkshelf::Downloader.new(double('store')) }
99
-
100
- it 'returns an array of default locations' do
101
- expect(subject.locations).to eq(Berkshelf::Downloader::DEFAULT_LOCATIONS)
102
- end
103
- end
104
-
105
- context 'when locations are explicitly added' do
106
- subject { Berkshelf::Downloader.new(double('store'), locations: locations) }
107
-
108
- it 'contains only the locations passed to the initializer' do
109
- expect(subject.locations).to eq(locations)
110
- end
111
-
112
- it 'does not include the array of default locations' do
113
- expect(subject.locations).to_not include(Berkshelf::Downloader::DEFAULT_LOCATIONS)
114
- end
115
- end
116
- end
117
-
118
- describe '#add_location' do
119
- let(:type) { :site }
120
- let(:value) { double('value') }
121
- let(:options) { double('options') }
122
-
123
- it 'adds a hash to the end of the array of locations' do
124
- subject.add_location(type, value, options)
125
- expect(subject.locations).to have(1).item
126
- end
127
-
128
- it 'adds a hash with a type, value, and options key' do
129
- subject.add_location(type, value, options)
130
- location = subject.locations.last
131
-
132
- [:type, :value, :options].each do |key|
133
- expect(location).to have_key(key)
134
- end
135
- end
136
-
137
- it 'sets the value of the given :value to the value of the key :value' do
138
- subject.add_location(type, value, options)
139
- expect(subject.locations.last[:value]).to eq(value)
140
- end
141
-
142
- it 'sets the value of the given :type to the value of the key :type' do
143
- subject.add_location(type, value, options)
144
- expect(subject.locations.last[:type]).to eq(type)
145
- end
146
-
147
- it 'sets the value of the given :options to the value of the key :options' do
148
- subject.add_location(type, value, options)
149
- expect(subject.locations.last[:options]).to eq(options)
150
- end
151
-
152
- it 'raises a DuplicateLocationDefined error if a location of the given type and value was already added' do
153
- subject.add_location(type, value, options)
154
-
155
- expect {
156
- subject.add_location(type, value, options)
157
- }.to raise_error(Berkshelf::DuplicateLocationDefined)
158
- end
159
-
160
- context 'adding multiple locations' do
161
- let(:type_2) { :site }
162
- let(:value_2) { double('value_2') }
163
- let(:options_2) { double('options_2') }
164
-
165
- it 'adds locations in the order they are added' do
166
- subject.add_location(type, value, options)
167
- subject.add_location(type_2, value_2, options_2)
168
-
169
- expect(subject.locations).to have(2).items
170
-
171
- expect(subject.locations[0][:value]).to eql(value)
172
- expect(subject.locations[1][:value]).to eql(value_2)
173
- end
174
- end
175
- end
176
-
177
- describe '#has_location?' do
178
- let(:type) { :site }
179
- let(:value) { double('value') }
180
-
181
- it 'returns true if a source of the given type and value was already added' do
182
- subject.add_location(type, value)
183
- expect(subject.has_location?(type, value)).to be_true
184
- end
185
-
186
- it 'returns false if a source of the given type and value was not added' do
187
- expect(subject.has_location?(type, value)).to be_false
188
- end
8
+ describe "#try_download" do
9
+ pending
189
10
  end
190
11
  end
@@ -7,7 +7,7 @@ describe Berkshelf::Formatters::Null do
7
7
  it "does not raise an error for :#{meth}" do
8
8
  expect {
9
9
  subject.send(meth)
10
- }.to_not raise_error
10
+ }.to_not raise_error(Berkshelf::AbstractFunction)
11
11
  end
12
12
 
13
13
  it "returns nil for :#{meth}" do
@@ -77,8 +77,6 @@ describe Berkshelf::Formatters do
77
77
  end
78
78
  end
79
79
 
80
-
81
-
82
80
  subject do
83
81
  Class.new { include Berkshelf::Formatters::AbstractFormatter }.new
84
82
  end
@@ -107,6 +105,10 @@ describe Berkshelf::Formatters do
107
105
  expect {
108
106
  subject.error('whoa this is bad')
109
107
  }.to raise_error(Berkshelf::AbstractFunction)
108
+
109
+ expect {
110
+ subject.fetch(double('dependency'))
111
+ }.to raise_error(Berkshelf::AbstractFunction)
110
112
  end
111
113
  end
112
114
  end
@@ -18,7 +18,7 @@ describe Berkshelf::Git do
18
18
  end
19
19
 
20
20
  describe '.clone' do
21
- let(:target) { clone_target_for('nginx') }
21
+ let(:target) { clone_path('nginx') }
22
22
 
23
23
  it 'clones the repository to the target path' do
24
24
  origin_uri = git_origin_for('nginx')
@@ -30,7 +30,7 @@ describe Berkshelf::Git do
30
30
  end
31
31
 
32
32
  describe '.checkout' do
33
- let(:repo_path) { clone_target_for('nginx') }
33
+ let(:repo_path) { clone_path('nginx') }
34
34
  let(:repo) {
35
35
  origin_uri = git_origin_for('nginx', tags: ['1.0.1', '1.0.2'], branches: ['topic', 'next_topic'])
36
36
  git.clone(origin_uri, repo_path)
@@ -48,7 +48,7 @@ describe Berkshelf::Git do
48
48
  end
49
49
 
50
50
  context 'with sha commit id' do
51
- let(:ref) { git_sha_for_ref('nginx', '1.0.1') }
51
+ let(:ref) { sha_for_ref('nginx', '1.0.1') }
52
52
 
53
53
  it_behaves_like 'able to checkout git ref'
54
54
  end
@@ -63,7 +63,7 @@ describe Berkshelf::Git do
63
63
  before do
64
64
  git.checkout(repo, other_tag)
65
65
  Dir.chdir repo_path do
66
- run! "echo 'uncommitted change' >> content_file"
66
+ shell_out "echo 'uncommitted change' >> content_file"
67
67
  end
68
68
  end
69
69
 
@@ -81,7 +81,7 @@ describe Berkshelf::Git do
81
81
  before do
82
82
  git.checkout(repo, other_branch)
83
83
  Dir.chdir repo_path do
84
- run! "echo 'uncommitted change' >> content_file"
84
+ shell_out "echo 'uncommitted change' >> content_file"
85
85
  end
86
86
  end
87
87
 
@@ -91,23 +91,23 @@ describe Berkshelf::Git do
91
91
  end
92
92
 
93
93
  describe '.rev_parse' do
94
- let(:repo_path) { clone_target_for('nginx') }
94
+ let(:repo_path) { clone_path('nginx') }
95
95
  before(:each) do |example|
96
96
  origin_uri = git_origin_for('nginx', tags: ['1.1.1'])
97
97
  Berkshelf::Git.clone(origin_uri, repo_path)
98
- Berkshelf::Git.checkout(repo_path, git_sha_for_ref('nginx', '1.1.1'))
98
+ Berkshelf::Git.checkout(repo_path, sha_for_ref('nginx', '1.1.1'))
99
99
  end
100
100
 
101
101
  it 'returns the ref for HEAD' do
102
102
  rev = Berkshelf::Git.rev_parse(repo_path)
103
- ref = git_sha_for_ref('nginx', '1.1.1')
103
+ ref = sha_for_ref('nginx', '1.1.1')
104
104
 
105
105
  expect(rev).to eql(ref)
106
106
  end
107
107
  end
108
108
 
109
109
  describe '.show_ref' do
110
- let(:repo_path) { clone_target_for('nginx') }
110
+ let(:repo_path) { clone_path('nginx') }
111
111
  let(:tags) { ['1.0.1'] }
112
112
  let(:branches) { ['topic'] }
113
113
  let!(:repo) {
@@ -117,14 +117,14 @@ describe Berkshelf::Git do
117
117
 
118
118
  it 'returns the commit id for the given tag' do
119
119
  show = git.show_ref(repo_path, '1.0.1')
120
- ref = git_sha_for_ref('nginx', '1.0.1')
120
+ ref = sha_for_ref('nginx', '1.0.1')
121
121
 
122
122
  expect(show).to eq(ref)
123
123
  end
124
124
 
125
125
  it 'returns the commit id for the given branch' do
126
126
  show = git.show_ref(repo_path, 'topic')
127
- ref = git_sha_for_ref('nginx', 'topic')
127
+ ref = sha_for_ref('nginx', 'topic')
128
128
  expect(show).to eq(ref)
129
129
  end
130
130
 
@@ -141,7 +141,7 @@ describe Berkshelf::Git do
141
141
  end
142
142
 
143
143
  describe '.revision_from_ref' do
144
- let(:repo_path) { clone_target_for('nginx') }
144
+ let(:repo_path) { clone_path('nginx') }
145
145
  let(:tags) { ['1.0.1'] }
146
146
  let(:branches) { ['topic'] }
147
147
  let!(:repo) {
@@ -150,7 +150,7 @@ describe Berkshelf::Git do
150
150
  }
151
151
 
152
152
  context 'with sha commit id' do
153
- let(:revision) { git_sha_for_ref('nginx', '1.0.1') }
153
+ let(:revision) { sha_for_ref('nginx', '1.0.1') }
154
154
  it 'returns the passed revision' do
155
155
  rev = git.revision_from_ref(repo_path, revision)
156
156
  expect(rev).to eq(revision)
@@ -158,7 +158,7 @@ describe Berkshelf::Git do
158
158
  end
159
159
 
160
160
  context 'with tag' do
161
- let(:revision) { git_sha_for_ref('nginx', '1.0.1') }
161
+ let(:revision) { sha_for_ref('nginx', '1.0.1') }
162
162
  it 'returns the revision' do
163
163
  rev = git.revision_from_ref(repo_path, '1.0.1')
164
164
  expect(rev).to eq(revision)
@@ -166,7 +166,7 @@ describe Berkshelf::Git do
166
166
  end
167
167
 
168
168
  context 'with branch' do
169
- let(:revision) { git_sha_for_ref('nginx', 'topic') }
169
+ let(:revision) { sha_for_ref('nginx', 'topic') }
170
170
  it 'returns the revision' do
171
171
  rev = git.revision_from_ref(repo_path, 'topic')
172
172
  expect(rev).to eq(revision)
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe Berkshelf::Installer do
4
+ let(:berksfile) { double('berksfile') }
5
+ subject { described_class.new(berksfile) }
6
+
7
+ describe "#build_universe" do
8
+ let(:source_one) { double('one') }
9
+ let(:source_two) { double('two') }
10
+ let(:sources) { [ source_one, source_two ] }
11
+
12
+ before { berksfile.stub(sources: sources) }
13
+
14
+ it "sends the message #universe on each source" do
15
+ source_one.should_receive(:universe)
16
+ source_two.should_receive(:universe)
17
+
18
+ subject.build_universe
19
+ end
20
+ end
21
+
22
+ describe "#run" do
23
+ context 'when a lockfile is not present' do
24
+ pending
25
+ end
26
+
27
+ context 'when a value for :except is given' do
28
+ pending
29
+ end
30
+
31
+ context 'when a value for :only is given' do
32
+ pending
33
+ end
34
+ end
35
+
36
+ describe "#verify_licenses!" do
37
+ pending
38
+ end
39
+ end
@@ -1,150 +1,123 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Berkshelf::Location do
4
- # Since this is a module, we need to test the implementation via a class
5
- let(:klass) { Class.new { include Berkshelf::Location } }
4
+ describe "ClassMethods" do
5
+ describe "::init" do
6
+ let(:dependency) { double('dependency') }
6
7
 
7
- describe '.set_location_key' do
8
- before do
9
- @original = Berkshelf::CookbookSource.class_variable_get :@@location_keys
10
- Berkshelf::CookbookSource.class_variable_set :@@location_keys, {}
11
- end
12
-
13
- after do
14
- Berkshelf::CookbookSource.class_variable_set :@@location_keys, @original
15
- end
16
-
17
- it 'adds the given location key CookbookSource.location_keys' do
18
- klass.set_location_key(:reset)
19
-
20
- expect(Berkshelf::CookbookSource.location_keys).to have(1).item
21
- expect(Berkshelf::CookbookSource.location_keys).to include(:reset)
22
- expect(Berkshelf::CookbookSource.location_keys[:reset]).to eq(klass)
23
- end
24
- end
25
-
26
- describe '.location_key' do
27
- before do
28
- @original = Berkshelf::CookbookSource.class_variable_get :@@location_keys
29
- Berkshelf::CookbookSource.class_variable_set :@@location_keys, {}
30
- end
8
+ it 'returns an instance of PathLocation given a path: option key' do
9
+ result = described_class.init(dependency, path: '/Users/reset/code')
10
+ expect(result).to be_a(Berkshelf::PathLocation)
11
+ end
31
12
 
32
- after do
33
- Berkshelf::CookbookSource.class_variable_set :@@location_keys, @original
34
- end
13
+ it 'returns an instance of GitLocation given a git: option key' do
14
+ result = described_class.init(dependency, git: 'git://github.com/something.git')
15
+ expect(result).to be_a(Berkshelf::GitLocation)
16
+ end
35
17
 
36
- it "returns the class' registered location key" do
37
- klass.set_location_key(:reset)
38
- expect(klass.location_key).to eq(:reset)
18
+ context 'given two location_keys' do
19
+ it 'raises an InternalError' do
20
+ expect {
21
+ described_class.init(dependency, git: :value, path: :value)
22
+ }.to raise_error(Berkshelf::InternalError)
23
+ end
24
+ end
39
25
  end
40
26
  end
27
+ end
41
28
 
42
- describe '.set_valid_options' do
43
- before do
44
- @original = Berkshelf::CookbookSource.class_variable_get :@@valid_options
45
- Berkshelf::CookbookSource.class_variable_set :@@valid_options, []
46
- end
47
-
48
- after do
49
- Berkshelf::CookbookSource.class_variable_set :@@valid_options, @original
50
- end
29
+ describe Berkshelf::Location::Base do
30
+ describe "ClassMethods" do
31
+ subject { Class.new(described_class) }
51
32
 
52
- it 'adds the given symbol to the list of valid options on CookbookSource' do
53
- klass.set_valid_options(:mundo)
33
+ describe "::set_location_key" do
34
+ before do
35
+ @original = Berkshelf::Dependency.class_variable_get :@@location_keys
36
+ Berkshelf::Dependency.class_variable_set :@@location_keys, {}
37
+ end
54
38
 
55
- expect(Berkshelf::CookbookSource.valid_options).to have(1).item
56
- expect(Berkshelf::CookbookSource.valid_options).to include(:mundo)
57
- end
39
+ after do
40
+ Berkshelf::Dependency.class_variable_set :@@location_keys, @original
41
+ end
58
42
 
59
- it 'adds parameters to the list of valid options on the CookbookSource' do
60
- klass.set_valid_options(:riot, :arenanet)
43
+ it 'adds the given location key Berkshelf::Dependency.location_keys' do
44
+ subject.set_location_key(:reset)
61
45
 
62
- expect(Berkshelf::CookbookSource.valid_options).to have(2).items
63
- expect(Berkshelf::CookbookSource.valid_options).to include(:riot)
64
- expect(Berkshelf::CookbookSource.valid_options).to include(:arenanet)
46
+ expect(Berkshelf::Dependency.location_keys).to have(1).item
47
+ expect(Berkshelf::Dependency.location_keys).to include(:reset)
48
+ expect(Berkshelf::Dependency.location_keys[:reset]).to eq(subject)
49
+ end
65
50
  end
66
- end
67
51
 
68
- describe '.solve_for_constraint' do
69
- let(:constraint) { '~> 0.101.2' }
70
- let(:versions) do
71
- {
72
- '0.101.2' => 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/0_101_2',
73
- '0.101.0' => 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/0_101_0',
74
- '0.100.2' => 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/0_100_2',
75
- '0.100.0' => 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/0_100_0'
76
- }
77
- end
52
+ describe "::location_key" do
53
+ before do
54
+ @original = Berkshelf::Dependency.class_variable_get :@@location_keys
55
+ Berkshelf::Dependency.class_variable_set :@@location_keys, {}
56
+ end
78
57
 
79
- it 'returns an array with a string containing the version of the solution at index 0' do
80
- result = klass.solve_for_constraint(constraint, versions)
81
- expect(result[0]).to eq('0.101.2')
82
- end
58
+ after do
59
+ Berkshelf::Dependency.class_variable_set :@@location_keys, @original
60
+ end
83
61
 
84
- it 'returns an array containing a URI at index 0' do
85
- result = klass.solve_for_constraint(constraint, versions)
86
- expect(result[1]).to match(URI.regexp)
62
+ it "returns the class' registered location key" do
63
+ subject.set_location_key(:reset)
64
+ expect(subject.location_key).to eq(:reset)
65
+ end
87
66
  end
88
67
 
89
- it 'returns the best match for the constraint and versions given' do
90
- expect(klass.solve_for_constraint(constraint, versions)[0].to_s).to eql('0.101.2')
91
- end
68
+ describe "::set_valid_options" do
69
+ before do
70
+ @original = Berkshelf::Dependency.class_variable_get :@@valid_options
71
+ Berkshelf::Dependency.class_variable_set :@@valid_options, []
72
+ end
92
73
 
93
- context 'given a solution can not be found for constraint' do
94
- it 'returns nil' do
95
- result = klass.solve_for_constraint(Solve::Constraint.new('>= 1.0'), versions)
96
- expect(result).to be_nil
74
+ after do
75
+ Berkshelf::Dependency.class_variable_set :@@valid_options, @original
97
76
  end
98
- end
99
- end
100
77
 
101
- describe ';init' do
102
- let(:name) { 'artifact' }
103
- let(:constraint) { double('constraint') }
78
+ it 'adds the given symbol to the list of valid options on Berkshelf::Dependency' do
79
+ subject.set_valid_options(:mundo)
104
80
 
105
- it 'returns an instance of SiteLocation given a site: option key' do
106
- result = Berkshelf::Location.init(name, constraint, site: 'http://site/value')
107
- expect(result).to be_a(Berkshelf::SiteLocation)
108
- end
81
+ expect(Berkshelf::Dependency.valid_options).to have(1).item
82
+ expect(Berkshelf::Dependency.valid_options).to include(:mundo)
83
+ end
109
84
 
110
- it 'returns an instance of PathLocation given a path: option key' do
111
- result = Berkshelf::Location.init(name, constraint, path: '/Users/reset/code')
112
- expect(result).to be_a(Berkshelf::PathLocation)
113
- end
85
+ it 'adds parameters to the list of valid options on the Berkshelf::Dependency' do
86
+ subject.set_valid_options(:riot, :arenanet)
114
87
 
115
- it 'returns an instance of GitLocation given a git: option key' do
116
- result = Berkshelf::Location.init(name, constraint, git: 'git://github.com/something.git')
117
- expect(result).to be_a(Berkshelf::GitLocation)
88
+ expect(Berkshelf::Dependency.valid_options).to have(2).items
89
+ expect(Berkshelf::Dependency.valid_options).to include(:riot)
90
+ expect(Berkshelf::Dependency.valid_options).to include(:arenanet)
91
+ end
118
92
  end
93
+ end
119
94
 
120
- it 'returns an instance of SiteLocation when no option key is given that matches a registered location_key' do
121
- result = Berkshelf::Location.init(name, constraint)
122
- expect(result).to be_a(Berkshelf::SiteLocation)
123
- end
95
+ let(:name) { "nginx" }
96
+ let(:constraint) { double('constraint') }
97
+ let(:dependency) { double('dependency', name: name, version_constraint: constraint) }
98
+ subject { Class.new(Berkshelf::Location::Base).new(dependency) }
124
99
 
125
- context 'given two location_keys' do
126
- it 'raises an InternalError' do
127
- expect {
128
- Berkshelf::Location.init(name, constraint, git: :value, path: :value)
129
- }.to raise_error(Berkshelf::InternalError)
100
+ describe "#download" do
101
+ context "when #do_download is not defined" do
102
+ it "raises a AbstractFunction" do
103
+ expect { subject.download }.to raise_error(Berkshelf::AbstractFunction)
130
104
  end
131
105
  end
132
- end
133
-
134
106
 
107
+ context "when #do_download is defined" do
108
+ let(:cached) { double('cached') }
109
+ before { subject.stub(do_download: cached) }
135
110
 
136
- let(:name) { 'nginx' }
137
- let(:constraint) { double('constraint') }
111
+ it "validates the returned cached cookbook" do
112
+ subject.should_receive(:validate_cached).with(cached).and_return(true)
113
+ subject.download
114
+ end
138
115
 
139
- subject do
140
- Class.new { include Berkshelf::Location }.new(name, constraint)
141
- end
116
+ it "returns the cached cookbook if valid" do
117
+ subject.stub(validate_cached: true)
142
118
 
143
- describe '#download' do
144
- it 'raises a AbstractFunction if not defined' do
145
- expect {
146
- subject.download(double('destination'))
147
- }.to raise_error(Berkshelf::AbstractFunction)
119
+ expect(subject.download).to eq(cached)
120
+ end
148
121
  end
149
122
  end
150
123
 
@@ -174,7 +147,7 @@ describe Berkshelf::Location do
174
147
  it "warns about the MismatchedCookbookName if the cached_cookbook's name does not match the location's" do
175
148
  constraint.should_receive(:satisfies?).with(cached.version).and_return(true)
176
149
  cached.stub(:cookbook_name) { "artifact" }
177
- msg = Berkshelf::MismatchedCookbookName.new(subject, cached).to_s
150
+ msg = Berkshelf::MismatchedCookbookName.new(dependency, cached).to_s
178
151
 
179
152
  Berkshelf.ui.should_receive(:warn).with(msg)
180
153
  subject.validate_cached(cached)