berkshelf 3.1.5 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/berkshelf.gemspec +6 -5
  4. data/features/commands/search.feature +2 -2
  5. data/features/commands/vendor.feature +6 -2
  6. data/features/commands/verify.feature +29 -0
  7. data/features/config.feature +13 -48
  8. data/features/step_definitions/filesystem_steps.rb +2 -2
  9. data/features/step_definitions/gem_steps.rb +3 -1
  10. data/features/step_definitions/utility_steps.rb +2 -2
  11. data/generator_files/Vagrantfile.erb +30 -30
  12. data/generator_files/metadata.rb.erb +0 -1
  13. data/lib/berkshelf.rb +5 -2
  14. data/lib/berkshelf/berksfile.rb +41 -41
  15. data/lib/berkshelf/cli.rb +11 -1
  16. data/lib/berkshelf/community_rest.rb +1 -0
  17. data/lib/berkshelf/config.rb +18 -4
  18. data/lib/berkshelf/cookbook_store.rb +1 -1
  19. data/lib/berkshelf/downloader.rb +4 -0
  20. data/lib/berkshelf/errors.rb +0 -1
  21. data/lib/berkshelf/file_syncer.rb +134 -0
  22. data/lib/berkshelf/locations/base.rb +6 -1
  23. data/lib/berkshelf/locations/git.rb +2 -2
  24. data/lib/berkshelf/lockfile.rb +14 -2
  25. data/lib/berkshelf/uploader.rb +10 -17
  26. data/lib/berkshelf/validator.rb +37 -0
  27. data/lib/berkshelf/version.rb +1 -1
  28. data/lib/berkshelf/visualizer.rb +13 -6
  29. data/spec/spec_helper.rb +1 -1
  30. data/spec/support/kitchen.rb +3 -1
  31. data/spec/support/matchers/file_system_matchers.rb +1 -1
  32. data/spec/support/matchers/filepath_matchers.rb +38 -2
  33. data/spec/support/shared_examples/formatter.rb +7 -7
  34. data/spec/unit/berkshelf/berksfile_spec.rb +51 -21
  35. data/spec/unit/berkshelf/cached_cookbook_spec.rb +5 -5
  36. data/spec/unit/berkshelf/cli_spec.rb +1 -1
  37. data/spec/unit/berkshelf/community_rest_spec.rb +12 -12
  38. data/spec/unit/berkshelf/config_spec.rb +4 -4
  39. data/spec/unit/berkshelf/cookbook_generator_spec.rb +2 -2
  40. data/spec/unit/berkshelf/cookbook_store_spec.rb +6 -6
  41. data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +3 -3
  42. data/spec/unit/berkshelf/core_ext/pathname_spec.rb +23 -6
  43. data/spec/unit/berkshelf/dependency_spec.rb +4 -4
  44. data/spec/unit/berkshelf/downloader_spec.rb +5 -1
  45. data/spec/unit/berkshelf/errors_spec.rb +1 -1
  46. data/spec/unit/berkshelf/file_syncer_spec.rb +206 -0
  47. data/spec/unit/berkshelf/init_generator_spec.rb +19 -22
  48. data/spec/unit/berkshelf/installer_spec.rb +6 -6
  49. data/spec/unit/berkshelf/locations/base_spec.rb +17 -8
  50. data/spec/unit/berkshelf/locations/git_spec.rb +34 -34
  51. data/spec/unit/berkshelf/locations/path_spec.rb +3 -3
  52. data/spec/unit/berkshelf/lockfile_parser_spec.rb +1 -1
  53. data/spec/unit/berkshelf/lockfile_spec.rb +50 -36
  54. data/spec/unit/berkshelf/packager_spec.rb +6 -4
  55. data/spec/unit/berkshelf/resolver/graph_spec.rb +3 -3
  56. data/spec/unit/berkshelf/resolver_spec.rb +3 -3
  57. data/spec/unit/berkshelf/shell_spec.rb +30 -24
  58. data/spec/unit/berkshelf/uploader_spec.rb +10 -36
  59. data/spec/unit/berkshelf/validator_spec.rb +30 -0
  60. data/spec/unit/berkshelf/visualizer_spec.rb +17 -2
  61. metadata +34 -15
  62. data/lib/berkshelf/mixin/dsl_eval.rb +0 -58
  63. data/spec/unit/berkshelf/mixin/dsl_eval_spec.rb +0 -55
@@ -33,7 +33,7 @@ module Berkshelf
33
33
 
