berkshelf 7.0.9 → 8.0.9

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -13
  3. data/Rakefile +2 -2
  4. data/berkshelf.gemspec +13 -5
  5. data/bin/berks +1 -1
  6. data/lib/berkshelf/api_client/chef_server_connection.rb +4 -6
  7. data/lib/berkshelf/api_client/remote_cookbook.rb +1 -1
  8. data/lib/berkshelf/api_client.rb +2 -2
  9. data/lib/berkshelf/berksfile.rb +34 -34
  10. data/lib/berkshelf/chef_config_compat.rb +1 -1
  11. data/lib/berkshelf/cli.rb +5 -5
  12. data/lib/berkshelf/community_rest.rb +3 -3
  13. data/lib/berkshelf/config.rb +2 -2
  14. data/lib/berkshelf/cookbook_store.rb +2 -4
  15. data/lib/berkshelf/core_ext/file_utils.rb +3 -3
  16. data/lib/berkshelf/downloader.rb +6 -6
  17. data/lib/berkshelf/errors.rb +3 -0
  18. data/lib/berkshelf/file_syncer.rb +10 -12
  19. data/lib/berkshelf/installer.rb +7 -7
  20. data/lib/berkshelf/location.rb +4 -4
  21. data/lib/berkshelf/locations/git.rb +6 -12
  22. data/lib/berkshelf/locations/github.rb +1 -1
  23. data/lib/berkshelf/lockfile.rb +9 -9
  24. data/lib/berkshelf/mixin/git.rb +2 -2
  25. data/lib/berkshelf/packager.rb +40 -6
  26. data/lib/berkshelf/shell.rb +1 -1
  27. data/lib/berkshelf/shell_out.rb +4 -3
  28. data/lib/berkshelf/source.rb +2 -2
  29. data/lib/berkshelf/source_uri.rb +1 -1
  30. data/lib/berkshelf/ssl_policies.rb +6 -8
  31. data/lib/berkshelf/thor_ext/hash_with_indifferent_access.rb +1 -1
  32. data/lib/berkshelf/uploader.rb +36 -36
  33. data/lib/berkshelf/validator.rb +13 -8
  34. data/lib/berkshelf/version.rb +1 -1
  35. data/lib/berkshelf/visualizer.rb +2 -2
  36. data/lib/berkshelf.rb +7 -8
  37. data/spec/config/knife.rb +1 -1
  38. data/spec/spec_helper.rb +1 -1
  39. data/spec/support/git.rb +19 -19
  40. data/spec/support/path_helpers.rb +4 -4
  41. data/spec/unit/berkshelf/berkshelf/api_client/chef_server_connection_spec.rb +65 -0
  42. data/spec/unit/berkshelf/berkshelf/api_client/connection_spec.rb +3 -3
  43. data/spec/unit/berkshelf/community_rest_spec.rb +3 -3
  44. data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +2 -2
  45. data/spec/unit/berkshelf/dependency_spec.rb +1 -1
  46. data/spec/unit/berkshelf/location_spec.rb +1 -1
  47. data/spec/unit/berkshelf/locations/git_spec.rb +2 -5
  48. data/spec/unit/berkshelf/lockfile_spec.rb +2 -2
  49. data/spec/unit/berkshelf/ridley_compat_spec.rb +1 -1
  50. data/spec/unit/berkshelf/source_spec.rb +22 -12
  51. data/spec/unit/berkshelf/ssl_policies_spec.rb +0 -1
  52. data/spec/unit/berkshelf/validator_spec.rb +10 -7
  53. metadata +13 -9
@@ -1,5 +1,6 @@
1
1
  require "archive/tar/minitar"
2
- require "zlib"
2
+ require "find" unless defined?(Find)
3
+ require "zlib" unless defined?(Zlib)
3
4
 
4
5
  module Berkshelf
5
6
  # A class for archiving and compressing directory containing one or more cookbooks.
@@ -40,9 +41,17 @@ module Berkshelf
40
41
  # @return [String]
41
42
  # path to the generated archive
42
43
  def run(source)
