summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2016-12-07 09:44:16 +0000
committerGitHub <noreply@github.com>2016-12-07 09:44:16 +0000
commit811cbff2baaf0c5f8ad78cbaf6e62db969842827 (patch)
tree5a824fdbcc06e2cf4633c77baacce0da1e779686
parentfcb0ccc2480725f03c2f97c0eb5ebcf37e4b2f32 (diff)
parent6ec604f150023e93859af90dff08dba6dc624f79 (diff)
downloadchef-811cbff2baaf0c5f8ad78cbaf6e62db969842827.tar.gz
Merge pull request #5548 from chef/lcg/chefstyle-updates
Chefstyle updates
-rw-r--r--chef-config/lib/chef-config/mixin/fuzzy_hostname_matcher.rb8
-rw-r--r--lib/chef/application.rb9
-rw-r--r--lib/chef/application/windows_service_manager.rb10
-rw-r--r--lib/chef/chef_fs/chef_fs_data_store.rb2
-rw-r--r--lib/chef/chef_fs/command_line.rb2
-rw-r--r--lib/chef/cookbook/chefignore.rb2
-rw-r--r--lib/chef/cookbook/cookbook_version_loader.rb8
-rw-r--r--lib/chef/cookbook/metadata.rb4
-rw-r--r--lib/chef/cookbook_loader.rb2
-rw-r--r--lib/chef/data_collector.rb12
-rw-r--r--lib/chef/data_collector/messages.rb14
-rw-r--r--lib/chef/encrypted_data_bag_item.rb2
-rw-r--r--lib/chef/encrypted_data_bag_item/decryptor.rb4
-rw-r--r--lib/chef/environment.rb2
-rw-r--r--lib/chef/exceptions.rb10
-rw-r--r--lib/chef/file_access_control/unix.rb10
-rw-r--r--lib/chef/formatters/error_description.rb2
-rw-r--r--lib/chef/http/basic_client.rb2
-rw-r--r--lib/chef/knife/cookbook_site_install.rb2
-rw-r--r--lib/chef/knife/core/cookbook_scm_repo.rb2
-rw-r--r--lib/chef/knife/core/ui.rb2
-rw-r--r--lib/chef/mixin/deep_merge.rb2
-rw-r--r--lib/chef/mixin/wide_string.rb2
-rw-r--r--lib/chef/node.rb2
-rw-r--r--lib/chef/provider/git.rb2
-rw-r--r--lib/chef/provider/mount/mount.rb2
-rw-r--r--lib/chef/provider/osx_profile.rb6
-rw-r--r--lib/chef/provider/package.rb4
-rw-r--r--lib/chef/provider/package/easy_install.rb2
-rw-r--r--lib/chef/provider/package/powershell.rb6
-rw-r--r--lib/chef/provider/package/zypper.rb2
-rw-r--r--lib/chef/provider/route.rb6
-rw-r--r--lib/chef/provider/service/arch.rb4
-rw-r--r--lib/chef/provider/service/freebsd.rb2
-rw-r--r--lib/chef/provider/service/gentoo.rb4
-rw-r--r--lib/chef/provider/service/insserv.rb4
-rw-r--r--lib/chef/provider/service/macosx.rb2
-rw-r--r--lib/chef/provider/service/openbsd.rb2
-rw-r--r--lib/chef/provider/service/redhat.rb4
-rw-r--r--lib/chef/resource/file/verification.rb10
-rw-r--r--lib/chef/scan_access_control.rb8
-rw-r--r--lib/chef/util/dsc/resource_store.rb2
-rw-r--r--lib/chef/win32/memory.rb2
-rw-r--r--lib/chef/win32/security.rb4
-rw-r--r--lib/chef/win32/security/sid.rb4
-rw-r--r--omnibus/files/chef/build-chef.rb2
-rw-r--r--spec/functional/resource/user/useradd_spec.rb2
-rw-r--r--spec/integration/knife/chef_repo_path_spec.rb4
-rw-r--r--spec/integration/recipes/resource_load_spec.rb6
-rw-r--r--spec/spec_helper.rb8
-rw-r--r--spec/unit/cookbook/metadata_spec.rb6
-rw-r--r--spec/unit/decorator/lazy_spec.rb2
-rw-r--r--spec/unit/environment_spec.rb2
-rw-r--r--spec/unit/provider/package/msu_spec.rb2
-rwxr-xr-xtasks/bin/bundle-platform2
-rw-r--r--tasks/gemfile_util.rb4
56 files changed, 128 insertions, 111 deletions
diff --git a/chef-config/lib/chef-config/mixin/fuzzy_hostname_matcher.rb b/chef-config/lib/chef-config/mixin/fuzzy_hostname_matcher.rb
index 6dd678840a..ca1bdb4c0b 100644
--- a/chef-config/lib/chef-config/mixin/fuzzy_hostname_matcher.rb
+++ b/chef-config/lib/chef-config/mixin/fuzzy_hostname_matcher.rb
@@ -21,9 +21,11 @@ module ChefConfig
module FuzzyHostnameMatcher
def fuzzy_hostname_match_any?(hostname, matches)
- return matches.to_s.split(/\s*,\s*/).compact.any? do |m|
- fuzzy_hostname_match?(hostname, m)
- end if (hostname != nil) && (matches != nil)
+ if (!hostname.nil?) && (!matches.nil?)
+ return matches.to_s.split(/\s*,\s*/).compact.any? do |m|
+ fuzzy_hostname_match?(hostname, m)
+ end
+ end
false
end
diff --git a/lib/chef/application.rb b/lib/chef/application.rb
index e917a4eaf7..ab19e6571e 100644
--- a/lib/chef/application.rb
+++ b/lib/chef/application.rb
@@ -120,9 +120,10 @@ class Chef
end
def set_specific_recipes
- Chef::Config[:specific_recipes] =
- cli_arguments.map { |file| File.expand_path(file) } if
- cli_arguments.respond_to?(:map)
+ if cli_arguments.respond_to?(:map)
+ Chef::Config[:specific_recipes] =
+ cli_arguments.map { |file| File.expand_path(file) }
+ end
end
# Initialize and configure the logger.
@@ -342,7 +343,7 @@ class Chef
message = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
cause = e.cause if e.respond_to?(:cause)
- while cause != nil
+ until cause.nil?
message << "\n\n>>>> Caused by #{cause.class}: #{cause}\n#{cause.backtrace.join("\n")}"
cause = cause.respond_to?(:cause) ? cause.cause : nil
end
diff --git a/lib/chef/application/windows_service_manager.rb b/lib/chef/application/windows_service_manager.rb
index 6f81dccc67..fd0ce0b174 100644
--- a/lib/chef/application/windows_service_manager.rb
+++ b/lib/chef/application/windows_service_manager.rb
@@ -126,10 +126,12 @@ class Chef
:password => @password,
:dependencies => @dependencies
)
- ::Win32::Service.configure(
- :service_name => @service_name,
- :delayed_start => @delayed_start
- ) unless @delayed_start.nil?
+ unless @delayed_start.nil?
+ ::Win32::Service.configure(
+ :service_name => @service_name,
+ :delayed_start => @delayed_start
+ )
+ end
puts "Service '#{@service_name}' has successfully been installed."
end
when "status"
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb
index 6b3e830f8d..9893cf7245 100644
--- a/lib/chef/chef_fs/chef_fs_data_store.rb
+++ b/lib/chef/chef_fs/chef_fs_data_store.rb
@@ -326,7 +326,7 @@ class Chef
else
relative << path[1]
end
- relative = relative + file[:path].split("/")
+ relative += file[:path].split("/")
file["url"] = ChefZero::RestBase.build_uri(request.base_uri, relative)
end
end
diff --git a/lib/chef/chef_fs/command_line.rb b/lib/chef/chef_fs/command_line.rb
index 2d887f4780..1b6884514a 100644
--- a/lib/chef/chef_fs/command_line.rb
+++ b/lib/chef/chef_fs/command_line.rb
@@ -229,7 +229,7 @@ class Chef
end
end
- if old_value == :none || (old_value == nil && !old_entry.exists?)
+ if old_value == :none || (old_value.nil? && !old_entry.exists?)
return [ [ :added, old_entry, new_entry, old_value, new_value ] ]
elsif new_value == :none
return [ [ :deleted, old_entry, new_entry, old_value, new_value ] ]
diff --git a/lib/chef/cookbook/chefignore.rb b/lib/chef/cookbook/chefignore.rb
index 71ef53c9e5..dce58ecdb8 100644
--- a/lib/chef/cookbook/chefignore.rb
+++ b/lib/chef/cookbook/chefignore.rb
@@ -52,7 +52,7 @@ class Chef
ignore_globs << line.strip unless line =~ COMMENTS_AND_WHITESPACE
end
else
- Chef::Log.debug("No chefignore file found at #@ignore_file no files will be ignored")
+ Chef::Log.debug("No chefignore file found at #{@ignore_file} no files will be ignored")
end
ignore_globs
end
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb
index af8b2e043e..d253c956b2 100644
--- a/lib/chef/cookbook/cookbook_version_loader.rb
+++ b/lib/chef/cookbook/cookbook_version_loader.rb
@@ -308,7 +308,7 @@ class Chef
begin
@metadata.from_file(file)
rescue Chef::Exceptions::JSON::ParseError
- Chef::Log.error("Error evaluating metadata.rb for #@inferred_cookbook_name in " + file)
+ Chef::Log.error("Error evaluating metadata.rb for #{@inferred_cookbook_name} in " + file)
raise
end
end
@@ -317,7 +317,7 @@ class Chef
begin
@metadata.from_json(IO.read(file))
rescue Chef::Exceptions::JSON::ParseError
- Chef::Log.error("Couldn't parse cookbook metadata JSON for #@inferred_cookbook_name in " + file)
+ Chef::Log.error("Couldn't parse cookbook metadata JSON for #{@inferred_cookbook_name} in " + file)
raise
end
end
@@ -336,7 +336,7 @@ class Chef
# metadata contains a name key.
@metadata.name(data["cookbook_name"]) unless data["metadata"].key?("name")
rescue Chef::Exceptions::JSON::ParseError
- Chef::Log.error("Couldn't parse cookbook metadata JSON for #@inferred_cookbook_name in " + file)
+ Chef::Log.error("Couldn't parse cookbook metadata JSON for #{@inferred_cookbook_name} in " + file)
raise
end
end
@@ -347,7 +347,7 @@ class Chef
data = Chef::JSONCompat.parse(IO.read(uploaded_cookbook_version_file))
@frozen = data["frozen?"]
rescue Chef::Exceptions::JSON::ParseError
- Chef::Log.error("Couldn't parse cookbook metadata JSON for #@inferred_cookbook_name in #{uploaded_cookbook_version_file}")
+ Chef::Log.error("Couldn't parse cookbook metadata JSON for #{@inferred_cookbook_name} in #{uploaded_cookbook_version_file}")
raise
end
end
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index b2f3db9b8e..c3698f3315 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -862,12 +862,12 @@ INVALID
return if !options[:choice].is_a?(Array) || options[:choice].empty?
if options[:default].is_a?(String) && options[:default] != ""
- raise ArgumentError, "Default must be one of your choice values!" if options[:choice].index(options[:default]) == nil
+ raise ArgumentError, "Default must be one of your choice values!" if options[:choice].index(options[:default]).nil?
end
if options[:default].is_a?(Array) && !options[:default].empty?
options[:default].each do |val|
- raise ArgumentError, "Default values must be a subset of your choice values!" if options[:choice].index(val) == nil
+ raise ArgumentError, "Default values must be a subset of your choice values!" if options[:choice].index(val).nil?
end
end
end
diff --git a/lib/chef/cookbook_loader.rb b/lib/chef/cookbook_loader.rb
index bff77fa13b..a965b43c61 100644
--- a/lib/chef/cookbook_loader.rb
+++ b/lib/chef/cookbook_loader.rb
@@ -137,7 +137,7 @@ class Chef
alias :key? :has_key?
def each
- @cookbooks_by_name.keys.sort { |a, b| a.to_s <=> b.to_s }.each do |cname|
+ @cookbooks_by_name.keys.sort_by(&:to_s).each do |cname|
yield(cname, @cookbooks_by_name[cname])
end
end
diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb
index 0e676145eb..df3bce6167 100644
--- a/lib/chef/data_collector.rb
+++ b/lib/chef/data_collector.rb
@@ -462,8 +462,10 @@ class Chef
end
def validate_data_collector_server_url!
- raise Chef::Exceptions::ConfigurationError,
- "Chef::Config[:data_collector][:server_url] is empty. Please supply a valid URL." if data_collector_server_url.empty?
+ if data_collector_server_url.empty?
+ raise Chef::Exceptions::ConfigurationError,
+ "Chef::Config[:data_collector][:server_url] is empty. Please supply a valid URL."
+ end
begin
uri = URI(data_collector_server_url)
@@ -471,8 +473,10 @@ class Chef
raise Chef::Exceptions::ConfigurationError, "Chef::Config[:data_collector][:server_url] (#{data_collector_server_url}) is not a valid URI."
end
- raise Chef::Exceptions::ConfigurationError,
- "Chef::Config[:data_collector][:server_url] (#{data_collector_server_url}) is a URI with no host. Please supply a valid URL." if uri.host.nil?
+ if uri.host.nil?
+ raise Chef::Exceptions::ConfigurationError,
+ "Chef::Config[:data_collector][:server_url] (#{data_collector_server_url}) is a URI with no host. Please supply a valid URL."
+ end
end
end
end
diff --git a/lib/chef/data_collector/messages.rb b/lib/chef/data_collector/messages.rb
index f63242f85e..c0683534a9 100644
--- a/lib/chef/data_collector/messages.rb
+++ b/lib/chef/data_collector/messages.rb
@@ -82,12 +82,14 @@ class Chef
"deprecations" => reporter_data[:deprecations],
}
- message["error"] = {
- "class" => run_status.exception.class,
- "message" => run_status.exception.message,
- "backtrace" => run_status.exception.backtrace,
- "description" => reporter_data[:error_descriptions],
- } if run_status.exception
+ if run_status.exception
+ message["error"] = {
+ "class" => run_status.exception.class,
+ "message" => run_status.exception.message,
+ "backtrace" => run_status.exception.backtrace,
+ "description" => reporter_data[:error_descriptions],
+ }
+ end
message
end
diff --git a/lib/chef/encrypted_data_bag_item.rb b/lib/chef/encrypted_data_bag_item.rb
index e696199c63..d30c7945e9 100644
--- a/lib/chef/encrypted_data_bag_item.rb
+++ b/lib/chef/encrypted_data_bag_item.rb
@@ -121,7 +121,7 @@ class Chef::EncryptedDataBagItem
#
def self.load(data_bag, name, secret = nil)
raw_hash = Chef::DataBagItem.load(data_bag, name)
- secret = secret || self.load_secret
+ secret ||= self.load_secret
self.new(raw_hash, secret)
end
diff --git a/lib/chef/encrypted_data_bag_item/decryptor.rb b/lib/chef/encrypted_data_bag_item/decryptor.rb
index 773ff4e154..f35611d185 100644
--- a/lib/chef/encrypted_data_bag_item/decryptor.rb
+++ b/lib/chef/encrypted_data_bag_item/decryptor.rb
@@ -93,7 +93,7 @@ class Chef::EncryptedDataBagItem
plaintext << openssl_decryptor.final
rescue OpenSSL::Cipher::CipherError => e
# if the key length is less than 255 characters, and it contains slashes, we think it may be a path.
- raise DecryptionFailure, "Error decrypting data bag value: '#{e.message}'. Most likely the provided key is incorrect. #{ (@key.length < 255 && @key.include?('/')) ? 'You may need to use --secret-file rather than --secret.' : '' }"
+ raise DecryptionFailure, "Error decrypting data bag value: '#{e.message}'. Most likely the provided key is incorrect. #{(@key.length < 255 && @key.include?('/')) ? 'You may need to use --secret-file rather than --secret.' : ''}"
end
end
@@ -144,7 +144,7 @@ class Chef::EncryptedDataBagItem
plaintext << openssl_decryptor.final
rescue OpenSSL::Cipher::CipherError => e
# if the key length is less than 255 characters, and it contains slashes, we think it may be a path.
- raise DecryptionFailure, "Error decrypting data bag value: '#{e.message}'. Most likely the provided key is incorrect. #{ ( @key.length < 255 && @key.include?('/')) ? 'You may need to use --secret-file rather than --secret.' : '' }"
+ raise DecryptionFailure, "Error decrypting data bag value: '#{e.message}'. Most likely the provided key is incorrect. #{( @key.length < 255 && @key.include?('/')) ? 'You may need to use --secret-file rather than --secret.' : ''}"
end
end
diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb
index c41df768b9..eb335b0237 100644
--- a/lib/chef/environment.rb
+++ b/lib/chef/environment.rb
@@ -171,7 +171,7 @@ class Chef
unless params[:cookbook_version].nil?
params[:cookbook_version].each do |index, cookbook_constraint_spec|
unless cookbook_constraint_spec.nil? || cookbook_constraint_spec.size == 0
- valid = valid && update_cookbook_constraint_from_param(index, cookbook_constraint_spec)
+ valid &&= update_cookbook_constraint_from_param(index, cookbook_constraint_spec)
end
end
end
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index c933841726..2d6dcef17e 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -76,10 +76,10 @@ class Chef
class Group < RuntimeError; end
class Link < RuntimeError; end
class Mount < RuntimeError; end
- class Reboot < Exception; end
- class RebootPending < Exception; end
+ class Reboot < Exception; end # rubocop:disable Lint/InheritException
+ class RebootPending < Exception; end # rubocop:disable Lint/InheritException
class RebootFailed < Mixlib::ShellOut::ShellCommandFailed; end
- class ClientUpgraded < Exception; end
+ class ClientUpgraded < Exception; end # rubocop:disable Lint/InheritException
class PrivateKeyMissing < RuntimeError; end
class CannotWritePrivateKey < RuntimeError; end
class RoleNotFound < RuntimeError; end
@@ -159,7 +159,7 @@ class Chef
# Thrown when Win32 API layer binds to non-existent Win32 function. Occurs
# when older versions of Windows don't support newer Win32 API functions.
- class Win32APIFunctionNotImplemented < NotImplementedError; end
+ class Win32APIFunctionNotImplemented < NotImplementedError; end # rubocop:disable Lint/InheritException
# Attempting to run windows code on a not-windows node
class Win32NotWindows < RuntimeError; end
class WindowsNotAdmin < RuntimeError; end
@@ -196,7 +196,7 @@ class Chef
class InvalidVersionConstraint < ArgumentError; end
# Version constraints are not allowed in chef-solo
- class IllegalVersionConstraint < NotImplementedError; end
+ class IllegalVersionConstraint < NotImplementedError; end # rubocop:disable Lint/InheritException
class MetadataNotValid < StandardError; end
class MetadataNotFound < StandardError
diff --git a/lib/chef/file_access_control/unix.rb b/lib/chef/file_access_control/unix.rb
index 1746db44d3..0dfbff8422 100644
--- a/lib/chef/file_access_control/unix.rb
+++ b/lib/chef/file_access_control/unix.rb
@@ -117,13 +117,13 @@ class Chef
end
def gid_from_resource(resource)
- return nil if resource == nil || resource.group.nil?
+ return nil if resource.nil? || resource.group.nil?
if resource.group.kind_of?(String)
diminished_radix_complement( Etc.getgrnam(resource.group).gid )
elsif resource.group.kind_of?(Integer)
resource.group
else
- Chef::Log.error("The `group` parameter of the #@resource resource is set to an invalid value (#{resource.owner.inspect})")
+ Chef::Log.error("The `group` parameter of the #{@resource} resource is set to an invalid value (#{resource.owner.inspect})")
raise ArgumentError, "cannot resolve #{resource.group.inspect} to gid, group must be a string or integer"
end
rescue ArgumentError
@@ -168,7 +168,7 @@ class Chef
end
def mode_from_resource(res)
- return nil if res == nil || res.mode.nil?
+ return nil if res.nil? || res.mode.nil?
(res.mode.respond_to?(:oct) ? res.mode.oct : res.mode.to_i) & 007777
end
@@ -264,13 +264,13 @@ class Chef
end
def uid_from_resource(resource)
- return nil if resource == nil || resource.owner.nil?
+ return nil if resource.nil? || resource.owner.nil?
if resource.owner.kind_of?(String)
diminished_radix_complement( Etc.getpwnam(resource.owner).uid )
elsif resource.owner.kind_of?(Integer)
resource.owner
else
- Chef::Log.error("The `owner` parameter of the #@resource resource is set to an invalid value (#{resource.owner.inspect})")
+ Chef::Log.error("The `owner` parameter of the #{@resource} resource is set to an invalid value (#{resource.owner.inspect})")
raise ArgumentError, "cannot resolve #{resource.owner.inspect} to uid, owner must be a string or integer"
end
rescue ArgumentError
diff --git a/lib/chef/formatters/error_description.rb b/lib/chef/formatters/error_description.rb
index 8d7f940181..ece33bdd49 100644
--- a/lib/chef/formatters/error_description.rb
+++ b/lib/chef/formatters/error_description.rb
@@ -48,7 +48,7 @@ class Chef
display_section("Platform:", RUBY_PLATFORM, out)
end
- def for_json()
+ def for_json
{
"title" => @title,
"sections" => @sections,
diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb
index 460744ea2a..9a000136e6 100644
--- a/lib/chef/http/basic_client.rb
+++ b/lib/chef/http/basic_client.rb
@@ -111,7 +111,7 @@ class Chef
# match no_proxy with a fuzzy matcher, rather than letting Net::HTTP
# do it.
http_client = http_client_builder.new(host, port, nil)
- http_client.proxy_port = nil if http_client.proxy_address == nil
+ http_client.proxy_port = nil if http_client.proxy_address.nil?
if url.scheme == HTTPS
configure_ssl(http_client)
diff --git a/lib/chef/knife/cookbook_site_install.rb b/lib/chef/knife/cookbook_site_install.rb
index 43d015dcc4..5b2d7d3517 100644
--- a/lib/chef/knife/cookbook_site_install.rb
+++ b/lib/chef/knife/cookbook_site_install.rb
@@ -83,7 +83,7 @@ class Chef
# Check to ensure we have a valid source of cookbooks before continuing
#
@install_path = File.expand_path(Array(config[:cookbook_path]).first)
- ui.info "Installing #@cookbook_name to #{@install_path}"
+ ui.info "Installing #{@cookbook_name} to #{@install_path}"
@repo = CookbookSCMRepo.new(@install_path, ui, config)
#cookbook_path = File.join(vendor_path, name_args[0])
diff --git a/lib/chef/knife/core/cookbook_scm_repo.rb b/lib/chef/knife/core/cookbook_scm_repo.rb
index e909066b02..2c678e07b9 100644
--- a/lib/chef/knife/core/cookbook_scm_repo.rb
+++ b/lib/chef/knife/core/cookbook_scm_repo.rb
@@ -122,7 +122,7 @@ class Chef
git("branch --no-color").stdout.lines.any? { |l| l =~ /\s#{Regexp.escape(branch_name)}(?:\s|$)/ }
end
- def get_current_branch()
+ def get_current_branch
ref = git("symbolic-ref HEAD").stdout
ref.chomp.split("/")[2]
end
diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb
index 0e07dd704f..e9a9a236c2 100644
--- a/lib/chef/knife/core/ui.rb
+++ b/lib/chef/knife/core/ui.rb
@@ -138,7 +138,7 @@ class Chef
end
def ask_question(question, opts = {})
- question = question + "[#{opts[:default]}] " if opts[:default]
+ question += "[#{opts[:default]}] " if opts[:default]
if opts[:default] && config[:defaults]
opts[:default]
diff --git a/lib/chef/mixin/deep_merge.rb b/lib/chef/mixin/deep_merge.rb
index c0b2d0d0c5..7016b08ff7 100644
--- a/lib/chef/mixin/deep_merge.rb
+++ b/lib/chef/mixin/deep_merge.rb
@@ -75,7 +75,7 @@ class Chef
end
when Array
if dest.kind_of?(Array)
- dest = dest | source
+ dest |= source
else
dest = source
end
diff --git a/lib/chef/mixin/wide_string.rb b/lib/chef/mixin/wide_string.rb
index 4342ef1650..ef7828e2d8 100644
--- a/lib/chef/mixin/wide_string.rb
+++ b/lib/chef/mixin/wide_string.rb
@@ -34,7 +34,7 @@ class Chef
ustring = (ustring + "").force_encoding("UTF-8") if ustring.respond_to?(:force_encoding) && ustring.encoding.name != "UTF-8"
# ensure we have the double-null termination Windows Wide likes
- ustring = ustring + "\000\000" if ustring.length == 0 || ustring[-1].chr != "\000"
+ ustring += "\000\000" if ustring.length == 0 || ustring[-1].chr != "\000"
# encode it all as UTF-16LE AKA Windows Wide Character AKA Windows Unicode
ustring = begin
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index f2a5cab1f5..087a173880 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -111,7 +111,7 @@ class Chef
# Set the name of this Node, or return the current name.
def name(arg = nil)
- if arg != nil
+ if !arg.nil?
validate(
{ :name => arg },
{ :name => { :kind_of => String,
diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb
index d051bb1d92..a5c5e0d267 100644
--- a/lib/chef/provider/git.rb
+++ b/lib/chef/provider/git.rb
@@ -65,7 +65,7 @@ class Chef
# this can't be recovered from in why-run mode, because nothing that
# we do in the course of a run is likely to create a valid target_revision
# if we can't resolve it up front.
- a.assertion { target_revision != nil }
+ a.assertion { !target_revision.nil? }
a.failure_message Chef::Exceptions::UnresolvableGitReference,
"Unable to parse SHA reference for '#{@new_resource.revision}' in repository '#{@new_resource.repository}'. " +
"Verify your (case-sensitive) repository URL and revision.\n" +
diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb
index 49e825e39f..e00f3290fa 100644
--- a/lib/chef/provider/mount/mount.rb
+++ b/lib/chef/provider/mount/mount.rb
@@ -210,7 +210,7 @@ class Chef
end
def device_real
- if @real_device == nil
+ if @real_device.nil?
if @new_resource.device_type == :device
@real_device = @new_resource.device
else
diff --git a/lib/chef/provider/osx_profile.rb b/lib/chef/provider/osx_profile.rb
index 69ecf2ddb9..a25ac9539f 100644
--- a/lib/chef/provider/osx_profile.rb
+++ b/lib/chef/provider/osx_profile.rb
@@ -44,8 +44,10 @@ class Chef
)
@new_profile_hash = get_profile_hash(@new_resource.profile)
- @new_profile_hash["PayloadUUID"] =
- config_uuid(@new_profile_hash) if @new_profile_hash
+ if @new_profile_hash
+ @new_profile_hash["PayloadUUID"] =
+ config_uuid(@new_profile_hash)
+ end
if @new_profile_hash
@new_profile_identifier = @new_profile_hash["PayloadIdentifier"]
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb
index 048807dd05..ecf3dbecb5 100644
--- a/lib/chef/provider/package.rb
+++ b/lib/chef/provider/package.rb
@@ -56,7 +56,7 @@ class Chef
def check_resource_semantics!
# FIXME: this is not universally true and subclasses are needing to override this and no-ops it. It should be turned into
# another "subclass_directive" and the apt and yum providers should declare that they need this behavior.
- if new_resource.package_name.is_a?(Array) && new_resource.source != nil
+ if new_resource.package_name.is_a?(Array) && !new_resource.source.nil?
raise Chef::Exceptions::InvalidResourceSpecification, "You may not specify both multipackage and source"
end
end
@@ -196,7 +196,7 @@ class Chef
end
action :reconfig do
- if @current_resource.version == nil
+ if @current_resource.version.nil?
Chef::Log.debug("#{@new_resource} is NOT installed - nothing to do")
return
end
diff --git a/lib/chef/provider/package/easy_install.rb b/lib/chef/provider/package/easy_install.rb
index 926f609092..a9c6e2a792 100644
--- a/lib/chef/provider/package/easy_install.rb
+++ b/lib/chef/provider/package/easy_install.rb
@@ -122,7 +122,7 @@ class Chef
def remove_package(name, version)
Chef.deprecated(:easy_install, "The easy_install package provider is deprecated and will be removed in Chef 13.")
- run_command(:command => "#{easy_install_binary_path }#{expand_options(@new_resource.options)} -m #{name}")
+ run_command(:command => "#{easy_install_binary_path}#{expand_options(@new_resource.options)} -m #{name}")
end
def purge_package(name, version)
diff --git a/lib/chef/provider/package/powershell.rb b/lib/chef/provider/package/powershell.rb
index 5206b5b696..caeda6d412 100644
--- a/lib/chef/provider/package/powershell.rb
+++ b/lib/chef/provider/package/powershell.rb
@@ -60,7 +60,7 @@ class Chef
# Removes the package for the version passed and if no version is passed, then all installed versions of the package are removed
def remove_package(names, versions)
names.each_with_index do |name, index|
- if versions && versions[index] != nil
+ if versions && !versions[index].nil?
powershell_out( "Uninstall-Package '#{name}' -Force -ForceBootstrap -RequiredVersion #{versions[index]}", { :timeout => @new_resource.timeout })
else
version = "0"
@@ -78,7 +78,7 @@ class Chef
def build_candidate_versions
versions = []
new_resource.package_name.each_with_index do |name, index|
- if new_resource.version && new_resource.version[index] != nil
+ if new_resource.version && !new_resource.version[index].nil?
version = powershell_out("(Find-Package '#{name}' -RequiredVersion #{new_resource.version[index]} -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip()
else
version = powershell_out("(Find-Package '#{name}' -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip()
@@ -95,7 +95,7 @@ class Chef
def build_current_versions
version_list = []
new_resource.package_name.each_with_index do |name, index|
- if new_resource.version && new_resource.version[index] != nil
+ if new_resource.version && !new_resource.version[index].nil?
version = powershell_out("(Get-Package -Name '#{name}' -RequiredVersion #{new_resource.version[index]} -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip()
else
version = powershell_out("(Get-Package -Name '#{name}' -ForceBootstrap -Force | select version | Format-Table -HideTableHeaders | Out-String).Trim()", { :timeout => @new_resource.timeout }).stdout.strip()
diff --git a/lib/chef/provider/package/zypper.rb b/lib/chef/provider/package/zypper.rb
index edad45c3e4..6965052723 100644
--- a/lib/chef/provider/package/zypper.rb
+++ b/lib/chef/provider/package/zypper.rb
@@ -144,7 +144,7 @@ class Chef
end
end
- def gpg_checks()
+ def gpg_checks
case Chef::Config[:zypper_check_gpg]
when true
""
diff --git a/lib/chef/provider/route.rb b/lib/chef/provider/route.rb
index 64c89aac6d..7c6f91cdca 100644
--- a/lib/chef/provider/route.rb
+++ b/lib/chef/provider/route.rb
@@ -134,7 +134,7 @@ class Chef::Provider::Route < Chef::Provider
Chef::Log.debug("#{@new_resource} route already active - nothing to do")
else
command = generate_command(:add)
- converge_by ("run #{ command } to add route") do
+ converge_by ("run #{command} to add route") do
run_command( :command => command )
Chef::Log.info("#{@new_resource} added")
end
@@ -147,7 +147,7 @@ class Chef::Provider::Route < Chef::Provider
def action_delete
if is_running
command = generate_command(:delete)
- converge_by ("run #{ command } to delete route ") do
+ converge_by ("run #{command} to delete route ") do
run_command( :command => command )
Chef::Log.info("#{@new_resource} removed")
end
@@ -186,7 +186,7 @@ class Chef::Provider::Route < Chef::Provider
end
conf.each do |k, v|
network_file_name = "/etc/sysconfig/network-scripts/route-#{k}"
- converge_by ("write route route.#{k}\n#{conf[k]} to #{ network_file_name }") do
+ converge_by ("write route route.#{k}\n#{conf[k]} to #{network_file_name}") do
network_file = ::File.new(network_file_name, "w")
network_file.puts(conf[k])
Chef::Log.debug("#{@new_resource} writing route.#{k}\n#{conf[k]}")
diff --git a/lib/chef/provider/service/arch.rb b/lib/chef/provider/service/arch.rb
index 2fd32e37aa..e34227036a 100644
--- a/lib/chef/provider/service/arch.rb
+++ b/lib/chef/provider/service/arch.rb
@@ -66,7 +66,7 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
end
end
- def enable_service()
+ def enable_service
new_daemons = []
entries = daemons
@@ -92,7 +92,7 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
end
end
- def disable_service()
+ def disable_service
new_daemons = []
entries = daemons
diff --git a/lib/chef/provider/service/freebsd.rb b/lib/chef/provider/service/freebsd.rb
index 76d8c1d17b..9746dfdef0 100644
--- a/lib/chef/provider/service/freebsd.rb
+++ b/lib/chef/provider/service/freebsd.rb
@@ -74,7 +74,7 @@ class Chef
end
requirements.assert(:start, :enable, :reload, :restart) do |a|
- a.assertion { service_enable_variable_name != nil }
+ a.assertion { !service_enable_variable_name.nil? }
a.failure_message Chef::Exceptions::Service, "Could not find the service name in #{init_command} and rcvar"
# No recovery in whyrun mode - the init file is present but not correct.
end
diff --git a/lib/chef/provider/service/gentoo.rb b/lib/chef/provider/service/gentoo.rb
index 8fb6d1f9af..7bb57113ac 100644
--- a/lib/chef/provider/service/gentoo.rb
+++ b/lib/chef/provider/service/gentoo.rb
@@ -61,11 +61,11 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
end
end
- def enable_service()
+ def enable_service
shell_out!("/sbin/rc-update add #{@new_resource.service_name} default")
end
- def disable_service()
+ def disable_service
shell_out!("/sbin/rc-update del #{@new_resource.service_name} default")
end
end
diff --git a/lib/chef/provider/service/insserv.rb b/lib/chef/provider/service/insserv.rb
index 76b2ee7477..c3dca10495 100644
--- a/lib/chef/provider/service/insserv.rb
+++ b/lib/chef/provider/service/insserv.rb
@@ -45,12 +45,12 @@ class Chef
current_resource
end
- def enable_service()
+ def enable_service
shell_out!("/sbin/insserv -r -f #{new_resource.service_name}")
shell_out!("/sbin/insserv -d -f #{new_resource.service_name}")
end
- def disable_service()
+ def disable_service
shell_out!("/sbin/insserv -r -f #{new_resource.service_name}")
end
end
diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb
index 648cd9748b..8663e7eabf 100644
--- a/lib/chef/provider/service/macosx.rb
+++ b/lib/chef/provider/service/macosx.rb
@@ -181,7 +181,7 @@ class Chef
end
def set_service_status
- return if @plist == nil || @service_label.to_s.empty?
+ return if @plist.nil? || @service_label.to_s.empty?
cmd = "launchctl list #{@service_label}"
res = shell_out_as_user(cmd)
diff --git a/lib/chef/provider/service/openbsd.rb b/lib/chef/provider/service/openbsd.rb
index c60bbf170c..780337e1b6 100644
--- a/lib/chef/provider/service/openbsd.rb
+++ b/lib/chef/provider/service/openbsd.rb
@@ -72,7 +72,7 @@ class Chef
end
requirements.assert(:start, :enable, :reload, :restart) do |a|
- a.assertion { init_command && builtin_service_enable_variable_name != nil }
+ a.assertion { init_command && !builtin_service_enable_variable_name.nil? }
a.failure_message Chef::Exceptions::Service, "Could not find the service name in #{init_command} and rcvar"
# No recovery in whyrun mode - the init file is present but not correct.
end
diff --git a/lib/chef/provider/service/redhat.rb b/lib/chef/provider/service/redhat.rb
index 200a2d3400..21ab678706 100644
--- a/lib/chef/provider/service/redhat.rb
+++ b/lib/chef/provider/service/redhat.rb
@@ -109,7 +109,7 @@ class Chef
(run_levels.nil? || run_levels.empty?) ? "" : "--level #{run_levels.join('')} "
end
- def enable_service()
+ def enable_service
unless run_levels.nil? || run_levels.empty?
disable_levels = current_run_levels - run_levels
shell_out! "/sbin/chkconfig --level #{disable_levels.join('')} #{new_resource.service_name} off" unless disable_levels.empty?
@@ -117,7 +117,7 @@ class Chef
shell_out! "/sbin/chkconfig #{levels}#{new_resource.service_name} on"
end
- def disable_service()
+ def disable_service
shell_out! "/sbin/chkconfig #{levels}#{new_resource.service_name} off"
end
end
diff --git a/lib/chef/resource/file/verification.rb b/lib/chef/resource/file/verification.rb
index cf5585e5cf..3400684bc5 100644
--- a/lib/chef/resource/file/verification.rb
+++ b/lib/chef/resource/file/verification.rb
@@ -108,10 +108,12 @@ class Chef
def verify_command(path, opts)
# First implementation interpolated `file`; docs & RFC claim `path`
# is interpolated. Until `file` can be deprecated, interpolate both.
- Chef.deprecated(:verify_file,
- "%{file} is deprecated in verify command and will not be "\
- "supported in Chef 13. Please use %{path} instead."
- ) if @command.include?("%{file}")
+ if @command.include?("%{file}")
+ Chef.deprecated(:verify_file,
+ "%{file} is deprecated in verify command and will not be "\
+ "supported in Chef 13. Please use %{path} instead."
+ )
+ end
command = @command % { :file => path, :path => path }
interpreter = Chef::GuardInterpreter.for_resource(@parent_resource, command, @command_opts)
interpreter.evaluate
diff --git a/lib/chef/scan_access_control.rb b/lib/chef/scan_access_control.rb
index f55a106e6d..0e6df30303 100644
--- a/lib/chef/scan_access_control.rb
+++ b/lib/chef/scan_access_control.rb
@@ -70,7 +70,7 @@ class Chef
when Integer
stat.uid
else
- Chef::Log.error("The `owner` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.owner.inspect})")
+ Chef::Log.error("The `owner` parameter of the #{@new_resource} resource is set to an invalid value (#{new_resource.owner.inspect})")
raise ArgumentError, "cannot resolve #{new_resource.owner.inspect} to uid, owner must be a string or integer"
end
end
@@ -97,7 +97,7 @@ class Chef
when Integer
stat.gid
else
- Chef::Log.error("The `group` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.owner.inspect})")
+ Chef::Log.error("The `group` parameter of the #{@new_resource} resource is set to an invalid value (#{new_resource.owner.inspect})")
raise ArgumentError, "cannot resolve #{new_resource.group.inspect} to gid, group must be a string or integer"
end
end
@@ -121,8 +121,8 @@ class Chef
when String, Integer, nil
"0#{(stat.mode & 07777).to_s(8)}"
else
- Chef::Log.error("The `mode` parameter of the #@new_resource resource is set to an invalid value (#{new_resource.mode.inspect})")
- raise ArgumentError, "Invalid value #{new_resource.mode.inspect} for `mode` on resource #@new_resource"
+ Chef::Log.error("The `mode` parameter of the #{@new_resource} resource is set to an invalid value (#{new_resource.mode.inspect})")
+ raise ArgumentError, "Invalid value #{new_resource.mode.inspect} for `mode` on resource #{@new_resource}"
end
end
diff --git a/lib/chef/util/dsc/resource_store.rb b/lib/chef/util/dsc/resource_store.rb
index be8d0b301b..43b7d1bdf9 100644
--- a/lib/chef/util/dsc/resource_store.rb
+++ b/lib/chef/util/dsc/resource_store.rb
@@ -74,7 +74,7 @@ class Chef
found = rs.find_all do |r|
name_matches = r["Name"].casecmp(name) == 0
if name_matches
- module_name == nil || (r["Module"] && r["Module"]["Name"].casecmp(module_name) == 0)
+ module_name.nil? || (r["Module"] && r["Module"]["Name"].casecmp(module_name) == 0)
else
false
end
diff --git a/lib/chef/win32/memory.rb b/lib/chef/win32/memory.rb
index 49dcdfbd41..2a9d5d8eb5 100644
--- a/lib/chef/win32/memory.rb
+++ b/lib/chef/win32/memory.rb
@@ -35,7 +35,7 @@ class Chef
Chef::ReservedNames::Win32::Error.raise!
end
# If a block is passed, handle freeing the memory at the end
- if block != nil
+ if !block.nil?
begin
yield result
ensure
diff --git a/lib/chef/win32/security.rb b/lib/chef/win32/security.rb
index 7fc3215786..8bf2bfa762 100644
--- a/lib/chef/win32/security.rb
+++ b/lib/chef/win32/security.rb
@@ -551,7 +551,7 @@ class Chef
def set_security_descriptor_dacl(security_descriptor, acl, defaulted = false, present = nil)
security_descriptor = security_descriptor.pointer if security_descriptor.respond_to?(:pointer)
acl = acl.pointer if acl.respond_to?(:pointer)
- present = !security_descriptor.null? if present == nil
+ present = !security_descriptor.null? if present.nil?
unless SetSecurityDescriptorDacl(security_descriptor, present, acl, defaulted)
Chef::ReservedNames::Win32::Error.raise!
@@ -579,7 +579,7 @@ class Chef
def self.set_security_descriptor_sacl(security_descriptor, acl, defaulted = false, present = nil)
security_descriptor = security_descriptor.pointer if security_descriptor.respond_to?(:pointer)
acl = acl.pointer if acl.respond_to?(:pointer)
- present = !security_descriptor.null? if present == nil
+ present = !security_descriptor.null? if present.nil?
unless SetSecurityDescriptorSacl(security_descriptor, present, acl, defaulted)
Chef::ReservedNames::Win32::Error.raise!
diff --git a/lib/chef/win32/security/sid.rb b/lib/chef/win32/security/sid.rb
index f6b88c60ce..983166ac70 100644
--- a/lib/chef/win32/security/sid.rb
+++ b/lib/chef/win32/security/sid.rb
@@ -50,7 +50,7 @@ class Chef
end
def ==(other)
- other != nil && Chef::ReservedNames::Win32::Security.equal_sid(self, other)
+ !other.nil? && Chef::ReservedNames::Win32::Security.equal_sid(self, other)
end
attr_reader :pointer
@@ -61,7 +61,7 @@ class Chef
def account_name
domain, name, use = account
- (domain != nil && domain.length > 0) ? "#{domain}\\#{name}" : name
+ (!domain.nil? && domain.length > 0) ? "#{domain}\\#{name}" : name
end
def size
diff --git a/omnibus/files/chef/build-chef.rb b/omnibus/files/chef/build-chef.rb
index ba7a84c791..4b8ec78054 100644
--- a/omnibus/files/chef/build-chef.rb
+++ b/omnibus/files/chef/build-chef.rb
@@ -11,7 +11,7 @@ module BuildChef
def create_bundle_config(gemfile, without: without_groups, retries: nil, jobs: nil, frozen: nil)
bundle_config = File.expand_path("../.bundle/config", gemfile)
- block "Put build config into #{bundle_config}: #{ { without: without, retries: retries, jobs: jobs, frozen: frozen } }" do
+ block "Put build config into #{bundle_config}: #{{ without: without, retries: retries, jobs: jobs, frozen: frozen }}" do
# bundle config build.nokogiri #{nokogiri_build_config} messes up the line,
# so we write it directly ourselves.
new_bundle_config = "---\n"
diff --git a/spec/functional/resource/user/useradd_spec.rb b/spec/functional/resource/user/useradd_spec.rb
index 874155c107..268ce5c9d2 100644
--- a/spec/functional/resource/user/useradd_spec.rb
+++ b/spec/functional/resource/user/useradd_spec.rb
@@ -119,7 +119,7 @@ describe Chef::Provider::User::Useradd, metadata do
break if status.exitstatus != 8
sleep 1
- max_retries = max_retries - 1
+ max_retries -= 1
rescue UserNotFound
break
end
diff --git a/spec/integration/knife/chef_repo_path_spec.rb b/spec/integration/knife/chef_repo_path_spec.rb
index 1388aa8716..e609fa60b3 100644
--- a/spec/integration/knife/chef_repo_path_spec.rb
+++ b/spec/integration/knife/chef_repo_path_spec.rb
@@ -843,7 +843,7 @@ EOM
context "when data_bag_path and chef_repo_path are set, and nothing else" do
before :each do
- %w{client cookbook environment node role user}.each do |object_name|
+ %w{client cookbook environment node role user}.each do |object_name|
Chef::Config.delete("#{object_name}_path".to_sym)
end
Chef::Config.data_bag_path = File.join(Chef::Config.chef_repo_path, "data_bags")
@@ -903,7 +903,7 @@ EOM
include_context "default config options"
before :each do
- %w{client cookbook environment node role user}.each do |object_name|
+ %w{client cookbook environment node role user}.each do |object_name|
Chef::Config.delete("#{object_name}_path".to_sym)
end
Chef::Config.delete(:chef_repo_path)
diff --git a/spec/integration/recipes/resource_load_spec.rb b/spec/integration/recipes/resource_load_spec.rb
index 954fbf53a4..791b83c23a 100644
--- a/spec/integration/recipes/resource_load_spec.rb
+++ b/spec/integration/recipes/resource_load_spec.rb
@@ -48,7 +48,7 @@ describe "Resource.load_current_value" do
x "loaded #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }.
select { |name, p| p.is_set?(self) }.
map { |name, p| "#{name}=#{p.get(self)}" }.
- join(", ") })"
+ join(", ")})"
end
end
@@ -175,7 +175,7 @@ describe "Resource.load_current_value" do
y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }.
select { |name, p| p.is_set?(self) }.
map { |name, p| "#{name}=#{p.get(self)}" }.
- join(", ") })"
+ join(", ")})"
end
end
@@ -193,7 +193,7 @@ describe "Resource.load_current_value" do
y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }.
select { |name, p| p.is_set?(self) }.
map { |name, p| "#{name}=#{p.get(self)}" }.
- join(", ") })"
+ join(", ")})"
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index dff2450dd8..9fd8e935c7 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -218,9 +218,11 @@ RSpec.configure do |config|
end
# raise if anyone commits any test to CI with :focus set on it
- config.before(:example, :focus) do
- raise "This example was committed with `:focus` and should not have been"
- end if ENV["CI"]
+ if ENV["CI"]
+ config.before(:example, :focus) do
+ raise "This example was committed with `:focus` and should not have been"
+ end
+ end
config.before(:suite) do
ARGV.clear
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb
index 389f02501a..d1117127f1 100644
--- a/spec/unit/cookbook/metadata_spec.rb
+++ b/spec/unit/cookbook/metadata_spec.rb
@@ -206,7 +206,7 @@ describe Chef::Cookbook::Metadata do
:issues_url => "http://example.com/issues",
:privacy => true,
}
- params.sort { |a, b| a.to_s <=> b.to_s }.each do |field, field_value|
+ params.sort_by(&:to_s).each do |field, field_value|
describe field do
it "should be set-able via #{field}" do
expect(metadata.send(field, field_value)).to eql(field_value)
@@ -240,7 +240,7 @@ describe Chef::Cookbook::Metadata do
:provides => [ :providing, "foo::bar", "<= 0.2" ],
:replaces => [ :replacing, "foo::bar", "= 0.2.1" ],
}
- dep_types.sort { |a, b| a.to_s <=> b.to_s }.each do |dep, dep_args|
+ dep_types.sort_by(&:to_s).each do |dep, dep_args|
check_with = dep_args.shift
describe dep do
it "should be set-able via #{dep}" do
@@ -261,7 +261,7 @@ describe Chef::Cookbook::Metadata do
:provides => [ :providing, "foo::bar", "<=0.2", "<= 0.2" ],
:replaces => [ :replacing, "foo::bar", "=0.2.1", "= 0.2.1" ],
}
- dep_types.sort { |a, b| a.to_s <=> b.to_s }.each do |dep, dep_args|
+ dep_types.sort_by(&:to_s).each do |dep, dep_args|
check_with = dep_args.shift
normalized_version = dep_args.pop
describe dep do
diff --git a/spec/unit/decorator/lazy_spec.rb b/spec/unit/decorator/lazy_spec.rb
index 4ea8301b63..46c8955ae8 100644
--- a/spec/unit/decorator/lazy_spec.rb
+++ b/spec/unit/decorator/lazy_spec.rb
@@ -21,7 +21,7 @@ require "spec_helper"
describe Chef::Decorator::Lazy do
let(:decorator) do
@a = 0
- Chef::Decorator::Lazy.new { @a = @a + 1 }
+ Chef::Decorator::Lazy.new { @a += 1 }
end
it "decorates an object" do
diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb
index 63c96ad93e..3daae16749 100644
--- a/spec/unit/environment_spec.rb
+++ b/spec/unit/environment_spec.rb
@@ -295,7 +295,7 @@ describe Chef::Environment do
Chef::Config[:solo_legacy_mode] = false
end
- it "should raise and exception" do
+ it "should raise an exception" do
expect do
Chef::Environment.validate_cookbook_version("= 1.2.3.4")
end.to raise_error Chef::Exceptions::IllegalVersionConstraint,
diff --git a/spec/unit/provider/package/msu_spec.rb b/spec/unit/provider/package/msu_spec.rb
index 26cde5bd5f..79bc51bbeb 100644
--- a/spec/unit/provider/package/msu_spec.rb
+++ b/spec/unit/provider/package/msu_spec.rb
@@ -148,7 +148,7 @@ The operation completed successfully.
expect(source_resource.name).to be == "windows_test_pkg"
expect(source_resource.source).to be == [new_resource.source]
expect(source_resource.cookbook_name).to be == "Msu_package"
- expect(source_resource.checksum).to be == nil
+ expect(source_resource.checksum).to be.nil?
end
end
diff --git a/tasks/bin/bundle-platform b/tasks/bin/bundle-platform
index aa8443e74c..aaf433c98d 100755
--- a/tasks/bin/bundle-platform
+++ b/tasks/bin/bundle-platform
@@ -6,7 +6,7 @@ platforms = platforms.split(" ").map { |p| Gem::Platform.new(p) }
Gem::Platform.instance_eval { @local = platforms.last }
old_platforms = Gem.platforms
Gem.platforms = platforms
-puts "bundle-platform set Gem.platforms to #{Gem.platforms.map { |p| p.to_s }} (was #{old_platforms.map { |p| p.to_s } })"
+puts "bundle-platform set Gem.platforms to #{Gem.platforms.map { |p| p.to_s }} (was #{old_platforms.map { |p| p.to_s }})"
desired_version = ARGV.shift.delete("_")
diff --git a/tasks/gemfile_util.rb b/tasks/gemfile_util.rb
index e21299705a..03a729148a 100644
--- a/tasks/gemfile_util.rb
+++ b/tasks/gemfile_util.rb
@@ -255,8 +255,8 @@ module GemfileUtil
result = {}
gems.each do |name, g|
dep_groups = g[:declared_groups] - [ :only_a_runtime_dependency_of_other_gems ]
- dep_groups = dep_groups & groups if groups
- dep_groups = dep_groups - without_groups if without_groups
+ dep_groups &= groups if groups
+ dep_groups -= without_groups if without_groups
if dep_groups.any?
result[name] ||= g
g[:dependencies].each do |dep|