34
34
  describe '#validate_cached!' do
35
35
  context 'when the path is not a cookbook' do
36
- before { File.stub(:cookbook?).and_return(false) }
36
+ before { allow(File).to receive(:cookbook?).and_return(false) }
37
37
 
38
38
  it 'raises an error' do
39
39
  expect {
@@ -51,28 +51,37 @@ module Berkshelf
51
51
  end
52
52
 
53
53
  before do
54
- File.stub(:cookbook?).and_return(true)
55
- CachedCookbook.stub(:from_path).and_return(cookbook)
54
+ allow(File).to receive(:cookbook?).and_return(true)
55
+ allow(CachedCookbook).to receive(:from_path).and_return(cookbook)
56
+ end
57
+
58
+ it 'raises an error if the metadata does not have a name attribute' do
59
+ allow(CachedCookbook).to receive(:from_path)
60
+ .and_raise(ArgumentError)
61
+
62
+ expect {
63
+ subject.validate_cached!(cookbook)
64
+ }.to raise_error(InternalError)
56
65
  end
57
66
 
58
67
  it 'raises an error if the constraint does not satisfy' do
59
- constraint.stub(:satisfies?).with('0.1.0').and_return(false)
68
+ allow(constraint).to receive(:satisfies?).with('0.1.0').and_return(false)
60
69
  expect {
61
70
  subject.validate_cached!(cookbook)
62
71
  }.to raise_error(CookbookValidationFailure)
63
72
  end
64
73
 
65
74
  it 'raises an error if the names do not match' do
66
- constraint.stub(:satisfies?).with('0.1.0').and_return(true)
67
- cookbook.stub(:cookbook_name).and_return('different_name')
75
+ allow(constraint).to receive(:satisfies?).with('0.1.0').and_return(true)
76
+ allow(cookbook).to receive(:cookbook_name).and_return('different_name')
68
77
  expect {
69
78
  subject.validate_cached!(cookbook)
70
79
  }.to raise_error(MismatchedCookbookName)
71
80
  end
72
81
 
73
82
  it 'returns true when the validation succeeds' do
74
- constraint.stub(:satisfies?).with('0.1.0').and_return(true)
75
- expect(subject.validate_cached!(cookbook)).to be_true
83
+ allow(constraint).to receive(:satisfies?).with('0.1.0').and_return(true)
84
+ expect(subject.validate_cached!(cookbook)).to be(true)
76
85
  end
77
86
  end
78
87
  end
@@ -77,36 +77,36 @@ module Berkshelf
77
77
 
78
78
  describe '#installed?' do
79
79
  it 'returns false when there is no revision' do
80
- subject.stub(:revision).and_return(nil)
81
- expect(subject.installed?).to be_false
80
+ allow(subject).to receive(:revision).and_return(nil)
81
+ expect(subject.installed?).to be(false)
82
82
  end
83
83
 
84
84
  it 'returns false when the install_path does not exist' do
85
- subject.stub(:revision).and_return('abcd1234')
86
- subject.stub(:install_path).and_return(double(exist?: false))
87
- expect(subject.installed?).to be_false
85
+ allow(subject).to receive(:revision).and_return('abcd1234')
86
+ allow(subject).to receive(:install_path).and_return(double(exist?: false))
87
+ expect(subject.installed?).to be(false)
88
88
  end
89
89
 
90
90
  it 'returns true when the location is installed' do
91
- subject.stub(:revision).and_return('abcd1234')
92
- subject.stub(:install_path).and_return(double(exist?: true))
93
- expect(subject.installed?).to be_true
91
+ allow(subject).to receive(:revision).and_return('abcd1234')
92
+ allow(subject).to receive(:install_path).and_return(double(exist?: true))
93
+ expect(subject.installed?).to be(true)
94
94
  end
95
95
  end
96
96
 
97
97
  describe '#install' do
98
98
  before do
99
- File.stub(:chmod)
100
- FileUtils.stub(:cp_r)
101
- subject.stub(:validate_cached!)
102
- subject.stub(:git)
99
+ allow(File).to receive(:chmod)
100
+ allow(FileUtils).to receive(:cp_r)
101
+ allow(subject).to receive(:validate_cached!)
102
+ allow(subject).to receive(:git)
103
103
  end
104
104
 
105
105
  context 'when the repository is cached' do
106
106
  it 'pulls a new version' do
107
- Dir.stub(:chdir) { |args, &b| b.call } # Force eval the chdir block
107
+ allow(Dir).to receive(:chdir) { |args, &b| b.call } # Force eval the chdir block
108
108
 
109
- subject.stub(:cached?).and_return(true)
109
+ allow(subject).to receive(:cached?).and_return(true)
110
110
  expect(subject).to receive(:git).with(
111
111
  'fetch --force --tags https://repo.com "refs/heads/*:refs/heads/*"'
112
112
  )
@@ -116,10 +116,10 @@ module Berkshelf
116
116
 
117
117
  context 'when the revision is not cached' do
118
118
  it 'clones the repository' do
119
- Dir.stub(:chdir) { |args, &b| b.call } # Force eval the chdir block
119
+ allow(Dir).to receive(:chdir) { |args, &b| b.call } # Force eval the chdir block
120
120
 
121
121
  cache_path = subject.send(:cache_path)
122
- subject.stub(:cached?).and_return(false)
122
+ allow(subject).to receive(:cached?).and_return(false)
123
123
  expect(subject).to receive(:git).with(
124
124
  %|clone https://repo.com "#{cache_path}" --bare --no-hardlinks|
125
125
  )
@@ -130,13 +130,13 @@ module Berkshelf
130
130
 
131
131
  describe '#cached_cookbook' do
132
132
  it 'returns nil if the cookbook is not installed' do
133
- subject.stub(:installed?).and_return(false)
133
+ allow(subject).to receive(:installed?).and_return(false)
134
134
  expect(subject.cached_cookbook).to be_nil
135
135
  end
136
136
 
137
137
  it 'returns the cookbook at the install_path' do
138
- subject.stub(:installed?).and_return(true)
139
- CachedCookbook.stub(:from_path)
138
+ allow(subject).to receive(:installed?).and_return(true)
139
+ allow(CachedCookbook).to receive(:from_path)
140
140
 
141
141
  expect(CachedCookbook).to receive(:from_path).once
142
142
  subject.cached_cookbook
@@ -151,32 +151,32 @@ module Berkshelf
151
151
  end
152
152
 
153
153
  it 'returns false when the other location is not an GitLocation' do
154
- other.stub(:is_a?).and_return(false)
154
+ allow(other).to receive(:is_a?).and_return(false)
155
155
  expect(subject).to_not eq(other)
156
156
  end
157
157
 
158
158
  it 'returns false when the uri is different' do
159
- other.stub(:uri).and_return('different')
159
+ allow(other).to receive(:uri).and_return('different')
160
160
  expect(subject).to_not eq(other)
161
161
  end
162
162
 
163
163
  it 'returns false when the branch is different' do
164
- other.stub(:branch).and_return('different')
164
+ allow(other).to receive(:branch).and_return('different')
165
165
  expect(subject).to_not eq(other)
166
166
  end
167
167
 
168
168
  it 'returns false when the tag is different' do
169
- other.stub(:tag).and_return('different')
169
+ allow(other).to receive(:tag).and_return('different')
170
170
  expect(subject).to_not eq(other)
171
171
  end
172
172
 
173
173
  it 'returns false when the ref is different' do
174
- other.stub(:ref).and_return('different')
174
+ allow(other).to receive(:ref).and_return('different')
175
175
  expect(subject).to_not eq(other)
176
176
  end
177
177
 
178
178
  it 'returns false when the rel is different' do
179
- other.stub(:rel).and_return('different')
179
+ allow(other).to receive(:rel).and_return('different')
180
180
  expect(subject).to_not eq(other)
181
181
  end
182
182
  end
@@ -187,18 +187,18 @@ module Berkshelf
187
187
  end
188
188
 
189
189
  it 'prefers the branch' do
190
- subject.stub(:tag).and_return(nil)
190
+ allow(subject).to receive(:tag).and_return(nil)
191
191
  expect(subject.to_s).to eq('https://repo.com (at ham/hi)')
192
192
  end
193
193
 
194
194
  it 'falls back to the ref' do
195
- subject.stub(:tag).and_return(nil)
196
- subject.stub(:branch).and_return(nil)
195
+ allow(subject).to receive(:tag).and_return(nil)
196
+ allow(subject).to receive(:branch).and_return(nil)
197
197
  expect(subject.to_s).to eq('https://repo.com (at abc123/hi)')
198
198
  end
199
199
 
200
200
  it 'does not use the rel if missing' do
201
- subject.stub(:rel).and_return(nil)
201
+ allow(subject).to receive(:rel).and_return(nil)
202
202
  expect(subject.to_s).to eq('https://repo.com (at v1.2.3)')
203
203
  end
204
204
  end
@@ -216,17 +216,17 @@ module Berkshelf
216
216
  end
217
217
 
218
218
  it 'does not include the branch if missing' do
219
- subject.stub(:branch).and_return(nil)
219
+ allow(subject).to receive(:branch).and_return(nil)
220
220
  expect(subject.to_lock).to_not include('branch')
221
221
  end
222
222
 
223
223
  it 'does not include the tag if missing' do
224
- subject.stub(:tag).and_return(nil)
224
+ allow(subject).to receive(:tag).and_return(nil)
225
225
  expect(subject.to_lock).to_not include('tag')
226
226
  end
227
227
 
228
228
  it 'does not include the rel if missing' do
229
- subject.stub(:rel).and_return(nil)
229
+ allow(subject).to receive(:rel).and_return(nil)
230
230
  expect(subject.to_lock).to_not include('rel')
231
231
  end
232
232
  end
@@ -235,13 +235,13 @@ module Berkshelf
235
235
  before { described_class.send(:public, :git) }
236
236
 
237
237
  it 'raises an error if Git is not installed' do
238
- Berkshelf.stub(:which).and_return(false)
238
+ allow(Berkshelf).to receive(:which).and_return(false)
239
239
  expect { subject.git('foo') }.to raise_error(GitNotInstalled)
240
240
  end
241
241
 
242
242
  it 'raises an error if the command fails' do
243
243
  shell_out = double('shell_out', success?: false, stderr: nil)
244
- Buff::ShellOut.stub(:shell_out).and_return(shell_out)
244
+ allow(Buff::ShellOut).to receive(:shell_out).and_return(shell_out)
245
245
  expect { subject.git('foo') }.to raise_error(GitCommandError)
246
246
  end
247
247
  end
@@ -18,7 +18,7 @@ module Berkshelf
18
18
 
19
19
  describe '#installed?' do
20
20
  it 'returns false' do
21
- expect(subject.installed?).to be_false
21
+ expect(subject.installed?).to be(false)
22
22
  end
23
23
  end
24
24
 
@@ -83,7 +83,7 @@ module Berkshelf
83
83
  end
84
84
 
85
85
  it 'includes the metadata attribute' do
86
- subject.stub(:metadata?).and_return(true)
86
+ allow(subject).to receive(:metadata?).and_return(true)
87
87
  expect(subject.to_lock).to eq <<-EOH.gsub(/^ {10}/, '')
88
88
  path: #{relative_path}
89
89
  metadata: true
@@ -99,7 +99,7 @@ module Berkshelf
99
99
 
100
100
  describe '#inspect' do
101
101
  it 'includes the right information' do
102
- subject.stub(:metadata?).and_return(true)
102
+ allow(subject).to receive(:metadata?).and_return(true)
103
103
  expect(subject.inspect).to eq("#<Berkshelf::PathLocation metadata: true, path: #{relative_path}>")
104
104
  end
105
105
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Berkshelf::Lockfile do
4
4
  before do
5
- subject.stub(:filepath).and_return(fixture) if defined?(fixture)
5
+ allow(subject).to receive(:filepath).and_return(fixture) if defined?(fixture)
6
6
  subject.parse
7
7
  end
8
8
 
@@ -4,6 +4,20 @@ describe Berkshelf::Lockfile do
4
4
  let(:filepath) { fixtures_path.join('lockfiles/default.lock').to_s }
5
5
  subject { Berkshelf::Lockfile.new(filepath: filepath) }
6
6
 
7
+ describe '.from_berksfile' do
8
+ let(:berksfile) do
9
+ double('Berksfile',
10
+ filepath: '/path/to/Bacon',
11
+ )
12
+ end
13
+
14
+ subject { described_class.from_berksfile(berksfile) }
15
+
16
+ it 'uses the basename of the Berksfile' do
17
+ expect(subject.filepath).to eq("/path/to/Bacon.lock")
18
+ end
19
+ end
20
+
7
21
  describe '.initialize' do
8
22
  subject { described_class.new(filepath: filepath) }
9
23
 
@@ -23,7 +37,7 @@ describe Berkshelf::Lockfile do
23
37
  let(:parser) { double('parser', run: true) }
24
38
 
25
39
  before do
26
- Berkshelf::Lockfile::LockfileParser.stub(:new).and_return(parser)
40
+ allow(Berkshelf::Lockfile::LockfileParser).to receive(:new).and_return(parser)
27
41
  end
28
42
 
29
43
  it 'creates a new parser object' do
@@ -33,23 +47,23 @@ describe Berkshelf::Lockfile do
33
47
  end
34
48
 
35
49
  it 'returns true (always)' do
36
- expect(subject.parse).to be_true
50
+ expect(subject.parse).to be(true)
37
51
  end
38
52
  end
39
53
 
40
54
  describe '#present?' do
41
55
  it 'returns true when the file exists' do
42
- expect(subject.present?).to be_true
56
+ expect(subject.present?).to be(true)
43
57
  end
44
58
 
45
59
  it 'returns false when the file does not exist' do
46
- File.stub(:exists?).and_return(false)
47
- expect(subject.present?).to be_false
60
+ allow(File).to receive(:exists?).and_return(false)
61
+ expect(subject.present?).to be(false)
48
62
  end
49
63
 
50
64
  it 'returns false when the file is empty' do
51
- File.stub(:read).and_return('')
52
- expect(subject.present?).to be_false
65
+ allow(File).to receive(:read).and_return('')
66
+ expect(subject.present?).to be(false)
53
67
  end
54
68
  end
55
69
 
@@ -66,10 +80,10 @@ describe Berkshelf::Lockfile do
66
80
  )