43
- Dir.chdir(source.to_s) do |dir|
44
- tgz = Zlib::GzipWriter.new(File.open(out_file, "wb"))
45
- Archive::Tar::Minitar.pack(Dir.glob("*"), tgz)
44
+ begin
45
+ dest = Zlib::GzipWriter.open(out_file)
46
+ tar = RelativeTarWriter.new(dest, source)
47
+ Find.find(source) do |entry|
48
+ next if source == entry
49
+
50
+ Archive::Tar::Minitar.pack_file(entry, tar)
51
+ end
52
+ ensure
53
+ tar.close
54
+ dest.close
46
55
  end
47
56
 
48
57
  out_file
@@ -64,10 +73,35 @@ module Berkshelf
64
73
 
65
74
  private
66
75
 
67
- # @return [String]
76
+ # @return [String]
68
77
  attr_reader :out_dir
69
78
 
70
- # @return [String]
79
+ # @return [String]
71
80
  attr_reader :filename
81
+
82
+ # A private decorator for Archive::Tar::Minitar::Writer that
83
+ # turns absolute paths into relative ones.
84
+ class RelativeTarWriter < SimpleDelegator # :nodoc:
85
+ def initialize(io, base_path)
86
+ @base_path = Pathname.new(base_path)
87
+ super(Archive::Tar::Minitar::Writer.new(io))
88
+ end
89
+
90
+ %w{add_file add_file_simple mkdir}.each do |method|
91
+ class_eval <<~RUBY
92
+ def #{method}(name, *opts, &block)
93
+ super(relative_path(name), *opts, &block)
94
+ end
95
+ RUBY
96
+ end
97
+
98
+ private
99
+
100
+ attr_reader :base_path
101
+
102
+ def relative_path(path)
103
+ Pathname.new(path).relative_path_from(base_path).to_s
104
+ end
105
+ end
72
106
  end
73
107
  end
@@ -1,4 +1,4 @@
1
- require "thor"
1
+ require "thor" unless defined?(Thor)
2
2
 
3
3
  module Berkshelf
4
4
  # Subclass the current shell (which is different based on the OS)
@@ -1,4 +1,4 @@
1
- require "mixlib/shellout"
1
+ require "mixlib/shellout" unless defined?(Mixlib::ShellOut)
2
2
 
3
3
  module Berkshelf
4
4
  module ShellOut
@@ -8,8 +8,9 @@ module Berkshelf
8
8
  cmd
9
9
  end
10
10
 
11
- def shell_out!(*args)
12
- cmd = shell_out(*args)
11
+ def shell_out!(*args, **options)
12
+ cmd = Mixlib::ShellOut.new(*args, **options)
13
+ cmd.run_command
13
14
  cmd.error!
14
15
  cmd
15
16
  end
@@ -1,7 +1,7 @@
1
1
  require_relative "api-client"
2
2
  require_relative "chef_repo_universe"
3
3
  require_relative "ssl_policies"
4
- require "openssl"
4
+ require "openssl" unless defined?(OpenSSL)
5
5
 
6
6
  module Berkshelf
7
7
  class Source
@@ -132,7 +132,7 @@ module Berkshelf
132
132
  #
133
133
  # @return [APIClient::RemoteCookbook]
134
134
  def latest(name)
135
- versions(name).sort.last
135
+ versions(name).max
136
136
  end
137
137
 
138
138
  # @param [String] name
@@ -1,4 +1,4 @@
1
- require "addressable/uri"
1
+ require "addressable/uri" unless defined?(Addressable::URI)
2
2
 
3
3
  module Berkshelf
4
4
  class SourceURI < Addressable::URI
@@ -1,4 +1,4 @@
1
- require "openssl"
1
+ require "openssl" unless defined?(OpenSSL)
2
2
 
3
3
  module Berkshelf
4
4
  class SSLPolicy
@@ -16,11 +16,11 @@ module Berkshelf
16
16
  def add_trusted_cert(cert)
17
17
  @store.add_cert(cert)
18
18
  rescue OpenSSL::X509::StoreError => e
19
- raise e unless e.message == "cert already in hash table"
19
+ raise e unless e.message.match(/cert already in hash table/)
20
20
  end
21
21
 
22
22
  def trusted_certs_dir
23
- config_dir = Berkshelf.config.chef.trusted_certs_dir.to_s.tr('\\', "/")
23
+ config_dir = Berkshelf.config.chef.trusted_certs_dir.to_s.tr("\\", "/")
24
24
  if config_dir.empty? || !::File.exist?(config_dir)
25
25
  File.join(ENV["HOME"], ".chef", "trusted_certs")
26
26
  else