67
81
  berksfile = double('berksfile', dependencies: [apt])
68
82
  subject.instance_variable_set(:@berksfile, berksfile)
69
- subject.stub(:find).with(apt).and_return(apt)
70
- subject.graph.stub(:find).with(apt).and_return(apt)
83
+ allow(subject).to receive(:find).with(apt).and_return(apt)
84
+ allow(subject.graph).to receive(:find).with(apt).and_return(apt)
71
85
 
72
- expect(subject.trusted?).to be_true
86
+ expect(subject.trusted?).to be(true)
73
87
  end
74
88
 
75
89
  it 'returns true when the lockfile is trusted with transitive dependencies' do
@@ -85,11 +99,11 @@ describe Berkshelf::Lockfile do
85
99
  bacon = double(name: 'bacon', version: '1.0.0', dependencies: {})
86
100
  berksfile = double('berksfile', dependencies: [apt])
87
101
  subject.instance_variable_set(:@berksfile, berksfile)
88
- subject.stub(:find).with(apt).and_return(apt)
89
- subject.graph.stub(:find).with('bacon').and_return(bacon)
90
- subject.graph.stub(:find).with(apt).and_return(apt)
102
+ allow(subject).to receive(:find).with(apt).and_return(apt)
103
+ allow(subject.graph).to receive(:find).with('bacon').and_return(bacon)
104
+ allow(subject.graph).to receive(:find).with(apt).and_return(apt)
91
105
 