@@ -29,11 +29,9 @@ module Berkshelf
29
29
  end
30
30
 
31
31
  def set_custom_certs
32
- Dir.chdir(trusted_certs_dir) do
33
- ::Dir.glob("{*.crt,*.pem}").each do |cert|
34
- cert = OpenSSL::X509::Certificate.new(IO.read(cert))
35
- add_trusted_cert(cert)
36
- end
32
+ ::Dir.glob("#{trusted_certs_dir}/{*.crt,*.pem}").each do |cert|
33
+ cert = OpenSSL::X509::Certificate.new(IO.read(cert))
34
+ add_trusted_cert(cert)
37
35
  end
38
36
  end
39
37
  end
@@ -1,5 +1,5 @@
1
1
  class Thor
2
- module CoreExt #:nodoc:
2
+ module CoreExt # :nodoc:
3
3
  class HashWithIndifferentAccess < ::Hash
4
4
  def has_key?(key)
5
5
  super(convert_key(key))
@@ -45,10 +45,10 @@ module Berkshelf
45
45
 
46
46
  private
47
47
 
48
- # Upload the list of cookbooks to the Chef Server, with some exception
49
- # wrapping.
50
- #
51
- # @param [Array<String>] cookbooks
48
+ # Upload the list of cookbooks to the Chef Server, with some exception
49
+ # wrapping.
50
+ #
51
+ # @param [Array<String>] cookbooks
52
52
  def upload(cookbooks)
53
53
  Berkshelf.log.info "Starting upload"
54
54
 
@@ -59,41 +59,41 @@ module Berkshelf
59
59
  connection.get("users/#{Berkshelf.config.chef.node_name}") rescue nil
60
60
 
61
61
  cookbooks.map do |cookbook|
62
+
63
+ compiled_metadata = cookbook.compile_metadata
64
+ cookbook.reload if compiled_metadata
65
+ cookbook_version = cookbook.cookbook_version
66
+ Berkshelf.log.debug " Uploading #{cookbook.cookbook_name}"
67
+ cookbook_version.freeze_version if options[:freeze]
68
+
69
+ # another two lines that are necessary for chef < 13.2 support (affects 11.x/12.x as well)
70
+ cookbook_version.metadata.maintainer "" if cookbook_version.metadata.maintainer.nil?
71
+ cookbook_version.metadata.maintainer_email "" if cookbook_version.metadata.maintainer_email.nil?
72
+
62
73
  begin
63
- compiled_metadata = cookbook.compile_metadata
64
- cookbook.reload if compiled_metadata
65
- cookbook_version = cookbook.cookbook_version
66
- Berkshelf.log.debug " Uploading #{cookbook.cookbook_name}"
67
- cookbook_version.freeze_version if options[:freeze]
68
-
69
- # another two lines that are necessary for chef < 13.2 support (affects 11.x/12.x as well)
70
- cookbook_version.metadata.maintainer "" if cookbook_version.metadata.maintainer.nil?
71
- cookbook_version.metadata.maintainer_email "" if cookbook_version.metadata.maintainer_email.nil?
72
-
73
- begin
74
- Chef::CookbookUploader.new(
75
- [ cookbook_version ],
76
- force: options[:force],
77
- concurrency: 1, # sadly
78
- rest: connection,
79
- skip_syntax_check: options[:skip_syntax_check]
80
- ).upload_cookbooks
81
- Berkshelf.formatter.uploaded(cookbook, connection)
82
- rescue Chef::Exceptions::CookbookFrozen
83
- if options[:halt_on_frozen]
84
- raise FrozenCookbook.new(cookbook)
85
- end
86
-
87
- Berkshelf.formatter.skipping(cookbook, connection)
88
- end
89
- ensure
90
- if compiled_metadata
91
- # this is necessary on windows to clean up the ruby object that was pointing at the file
92
- # so that we can reliably delete it. windows is terrible.
93
- GC.start
94
- File.unlink(compiled_metadata)
74
+ Chef::CookbookUploader.new(
75
+ [ cookbook_version ],
76
+ force: options[:force],
77
+ concurrency: 1, # sadly
78
+ rest: connection,
79
+ skip_syntax_check: options[:skip_syntax_check]
80
+ ).upload_cookbooks
81
+ Berkshelf.formatter.uploaded(cookbook, connection)
82
+ rescue Chef::Exceptions::CookbookFrozen
83
+ if options[:halt_on_frozen]
84
+ raise FrozenCookbook.new(cookbook)
95
85
  end
86
+
87
+ Berkshelf.formatter.skipping(cookbook, connection)
96
88
  end
89
+ ensure
90
+ if compiled_metadata
91
+ # this is necessary on windows to clean up the ruby object that was pointing at the file
92
+ # so that we can reliably delete it. windows is terrible.
93
+ GC.start
94
+ File.unlink(compiled_metadata)
95
+ end
96
+
97
97
  end
98
98
  end
99
99
  end
@@ -1,3 +1,5 @@
1
+ require 'chef/version_class'
2
+
1
3
  module Berkshelf
2
4
  module Validator
3
5
  class << self
@@ -22,19 +24,22 @@ module Berkshelf
22
24
  # the Cookbook(s) to validate
23
25
  def validate_files(cookbooks)
24
26
  Array(cookbooks).each do |cookbook|
25
- path = cookbook.path.to_s
27
+ base, name = Pathname.new(cookbook.path.to_s).split
26
28
 
27
- files = Dir.chdir(path) do
28
- Dir.glob(File.join("**", "*.rb")).select do |f|
29
- f = File.join(path, f)
30
- parent = Pathname.new(path).dirname.to_s
31
- f.gsub(parent, "") =~ /[[:space:]]/
32
- end
33
- end
29
+ files = Dir.glob("#{name}/**/*.rb", base: base.to_s).select { |f| f =~ /[[:space:]]/ }
30
+ validate_versions(cookbook)
34
31
 
35
32
  raise InvalidCookbookFiles.new(cookbook, files) unless files.empty?
36
33
  end
37
34
  end
35
+
36
+ def validate_versions(cookbook)
37
+ cookbook_dependencies = cookbook.dependencies
38
+ cookbook_dependencies.each do |cookbook_name, cookbook_version|
39
+ version = cookbook_version.gsub(/[^\d,\.]/, '')
40
+ Chef::Version.new(version)
41
+ end
42
+ end
38
43
  end
39
44
  end
40
45
  end
@@ -1,3 +1,3 @@
1
1
  module Berkshelf
2
- VERSION = "7.0.9".freeze
2
+ VERSION = "8.0.9".freeze
3
3
  end
@@ -1,5 +1,5 @@
1
- require "set"
2
- require "tempfile"
1
+ require "set" unless defined?(Set)
2
+ require "tempfile" unless defined?(Tempfile)
3
3
  require_relative "shell_out"
4
4
 
5
5
  module Berkshelf
data/lib/berkshelf.rb CHANGED
@@ -10,14 +10,14 @@ rescue LoadError
10
10
  end
11
11
 
12
12
  require "cleanroom"
13
- require "digest/md5"
14
- require "forwardable"
15
- require "json"
16
- require "pathname"
13
+ require "digest/md5" unless defined?(Digest::MD5)
14
+ require "forwardable" unless defined?(Forwardable)
15
+ require "json" unless defined?(JSON)
16
+ require "pathname" unless defined?(Pathname)
17
17
  require "semverse"
18
18
  require "solve"
19
- require "thor"
20
- require "uri"
19
+ require "thor" unless defined?(Thor)
20
+ require "uri" unless defined?(URI)
21
21
 
22
22
  JSON.create_id = nil
23
23
 
@@ -169,7 +169,7 @@ module Berkshelf
169
169
  raise ChefConnectionError, "Missing required attribute in your Berkshelf configuration: chef.client_key"
170
170
  end
171
171
 
172
- RidleyCompat.new_client(ridley_options, &block)
172
+ RidleyCompat.new_client(**ridley_options, &block)
173
173
  rescue ChefConnectionError, BerkshelfError
174
174
  raise
175
175
  rescue => ex
@@ -222,7 +222,6 @@ require_relative "berkshelf/lockfile"
222
222
  require_relative "berkshelf/berksfile"
223
223
  require_relative "berkshelf/cached_cookbook"
224
224
  require_relative "berkshelf/cli"
225
- require_relative "berkshelf/chef_config_compat"
226
225
  require_relative "berkshelf/community_rest"
227
226
  require_relative "berkshelf/cookbook_store"
228
227
  require_relative "berkshelf/config"