92
- expect(subject.trusted?).to be_true
106
+ expect(subject.trusted?).to be(true)
93
107
  end
94
108
 
95
109
  it 'returns true when the lockfile is trusted with cyclic transitive dependencies' do
@@ -111,11 +125,11 @@ describe Berkshelf::Lockfile do
111
125
  )
112
126
  berksfile = double('berksfile', dependencies: [apt])
113
127
  subject.instance_variable_set(:@berksfile, berksfile)
114
- subject.stub(:find).with(apt).and_return(apt)
115
- subject.graph.stub(:find).with('bacon').and_return(bacon)
116
- subject.graph.stub(:find).with(apt).and_return(apt)
128
+ allow(subject).to receive(:find).with(apt).and_return(apt)
129
+ allow(subject.graph).to receive(:find).with('bacon').and_return(bacon)
130
+ allow(subject.graph).to receive(:find).with(apt).and_return(apt)
117
131
 
118
- expect(subject.trusted?).to be_true
132
+ expect(subject.trusted?).to be(true)
119
133
  end
120
134
 
121
135
  it 'returns false when the lockfile is not trusted because of transitive dependencies' do
@@ -130,10 +144,10 @@ describe Berkshelf::Lockfile do
130
144
  )
131
145
  berksfile = double('berksfile', dependencies: [apt])