data/spec/config/knife.rb CHANGED
@@ -4,7 +4,7 @@ node_name "berkshelf"
4
4
  client_key File.expand_path("spec/config/berkshelf.pem")
5
5
  validation_client_name "validator"
6
6
  validation_key File.expand_path("spec/config/validator.pem")
7
- chef_server_url "http://localhost:26310"
7
+ chef_server_url "http://127.0.0.1:26310"
8
8
  cache_type "BasicFile"
9
9
  cache_options( path: "#{ENV["HOME"]}/.chef/checksums" )
10
10
  cookbook_path []
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ def windows?
2
2
  !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
3
3
  end
4
4
 
5
- BERKS_SPEC_DATA = File.expand_path("../data", __FILE__)
5
+ BERKS_SPEC_DATA = File.expand_path("data", __dir__)
6
6
 
7
7
  require "rspec"
8
8
  require "cleanroom/rspec"
data/spec/support/git.rb CHANGED
@@ -5,7 +5,7 @@ module Berkshelf
5
5
  include Berkshelf::RSpec::PathHelpers
6
6
 
7
7
  def git_origin_for(repo, options = {})
8
- "file://#{generate_fake_git_remote("git@github.com/RiotGames/#{repo}.git", options)}/.git"
8
+ "file://#{generate_fake_git_remote("git@github.com/chef/#{repo}.git", options)}/.git"
9
9
  end
10
10
 
11
11
  def generate_fake_git_remote(uri, options = {})
@@ -84,26 +84,26 @@ module Berkshelf
84
84
 
85
85
  private
86
86
 
87
- # The path to store the local git clones.
88
- #
89
- # @return [Pathname]
87
+ # The path to store the local git clones.
88
+ #
89
+ # @return [Pathname]
90
90
  def clones
91
91
  ensure_and_return(tmp_path.join("clones"))
92
92
  end
93
93
 
94
- # The path to store the git remotes.
95
- #
96
- # @return [Pathname]
94
+ # The path to store the git remotes.
95
+ #
96
+ # @return [Pathname]
97
97
  def remotes
98
98
  ensure_and_return(tmp_path.join("remotes"))
99
99
  end
100
100
 
101
- # Generate a cookbook by the given name.
102
- #
103
- # @param [#to_s] name
104
- # the name of the cookbook to create
105
- # @param [Hash] options
106
- # the list ooptions to pass to the generator
101
+ # Generate a cookbook by the given name.
102
+ #
103
+ # @param [#to_s] name
104
+ # the name of the cookbook to create
105
+ # @param [Hash] options
106
+ # the list ooptions to pass to the generator
107
107
  def generate_git_cookbook(name, options = {})