132
146
  subject.instance_variable_set(:@berksfile, berksfile)
133
- subject.stub(:find).with(apt).and_return(apt)
134
- subject.graph.stub(:find).with(apt).and_return(apt)
147
+ allow(subject).to receive(:find).with(apt).and_return(apt)
148
+ allow(subject.graph).to receive(:find).with(apt).and_return(apt)
135
149
 
136
- expect(subject.trusted?).to be_false
150
+ expect(subject.trusted?).to be(false)
137
151
  end
138
152
 
139
153
  it 'returns false if the dependency is not in the lockfile' do
@@ -141,17 +155,17 @@ describe Berkshelf::Lockfile do
141
155
  berksfile = double('berksfile', dependencies: [apt])
142
156
  subject.instance_variable_set(:@berksfile, berksfile)
143
157
 
144
- expect(subject.trusted?).to be_false
158
+ expect(subject.trusted?).to be(false)
145
159
  end
146
160
 
147
161
  it 'returns false if the dependency is not in the graph' do
148
162
  apt = double('apt', name: 'apt', version_constraint: nil)
149
163
  berksfile = double('berksfile', dependencies: [apt])
150
164
  subject.instance_variable_set(:@berksfile, berksfile)
151
- subject.stub(:find).with(apt).and_return(true)
152
- subject.graph.stub(:find).with(apt).and_return(nil)
165
+ allow(subject).to receive(:find).with(apt).and_return(true)
166
+ allow(subject.graph).to receive(:find).with(apt).and_return(nil)
153
167
 
154
- expect(subject.trusted?).to be_false
168
+ expect(subject.trusted?).to be(false)
155
169
  end
156
170
 
157
171
  it 'returns false if the constraint is not satisfied' do
@@ -166,10 +180,10 @@ describe Berkshelf::Lockfile do
166
180
  )
167
181
  berksfile = double('berksfile', dependencies: [apt])
168
182
  subject.instance_variable_set(:@berksfile, berksfile)
169
- subject.stub(:find).with(apt).and_return(apt)
170
- subject.graph.stub(:find).with(apt).and_return(apt)
183
+ allow(subject).to receive(:find).with(apt).and_return(apt)
184
+ allow(subject.graph).to receive(:find).with(apt).and_return(apt)
171
185
 
172
- expect(subject.trusted?).to be_false
186
+ expect(subject.trusted?).to be(false)
173
187
  end
174
188
 
175
189
  it 'returns false if the locations are different' do
@@ -183,13 +197,13 @@ describe Berkshelf::Lockfile do
183
197
  cached_cookbook: cookbook,
184
198
  )
185
199
  apt_master = apt.dup
186
- apt_master.stub(location: 'github')
200
+ allow(apt_master).to receive_messages(location: 'github')
187
201
  berksfile = double('berksfile', dependencies: [apt])
188
202
  subject.instance_variable_set(:@berksfile, berksfile)
189
- subject.stub(:find).with(apt).and_return(apt_master)
190
- subject.graph.stub(:find).with(apt).and_return(apt)
203
+ allow(subject).to receive(:find).with(apt).and_return(apt_master)
204
+ allow(subject.graph).to receive(:find).with(apt).and_return(apt)
191
205
 
192
- expect(subject.trusted?).to be_false
206
+ expect(subject.trusted?).to be(false)
193
207
  end
194
208
  end
195
209
 
@@ -197,12 +211,12 @@ describe Berkshelf::Lockfile do
197
211
  let(:connection) { double('connection') }
198
212
 
199
213
  before do
200
- Berkshelf.stub(:ridley_connection).and_yield(connection)
214
+ allow(Berkshelf).to receive(:ridley_connection).and_yield(connection)
201
215
  end
202
216
 
203
217
  context 'when the Chef environment does not exist' do
204
218
  it 'raises an exception' do
205
- connection.stub(:environment).and_return(double(find: nil))
219
+ allow(connection).to receive(:environment).and_return(double(find: nil))
206
220
  expect {
207
221
  subject.apply('production')
208
222
  }.to raise_error(Berkshelf::EnvironmentNotFound)
@@ -212,10 +226,10 @@ describe Berkshelf::Lockfile do
212
226
  it 'locks the environment cookbook versions' do
213
227
  apt = double(name: 'apt', locked_version: '1.0.0')
214
228
  jenkins = double(name: 'jenkins', locked_version: '1.4.5')
215
- subject.graph.stub(:locks).and_return('apt' => apt, 'jenkins' => jenkins)
229
+ allow(subject.graph).to receive(:locks).and_return('apt' => apt, 'jenkins' => jenkins)
216
230
 
217
231
  environment = double('environment', :cookbook_versions= => nil, save: true)
218
- connection.stub(:environment).and_return(double(find: environment))
232
+ allow(connection).to receive(:environment).and_return(double(find: environment))
219
233
 
220
234
  expect(environment).to receive(:cookbook_versions=).with(
221
235
  'apt' => '= 1.0.0',