108
108
  options = {
109
109
  skip_vagrant: true,
@@ -114,12 +114,12 @@ module Berkshelf
114
114
  Berkshelf::Cli.new.invoke(:cookbook, [name.to_s], options)
115
115
  end
116
116
 
117
- # Make sure the given path exists and return the path
118
- #
119
- # @param [#to_s] path
120
- # the path to create and return
121
- #
122
- # @return [Pathname]
117
+ # Make sure the given path exists and return the path
118
+ #
119
+ # @param [#to_s] path
120
+ # the path to create and return
121
+ #
122
+ # @return [Pathname]
123
123
  def ensure_and_return(path)
124
124
  FileUtils.mkdir(path) unless File.exist?(path)
125
125
  Pathname.new(path).expand_path
@@ -50,10 +50,10 @@ module Berkshelf
50
50
 
51
51
  private
52
52
 
53
- # This is the magical "reset" function that gives us a clean working
54
- # directory on each run.
55
- #
56
- # @return [nil]
53
+ # This is the magical "reset" function that gives us a clean working
54
+ # directory on each run.
55
+ #
56
+ # @return [nil]
57
57
  def reload_configs
58
58
  Berkshelf.chef_config = chef_config
59
59
 
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+
3
+ describe Berkshelf::APIClient::ChefServerConnection do
4
+ let(:instance) do
5
+ described_class.new(
6
+ server_url: "https://chef.example.org/organizations/foobar",
7
+ timeout: 30,
8
+ open_timeout: 3,
9
+ ssl: {}
10
+ )
11
+ end
12
+
13
+ describe "#universe" do
14
+ before do
15
+ body_response = %q{{"ruby":{"1.2.3":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"},"2.0.0":{"endpoint_priority":0,"platforms":{},"dependencies":{"build-essential":">= 1.2.2"},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}},"elixir":{"1.0.0":{"endpoint_priority":0,"platforms":{"CentOS":"= 6.0.0"},"dependencies":{},"location_type":"supermarket","location_path":"https://supermarket.getchef.com/"}}}}
16
+
17
+ stub_request(:get, "https://chef.example.org/organizations/foobar/universe")
18
+ .to_return(status: 200, body: body_response, headers: { "Content-Type" => "application/json; charset=utf-8" })
19
+ end
20
+
21
+ subject { instance.universe }
22
+
23
+ it "returns an array of APIClient::RemoteCookbook" do
24
+ expect(subject).to be_a(Array)
25
+
26
+ subject.each do |remote|
27
+ expect(remote).to be_a(Berkshelf::APIClient::RemoteCookbook)
28
+ end
29
+ end
30
+
31
+ it "contains a item for each dependency" do
32
+ expect(subject.size).to eq(3)
33
+ expect(subject[0].name).to eql("ruby")
34
+ expect(subject[0].version).to eql("1.2.3")
35
+ expect(subject[1].name).to eql("ruby")
36
+ expect(subject[1].version).to eql("2.0.0")
37
+ expect(subject[2].name).to eql("elixir")
38
+ expect(subject[2].version).to eql("1.0.0")
39
+ end
40
+
41
+ it "has the dependencies for each" do
42
+ expect(subject[0].dependencies).to include("build-essential" => ">= 1.2.2")
43
+ expect(subject[1].dependencies).to include("build-essential" => ">= 1.2.2")
44
+ expect(subject[2].dependencies).to be_empty
45
+ end
46
+
47
+ it "has the platforms for each" do
48
+ expect(subject[0].platforms).to be_empty
49
+ expect(subject[1].platforms).to be_empty
50
+ expect(subject[2].platforms).to include("CentOS" => "= 6.0.0")
51
+ end
52
+
53
+ it "has a location_path for each" do
54
+ subject.each do |remote|
55
+ expect(remote.location_path).to_not be_nil
56
+ end
57
+ end
58
+
59
+ it "has a location_type for each" do
60
+ subject.each do |remote|
61
+ expect(remote.location_type).to_not be_nil
62
+ end
63
+ end
64
+ end
65
+ end
@@ -130,17 +130,17 @@ describe Berkshelf::APIClient::Connection do
130
130
  end
131
131
 
132
132
  it "raises Berkshelf::APIClient::ServiceUnavailable for 500s" do
133
- stub_request(:get, "http://supermarket.getchef.com/universe").to_return(status: [500, "Internal Server Error"])
133
+ stub_request(:get, "http://supermarket.getchef.com/universe").to_return(status: 500, body: "Internal Server Error")
134
134
  expect { subject }.to raise_error(Berkshelf::APIClient::ServiceUnavailable)
135
135
  end
136
136
 
137
137
  it "raises Berkshelf::APIClient::ServiceNotFound for 404s" do
138
- stub_request(:get, "http://supermarket.getchef.com/universe").to_return(status: [404, "Not Found"])
138
+ stub_request(:get, "http://supermarket.getchef.com/universe").to_return(status: 404, body: "Not Found")
139
139
  expect { subject }.to raise_error(Berkshelf::APIClient::ServiceNotFound)
140
140
  end
141
141
 
142
142
  it "raises Net::HTTPBadRequest for 400s" do
143
- stub_request(:get, "http://supermarket.getchef.com/universe").to_return(status: [400, "Bad Request"])
143
+ stub_request(:get, "http://supermarket.getchef.com/universe").to_return(status: 400, body: "Bad Request")
144
144
  expect { subject }.to raise_error(Berkshelf::APIClient::BadResponse)
145
145
  end
146
146
 
@@ -107,7 +107,7 @@ describe Berkshelf::CommunityREST do
107
107
  it "raises a CookbookNotFound error on a 404 response for a non-existent cookbook" do
108
108
  stub_request(:get, "#{api_uri}/cookbooks/not_real/versions/1_0_0").to_return(
109
109
  status: 404,
110
- body: nil
110
+ body: "Not Found"
111
111
  )
112
112
 
113
113
  expect do
@@ -142,7 +142,7 @@ describe Berkshelf::CommunityREST do
142
142
  it "raises a CookbookNotFound error on a 404 response" do
143
143
  stub_request(:get, "#{api_uri}/cookbooks/not_real").to_return(
144
144
  status: 404,
145
- body: nil
145
+ body: "Not Found"
146
146
  )
147
147
 
148
148
  expect do
@@ -177,7 +177,7 @@ describe Berkshelf::CommunityREST do
177
177
  it "raises a CookbookNotFound error on a 404 response" do
178
178
  stub_request(:get, "#{api_uri}/cookbooks/not_real").to_return(
179
179
  status: 404,
180
- body: nil
180
+ body: "Not Found"
181
181
  )
182
182
 
183
183
  expect do
@@ -7,12 +7,12 @@ describe FileUtils do
7
7
  let(:options) { {} }
8
8
 
9
9
  it "uses mv by default" do
10
- expect(FileUtils).to receive(:old_mv).with(src, dest, options)
10
+ expect(FileUtils).to receive(:old_mv).with(src, dest, **options)
11
11
  FileUtils.mv(src, dest, options)
12
12
  end
13
13
 
14
14
  it "replaces mv with cp_r and rm_rf" do
15
- expect(FileUtils).to receive(:cp_r).with(src, dest, options)
15
+ expect(FileUtils).to receive(:cp_r).with(src, dest, **options)
16
16
  expect(FileUtils).to receive(:rm_rf).with(src)
17
17
 
18
18
  FileUtils.mv(src, dest, options)
@@ -35,7 +35,7 @@ describe Berkshelf::Dependency do
35
35
  end
36
36
 
37
37
  context "given a location key :git" do
38
- let(:url) { "git://url_to_git" }
38
+ let(:url) { "https://url_to_git" }
39
39
  let(:source) { described_class.new(berksfile, cookbook_name, git: url) }
40
40
 
41
41
  it "initializes a GitLocation for location" do
@@ -11,7 +11,7 @@ module Berkshelf
11
11
  end
12
12
 
13
13
  it "finds a :git location by key" do
14
- instance = described_class.init(dependency, git: "git://foo.com/meats/bacon.git")
14
+ instance = described_class.init(dependency, git: "https://foo.com/meats/bacon.git")
15
15
  expect(instance).to be_a(GitLocation)
16
16
  end
17
17
 
@@ -104,11 +104,10 @@ module Berkshelf
104
104
 
105
105
  context "when the repository is cached" do
106
106
  it "pulls a new version" do
107
- allow(Dir).to receive(:chdir) { |args, &b| b.call } # Force eval the chdir block
108
-
107
+ cache_path = subject.send(:cache_path)
109
108
  allow(subject).to receive(:cached?).and_return(true)
110
109
  expect(subject).to receive(:git).with(
111
- 'fetch --force --tags https://repo.com "refs/heads/*:refs/heads/*"'
110
+ 'fetch --force --tags https://repo.com "refs/heads/*:refs/heads/*"', cwd: cache_path.to_s
112
111
  )
113
112
  subject.install
114
113
  end
@@ -116,8 +115,6 @@ module Berkshelf
116
115
 
117
116
  context "when the revision is not cached" do
118
117
  it "clones the repository" do
119
- allow(Dir).to receive(:chdir) { |args, &b| b.call } # Force eval the chdir block
120
-
121
118
  cache_path = subject.send(:cache_path)
122
119
  allow(subject).to receive(:cached?).and_return(false)
123
120
  expect(subject).to receive(:git).with(
@@ -231,8 +231,8 @@ describe Berkshelf::Lockfile do
231
231
  expect(Chef::Environment).to receive(:from_hash).with(env_hash).and_return(environment)
232
232
 
233
233
  expect(environment).to receive(:cookbook_versions).with(
234
- "apt" => "= 1.0.0",
235
- "jenkins" => "= 1.4.5"
234
+ {"apt" => "= 1.0.0",
235
+ "jenkins" => "= 1.4.5"}
236
236
  )
237
237
 
238
238
  expect(environment).to receive(:save)
@@ -4,7 +4,7 @@ require "chef/cookbook_manifest"
4
4
  describe Berkshelf::RidleyCompat do
5
5
  let(:opts) { {} }
6
6
 
7
- subject { described_class.new(opts) }
7
+ subject { described_class.new(**opts) }
8
8
 
9
9
  context "default" do
10
10
  it "has a cookbook version_class" do