diff options
| author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-07-08 13:47:01 -0700 |
|---|---|---|
| committer | Lamont Granquist <lamont@scriptkiddie.org> | 2019-07-08 13:47:01 -0700 |
| commit | efd4d5463f45229b1a1b0fcdb5da80dc04e27d2c (patch) | |
| tree | def766a9e833f4a1e1d65109996498b86f3d9323 | |
| parent | 9e9a408aea747e86385f4d49ef715e9745b6ef50 (diff) | |
| download | chef-lcg/new-chefstyle2.tar.gz | |
Layout/FirstMethodArgumentLineBreaklcg/new-chefstyle2
94 files changed, 834 insertions, 444 deletions
diff --git a/lib/chef/api_client/registration.rb b/lib/chef/api_client/registration.rb index fea4b001bc..ba64cdd6d2 100644 --- a/lib/chef/api_client/registration.rb +++ b/lib/chef/api_client/registration.rb @@ -157,12 +157,14 @@ class Chef end def http_api - @http_api ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], + @http_api ||= Chef::ServerAPI.new( + Chef::Config[:chef_server_url], { api_version: "0", client_name: Chef::Config[:validation_client_name], signing_key_filename: Chef::Config[:validation_key], - }) + } + ) end # Whether or not to generate keys locally and post the public key to the diff --git a/lib/chef/chef_fs/data_handler/acl_data_handler.rb b/lib/chef/chef_fs/data_handler/acl_data_handler.rb index e64f3d245c..88edd926a9 100644 --- a/lib/chef/chef_fs/data_handler/acl_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/acl_data_handler.rb @@ -6,13 +6,15 @@ class Chef class AclDataHandler < DataHandlerBase def normalize(acl, entry) # Normalize the order of the keys for easier reading - result = normalize_hash(acl, { + result = normalize_hash( + acl, { "create" => {}, "read" => {}, "update" => {}, "delete" => {}, "grant" => {}, - }) + } + ) result.each_key do |key| result[key] = normalize_hash(result[key], { "actors" => [], "groups" => [] }) result[key]["actors"] = result[key]["actors"].sort diff --git a/lib/chef/chef_fs/data_handler/container_data_handler.rb b/lib/chef/chef_fs/data_handler/container_data_handler.rb index 25bdf73b04..b3f8432512 100644 --- a/lib/chef/chef_fs/data_handler/container_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/container_data_handler.rb @@ -5,10 +5,12 @@ class Chef module DataHandler class ContainerDataHandler < DataHandlerBase def normalize(container, entry) - normalize_hash(container, { + normalize_hash( + container, { "containername" => remove_dot_json(entry.name), "containerpath" => remove_dot_json(entry.name), - }) + } + ) end def preserve_key?(key) diff --git a/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb b/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb index 222e6069f3..99d3ecfed9 100644 --- a/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb @@ -8,7 +8,8 @@ class Chef def normalize(cookbook, entry) version = entry.name name = entry.parent.name - result = normalize_hash(cookbook, { + result = normalize_hash( + cookbook, { "name" => "#{name}-#{version}", "version" => version, "cookbook_name" => name, @@ -16,11 +17,14 @@ class Chef "chef_type" => "cookbook_version", "frozen?" => false, "metadata" => {}, - }) - result["metadata"] = normalize_hash(result["metadata"], { + } + ) + result["metadata"] = normalize_hash( + result["metadata"], { "version" => version, "name" => name, - }) + } + ) end def preserve_key?(key) diff --git a/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb b/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb index bb42b89cfd..edf770feb2 100644 --- a/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb @@ -14,9 +14,11 @@ class Chef end # chef_type and data_bag come back in PUT and POST results, but we don't # use those in knife-essentials. - normalize_hash(data_bag_item, { + normalize_hash( + data_bag_item, { "id" => remove_dot_json(entry.name), - }) + } + ) end def normalize_for_post(data_bag_item, entry) diff --git a/lib/chef/chef_fs/data_handler/environment_data_handler.rb b/lib/chef/chef_fs/data_handler/environment_data_handler.rb index e3aa242fc9..c85cd9d1d8 100644 --- a/lib/chef/chef_fs/data_handler/environment_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/environment_data_handler.rb @@ -6,7 +6,8 @@ class Chef module DataHandler class EnvironmentDataHandler < DataHandlerBase def normalize(environment, entry) - normalize_hash(environment, { + normalize_hash( + environment, { "name" => remove_file_extension(entry.name), "description" => "", "cookbook_versions" => {}, @@ -14,7 +15,8 @@ class Chef "override_attributes" => {}, "json_class" => "Chef::Environment", "chef_type" => "environment", - }) + } + ) end def preserve_key?(key) diff --git a/lib/chef/chef_fs/data_handler/node_data_handler.rb b/lib/chef/chef_fs/data_handler/node_data_handler.rb index c4698afd2b..879ffa01c7 100644 --- a/lib/chef/chef_fs/data_handler/node_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/node_data_handler.rb @@ -6,7 +6,8 @@ class Chef module DataHandler class NodeDataHandler < DataHandlerBase def normalize(node, entry) - result = normalize_hash(node, { + result = normalize_hash( + node, { "name" => remove_dot_json(entry.name), "json_class" => "Chef::Node", "chef_type" => "node", @@ -16,7 +17,8 @@ class Chef "default" => {}, "automatic" => {}, "run_list" => [], - }) + } + ) result["run_list"] = normalize_run_list(result["run_list"]) result end diff --git a/lib/chef/chef_fs/data_handler/organization_data_handler.rb b/lib/chef/chef_fs/data_handler/organization_data_handler.rb index f107e8920b..21e6ceda48 100644 --- a/lib/chef/chef_fs/data_handler/organization_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/organization_data_handler.rb @@ -5,13 +5,15 @@ class Chef module DataHandler class OrganizationDataHandler < DataHandlerBase def normalize(organization, entry) - result = normalize_hash(organization, { + result = normalize_hash( + organization, { "name" => entry.org, "full_name" => entry.org, "org_type" => "Business", "clientname" => "#{entry.org}-validator", "billing_plan" => "platform-free", - }) + } + ) result end diff --git a/lib/chef/chef_fs/data_handler/role_data_handler.rb b/lib/chef/chef_fs/data_handler/role_data_handler.rb index 1007a29c8a..57c613e046 100644 --- a/lib/chef/chef_fs/data_handler/role_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/role_data_handler.rb @@ -6,7 +6,8 @@ class Chef module DataHandler class RoleDataHandler < DataHandlerBase def normalize(role, entry) - result = normalize_hash(role, { + result = normalize_hash( + role, { "name" => remove_file_extension(entry.name), "description" => "", "json_class" => "Chef::Role", @@ -15,7 +16,8 @@ class Chef "override_attributes" => {}, "run_list" => [], "env_run_lists" => {}, - }) + } + ) result["run_list"] = normalize_run_list(result["run_list"]) result["env_run_lists"].each_pair do |env, run_list| result["env_run_lists"][env] = normalize_run_list(run_list) diff --git a/lib/chef/chef_fs/data_handler/user_data_handler.rb b/lib/chef/chef_fs/data_handler/user_data_handler.rb index 50a0c0682d..ac0eb7c52b 100644 --- a/lib/chef/chef_fs/data_handler/user_data_handler.rb +++ b/lib/chef/chef_fs/data_handler/user_data_handler.rb @@ -5,7 +5,8 @@ class Chef module DataHandler class UserDataHandler < DataHandlerBase def normalize(user, entry) - normalize_hash(user, { + normalize_hash( + user, { "name" => remove_dot_json(entry.name), "username" => remove_dot_json(entry.name), "display_name" => remove_dot_json(entry.name), @@ -15,7 +16,8 @@ class Chef "salt" => nil, "password" => nil, "openid" => nil, - }) + } + ) end def preserve_key?(key) diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 06370f5d07..249b8485be 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -379,8 +379,10 @@ class Chef # # @api private def rest - @rest ||= Chef::ServerAPI.new(Chef::Config[:chef_server_url], client_name: node_name, - signing_key_filename: Chef::Config[:client_key]) + @rest ||= Chef::ServerAPI.new( + Chef::Config[:chef_server_url], client_name: node_name, + signing_key_filename: Chef::Config[:client_key] + ) end # A rest object with validate_utf8 set to false. This will not throw exceptions @@ -391,8 +393,10 @@ class Chef # @api private def rest_clean @rest_clean ||= - Chef::ServerAPI.new(Chef::Config[:chef_server_url], client_name: node_name, - signing_key_filename: Chef::Config[:client_key], validate_utf8: false) + Chef::ServerAPI.new( + Chef::Config[:chef_server_url], client_name: node_name, + signing_key_filename: Chef::Config[:client_key], validate_utf8: false + ) end # diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb index 87716410db..37f0ab4197 100644 --- a/lib/chef/environment.rb +++ b/lib/chef/environment.rb @@ -108,13 +108,15 @@ class Chef end def cookbook(cookbook, version) - validate({ - version: version, - }, { + validate( + { + version: version, + }, { version: { callbacks: { "should be a valid version requirement" => lambda { |v| Chef::Environment.validate_cookbook_version(v) } }, }, - }) + } + ) @cookbook_versions[cookbook] = version end diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb index ef1de373d6..00831d1e6a 100644 --- a/lib/chef/http/basic_client.rb +++ b/lib/chef/http/basic_client.rb @@ -134,8 +134,10 @@ class Chef Net::HTTP else Chef::Log.trace("Using #{proxy_uri.host}:#{proxy_uri.port} for proxy") - Net::HTTP.Proxy(proxy_uri.host, proxy_uri.port, http_proxy_user(proxy_uri), - http_proxy_pass(proxy_uri)) + Net::HTTP.Proxy( + proxy_uri.host, proxy_uri.port, http_proxy_user(proxy_uri), + http_proxy_pass(proxy_uri) + ) end end diff --git a/lib/chef/key.rb b/lib/chef/key.rb index 632820efa4..7288b8db72 100644 --- a/lib/chef/key.rb +++ b/lib/chef/key.rb @@ -76,25 +76,33 @@ class Chef end def actor(arg = nil) - set_or_return(:actor, arg, - regex: /^[a-z0-9\-_]+$/) + set_or_return( + :actor, arg, + regex: /^[a-z0-9\-_]+$/ + ) end def name(arg = nil) - set_or_return(:name, arg, - kind_of: String) + set_or_return( + :name, arg, + kind_of: String + ) end def public_key(arg = nil) raise Chef::Exceptions::InvalidKeyAttribute, "you cannot set the public_key if create_key is true" if !arg.nil? && @create_key - set_or_return(:public_key, arg, - kind_of: String) + set_or_return( + :public_key, arg, + kind_of: String + ) end def private_key(arg = nil) - set_or_return(:private_key, arg, - kind_of: String) + set_or_return( + :private_key, arg, + kind_of: String + ) end def delete_public_key @@ -108,13 +116,17 @@ class Chef def create_key(arg = nil) raise Chef::Exceptions::InvalidKeyAttribute, "you cannot set create_key to true if the public_key field exists" if arg == true && !@public_key.nil? - set_or_return(:create_key, arg, - kind_of: [TrueClass, FalseClass]) + set_or_return( + :create_key, arg, + kind_of: [TrueClass, FalseClass] + ) end def expiration_date(arg = nil) - set_or_return(:expiration_date, arg, - regex: /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|infinity)$/) + set_or_return( + :expiration_date, arg, + regex: /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|infinity)$/ + ) end def to_h diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index e892f1f2c9..58ff37160e 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -865,10 +865,14 @@ class Chef # Common configuration for all protocols def base_opts - port = config_value(:connection_port, - knife_key_for_protocol(connection_protocol, :port)) - user = config_value(:connection_user, - knife_key_for_protocol(connection_protocol, :user)) + port = config_value( + :connection_port, + knife_key_for_protocol(connection_protocol, :port) + ) + user = config_value( + :connection_user, + knife_key_for_protocol(connection_protocol, :user) + ) {}.tap do |opts| opts[:logger] = Chef::Log # We do not store password in Chef::Config, so only use CLI `config` here diff --git a/lib/chef/knife/core/subcommand_loader.rb b/lib/chef/knife/core/subcommand_loader.rb index 5b9474515a..e26ca94e64 100644 --- a/lib/chef/knife/core/subcommand_loader.rb +++ b/lib/chef/knife/core/subcommand_loader.rb @@ -108,16 +108,20 @@ class Chef def command_class_from(args) cmd_words = positional_arguments(args) load_command(cmd_words) - result = Chef::Knife.subcommands[find_longest_key(Chef::Knife.subcommands, - cmd_words, "_")] + result = Chef::Knife.subcommands[find_longest_key( + Chef::Knife.subcommands, + cmd_words, "_" + )] result || Chef::Knife.subcommands[args.first.tr("-", "_")] end def guess_category(args) category_words = positional_arguments(args) category_words.map! { |w| w.split("-") }.flatten! - find_longest_key(Chef::Knife.subcommands_by_category, - category_words, " ") + find_longest_key( + Chef::Knife.subcommands_by_category, + category_words, " " + ) end # diff --git a/lib/chef/knife/data_bag_show.rb b/lib/chef/knife/data_bag_show.rb index aad94745dc..e6ff99c9da 100644 --- a/lib/chef/knife/data_bag_show.rb +++ b/lib/chef/knife/data_bag_show.rb @@ -43,9 +43,11 @@ class Chef if encrypted && secret # Users do not need to pass --encrypt to read data, we simply try to use the provided secret ui.info("Encrypted data bag detected, decrypting with provided secret.") - raw = Chef::EncryptedDataBagItem.load(@name_args[0], + raw = Chef::EncryptedDataBagItem.load( + @name_args[0], @name_args[1], - secret) + secret + ) format_for_display(raw.to_h) elsif encrypted && !secret ui.warn("Encrypted data bag detected, but no secret provided for decoding. Displaying encrypted data.") diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index 2a4334570e..1612cade57 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -184,9 +184,11 @@ class Chef fqdns = list.map { |v| v[0] } if fqdns.count != fqdns.uniq.count duplicated_fqdns = fqdns.uniq - ui.send(config[:duplicated_fqdns], + ui.send( + config[:duplicated_fqdns], "SSH #{duplicated_fqdns.count > 1 ? "nodes are" : "node is"} " + - "duplicated: #{duplicated_fqdns.join(",")}") + "duplicated: #{duplicated_fqdns.join(",")}" + ) exit 10 if config[:duplicated_fqdns] == :fatal end end diff --git a/lib/chef/knife/supermarket_share.rb b/lib/chef/knife/supermarket_share.rb index f178b4ab35..53ece98961 100644 --- a/lib/chef/knife/supermarket_share.rb +++ b/lib/chef/knife/supermarket_share.rb @@ -125,10 +125,12 @@ class Chef category_string = Chef::JSONCompat.to_json({ "category" => cookbook_category }) - http_resp = Chef::CookbookSiteStreamingUploader.post(uri, user_id, user_secret_filename, { + http_resp = Chef::CookbookSiteStreamingUploader.post( + uri, user_id, user_secret_filename, { tarball: File.open(cookbook_filename), cookbook: category_string, - }) + } + ) res = Chef::JSONCompat.from_json(http_resp.body) if http_resp.code.to_i != 201 diff --git a/lib/chef/mixin/openssl_helper.rb b/lib/chef/mixin/openssl_helper.rb index 5a4bd6077a..b4914c1875 100644 --- a/lib/chef/mixin/openssl_helper.rb +++ b/lib/chef/mixin/openssl_helper.rb @@ -286,8 +286,10 @@ class Chef cert.extensions = extension cert.add_extension ef.create_extension("subjectKeyIdentifier", "hash") - cert.add_extension ef.create_extension("authorityKeyIdentifier", - "keyid:always,issuer:always") + cert.add_extension ef.create_extension( + "authorityKeyIdentifier", + "keyid:always,issuer:always" + ) cert.sign(key, ::OpenSSL::Digest::SHA256.new) cert @@ -317,8 +319,10 @@ class Chef ef.issuer_certificate = info["issuer"] crl.add_extension ::OpenSSL::X509::Extension.new("crlNumber", ::OpenSSL::ASN1::Integer(1)) - crl.add_extension ef.create_extension("authorityKeyIdentifier", - "keyid:always,issuer:always") + crl.add_extension ef.create_extension( + "authorityKeyIdentifier", + "keyid:always,issuer:always" + ) crl.sign(ca_private_key, ::OpenSSL::Digest::SHA256.new) crl end @@ -364,8 +368,10 @@ class Chef end revoked.time = Time.now - ext = ::OpenSSL::X509::Extension.new("CRLReason", - ::OpenSSL::ASN1::Enumerated(revoke_info["reason"])) + ext = ::OpenSSL::X509::Extension.new( + "CRLReason", + ::OpenSSL::ASN1::Enumerated(revoke_info["reason"]) + ) revoked.add_extension(ext) crl.add_revoked(revoked) @@ -394,10 +400,14 @@ class Chef ef.config = ::OpenSSL::Config.load(::OpenSSL::Config::DEFAULT_CONFIG_FILE) ef.issuer_certificate = info["issuer"] - crl.extensions = [ ::OpenSSL::X509::Extension.new("crlNumber", - ::OpenSSL::ASN1::Integer(get_next_crl_number(crl)))] - crl.add_extension ef.create_extension("authorityKeyIdentifier", - "keyid:always,issuer:always") + crl.extensions = [ ::OpenSSL::X509::Extension.new( + "crlNumber", + ::OpenSSL::ASN1::Integer(get_next_crl_number(crl)) + )] + crl.add_extension ef.create_extension( + "authorityKeyIdentifier", + "keyid:always,issuer:always" + ) crl.sign(ca_private_key, ::OpenSSL::Digest::SHA256.new) crl end diff --git a/lib/chef/mixin/windows_env_helper.rb b/lib/chef/mixin/windows_env_helper.rb index 8036fa2bbe..92d7bb15da 100644 --- a/lib/chef/mixin/windows_env_helper.rb +++ b/lib/chef/mixin/windows_env_helper.rb @@ -46,9 +46,11 @@ class Chef if SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string("Environment").address, flags, 5000, nil) == 0 Chef::ReservedNames::Win32::Error.raise! end - if SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string( - utf8_to_wide("Environment") - ).address, flags, 5000, nil) == 0 + if SendMessageTimeoutW( + HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string( + utf8_to_wide("Environment") + ).address, flags, 5000, nil + ) == 0 Chef::ReservedNames::Win32::Error.raise! end end diff --git a/lib/chef/monkey_patches/webrick-utils.rb b/lib/chef/monkey_patches/webrick-utils.rb index fa52a753c4..1fb132993e 100644 --- a/lib/chef/monkey_patches/webrick-utils.rb +++ b/lib/chef/monkey_patches/webrick-utils.rb @@ -25,11 +25,13 @@ module WEBrick raise ArgumentError, "must specify port" end - res = Socket.getaddrinfo(address, port, + res = Socket.getaddrinfo( + address, port, Socket::AF_UNSPEC, # address family Socket::SOCK_STREAM, # socket type 0, # protocol - Socket::AI_PASSIVE) # flag + Socket::AI_PASSIVE + ) # flag last_error = nil sockets = [] res.each do |ai| diff --git a/lib/chef/org.rb b/lib/chef/org.rb index 1b47e1f255..85af257e49 100644 --- a/lib/chef/org.rb +++ b/lib/chef/org.rb @@ -39,23 +39,31 @@ class Chef end def name(arg = nil) - set_or_return(:name, arg, - regex: /^[a-z0-9\-_]+$/) + set_or_return( + :name, arg, + regex: /^[a-z0-9\-_]+$/ + ) end def full_name(arg = nil) - set_or_return(:full_name, - arg, kind_of: String) + set_or_return( + :full_name, + arg, kind_of: String + ) end def private_key(arg = nil) - set_or_return(:private_key, - arg, kind_of: String) + set_or_return( + :private_key, + arg, kind_of: String + ) end def guid(arg = nil) - set_or_return(:guid, - arg, kind_of: String) + set_or_return( + :guid, + arg, kind_of: String + ) end def to_h diff --git a/lib/chef/policy_builder/expand_node_object.rb b/lib/chef/policy_builder/expand_node_object.rb index 4afb4d7d60..3fdfdf6233 100644 --- a/lib/chef/policy_builder/expand_node_object.rb +++ b/lib/chef/policy_builder/expand_node_object.rb @@ -183,8 +183,10 @@ class Chef begin events.cookbook_resolution_start(@expanded_run_list_with_versions) - cookbook_hash = api_service.post("environments/#{node.chef_environment}/cookbook_versions", - { run_list: @expanded_run_list_with_versions }) + cookbook_hash = api_service.post( + "environments/#{node.chef_environment}/cookbook_versions", + { run_list: @expanded_run_list_with_versions } + ) cookbook_hash = cookbook_hash.inject({}) do |memo, (key, value)| memo[key] = Chef::CookbookVersion.from_hash(value) @@ -248,8 +250,10 @@ class Chef end def api_service - @api_service ||= Chef::ServerAPI.new(config[:chef_server_url], - { version_class: Chef::CookbookManifestVersions }) + @api_service ||= Chef::ServerAPI.new( + config[:chef_server_url], + { version_class: Chef::CookbookManifestVersions } + ) end def config diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb index 70a2e44635..16f3587156 100644 --- a/lib/chef/policy_builder/policyfile.rb +++ b/lib/chef/policy_builder/policyfile.rb @@ -302,9 +302,11 @@ class Chef # @api private def run_list if named_run_list_requested? - named_run_list || raise(ConfigurationError, + named_run_list || raise( + ConfigurationError, "Policy '#{retrieved_policy_name}' revision '#{revision_id}' does not have named_run_list '#{named_run_list_name}'" + - "(available named_run_lists: [#{available_named_run_lists.join(", ")}])") + "(available named_run_lists: [#{available_named_run_lists.join(", ")}])" + ) else policy["run_list"] end @@ -499,8 +501,10 @@ class Chef # @api private def api_service - @api_service ||= Chef::ServerAPI.new(config[:chef_server_url], - { version_class: Chef::CookbookManifestVersions }) + @api_service ||= Chef::ServerAPI.new( + config[:chef_server_url], + { version_class: Chef::CookbookManifestVersions } + ) end # @api private diff --git a/lib/chef/property.rb b/lib/chef/property.rb index 6aa76a5236..df22bab54a 100644 --- a/lib/chef/property.rb +++ b/lib/chef/property.rb @@ -688,7 +688,7 @@ class Chef # As of this writing, `name` is the only Chef::Resource property created with the # `property` definition, but this will allow for future properties to be extended # as needed. - !Chef::Resource.properties.keys.include?(name) + !Chef::Resource.properties.key?(name) end def exec_in_resource(resource, proc, *args) diff --git a/lib/chef/provider/directory.rb b/lib/chef/provider/directory.rb index ad627757f8..58c9ef3cbc 100644 --- a/lib/chef/provider/directory.rb +++ b/lib/chef/provider/directory.rb @@ -102,8 +102,10 @@ class Chef end end end - a.failure_message(Chef::Exceptions::InsufficientPermissions, - "Cannot create #{new_resource} at #{new_resource.path} due to insufficient permissions") + a.failure_message( + Chef::Exceptions::InsufficientPermissions, + "Cannot create #{new_resource} at #{new_resource.path} due to insufficient permissions" + ) end requirements.assert(:delete) do |a| diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb index b7ca81b3f8..93e7ed05dd 100644 --- a/lib/chef/provider/git.rb +++ b/lib/chef/provider/git.rb @@ -46,8 +46,10 @@ class Chef dirname = ::File.dirname(cwd) a.assertion { ::File.directory?(dirname) } a.whyrun("Directory #{dirname} does not exist, this run will fail unless it has been previously created. Assuming it would have been created.") - a.failure_message(Chef::Exceptions::MissingParentDirectory, - "Cannot clone #{new_resource} to #{cwd}, the enclosing directory #{dirname} does not exist") + a.failure_message( + Chef::Exceptions::MissingParentDirectory, + "Cannot clone #{new_resource} to #{cwd}, the enclosing directory #{dirname} does not exist" + ) end requirements.assert(:all_actions) do |a| diff --git a/lib/chef/provider/mount/windows.rb b/lib/chef/provider/mount/windows.rb index aea924b07f..29babd0faa 100644 --- a/lib/chef/provider/mount/windows.rb +++ b/lib/chef/provider/mount/windows.rb @@ -61,10 +61,12 @@ class Chef def mount_fs unless @current_resource.mounted - @mount.add(remote: @new_resource.device, - username: @new_resource.username, - domainname: @new_resource.domain, - password: @new_resource.password) + @mount.add( + remote: @new_resource.device, + username: @new_resource.username, + domainname: @new_resource.domain, + password: @new_resource.password + ) logger.trace("#{@new_resource} is mounted at #{@new_resource.mount_point}") else logger.trace("#{@new_resource} is already mounted at #{@new_resource.mount_point}") diff --git a/lib/chef/provider/subversion.rb b/lib/chef/provider/subversion.rb index dd3ece4786..787e888fd1 100644 --- a/lib/chef/provider/subversion.rb +++ b/lib/chef/provider/subversion.rb @@ -49,8 +49,10 @@ class Chef # for why run, print a message explaining the potential error. parent_directory = ::File.dirname(new_resource.destination) a.assertion { ::File.directory?(parent_directory) } - a.failure_message(Chef::Exceptions::MissingParentDirectory, - "Cannot clone #{new_resource} to #{new_resource.destination}, the enclosing directory #{parent_directory} does not exist") + a.failure_message( + Chef::Exceptions::MissingParentDirectory, + "Cannot clone #{new_resource} to #{new_resource.destination}, the enclosing directory #{parent_directory} does not exist" + ) a.whyrun("Directory #{parent_directory} does not exist, assuming it would have been created") end end diff --git a/lib/chef/provider/template/content.rb b/lib/chef/provider/template/content.rb index 6a9da01127..f9b107ccd2 100644 --- a/lib/chef/provider/template/content.rb +++ b/lib/chef/provider/template/content.rb @@ -64,13 +64,13 @@ class Chef context[:template_finder] = template_finder # helper variables - context[:cookbook_name] = new_resource.cookbook_name unless context.keys.include?(:coookbook_name) - context[:recipe_name] = new_resource.recipe_name unless context.keys.include?(:recipe_name) - context[:recipe_line_string] = new_resource.source_line unless context.keys.include?(:recipe_line_string) - context[:recipe_path] = new_resource.source_line_file unless context.keys.include?(:recipe_path) - context[:recipe_line] = new_resource.source_line_number unless context.keys.include?(:recipe_line) - context[:template_name] = new_resource.source unless context.keys.include?(:template_name) - context[:template_path] = template_location unless context.keys.include?(:template_path) + context[:cookbook_name] = new_resource.cookbook_name unless context.key?(:coookbook_name) + context[:recipe_name] = new_resource.recipe_name unless context.key?(:recipe_name) + context[:recipe_line_string] = new_resource.source_line unless context.key?(:recipe_line_string) + context[:recipe_path] = new_resource.source_line_file unless context.key?(:recipe_path) + context[:recipe_line] = new_resource.source_line_number unless context.key?(:recipe_line) + context[:template_name] = new_resource.source unless context.key?(:template_name) + context[:template_path] = template_location unless context.key?(:template_path) context._extend_modules(new_resource.helper_modules) output = context.render_template(template_location) diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index b8f85618da..797e32bfdb 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -79,9 +79,11 @@ class Chef true end end - a.failure_message(Chef::Exceptions::User, "SALTED-SHA512 passwords are not supported on Mac 10.8 and above. \ + a.failure_message( + Chef::Exceptions::User, "SALTED-SHA512 passwords are not supported on Mac 10.8 and above. \ If you want to set the user password using shadow info make sure you specify a SALTED-SHA512-PBKDF2 shadow hash \ -in 'password', with the associated 'salt' and 'iterations'.") +in 'password', with the associated 'salt' and 'iterations'." + ) end requirements.assert(:create, :modify, :manage) do |a| @@ -94,8 +96,10 @@ in 'password', with the associated 'salt' and 'iterations'.") true end end - a.failure_message(Chef::Exceptions::User, "SALTED-SHA512-PBKDF2 shadow hash is given without associated \ -'salt' and 'iterations'. Please specify 'salt' and 'iterations' in order to set the user password using shadow hash.") + a.failure_message( + Chef::Exceptions::User, "SALTED-SHA512-PBKDF2 shadow hash is given without associated \ +'salt' and 'iterations'. Please specify 'salt' and 'iterations' in order to set the user password using shadow hash." + ) end end @@ -343,8 +347,10 @@ in 'password', with the associated 'salt' and 'iterations'.") # Shadow info is saved as binary plist. Convert the info to binary plist. shadow_info_binary = StringIO.new - shell_out("plutil", "-convert", "binary1", "-o", "-", "-", - input: shadow_info.to_plist, live_stream: shadow_info_binary) + shell_out( + "plutil", "-convert", "binary1", "-o", "-", "-", + input: shadow_info.to_plist, live_stream: shadow_info_binary + ) if user_info.nil? # User is just created. read_user_info() will read the fresh information @@ -562,7 +568,7 @@ in 'password', with the associated 'salt' and 'iterations'.") # Sets a value in user information hash using Chef attributes as keys. # def dscl_set(user_hash, key, value) - raise "Unknown dscl key #{key}" unless DSCL_PROPERTY_MAP.keys.include?(key) + raise "Unknown dscl key #{key}" unless DSCL_PROPERTY_MAP.key?(key) user_hash[DSCL_PROPERTY_MAP[key]] = [ value ] user_hash @@ -572,7 +578,7 @@ in 'password', with the associated 'salt' and 'iterations'.") # Gets a value from user information hash using Chef attributes as keys. # def dscl_get(user_hash, key) - raise "Unknown dscl key #{key}" unless DSCL_PROPERTY_MAP.keys.include?(key) + raise "Unknown dscl key #{key}" unless DSCL_PROPERTY_MAP.key?(key) # DSCL values are set as arrays value = user_hash[DSCL_PROPERTY_MAP[key]] diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 7f0895d6c9..6b384be36b 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -647,7 +647,7 @@ class Chef ivars = instance_variables.map(&:to_sym) - HIDDEN_IVARS ivars.each do |ivar| iv = ivar.to_s.sub(/^@/, "") - if all_props.keys.include?(iv) + if all_props.key?(iv) text << " #{iv} #{all_props[iv]}\n" elsif (value = instance_variable_get(ivar)) && !(value.respond_to?(:empty?) && value.empty?) text << " #{iv} #{value_to_text(value)}\n" diff --git a/lib/chef/resource/homebrew_cask.rb b/lib/chef/resource/homebrew_cask.rb index 70e1d7c6bb..d8e97e99c3 100644 --- a/lib/chef/resource/homebrew_cask.rb +++ b/lib/chef/resource/homebrew_cask.rb @@ -59,10 +59,12 @@ class Chef unless casked? converge_by("install cask #{new_resource.cask_name} #{new_resource.options}") do - shell_out!("#{new_resource.homebrew_path} cask install #{new_resource.cask_name} #{new_resource.options}", + shell_out!( + "#{new_resource.homebrew_path} cask install #{new_resource.cask_name} #{new_resource.options}", user: new_resource.owner, env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner }, - cwd: ::Dir.home(new_resource.owner)) + cwd: ::Dir.home(new_resource.owner) + ) end end end @@ -74,10 +76,12 @@ class Chef if casked? converge_by("uninstall cask #{new_resource.cask_name}") do - shell_out!("#{new_resource.homebrew_path} cask uninstall #{new_resource.cask_name}", + shell_out!( + "#{new_resource.homebrew_path} cask uninstall #{new_resource.cask_name}", user: new_resource.owner, env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner }, - cwd: ::Dir.home(new_resource.owner)) + cwd: ::Dir.home(new_resource.owner) + ) end end end @@ -92,10 +96,12 @@ class Chef # @return [Boolean] def casked? unscoped_name = new_resource.cask_name.split("/").last - shell_out!("#{new_resource.homebrew_path} cask list 2>/dev/null", + shell_out!( + "#{new_resource.homebrew_path} cask list 2>/dev/null", user: new_resource.owner, env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner }, - cwd: ::Dir.home(new_resource.owner)).stdout.split.include?(unscoped_name) + cwd: ::Dir.home(new_resource.owner) + ).stdout.split.include?(unscoped_name) end end end diff --git a/lib/chef/resource/homebrew_tap.rb b/lib/chef/resource/homebrew_tap.rb index 23738d6e51..df66326faf 100644 --- a/lib/chef/resource/homebrew_tap.rb +++ b/lib/chef/resource/homebrew_tap.rb @@ -57,10 +57,12 @@ class Chef unless tapped?(new_resource.tap_name) converge_by("tap #{new_resource.tap_name}") do - shell_out!("#{new_resource.homebrew_path} tap #{new_resource.full ? "--full" : ""} #{new_resource.tap_name} #{new_resource.url || ""}", + shell_out!( + "#{new_resource.homebrew_path} tap #{new_resource.full ? "--full" : ""} #{new_resource.tap_name} #{new_resource.url || ""}", user: new_resource.owner, env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner }, - cwd: ::Dir.home(new_resource.owner)) + cwd: ::Dir.home(new_resource.owner) + ) end end end @@ -70,10 +72,12 @@ class Chef if tapped?(new_resource.tap_name) converge_by("untap #{new_resource.tap_name}") do - shell_out!("#{new_resource.homebrew_path} untap #{new_resource.tap_name}", + shell_out!( + "#{new_resource.homebrew_path} untap #{new_resource.tap_name}", user: new_resource.owner, env: { "HOME" => ::Dir.home(new_resource.owner), "USER" => new_resource.owner }, - cwd: ::Dir.home(new_resource.owner)) + cwd: ::Dir.home(new_resource.owner) + ) end end end diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb index cba3908b0c..fe9890aeec 100644 --- a/lib/chef/resource/remote_file.rb +++ b/lib/chef/resource/remote_file.rb @@ -46,11 +46,13 @@ class Chef # source returns an array of strings. def source(*args) arg = parse_source_args(args) - ret = set_or_return(:source, + ret = set_or_return( + :source, arg, { callbacks: { validate_source: method(:validate_source), - } }) + } } + ) if ret.is_a? String Array(ret) else diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb index e63459388d..77d10372ee 100644 --- a/lib/chef/resource_reporter.rb +++ b/lib/chef/resource_reporter.rb @@ -72,8 +72,10 @@ class Chef if reporting_enabled? begin resource_history_url = "reports/nodes/#{node_name}/runs" - server_response = rest_client.post(resource_history_url, { action: :start, run_id: run_id, - start_time: start_time.to_s }, headers) + server_response = rest_client.post( + resource_history_url, { action: :start, run_id: run_id, + start_time: start_time.to_s }, headers + ) rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e handle_error_starting_run(e, resource_history_url) end diff --git a/lib/chef/shell/shell_session.rb b/lib/chef/shell/shell_session.rb index 85e5b85ab3..2f12326db1 100644 --- a/lib/chef/shell/shell_session.rb +++ b/lib/chef/shell/shell_session.rb @@ -265,8 +265,10 @@ module Shell end def register - @rest = Chef::ServerAPI.new(Chef::Config[:chef_server_url], client_name: Chef::Config[:node_name], - signing_key_filename: Chef::Config[:client_key]) + @rest = Chef::ServerAPI.new( + Chef::Config[:chef_server_url], client_name: Chef::Config[:node_name], + signing_key_filename: Chef::Config[:client_key] + ) end end diff --git a/lib/chef/user.rb b/lib/chef/user.rb index 91749cc158..a605cbfeae 100644 --- a/lib/chef/user.rb +++ b/lib/chef/user.rb @@ -53,28 +53,38 @@ class Chef end def name(arg = nil) - set_or_return(:name, arg, - regex: /^[a-z0-9\-_]+$/) + set_or_return( + :name, arg, + regex: /^[a-z0-9\-_]+$/ + ) end def admin(arg = nil) - set_or_return(:admin, - arg, kind_of: [TrueClass, FalseClass]) + set_or_return( + :admin, + arg, kind_of: [TrueClass, FalseClass] + ) end def public_key(arg = nil) - set_or_return(:public_key, - arg, kind_of: String) + set_or_return( + :public_key, + arg, kind_of: String + ) end def private_key(arg = nil) - set_or_return(:private_key, - arg, kind_of: String) + set_or_return( + :private_key, + arg, kind_of: String + ) end def password(arg = nil) - set_or_return(:password, - arg, kind_of: String) + set_or_return( + :password, + arg, kind_of: String + ) end def to_h diff --git a/lib/chef/user_v1.rb b/lib/chef/user_v1.rb index 786bc3a057..42b8929c16 100644 --- a/lib/chef/user_v1.rb +++ b/lib/chef/user_v1.rb @@ -63,53 +63,73 @@ class Chef end def username(arg = nil) - set_or_return(:username, arg, - regex: /^[a-z0-9\-_]+$/) + set_or_return( + :username, arg, + regex: /^[a-z0-9\-_]+$/ + ) end def display_name(arg = nil) - set_or_return(:display_name, - arg, kind_of: String) + set_or_return( + :display_name, + arg, kind_of: String + ) end def first_name(arg = nil) - set_or_return(:first_name, - arg, kind_of: String) + set_or_return( + :first_name, + arg, kind_of: String + ) end def middle_name(arg = nil) - set_or_return(:middle_name, - arg, kind_of: String) + set_or_return( + :middle_name, + arg, kind_of: String + ) end def last_name(arg = nil) - set_or_return(:last_name, - arg, kind_of: String) + set_or_return( + :last_name, + arg, kind_of: String + ) end def email(arg = nil) - set_or_return(:email, - arg, kind_of: String) + set_or_return( + :email, + arg, kind_of: String + ) end def create_key(arg = nil) - set_or_return(:create_key, arg, - kind_of: [TrueClass, FalseClass]) + set_or_return( + :create_key, arg, + kind_of: [TrueClass, FalseClass] + ) end def public_key(arg = nil) - set_or_return(:public_key, - arg, kind_of: String) + set_or_return( + :public_key, + arg, kind_of: String + ) end def private_key(arg = nil) - set_or_return(:private_key, - arg, kind_of: String) + set_or_return( + :private_key, + arg, kind_of: String + ) end def password(arg = nil) - set_or_return(:password, - arg, kind_of: String) + set_or_return( + :password, + arg, kind_of: String + ) end def to_h diff --git a/lib/chef/util/dsc/resource_store.rb b/lib/chef/util/dsc/resource_store.rb index d064a397c3..92b33c9f10 100644 --- a/lib/chef/util/dsc/resource_store.rb +++ b/lib/chef/util/dsc/resource_store.rb @@ -83,16 +83,20 @@ class Chef # Returns a list of dsc resources def query_resources - cmdlet = Chef::Util::Powershell::Cmdlet.new(nil, "get-dscresource", - :object) + cmdlet = Chef::Util::Powershell::Cmdlet.new( + nil, "get-dscresource", + :object + ) result = cmdlet.run result.return_value end # Returns a list of dsc resources matching the provided name def query_resource(resource_name) - cmdlet = Chef::Util::Powershell::Cmdlet.new(nil, "get-dscresource #{resource_name}", - :object) + cmdlet = Chef::Util::Powershell::Cmdlet.new( + nil, "get-dscresource #{resource_name}", + :object + ) result = cmdlet.run ret_val = result.return_value if ret_val.nil? diff --git a/lib/chef/util/windows/net_user.rb b/lib/chef/util/windows/net_user.rb index 5545ff4ca5..04f792f763 100644 --- a/lib/chef/util/windows/net_user.rb +++ b/lib/chef/util/windows/net_user.rb @@ -94,8 +94,10 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows LOGON32_LOGON_NETWORK = Security::LOGON32_LOGON_NETWORK # XXX for an extra painful alternative, see: http://support.microsoft.com/kb/180548 def validate_credentials(passwd) - token = Security.logon_user(@username, nil, passwd, - LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT) + token = Security.logon_user( + @username, nil, passwd, + LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT + ) true rescue Chef::Exceptions::Win32APIError => e Chef::Log.trace(e) diff --git a/lib/chef/win32/api/file.rb b/lib/chef/win32/api/file.rb index bdc2d6f6e5..af4f83b56d 100644 --- a/lib/chef/win32/api/file.rb +++ b/lib/chef/win32/api/file.rb @@ -562,8 +562,10 @@ BOOL WINAPI VerQueryValue( # FIXME: yard with @yield def file_handle(path) path = canonical_encode_path(path) - handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, - nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, nil) + handle = CreateFileW( + path, GENERIC_READ, FILE_SHARE_READ, + nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, nil + ) if handle == INVALID_HANDLE_VALUE Chef::ReservedNames::Win32::Error.raise! @@ -576,8 +578,10 @@ BOOL WINAPI VerQueryValue( # FIXME: yard with @yield def symlink_file_handle(path) path = encode_path(path) - handle = CreateFileW(path, FILE_READ_EA, FILE_SHARE_READ, - nil, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, nil) + handle = CreateFileW( + path, FILE_READ_EA, FILE_SHARE_READ, + nil, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, nil + ) if handle == INVALID_HANDLE_VALUE Chef::ReservedNames::Win32::Error.raise! diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb index 4fac3fe797..121be4859e 100644 --- a/lib/chef/win32/file.rb +++ b/lib/chef/win32/file.rb @@ -192,8 +192,10 @@ class Chef mapping[:GenericExecute] = Chef::ReservedNames::Win32::Security::FILE_GENERIC_EXECUTE mapping[:GenericAll] = Chef::ReservedNames::Win32::Security::FILE_ALL_ACCESS - Chef::ReservedNames::Win32::Security.access_check(security_descriptor, duplicate_token, - desired_access, mapping) + Chef::ReservedNames::Win32::Security.access_check( + security_descriptor, duplicate_token, + desired_access, mapping + ) end def self.delete_volume_mount_point(mount_point) diff --git a/lib/chef/win32/file/info.rb b/lib/chef/win32/file/info.rb index 234c04cdbb..a958d9fc71 100644 --- a/lib/chef/win32/file/info.rb +++ b/lib/chef/win32/file/info.rb @@ -90,8 +90,10 @@ class Chef # Ruby +Time+ object. # def parse_time(file_time_struct) - wtime_to_time(make_uint64(file_time_struct[:dw_low_date_time], - file_time_struct[:dw_high_date_time])) + wtime_to_time(make_uint64( + file_time_struct[:dw_low_date_time], + file_time_struct[:dw_high_date_time] + )) end end diff --git a/lib/chef/win32/security.rb b/lib/chef/win32/security.rb index 5b78b652eb..01a144bd00 100644 --- a/lib/chef/win32/security.rb +++ b/lib/chef/win32/security.rb @@ -55,9 +55,11 @@ class Chef granted_access_ptr = FFI::MemoryPointer.new(:ulong) - unless AccessCheck(security_descriptor_ptr, token_handle, rights_ptr.read_ulong, + unless AccessCheck( + security_descriptor_ptr, token_handle, rights_ptr.read_ulong, generic_mapping, privileges, privileges_length_ptr, granted_access_ptr, - result_ptr) + result_ptr + ) Chef::ReservedNames::Win32::Error.raise! end result_ptr.read_ulong == 1 diff --git a/spec/functional/dsl/reboot_pending_spec.rb b/spec/functional/dsl/reboot_pending_spec.rb index 89701802b3..dafb310327 100644 --- a/spec/functional/dsl/reboot_pending_spec.rb +++ b/spec/functional/dsl/reboot_pending_spec.rb @@ -46,8 +46,10 @@ describe Chef::DSL::RebootPending, :windows_only do it "returns true if the registry value exists" do skip "found existing registry key" if original_set - registry.set_value(reg_key, - { name: "PendingFileRenameOperations", type: :multi_string, data: ['\??\C:\foo.txt|\??\C:\bar.txt'] }) + registry.set_value( + reg_key, + { name: "PendingFileRenameOperations", type: :multi_string, data: ['\??\C:\foo.txt|\??\C:\bar.txt'] } + ) expect(recipe.reboot_pending?).to be_truthy end diff --git a/spec/functional/resource/git_spec.rb b/spec/functional/resource/git_spec.rb index e978041038..1d00f2267f 100644 --- a/spec/functional/resource/git_spec.rb +++ b/spec/functional/resource/git_spec.rb @@ -219,8 +219,10 @@ describe Chef::Resource::Git, requires_git: true do context "when dealing with a repo with a degenerate tag named 'HEAD'" do before do - shell_out!("git tag -m\"degenerate tag\" HEAD ed181b3419b6f489bedab282348162a110d6d3a1", - cwd: origin_repo) + shell_out!( + "git tag -m\"degenerate tag\" HEAD ed181b3419b6f489bedab282348162a110d6d3a1", + cwd: origin_repo + ) end let(:basic_git_resource) do @@ -239,17 +241,21 @@ describe Chef::Resource::Git, requires_git: true do it "checks out the (master) HEAD revision and ignores the tag" do basic_git_resource.run_action(:sync) - head_rev = shell_out!("git rev-parse HEAD", + head_rev = shell_out!( + "git rev-parse HEAD", cwd: deploy_directory, - returns: [0]).stdout.strip + returns: [0] + ).stdout.strip expect(head_rev).to eq(rev_head) end it "checks out the (master) HEAD revision when no revision is specified (ignores tag)" do git_resource_default_rev.run_action(:sync) - head_rev = shell_out!("git rev-parse HEAD", + head_rev = shell_out!( + "git rev-parse HEAD", cwd: deploy_directory, - returns: [0]).stdout.strip + returns: [0] + ).stdout.strip expect(head_rev).to eq(rev_head) end diff --git a/spec/functional/resource/group_spec.rb b/spec/functional/resource/group_spec.rb index c17217b1f3..3674bd13f0 100644 --- a/spec/functional/resource/group_spec.rb +++ b/spec/functional/resource/group_spec.rb @@ -1,7 +1,7 @@ # # Author:: Chirag Jog (<chirag@clogeny.com>) # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>) -# Copyright:: Copyright 2013-2018, Chef Software Inc. +# Copyright:: Copyright 2013-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -334,9 +334,9 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do describe "when group name is length 256", :windows_only do let!(:group_name) do "theoldmanwalkingdownthestreetalwayshadagood\ - smileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisface\ - theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalking\ - downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestree" +smileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisface\ +theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalking\ +downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestree" end it "should create a group" do @@ -361,9 +361,9 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do context "group create action: when group name length is more than 256", :windows_only do let!(:group_name) do "theoldmanwalkingdownthestreetalwayshadagood\ - smileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisface\ - theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalking\ - downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" +smileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisface\ +theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalking\ +downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" end it "should not create a group" do diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb index 74ece0d33c..bd3801fb2d 100644 --- a/spec/functional/resource/powershell_script_spec.rb +++ b/spec/functional/resource/powershell_script_spec.rb @@ -329,8 +329,10 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do it "raises an error when executing a script with a 32-bit process on Windows Nano Server", :windows_nano_only do resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}") - expect { resource.architecture(:i386) }.to raise_error(Chef::Exceptions::Win32ArchitectureIncorrect, - "cannot execute script with requested architecture 'i386' on Windows Nano Server") + expect { resource.architecture(:i386) }.to raise_error( + Chef::Exceptions::Win32ArchitectureIncorrect, + "cannot execute script with requested architecture 'i386' on Windows Nano Server" + ) end end diff --git a/spec/functional/win32/security_spec.rb b/spec/functional/win32/security_spec.rb index a72088a079..3aefd4585b 100644 --- a/spec/functional/win32/security_spec.rb +++ b/spec/functional/win32/security_spec.rb @@ -96,8 +96,10 @@ describe "Chef::Win32::Security", :windows_only do let(:desired_access) { Chef::ReservedNames::Win32::Security::FILE_GENERIC_READ } it "should check if the provided token has the desired access" do - expect(Chef::ReservedNames::Win32::Security.access_check(security_descriptor, - token, desired_access, mapping)).to be true + expect(Chef::ReservedNames::Win32::Security.access_check( + security_descriptor, + token, desired_access, mapping + )).to be true end end diff --git a/spec/integration/client/exit_code_spec.rb b/spec/integration/client/exit_code_spec.rb index 37999ab431..80d0222f3f 100644 --- a/spec/integration/client/exit_code_spec.rb +++ b/spec/integration/client/exit_code_spec.rb @@ -35,9 +35,11 @@ describe "chef-client" do end def run_chef_client_and_expect_exit_code(exit_code) - shell_out!("#{chef_client} -c \"#{path_to("config/client.rb")}\" -o 'x::default'", + shell_out!( + "#{chef_client} -c \"#{path_to("config/client.rb")}\" -o 'x::default'", cwd: chef_dir, - returns: [exit_code]) + returns: [exit_code] + ) end context "has a cookbook" do diff --git a/spec/integration/knife/config_get_profile_spec.rb b/spec/integration/knife/config_get_profile_spec.rb index e97b24b869..545faf3977 100644 --- a/spec/integration/knife/config_get_profile_spec.rb +++ b/spec/integration/knife/config_get_profile_spec.rb @@ -26,10 +26,12 @@ describe "knife config get-profile", :workstation do let(:cmd_args) { [] } subject do - cmd = knife("config", "get-profile", *cmd_args, instance_filter: lambda { |instance| + cmd = knife( + "config", "get-profile", *cmd_args, instance_filter: lambda { |instance| # Fake the failsafe check because this command doesn't actually process knife.rb. - $__KNIFE_INTEGRATION_FAILSAFE_CHECK << " ole" - }) + $__KNIFE_INTEGRATION_FAILSAFE_CHECK << " ole" + } + ) cmd.stdout end diff --git a/spec/integration/knife/config_get_spec.rb b/spec/integration/knife/config_get_spec.rb index 98fefd729f..5fad0f15b5 100644 --- a/spec/integration/knife/config_get_spec.rb +++ b/spec/integration/knife/config_get_spec.rb @@ -26,14 +26,16 @@ describe "knife config get", :workstation do let(:cmd_args) { [] } subject do - cmd = knife("config", "get", *cmd_args, instance_filter: lambda { |instance| + cmd = knife( + "config", "get", *cmd_args, instance_filter: lambda { |instance| # Clear the stub set up in KnifeSupport. - allow(File).to receive(:file?).and_call_original + allow(File).to receive(:file?).and_call_original # Lies, damn lies, and config files. We need to allow normal config loading # behavior to be able to test stuff. - instance.config.delete(:config_file) - $__KNIFE_INTEGRATION_FAILSAFE_CHECK << " ole" - }) + instance.config.delete(:config_file) + $__KNIFE_INTEGRATION_FAILSAFE_CHECK << " ole" + } + ) cmd.stdout end diff --git a/spec/integration/knife/config_list_profiles_spec.rb b/spec/integration/knife/config_list_profiles_spec.rb index 044b50b5be..c95883b84c 100644 --- a/spec/integration/knife/config_list_profiles_spec.rb +++ b/spec/integration/knife/config_list_profiles_spec.rb @@ -25,10 +25,12 @@ describe "knife config list-profiles", :workstation do let(:cmd_args) { [] } let(:knife_list_profiles) do - knife("config", "list-profiles", *cmd_args, instance_filter: proc { + knife( + "config", "list-profiles", *cmd_args, instance_filter: proc { # Clear the stub set up in KnifeSupport. - allow(File).to receive(:file?).and_call_original - }) + allow(File).to receive(:file?).and_call_original + } + ) end subject { knife_list_profiles.stdout } diff --git a/spec/integration/knife/config_use_profile_spec.rb b/spec/integration/knife/config_use_profile_spec.rb index a021dbbe6f..7a3be37f18 100644 --- a/spec/integration/knife/config_use_profile_spec.rb +++ b/spec/integration/knife/config_use_profile_spec.rb @@ -26,10 +26,12 @@ describe "knife config use-profile", :workstation do let(:cmd_args) { [] } let(:knife_use_profile) do - knife("config", "use-profile", *cmd_args, instance_filter: lambda { |instance| + knife( + "config", "use-profile", *cmd_args, instance_filter: lambda { |instance| # Fake the failsafe check because this command doesn't actually process knife.rb. - $__KNIFE_INTEGRATION_FAILSAFE_CHECK << " ole" - }) + $__KNIFE_INTEGRATION_FAILSAFE_CHECK << " ole" + } + ) end subject { knife_use_profile.stdout } diff --git a/spec/support/shared/functional/http.rb b/spec/support/shared/functional/http.rb index f006c6a24a..d9fa7c0ddb 100644 --- a/spec/support/shared/functional/http.rb +++ b/spec/support/shared/functional/http.rb @@ -71,65 +71,77 @@ module ChefHTTPShared # # (expected_content should be uncompressed) - @api.get("/nyan_cat_content_length.png", 200, nil, + @api.get( + "/nyan_cat_content_length.png", 200, nil, { "Content-Length" => nyan_uncompressed_size.to_s, - }) do - File.open(nyan_uncompressed_filename, "rb", &:read) - end + } + ) do + File.open(nyan_uncompressed_filename, "rb", &:read) + end # (expected_content should be uncompressed) - @api.get("/nyan_cat_content_length_compressed.png", 200, nil, + @api.get( + "/nyan_cat_content_length_compressed.png", 200, nil, { "Content-Length" => nyan_compressed_size.to_s, "Content-Type" => "application/gzip", "Content-Encoding" => "gzip", - }) do - File.open(nyan_compressed_filename, "rb", &:read) - end + } + ) do + File.open(nyan_compressed_filename, "rb", &:read) + end # # endpoints that simulate truncated downloads (bad content-length header) # # (expected_content should be uncompressed) - @api.get("/nyan_cat_truncated.png", 200, nil, + @api.get( + "/nyan_cat_truncated.png", 200, nil, { "Content-Length" => (nyan_uncompressed_size + 1).to_s, - }) do - File.open(nyan_uncompressed_filename, "rb", &:read) - end + } + ) do + File.open(nyan_uncompressed_filename, "rb", &:read) + end # (expected_content should be uncompressed) - @api.get("/nyan_cat_truncated_compressed.png", 200, nil, + @api.get( + "/nyan_cat_truncated_compressed.png", 200, nil, { "Content-Length" => (nyan_compressed_size + 1).to_s, "Content-Type" => "application/gzip", "Content-Encoding" => "gzip", - }) do - File.open(nyan_compressed_filename, "rb", &:read) - end + } + ) do + File.open(nyan_compressed_filename, "rb", &:read) + end # # in the presence of a transfer-encoding header, we must ignore the content-length (this bad content-length should work) # # (expected_content should be uncompressed) - @api.get("/nyan_cat_transfer_encoding.png", 200, nil, + @api.get( + "/nyan_cat_transfer_encoding.png", 200, nil, { "Content-Length" => (nyan_uncompressed_size + 1).to_s, "Transfer-Encoding" => "anything", - }) do - File.open(nyan_uncompressed_filename, "rb", &:read) - end + } + ) do + File.open(nyan_uncompressed_filename, "rb", &:read) + end # # 403 with a Content-Length # - @api.get("/forbidden", 403, "Forbidden", + @api.get( + "/forbidden", 403, "Forbidden", { "Content-Length" => "Forbidden".bytesize.to_s, - }) + } + ) @api.post("/posty", 200, "Hi!") diff --git a/spec/support/shared/integration/app_server_support.rb b/spec/support/shared/integration/app_server_support.rb index 317a5a2679..586d5c6d15 100644 --- a/spec/support/shared/integration/app_server_support.rb +++ b/spec/support/shared/integration/app_server_support.rb @@ -24,12 +24,14 @@ module AppServerSupport def start_app_server(app, port) server = nil thread = Thread.new do - Rack::Handler::WEBrick.run(app, + Rack::Handler::WEBrick.run( + app, Port: 9018, AccessLog: [], - Logger: WEBrick::Log.new(StringIO.new, 7)) do |found_server| - server = found_server - end + Logger: WEBrick::Log.new(StringIO.new, 7) + ) do |found_server| + server = found_server + end end Timeout.timeout(30) do sleep(0.01) until server && server.status == :Running diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index 2771a371d4..198b7ef8ea 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -529,8 +529,10 @@ shared_examples_for Chef::Provider::File do let(:diff_for_reporting) { "+++\n---\n+foo\n-bar\n" } before do allow(provider).to receive(:contents_changed?).and_return(true) - diff = double("Diff", for_output: ["+++", "---", "+foo", "-bar"], - for_reporting: diff_for_reporting ) + diff = double( + "Diff", for_output: ["+++", "---", "+foo", "-bar"], + for_reporting: diff_for_reporting + ) allow(diff).to receive(:diff).with(resource_path, tempfile_path).and_return(true) expect(provider).to receive(:diff).at_least(:once).and_return(diff) expect(provider).to receive(:checksum).with(tempfile_path).and_return(tempfile_sha256) diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index b659f13fe8..68c7a153a5 100644 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -52,8 +52,10 @@ describe Chef::Application::Apply do describe "when recipe is nil" do it "should raise a fatal with the missing filename message" do - expect(Chef::Application).to receive(:fatal!).with("No recipe file was provided", - Chef::Exceptions::RecipeNotFound.new) + expect(Chef::Application).to receive(:fatal!).with( + "No recipe file was provided", + Chef::Exceptions::RecipeNotFound.new + ) @app.read_recipe_file(nil) end end @@ -62,8 +64,10 @@ describe Chef::Application::Apply do allow(File).to receive(:exist?).with(@recipe_path).and_return(false) end it "should raise a fatal with the file doesn't exist message" do - expect(Chef::Application).to receive(:fatal!).with(/^No file exists at/, - Chef::Exceptions::RecipeNotFound.new) + expect(Chef::Application).to receive(:fatal!).with( + /^No file exists at/, + Chef::Exceptions::RecipeNotFound.new + ) @app.read_recipe_file(@recipe_file_name) end end diff --git a/spec/unit/chef_fs/diff_spec.rb b/spec/unit/chef_fs/diff_spec.rb index 229a48c2db..2436a367b9 100644 --- a/spec/unit/chef_fs/diff_spec.rb +++ b/spec/unit/chef_fs/diff_spec.rb @@ -33,7 +33,8 @@ describe "diff", uses_diff: true do context "with two filesystems with all types of difference" do let(:a) do - memory_fs("a", { + memory_fs( + "a", { both_dirs: { sub_both_dirs: { subsub: nil }, sub_both_files: nil, @@ -57,10 +58,12 @@ describe "diff", uses_diff: true do a_only_file: nil, dir_in_a_file_in_b: {}, file_in_a_dir_in_b: nil, - }, /cannot_be_in_a/) + }, /cannot_be_in_a/ + ) end let(:b) do - memory_fs("b", { + memory_fs( + "b", { both_dirs: { sub_both_dirs: { subsub: nil }, sub_both_files: nil, @@ -84,7 +87,8 @@ describe "diff", uses_diff: true do b_only_file: nil, dir_in_a_file_in_b: nil, file_in_a_dir_in_b: {}, - }, /cannot_be_in_b/) + }, /cannot_be_in_b/ + ) end it "Chef::ChefFS::CommandLine.diff_print(/)" do results = [] diff --git a/spec/unit/chef_fs/file_system_spec.rb b/spec/unit/chef_fs/file_system_spec.rb index fed468f2cd..6ffefd5527 100644 --- a/spec/unit/chef_fs/file_system_spec.rb +++ b/spec/unit/chef_fs/file_system_spec.rb @@ -56,7 +56,8 @@ describe Chef::ChefFS::FileSystem do context "with a populated filesystem" do let(:fs) do - memory_fs("", { + memory_fs( + "", { a: { aa: { c: "", @@ -68,7 +69,8 @@ describe Chef::ChefFS::FileSystem do }, x: "", y: {}, - }) + } + ) end context "list" do it "/**" do diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 5182717af8..332705567a 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -216,8 +216,10 @@ shared_context "converge completed" do allow(node).to receive(:data_for_save).and_return(node.for_json) # --Client#save_updated_node - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], client_name: fqdn, - signing_key_filename: Chef::Config[:client_key], validate_utf8: false).and_return(http_node_save) + expect(Chef::ServerAPI).to receive(:new).with( + Chef::Config[:chef_server_url], client_name: fqdn, + signing_key_filename: Chef::Config[:client_key], validate_utf8: false + ).and_return(http_node_save) expect(http_node_save).to receive(:put).with("nodes/#{fqdn}", node.for_json).and_return(true) end end diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb index 0762a11771..241b00c748 100644 --- a/spec/unit/cookbook/synchronizer_spec.rb +++ b/spec/unit/cookbook/synchronizer_spec.rb @@ -198,23 +198,31 @@ describe Chef::CookbookSynchronizer do end let(:cookbook_a_default_recipe_tempfile) do - double("Tempfile for cookbook_a default.rb recipe", - path: "/tmp/cookbook_a_recipes_default_rb") + double( + "Tempfile for cookbook_a default.rb recipe", + path: "/tmp/cookbook_a_recipes_default_rb" + ) end let(:cookbook_a_default_attribute_tempfile) do - double("Tempfile for cookbook_a default.rb attr file", - path: "/tmp/cookbook_a_attributes_default_rb") + double( + "Tempfile for cookbook_a default.rb attr file", + path: "/tmp/cookbook_a_attributes_default_rb" + ) end let(:cookbook_a_file_default_tempfile) do - double("Tempfile for cookbook_a megaman.conf file", - path: "/tmp/cookbook_a_file_default_tempfile") + double( + "Tempfile for cookbook_a megaman.conf file", + path: "/tmp/cookbook_a_file_default_tempfile" + ) end let(:cookbook_a_template_default_tempfile) do - double("Tempfile for cookbook_a apache.conf.erb template", - path: "/tmp/cookbook_a_template_default_tempfile") + double( + "Tempfile for cookbook_a apache.conf.erb template", + path: "/tmp/cookbook_a_template_default_tempfile" + ) end def setup_common_files_missing_expectations diff --git a/spec/unit/cookbook_site_streaming_uploader_spec.rb b/spec/unit/cookbook_site_streaming_uploader_spec.rb index af714094d0..698b3335fc 100644 --- a/spec/unit/cookbook_site_streaming_uploader_spec.rb +++ b/spec/unit/cookbook_site_streaming_uploader_spec.rb @@ -100,24 +100,30 @@ describe Chef::CookbookSiteStreamingUploader do end it "should be able to receive files to attach as argument" do - Chef::CookbookSiteStreamingUploader.make_request(:put, @uri, "bill", @secret_filename, { + Chef::CookbookSiteStreamingUploader.make_request( + :put, @uri, "bill", @secret_filename, { myfile: File.new(File.join(CHEF_SPEC_DATA, "config.rb")), # a dummy file - }) + } + ) end it "should be able to receive strings to attach as argument" do - Chef::CookbookSiteStreamingUploader.make_request(:put, @uri, "bill", @secret_filename, { + Chef::CookbookSiteStreamingUploader.make_request( + :put, @uri, "bill", @secret_filename, { mystring: "Lorem ipsum", - }) + } + ) end it "should be able to receive strings and files as argument at the same time" do - Chef::CookbookSiteStreamingUploader.make_request(:put, @uri, "bill", @secret_filename, { + Chef::CookbookSiteStreamingUploader.make_request( + :put, @uri, "bill", @secret_filename, { myfile1: File.new(File.join(CHEF_SPEC_DATA, "config.rb")), mystring1: "Lorem ipsum", myfile2: File.new(File.join(CHEF_SPEC_DATA, "config.rb")), mystring2: "Dummy text", - }) + } + ) end end # make_request diff --git a/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb index 57f1f53f2c..567405f9c4 100644 --- a/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb @@ -76,9 +76,11 @@ describe Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector do @exception = Net::HTTPClientException.new("(exception) unauthorized", @response) @inspector = Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector.new(@node, @exception) - allow(@inspector).to receive(:config).and_return(node_name: "unit-test.example.com", - client_key: "/etc/chef/client.pem", - chef_server_url: "http://chef.example.com") + allow(@inspector).to receive(:config).and_return( + node_name: "unit-test.example.com", + client_key: "/etc/chef/client.pem", + chef_server_url: "http://chef.example.com" + ) @inspector.add_explanation(@description) end diff --git a/spec/unit/key_spec.rb b/spec/unit/key_spec.rb index efae549490..699653f424 100644 --- a/spec/unit/key_spec.rb +++ b/spec/unit/key_spec.rb @@ -405,10 +405,12 @@ describe Chef::Key do end it "creates a new key via the API with the fingerprint as the name" do - expect(rest).to receive(:post).with(url, + expect(rest).to receive(:post).with( + url, { "name" => "12:3e:33:73:0b:f4:ec:72:dc:f0:4c:51:62:27:08:76:96:24:f4:4a", "public_key" => key.public_key, - "expiration_date" => key.expiration_date }).and_return({}) + "expiration_date" => key.expiration_date } + ).and_return({}) key.create end end @@ -423,10 +425,12 @@ describe Chef::Key do context "when create_key is false" do it "creates a new key via the API" do - expect(rest).to receive(:post).with(url, + expect(rest).to receive(:post).with( + url, { "name" => key.name, "public_key" => key.public_key, - "expiration_date" => key.expiration_date }).and_return({}) + "expiration_date" => key.expiration_date } + ).and_return({}) key.create end end diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 5f4be8dfa2..7ed20c4081 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -32,10 +32,12 @@ describe Chef::Knife::Bootstrap do let(:ssh_test) { false } let(:connection) do - double("TrainConnector", + double( + "TrainConnector", windows?: windows_test, linux?: linux_test, - unix?: unix_test) + unix?: unix_test + ) end let(:knife) do diff --git a/spec/unit/knife/cookbook_delete_spec.rb b/spec/unit/knife/cookbook_delete_spec.rb index 4de907e94d..f26cb62484 100644 --- a/spec/unit/knife/cookbook_delete_spec.rb +++ b/spec/unit/knife/cookbook_delete_spec.rb @@ -75,9 +75,11 @@ describe Chef::Knife::CookbookDelete do it "should delete the specific cookbook version" do @knife.cookbook_name = "foobar" @knife.version = "1.0.0" - expect(@knife).to receive(:delete_object).with(Chef::CookbookVersion, + expect(@knife).to receive(:delete_object).with( + Chef::CookbookVersion, "foobar version 1.0.0", - "cookbook").and_yield + "cookbook" + ).and_yield expect(@knife).to receive(:delete_request).with("cookbooks/foobar/1.0.0") @knife.delete_explicit_version end diff --git a/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/spec/unit/knife/core/windows_bootstrap_context_spec.rb index e5a4e955e8..0cae87539d 100644 --- a/spec/unit/knife/core/windows_bootstrap_context_spec.rb +++ b/spec/unit/knife/core/windows_bootstrap_context_spec.rb @@ -151,13 +151,17 @@ describe Chef::Knife::Core::WindowsBootstrapContext do describe "#config_content" do before do - bootstrap_context.instance_variable_set(:@chef_config, Mash.new(config_log_level: :info, - config_log_location: STDOUT, - chef_server_url: "http://chef.example.com:4444", - validation_client_name: "chef-validator-testing", - file_cache_path: "c:/chef/cache", - file_backup_path: "c:/chef/backup", - cache_options: ({ path: "c:/chef/cache/checksums", skip_expires: true }))) + bootstrap_context.instance_variable_set( + :@chef_config, Mash.new( + config_log_level: :info, + config_log_location: STDOUT, + chef_server_url: "http://chef.example.com:4444", + validation_client_name: "chef-validator-testing", + file_cache_path: "c:/chef/cache", + file_backup_path: "c:/chef/backup", + cache_options: ({ path: "c:/chef/cache/checksums", skip_expires: true }) + ) + ) end it "generates the config file data" do diff --git a/spec/unit/knife/raw_spec.rb b/spec/unit/knife/raw_spec.rb index d1300e9437..e294f93d06 100644 --- a/spec/unit/knife/raw_spec.rb +++ b/spec/unit/knife/raw_spec.rb @@ -34,9 +34,11 @@ describe Chef::Knife::Raw do describe "run" do it "should set the x-ops-request-source header when --proxy-auth is set" do knife.config[:proxy_auth] = true - expect(rest).to receive(:request).with(:GET, "/nodes", + expect(rest).to receive(:request).with( + :GET, "/nodes", { "Content-Type" => "application/json", - "x-ops-request-source" => "web" }, false) + "x-ops-request-source" => "web" }, false + ) knife.run end end diff --git a/spec/unit/knife/supermarket_install_spec.rb b/spec/unit/knife/supermarket_install_spec.rb index 9c969106fc..2ac1f4d721 100644 --- a/spec/unit/knife/supermarket_install_spec.rb +++ b/spec/unit/knife/supermarket_install_spec.rb @@ -1,6 +1,6 @@ # # Author:: Steven Danna (<steve@chef.io>) -# Copyright:: Copyright 2011-2018, Chef Software, Inc. +# Copyright:: Copyright 2011-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,9 +26,11 @@ describe Chef::Knife::SupermarketInstall do let(:downloader) { {} } let(:archive) { double(Mixlib::Archive, extract: true) } let(:repo) do - double(sanity_check: true, reset_to_default_state: true, - prepare_to_import: true, finalize_updates_to: true, - merge_updates_from: true) + double( + sanity_check: true, reset_to_default_state: true, + prepare_to_import: true, finalize_updates_to: true, + merge_updates_from: true + ) end let(:install_path) do if Chef::Platform.windows? diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index 6ed7ddd70e..9210c96586 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -34,10 +34,12 @@ describe Chef::Knife do let(:config_location) { File.expand_path("~/.chef/config.rb") } let(:config_loader) do - instance_double("WorkstationConfigLoader", + instance_double( + "WorkstationConfigLoader", load: nil, no_config_found?: false, config_location: config_location, - chef_config_dir: "/etc/chef") + chef_config_dir: "/etc/chef" + ) end before(:each) do @@ -285,9 +287,11 @@ describe Chef::Knife do let(:command) { KnifeSpecs::TestYourself.new([]) } before do - KnifeSpecs::TestYourself.option(:opt_with_default, + KnifeSpecs::TestYourself.option( + :opt_with_default, short: "-D VALUE", - default: "default-value") + default: "default-value" + ) end # This supports a use case used by plugins, where the pattern # seems to follow: @@ -308,9 +312,11 @@ describe Chef::Knife do end describe "merging configuration options" do before do - KnifeSpecs::TestYourself.option(:opt_with_default, + KnifeSpecs::TestYourself.option( + :opt_with_default, short: "-D VALUE", - default: "default-value") + default: "default-value" + ) end it "sets the default log_location to STDERR for Chef::Log warnings" do diff --git a/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb b/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb index 701de06167..d24beb0c6f 100644 --- a/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +++ b/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb @@ -51,9 +51,11 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do allow_any_instance_of(Chef::FileAccessControl).to receive(:define_resource_requirements) allow_any_instance_of(Chef::FileAccessControl).to receive(:describe_changes) - passwd_struct = OpenStruct.new(name: "root", passwd: "x", - uid: 0, gid: 0, dir: "/root", - shell: "/bin/bash") + passwd_struct = OpenStruct.new( + name: "root", passwd: "x", + uid: 0, gid: 0, dir: "/root", + shell: "/bin/bash" + ) group_struct = OpenStruct.new(name: "root", passwd: "x", gid: 0) allow(Etc).to receive(:getpwuid).and_return(passwd_struct) @@ -75,9 +77,11 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do allow_any_instance_of(Chef::FileAccessControl).to receive(:uid_from_resource).and_return(0) allow_any_instance_of(Chef::FileAccessControl).to receive(:describe_changes) - passwd_struct = OpenStruct.new(name: "root", passwd: "x", - uid: 0, gid: 0, dir: "/root", - shell: "/bin/bash") + passwd_struct = OpenStruct.new( + name: "root", passwd: "x", + uid: 0, gid: 0, dir: "/root", + shell: "/bin/bash" + ) group_struct = OpenStruct.new(name: "root", passwd: "x", gid: 0) allow(Etc).to receive(:getpwuid).and_return(passwd_struct) diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb index 489742cb7d..4a73077665 100644 --- a/spec/unit/mixin/params_validate_spec.rb +++ b/spec/unit/mixin/params_validate_spec.rb @@ -164,11 +164,13 @@ describe Chef::Mixin::ParamsValidate do it "should let you set a default value with default => value" do arguments = {} - @vo.validate(arguments, { + @vo.validate( + arguments, { one: { default: "is the loneliest number", }, - }) + } + ) expect(arguments[:one]).to eq("is the loneliest number") end @@ -333,23 +335,31 @@ describe Chef::Mixin::ParamsValidate do it "asserts that a value returns false from a predicate method" do expect do - @vo.validate({ not_blank: "should pass" }, - { not_blank: { cannot_be: %i{nil empty} } }) + @vo.validate( + { not_blank: "should pass" }, + { not_blank: { cannot_be: %i{nil empty} } } + ) end.not_to raise_error expect do - @vo.validate({ not_blank: "" }, - { not_blank: { cannot_be: %i{nil empty} } }) + @vo.validate( + { not_blank: "" }, + { not_blank: { cannot_be: %i{nil empty} } } + ) end.to raise_error(Chef::Exceptions::ValidationFailed) end it "allows a custom validation message" do expect do - @vo.validate({ not_blank: "should pass" }, - { not_blank: { cannot_be: %i{nil empty}, validation_message: "my validation message" } }) + @vo.validate( + { not_blank: "should pass" }, + { not_blank: { cannot_be: %i{nil empty}, validation_message: "my validation message" } } + ) end.not_to raise_error expect do - @vo.validate({ not_blank: "" }, - { not_blank: { cannot_be: %i{nil empty}, validation_message: "my validation message" } }) + @vo.validate( + { not_blank: "" }, + { not_blank: { cannot_be: %i{nil empty}, validation_message: "my validation message" } } + ) end.to raise_error(Chef::Exceptions::ValidationFailed, "my validation message") end diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb index 1c4f59b50b..2fc27d3346 100644 --- a/spec/unit/mixin/shell_out_spec.rb +++ b/spec/unit/mixin/shell_out_spec.rb @@ -70,7 +70,8 @@ describe Chef::Mixin::ShellOut do it "should set environment language settings to the configured internal locale when they are not present" do options = { environment: { "HOME" => "/Users/morty" } } - expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, { + expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with( + cmd, { environment: { "HOME" => "/Users/morty", "LC_ALL" => Chef::Config[:internal_locale], @@ -78,13 +79,15 @@ describe Chef::Mixin::ShellOut do "LANGUAGE" => Chef::Config[:internal_locale], env_path => sanitized_path, }, - }).and_return(retobj) + } + ).and_return(retobj) shell_out_obj.send(method, cmd, options) end it "should not mutate the options hash when it adds language settings" do options = { environment: { "HOME" => "/Users/morty" } } - expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, { + expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with( + cmd, { environment: { "HOME" => "/Users/morty", "LC_ALL" => Chef::Config[:internal_locale], @@ -92,7 +95,8 @@ describe Chef::Mixin::ShellOut do "LANGUAGE" => Chef::Config[:internal_locale], env_path => sanitized_path, }, - }).and_return(retobj) + } + ).and_return(retobj) shell_out_obj.send(method, cmd, options) expect(options[:environment].key?("LC_ALL")).to be false end @@ -113,7 +117,8 @@ describe Chef::Mixin::ShellOut do it "should set environment language settings to the configured internal locale when they are not present" do options = { env: { "HOME" => "/Users/morty" } } - expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, { + expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with( + cmd, { env: { "HOME" => "/Users/morty", "LC_ALL" => Chef::Config[:internal_locale], @@ -121,13 +126,15 @@ describe Chef::Mixin::ShellOut do "LANGUAGE" => Chef::Config[:internal_locale], env_path => sanitized_path, }, - }).and_return(retobj) + } + ).and_return(retobj) shell_out_obj.send(method, cmd, options) end it "should not mutate the options hash when it adds language settings" do options = { env: { "HOME" => "/Users/morty" } } - expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, { + expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with( + cmd, { env: { "HOME" => "/Users/morty", "LC_ALL" => Chef::Config[:internal_locale], @@ -135,7 +142,8 @@ describe Chef::Mixin::ShellOut do "LANGUAGE" => Chef::Config[:internal_locale], env_path => sanitized_path, }, - }).and_return(retobj) + } + ).and_return(retobj) shell_out_obj.send(method, cmd, options) expect(options[:env].key?("LC_ALL")).to be false end @@ -144,7 +152,8 @@ describe Chef::Mixin::ShellOut do describe "and no env/environment option is present" do it "should set environment language settings to the configured internal locale" do options = { user: "morty" } - expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, { + expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with( + cmd, { user: "morty", environment: { "LC_ALL" => Chef::Config[:internal_locale], @@ -152,7 +161,8 @@ describe Chef::Mixin::ShellOut do "LANGUAGE" => Chef::Config[:internal_locale], env_path => sanitized_path, }, - }).and_return(retobj) + } + ).and_return(retobj) shell_out_obj.send(method, cmd, options) end end @@ -160,14 +170,16 @@ describe Chef::Mixin::ShellOut do describe "when the last argument is not a Hash" do it "should set environment language settings to the configured internal locale" do - expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with(cmd, { + expect(Chef::Mixin::ShellOut).to receive(:shell_out_command).with( + cmd, { environment: { "LC_ALL" => Chef::Config[:internal_locale], "LANG" => Chef::Config[:internal_locale], "LANGUAGE" => Chef::Config[:internal_locale], env_path => sanitized_path, }, - }).and_return(retobj) + } + ).and_return(retobj) shell_out_obj.send(method, cmd) end end diff --git a/spec/unit/provider/apt_repository_spec.rb b/spec/unit/provider/apt_repository_spec.rb index 11d505dad8..b3b37b844a 100644 --- a/spec/unit/provider/apt_repository_spec.rb +++ b/spec/unit/provider/apt_repository_spec.rb @@ -67,14 +67,18 @@ describe Chef::Provider::AptRepository do end let(:gpg_shell_out_success) do - double("shell_out", stdout: "pub 2048R/7BD9BF62 2011-08-19 nginx signing key <signing-key@nginx.com>", - exitstatus: 0, error?: false) + double( + "shell_out", stdout: "pub 2048R/7BD9BF62 2011-08-19 nginx signing key <signing-key@nginx.com>", + exitstatus: 0, error?: false + ) end let(:gpg_shell_out_failure) do - double("shell_out", stderr: "gpg: no valid OpenPGP data found.\n + double( + "shell_out", stderr: "gpg: no valid OpenPGP data found.\n gpg: processing message failed: eof", - exitstatus: 1, error?: true) + exitstatus: 1, error?: true + ) end let(:apt_fingerprints) do diff --git a/spec/unit/provider/dsc_resource_spec.rb b/spec/unit/provider/dsc_resource_spec.rb index cf6ab88eb4..3008c0c163 100644 --- a/spec/unit/provider/dsc_resource_spec.rb +++ b/spec/unit/provider/dsc_resource_spec.rb @@ -300,9 +300,11 @@ describe Chef::Provider::DscResource do before(:each) do allow(provider).to receive(:translate_type).and_return("my_properties") - provider.instance_variable_set(:@new_resource, double( - properties: "my_properties", resource: "my_resource", timeout: 123 - )) + provider.instance_variable_set( + :@new_resource, double( + properties: "my_properties", resource: "my_resource", timeout: 123 + ) + ) end context "when module_version is not given" do diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb index 9a6ae31397..831e2fafb6 100644 --- a/spec/unit/provider/git_spec.rb +++ b/spec/unit/provider/git_spec.rb @@ -364,10 +364,12 @@ describe Chef::Provider::Git do @resource.destination "/Application Support/with/space" @resource.ssh_wrapper "do_it_this_way.sh" expected_cmd = "git clone \"git://github.com/opscode/chef.git\" \"/Application Support/with/space\"" - expect(@provider).to receive(:shell_out!).with(expected_cmd, user: "deployNinja", + expect(@provider).to receive(:shell_out!).with( + expected_cmd, user: "deployNinja", log_tag: "git[web2.0 app]", environment: { "HOME" => "/home/deployNinja", - "GIT_SSH" => "do_it_this_way.sh" }) + "GIT_SSH" => "do_it_this_way.sh" } + ) @provider.clone end @@ -376,8 +378,10 @@ describe Chef::Provider::Git do expected_cmd = "git clone --depth 5 \"git://github.com/opscode/chef.git\" \"/my/deploy/dir\"" version_response = double("shell_out") allow(version_response).to receive(:stdout) { "git version 1.7.9" } - expect(@provider).to receive(:shell_out!).with("git --version", - log_tag: "git[web2.0 app]").and_return(version_response) + expect(@provider).to receive(:shell_out!).with( + "git --version", + log_tag: "git[web2.0 app]" + ).and_return(version_response) expect(@provider).to receive(:shell_out!).with(expected_cmd, log_tag: "git[web2.0 app]") @provider.clone end @@ -387,8 +391,10 @@ describe Chef::Provider::Git do expected_cmd = "git clone --depth 5 --no-single-branch \"git://github.com/opscode/chef.git\" \"/my/deploy/dir\"" version_response = double("shell_out") allow(version_response).to receive(:stdout) { "git version 1.7.10" } - expect(@provider).to receive(:shell_out!).with("git --version", - log_tag: "git[web2.0 app]").and_return(version_response) + expect(@provider).to receive(:shell_out!).with( + "git --version", + log_tag: "git[web2.0 app]" + ).and_return(version_response) expect(@provider).to receive(:shell_out!).with(expected_cmd, log_tag: "git[web2.0 app]") @provider.clone end @@ -401,18 +407,24 @@ describe Chef::Provider::Git do end it "runs a checkout command with default options" do - expect(@provider).to receive(:shell_out!).with("git branch -f deploy d35af14d41ae22b19da05d7d03a0bafc321b244c", cwd: "/my/deploy/dir", - log_tag: "git[web2.0 app]").ordered - expect(@provider).to receive(:shell_out!).with("git checkout deploy", cwd: "/my/deploy/dir", - log_tag: "git[web2.0 app]").ordered + expect(@provider).to receive(:shell_out!).with( + "git branch -f deploy d35af14d41ae22b19da05d7d03a0bafc321b244c", cwd: "/my/deploy/dir", + log_tag: "git[web2.0 app]" + ).ordered + expect(@provider).to receive(:shell_out!).with( + "git checkout deploy", cwd: "/my/deploy/dir", + log_tag: "git[web2.0 app]" + ).ordered @provider.checkout end it "runs an enable_submodule command" do @resource.enable_submodules true expected_cmd = "git submodule sync" - expect(@provider).to receive(:shell_out!).with(expected_cmd, cwd: "/my/deploy/dir", - log_tag: "git[web2.0 app]") + expect(@provider).to receive(:shell_out!).with( + expected_cmd, cwd: "/my/deploy/dir", + log_tag: "git[web2.0 app]" + ) expected_cmd = "git submodule update --init --recursive" expect(@provider).to receive(:shell_out!).with(expected_cmd, cwd: "/my/deploy/dir", log_tag: "git[web2.0 app]") @provider.enable_submodules @@ -441,20 +453,26 @@ describe Chef::Provider::Git do expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) expected_cmd1 = "git fetch --prune origin" - expect(@provider).to receive(:shell_out!).with(expected_cmd1, cwd: "/my/deploy/dir", + expect(@provider).to receive(:shell_out!).with( + expected_cmd1, cwd: "/my/deploy/dir", user: "whois", group: "thisis", log_tag: "git[web2.0 app]", - environment: { "HOME" => "/home/whois" }) + environment: { "HOME" => "/home/whois" } + ) expected_cmd2 = "git fetch origin --tags" - expect(@provider).to receive(:shell_out!).with(expected_cmd2, cwd: "/my/deploy/dir", + expect(@provider).to receive(:shell_out!).with( + expected_cmd2, cwd: "/my/deploy/dir", user: "whois", group: "thisis", log_tag: "git[web2.0 app]", - environment: { "HOME" => "/home/whois" }) + environment: { "HOME" => "/home/whois" } + ) expected_cmd3 = "git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" - expect(@provider).to receive(:shell_out!).with(expected_cmd3, cwd: "/my/deploy/dir", + expect(@provider).to receive(:shell_out!).with( + expected_cmd3, cwd: "/my/deploy/dir", user: "whois", group: "thisis", log_tag: "git[web2.0 app]", - environment: { "HOME" => "/home/whois" }) + environment: { "HOME" => "/home/whois" } + ) @provider.fetch_updates end @@ -488,14 +506,18 @@ describe Chef::Provider::Git do command_response = double("shell_out") allow(command_response).to receive(:exitstatus) { 1 } expected_command = "git config --get remote.#{@resource.remote}.url" - expect(@provider).to receive(:shell_out!).with(expected_command, + expect(@provider).to receive(:shell_out!).with( + expected_command, cwd: "/my/deploy/dir", log_tag: "git[web2.0 app]", - returns: [0, 1, 2]).and_return(command_response) + returns: [0, 1, 2] + ).and_return(command_response) add_remote_command = "git remote add #{@resource.remote} #{@resource.repository}" - expect(@provider).to receive(:shell_out!).with(add_remote_command, + expect(@provider).to receive(:shell_out!).with( + add_remote_command, cwd: "/my/deploy/dir", - log_tag: "git[web2.0 app]") + log_tag: "git[web2.0 app]" + ) @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository) end @@ -506,20 +528,24 @@ describe Chef::Provider::Git do command_response = double("shell_out") allow(command_response).to receive(:exitstatus) { 1 } expected_command = "git config --get remote.#{@resource.remote}.url" - expect(@provider).to receive(:shell_out!).with(expected_command, + expect(@provider).to receive(:shell_out!).with( + expected_command, cwd: "/my/deploy/dir", log_tag: "git[web2.0 app]", user: "whois", group: "thisis", environment: { "HOME" => "/home/whois" }, - returns: [0, 1, 2]).and_return(command_response) + returns: [0, 1, 2] + ).and_return(command_response) add_remote_command = "git remote add #{@resource.remote} #{@resource.repository}" - expect(@provider).to receive(:shell_out!).with(add_remote_command, + expect(@provider).to receive(:shell_out!).with( + add_remote_command, cwd: "/my/deploy/dir", log_tag: "git[web2.0 app]", user: "whois", group: "thisis", - environment: { "HOME" => "/home/whois" }) + environment: { "HOME" => "/home/whois" } + ) @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository) end @@ -528,14 +554,18 @@ describe Chef::Provider::Git do command_response = double("shell_out") allow(command_response).to receive(:exitstatus) { 1 } check_remote_command = "git config --get remote.#{@resource.remote}.url" - expect(@provider).to receive(:shell_out!).with(check_remote_command, + expect(@provider).to receive(:shell_out!).with( + check_remote_command, cwd: "/my/deploy/dir", log_tag: "git[web2.0 app]", - returns: [0, 1, 2]).and_return(command_response) + returns: [0, 1, 2] + ).and_return(command_response) expected_command = "git remote add #{@resource.remote} #{@resource.repository}" - expect(@provider).to receive(:shell_out!).with(expected_command, + expect(@provider).to receive(:shell_out!).with( + expected_command, cwd: "/my/deploy/dir", - log_tag: "git[web2.0 app]") + log_tag: "git[web2.0 app]" + ) @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository) end end @@ -546,14 +576,18 @@ describe Chef::Provider::Git do allow(command_response).to receive(:exitstatus) { 0 } allow(command_response).to receive(:stdout) { "some_other_url" } check_remote_command = "git config --get remote.#{@resource.remote}.url" - expect(@provider).to receive(:shell_out!).with(check_remote_command, + expect(@provider).to receive(:shell_out!).with( + check_remote_command, cwd: "/my/deploy/dir", log_tag: "git[web2.0 app]", - returns: [0, 1, 2]).and_return(command_response) + returns: [0, 1, 2] + ).and_return(command_response) expected_command = "git config --replace-all remote.#{@resource.remote}.url \"#{@resource.repository}\"" - expect(@provider).to receive(:shell_out!).with(expected_command, + expect(@provider).to receive(:shell_out!).with( + expected_command, cwd: "/my/deploy/dir", - log_tag: "git[web2.0 app]") + log_tag: "git[web2.0 app]" + ) @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository) end @@ -562,14 +596,18 @@ describe Chef::Provider::Git do allow(command_response).to receive(:exitstatus) { 0 } allow(command_response).to receive(:stdout) { @resource.repository } check_remote_command = "git config --get remote.#{@resource.remote}.url" - expect(@provider).to receive(:shell_out!).with(check_remote_command, + expect(@provider).to receive(:shell_out!).with( + check_remote_command, cwd: "/my/deploy/dir", log_tag: "git[web2.0 app]", - returns: [0, 1, 2]).and_return(command_response) + returns: [0, 1, 2] + ).and_return(command_response) unexpected_command = "git config --replace-all remote.#{@resource.remote}.url \"#{@resource.repository}\"" - expect(@provider).not_to receive(:shell_out!).with(unexpected_command, + expect(@provider).not_to receive(:shell_out!).with( + unexpected_command, cwd: "/my/deploy/dir", - log_tag: "git[web2.0 app]") + log_tag: "git[web2.0 app]" + ) @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository) end @@ -577,14 +615,18 @@ describe Chef::Provider::Git do command_response = double("shell_out") allow(command_response).to receive(:exitstatus) { 2 } check_remote_command = "git config --get remote.#{@resource.remote}.url" - expect(@provider).to receive(:shell_out!).with(check_remote_command, + expect(@provider).to receive(:shell_out!).with( + check_remote_command, cwd: "/my/deploy/dir", log_tag: "git[web2.0 app]", - returns: [0, 1, 2]).and_return(command_response) + returns: [0, 1, 2] + ).and_return(command_response) expected_command = "git config --replace-all remote.#{@resource.remote}.url \"#{@resource.repository}\"" - expect(@provider).to receive(:shell_out!).with(expected_command, + expect(@provider).to receive(:shell_out!).with( + expected_command, cwd: "/my/deploy/dir", - log_tag: "git[web2.0 app]") + log_tag: "git[web2.0 app]" + ) @provider.setup_remote_tracking_branches(@resource.remote, @resource.repository) end end diff --git a/spec/unit/provider/group_spec.rb b/spec/unit/provider/group_spec.rb index d7fdfb299c..2ccee2c450 100644 --- a/spec/unit/provider/group_spec.rb +++ b/spec/unit/provider/group_spec.rb @@ -36,10 +36,12 @@ describe Chef::Provider::User do @provider.current_resource = @current_resource - @pw_group = double("Struct::Group", + @pw_group = double( + "Struct::Group", name: "wheel", gid: 20, - mem: %w{root aj}) + mem: %w{root aj} + ) allow(Etc).to receive(:getgrnam).with("wheel").and_return(@pw_group) end diff --git a/spec/unit/provider/mount/windows_spec.rb b/spec/unit/provider/mount/windows_spec.rb index aeff294347..a275e6fd85 100644 --- a/spec/unit/provider/mount/windows_spec.rb +++ b/spec/unit/provider/mount/windows_spec.rb @@ -99,10 +99,12 @@ describe Chef::Provider::Mount::Windows do end it "should mount the filesystem if it is not mounted" do - expect(@vol).to receive(:add).with(remote: @new_resource.device, - username: @new_resource.username, - domainname: @new_resource.domain, - password: @new_resource.password) + expect(@vol).to receive(:add).with( + remote: @new_resource.device, + username: @new_resource.username, + domainname: @new_resource.domain, + password: @new_resource.password + ) @provider.mount_fs end diff --git a/spec/unit/provider/ohai_spec.rb b/spec/unit/provider/ohai_spec.rb index 11f11e3373..eb448bb79b 100644 --- a/spec/unit/provider/ohai_spec.rb +++ b/spec/unit/provider/ohai_spec.rb @@ -42,8 +42,10 @@ describe Chef::Provider::Ohai do }, } allow(mock_ohai).to receive(:all_plugins).and_return(true) - allow(mock_ohai).to receive(:data).and_return(mock_ohai[:data], - mock_ohai[:data2]) + allow(mock_ohai).to receive(:data).and_return( + mock_ohai[:data], + mock_ohai[:data2] + ) allow(Ohai::System).to receive(:new).and_return(mock_ohai) allow(Chef::Platform).to receive(:find_platform_and_version).and_return({ "platform" => @platform, "platform_version" => @platform_version }) diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb index 2fafb3bd0e..720d6cd62f 100644 --- a/spec/unit/provider/package/windows_spec.rb +++ b/spec/unit/provider/package/windows_spec.rb @@ -49,8 +49,10 @@ describe Chef::Provider::Package::Windows, :windows_only do shared_examples "a local file" do before(:each) do allow(Chef::Util::PathHelper).to receive(:validate_path) - allow(provider).to receive(:package_provider).and_return(double("package_provider", - installed_version: "1.0", package_version: "2.0")) + allow(provider).to receive(:package_provider).and_return(double( + "package_provider", + installed_version: "1.0", package_version: "2.0" + )) end it "creates a current resource with the name of the new resource" do diff --git a/spec/unit/provider/remote_directory_spec.rb b/spec/unit/provider/remote_directory_spec.rb index f9559d8827..1659280e2c 100644 --- a/spec/unit/provider/remote_directory_spec.rb +++ b/spec/unit/provider/remote_directory_spec.rb @@ -89,9 +89,11 @@ describe Chef::Provider::RemoteDirectory do it "configures access control on files in the directory" do @resource.cookbook "berlin_style_tasty_cupcakes" - cookbook_file = @provider.send(:cookbook_file_resource, + cookbook_file = @provider.send( + :cookbook_file_resource, "/target/destination/path.txt", - "relative/source/path.txt") + "relative/source/path.txt" + ) expect(cookbook_file.cookbook_name).to eq("berlin_style_tasty_cupcakes") expect(cookbook_file.source).to eq("remotedir_root/relative/source/path.txt") expect(cookbook_file.mode).to eq("0640") @@ -103,15 +105,19 @@ describe Chef::Provider::RemoteDirectory do it "respects sensitive flag" do @resource.cookbook "gondola_rides" @resource.sensitive true - cookbook_file = @provider.send(:cookbook_file_resource, + cookbook_file = @provider.send( + :cookbook_file_resource, "/target/destination/path.txt", - "relative/source/path.txt") + "relative/source/path.txt" + ) expect(cookbook_file.sensitive).to eq(true) @resource.sensitive false - cookbook_file = @provider.send(:cookbook_file_resource, + cookbook_file = @provider.send( + :cookbook_file_resource, "/target/destination/path.txt", - "relative/source/path.txt") + "relative/source/path.txt" + ) expect(cookbook_file.sensitive).to eq(false) end end diff --git a/spec/unit/provider/remote_file/http_spec.rb b/spec/unit/provider/remote_file/http_spec.rb index 8ece1a854b..53695b9727 100644 --- a/spec/unit/provider/remote_file/http_spec.rb +++ b/spec/unit/provider/remote_file/http_spec.rb @@ -105,9 +105,11 @@ describe Chef::Provider::RemoteFile::HTTP do context "and custom headers are provided" do before do - new_resource.headers("x-myapp-header" => "app-specific-header", - "if-none-match" => "custom-etag", - "if-modified-since" => "custom-last-modified") + new_resource.headers( + "x-myapp-header" => "app-specific-header", + "if-none-match" => "custom-etag", + "if-modified-since" => "custom-last-modified" + ) end it "preserves non-conflicting headers" do diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb index 5f89605b2e..af30429f8a 100644 --- a/spec/unit/provider/service/debian_service_spec.rb +++ b/spec/unit/provider/service/debian_service_spec.rb @@ -184,10 +184,12 @@ describe Chef::Provider::Service::Debian do let(:service_name) { @new_resource.service_name } context "when the service doesn't set a priority" do it "calls update-rc.d 'service_name' defaults" do - expect_commands(@provider, [ + expect_commands( + @provider, [ "/usr/sbin/update-rc.d -f #{service_name} remove", "/usr/sbin/update-rc.d #{service_name} defaults", - ]) + ] + ) @provider.enable_service end end @@ -198,10 +200,12 @@ describe Chef::Provider::Service::Debian do end it "calls update-rc.d 'service_name' defaults" do - expect_commands(@provider, [ + expect_commands( + @provider, [ "/usr/sbin/update-rc.d -f #{service_name} remove", "/usr/sbin/update-rc.d #{service_name} defaults 75 25", - ]) + ] + ) @provider.enable_service end end @@ -212,10 +216,12 @@ describe Chef::Provider::Service::Debian do end it "calls update-rc.d 'service_name' with those priorities" do - expect_commands(@provider, [ + expect_commands( + @provider, [ "/usr/sbin/update-rc.d -f #{service_name} remove", "/usr/sbin/update-rc.d #{service_name} start 20 2 . stop 55 3 . ", - ]) + ] + ) @provider.enable_service end end @@ -225,10 +231,12 @@ describe Chef::Provider::Service::Debian do let(:service_name) { @new_resource.service_name } context "when the service doesn't set a priority" do it "calls update-rc.d -f 'service_name' remove + stop with default priority" do - expect_commands(@provider, [ + expect_commands( + @provider, [ "/usr/sbin/update-rc.d -f #{service_name} remove", "/usr/sbin/update-rc.d -f #{service_name} stop 80 2 3 4 5 .", - ]) + ] + ) @provider.disable_service end end @@ -239,10 +247,12 @@ describe Chef::Provider::Service::Debian do end it "calls update-rc.d -f 'service_name' remove + stop with the specified priority" do - expect_commands(@provider, [ + expect_commands( + @provider, [ "/usr/sbin/update-rc.d -f #{service_name} remove", "/usr/sbin/update-rc.d -f #{service_name} stop #{100 - @new_resource.priority} 2 3 4 5 .", - ]) + ] + ) @provider.disable_service end end diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 420fd329f6..15f0d1f3ef 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -84,8 +84,10 @@ describe Chef::Provider::Service::Macosx do cmd = "launchctl list #{service_label}" allow(provider).to receive(:shell_out) .with(/(#{su_cmd} '#{cmd}'|#{cmd})/, default_env: false) - .and_return(double("Status", - stdout: launchctl_stdout, exitstatus: 0)) + .and_return(double( + "Status", + stdout: launchctl_stdout, exitstatus: 0 + )) allow(File).to receive(:exists?).and_return([true], []) allow(provider).to receive(:shell_out!) .with(/plutil -convert xml1 -o/, default_env: false) diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb index 860c0b1d6a..e0edc98f53 100644 --- a/spec/unit/provider/service/windows_spec.rb +++ b/spec/unit/provider/service/windows_spec.rb @@ -32,7 +32,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl 'C:\\opscode\\chef\\embedded\\bin\\ruby.exe C:\\opscode\\chef\\bin\\chef-windows-service' end let(:chef_service_config_info) do - double("Struct::ServiceConfigInfo", + double( + "Struct::ServiceConfigInfo", service_type: "own process", start_type: "auto start", error_control: "ignore", @@ -41,12 +42,14 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl tag_id: 0, dependencies: ["Winmgmt"], service_start_name: "LocalSystem", - display_name: "Chef Client Service") + display_name: "Chef Client Service" + ) end # Actual response from Win32::Service.services let(:chef_service_info) do - double("Struct::ServiceInfo", + double( + "Struct::ServiceInfo", service_name: chef_service_name, display_name: "Chef Client Service", service_type: "own process", @@ -72,7 +75,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl command: nil, num_actions: 0, actions: nil, - delayed_start: 1) + delayed_start: 1 + ) end let(:provider) do @@ -145,7 +149,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl before do allow(Win32::Service).to receive(:exists?).with(chef_service_name).and_return(true) allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return( - double("Struct::ServiceConfigInfo", + double( + "Struct::ServiceConfigInfo", service_type: "share process", start_type: "demand start", error_control: "normal", @@ -154,14 +159,16 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl tag_id: 0, dependencies: %w{NSI Tdx Afd}, service_start_name: 'NT Authority\\LocalService', - display_name: "DHCP Client") + display_name: "DHCP Client" + ) ) end context "startup_type is neither :automatic or :disabled" do before do allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return( - double("Struct::ServiceConfigInfo", + double( + "Struct::ServiceConfigInfo", service_type: "share process", start_type: "demand start", error_control: "normal", @@ -170,7 +177,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl tag_id: 0, dependencies: %w{NSI Tdx Afd}, service_start_name: 'NT Authority\\LocalService', - display_name: "DHCP Client") + display_name: "DHCP Client" + ) ) end diff --git a/spec/unit/provider/template/content_spec.rb b/spec/unit/provider/template/content_spec.rb index 60ff18c123..912c4ad5e3 100644 --- a/spec/unit/provider/template/content_spec.rb +++ b/spec/unit/provider/template/content_spec.rb @@ -29,7 +29,8 @@ describe Chef::Provider::Template::Content do end let(:new_resource) do - double("Chef::Resource::Template (new)", + double( + "Chef::Resource::Template (new)", cookbook_name: "openldap", recipe_name: "default", source_line: "/Users/lamont/solo/cookbooks/openldap/recipes/default.rb:2:in `from_file'", @@ -43,7 +44,8 @@ describe Chef::Provider::Template::Content do variables: {}, inline_helper_blocks: {}, inline_helper_modules: [], - helper_modules: []) + helper_modules: [] + ) end let(:rendered_file_locations) do @@ -129,7 +131,8 @@ describe Chef::Provider::Template::Content do describe "when using location helpers" do let(:new_resource) do - double("Chef::Resource::Template (new)", + double( + "Chef::Resource::Template (new)", cookbook_name: "openldap", recipe_name: "default", source_line: CHEF_SPEC_DATA + "/cookbooks/openldap/recipes/default.rb:2:in `from_file'", @@ -143,7 +146,8 @@ describe Chef::Provider::Template::Content do variables: {}, inline_helper_blocks: {}, inline_helper_modules: [], - helper_modules: []) + helper_modules: [] + ) end it "creates the template with the rendered content" do diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb index ddfe9e6c86..6179d94ded 100644 --- a/spec/unit/provider/user_spec.rb +++ b/spec/unit/provider/user_spec.rb @@ -166,8 +166,10 @@ describe Chef::Provider::User do @provider.action = "create" original_method = @provider.method(:require) expect(@provider).to receive(:require) { |*args| original_method.call(*args) } - passwd_info = Struct::PasswdEntry.new(sp_namp: "adm ", sp_pwdp: "$1$T0N0Q.lc$nyG6pFI3Dpqa5cxUz/57j0", sp_lstchg: 14861, sp_min: 0, sp_max: 99999, - sp_warn: 7, sp_inact: -1, sp_expire: -1, sp_flag: -1) + passwd_info = Struct::PasswdEntry.new( + sp_namp: "adm ", sp_pwdp: "$1$T0N0Q.lc$nyG6pFI3Dpqa5cxUz/57j0", sp_lstchg: 14861, sp_min: 0, sp_max: 99999, + sp_warn: 7, sp_inact: -1, sp_expire: -1, sp_flag: -1 + ) expect(Shadow::Passwd).to receive(:getspnam).with("notarealuser").and_return(passwd_info) @provider.load_current_resource @provider.define_resource_requirements diff --git a/spec/unit/resource/dsc_resource_spec.rb b/spec/unit/resource/dsc_resource_spec.rb index e0beb309ab..68b8702234 100644 --- a/spec/unit/resource/dsc_resource_spec.rb +++ b/spec/unit/resource/dsc_resource_spec.rb @@ -84,9 +84,11 @@ describe Chef::Resource::DscResource do context "when using DelayedEvaluators" do it "allows setting a dsc property with a property name of type Symbol" do - dsc_test_resource.property(dsc_test_property_name, Chef::DelayedEvaluator.new do - dsc_test_property_value - end) + dsc_test_resource.property( + dsc_test_property_name, Chef::DelayedEvaluator.new do + dsc_test_property_value + end + ) expect(dsc_test_resource.property(dsc_test_property_name)).to eq(dsc_test_property_value) expect(dsc_test_resource.properties[dsc_test_property_name]).to eq(dsc_test_property_value) end diff --git a/spec/unit/resource_collection/resource_set_spec.rb b/spec/unit/resource_collection/resource_set_spec.rb index 30a55cd3e1..63d164a2a2 100644 --- a/spec/unit/resource_collection/resource_set_spec.rb +++ b/spec/unit/resource_collection/resource_set_spec.rb @@ -91,16 +91,20 @@ describe Chef::ResourceCollection::ResourceSet do it "should find resources of multiple kinds (:zen_master => a, :zen_follower => b)" do collection.insert_as(zen_master) collection.insert_as(zen_follower) - check_by_names(collection.find(zen_master: [zen_master_name], zen_follower: [zen_follower_name]), - zen_master_name, zen_follower_name) + check_by_names( + collection.find(zen_master: [zen_master_name], zen_follower: [zen_follower_name]), + zen_master_name, zen_follower_name + ) end it "should find resources of multiple kinds (:zen_master => a, :zen_follower => b with custom names)" do collection.insert_as(zen_master, :zzz, "name1") collection.insert_as(zen_master2, :zzz, "name2") collection.insert_as(zen_follower, :yyy, "name3") - check_by_names(collection.find(zzz: %w{name1 name2}, yyy: ["name3"]), - zen_master_name, zen_follower_name, zen_master2_name) + check_by_names( + collection.find(zzz: %w{name1 name2}, yyy: ["name3"]), + zen_master_name, zen_follower_name, zen_master2_name + ) end it "should find a resource by string zen_master[a]" do @@ -117,8 +121,10 @@ describe Chef::ResourceCollection::ResourceSet do Chef::Config[:treat_deprecation_warnings_as_errors] = false collection.insert_as(zen_master) collection.insert_as(zen_master2) - check_by_names(collection.find("zen_master[#{zen_master_name},#{zen_master2_name}]"), - zen_master_name, zen_master2_name) + check_by_names( + collection.find("zen_master[#{zen_master_name},#{zen_master2_name}]"), + zen_master_name, zen_master2_name + ) end it "should find array names" do @@ -137,15 +143,19 @@ describe Chef::ResourceCollection::ResourceSet do Chef::Config[:treat_deprecation_warnings_as_errors] = false collection.insert_as(zen_master, :zzz, "name1") collection.insert_as(zen_master2, :zzz, "name2") - check_by_names(collection.find("zzz[name1,name2]"), - zen_master_name, zen_master2_name) + check_by_names( + collection.find("zzz[name1,name2]"), + zen_master_name, zen_master2_name + ) end it "should find resources of multiple types by strings of zen_master[a]" do collection.insert_as(zen_master) collection.insert_as(zen_follower) - check_by_names(collection.find("zen_master[#{zen_master_name}]", "zen_follower[#{zen_follower_name}]"), - zen_master_name, zen_follower_name) + check_by_names( + collection.find("zen_master[#{zen_master_name}]", "zen_follower[#{zen_follower_name}]"), + zen_master_name, zen_follower_name + ) end it "should find resources of multiple types by strings of zen_master[a] with custom names" do @@ -153,8 +163,10 @@ describe Chef::ResourceCollection::ResourceSet do collection.insert_as(zen_master, :zzz, "name1") collection.insert_as(zen_master2, :zzz, "name2") collection.insert_as(zen_follower, :yyy, "name3") - check_by_names(collection.find("zzz[name1,name2]", "yyy[name3]"), - zen_master_name, zen_follower_name, zen_master2_name) + check_by_names( + collection.find("zzz[name1,name2]", "yyy[name3]"), + zen_master_name, zen_follower_name, zen_master2_name + ) end it "should only keep the last copy when multiple instances of a Resource are inserted" do diff --git a/spec/unit/shell/shell_session_spec.rb b/spec/unit/shell/shell_session_spec.rb index c98989491d..2931cfa391 100644 --- a/spec/unit/shell/shell_session_spec.rb +++ b/spec/unit/shell/shell_session_spec.rb @@ -52,12 +52,14 @@ describe Shell::ClientSession do let(:node) { Chef::Node.build("foo") } let(:session) { Shell::ClientSession.instance } let(:client) do - double("Chef::Client.new", + double( + "Chef::Client.new", run_ohai: true, load_node: true, build_node: true, register: true, - sync_cookbooks: {}) + sync_cookbooks: {} + ) end before do @@ -88,12 +90,14 @@ describe Shell::SoloSession do let(:node) { Chef::Node.build("foo") } let(:session) { Shell::SoloSession.instance } let(:client) do - double("Chef::Client.new", + double( + "Chef::Client.new", run_ohai: true, load_node: true, build_node: true, register: true, - sync_cookbooks: {}) + sync_cookbooks: {} + ) end before do @@ -125,12 +129,14 @@ describe Shell::StandAloneSession do let(:events) { Chef::EventDispatch::Dispatcher.new } let(:session) { Shell::StandAloneSession.instance } let(:client) do - double("Chef::Client.new", + double( + "Chef::Client.new", run_ohai: true, load_node: true, build_node: true, register: true, - sync_cookbooks: {}) + sync_cookbooks: {} + ) end let(:recipe) { Chef::Recipe.new(nil, nil, run_context) } let(:run_context) { Chef::RunContext.new(node, {}, events) } @@ -234,12 +240,14 @@ describe Shell::SoloLegacySession do end it "passes the shell CLI args to the client" do - @client = double("Chef::Client.new", + @client = double( + "Chef::Client.new", run_ohai: true, load_node: true, build_node: true, register: true, - sync_cookbooks: {}) + sync_cookbooks: {} + ) expect(Chef::Client).to receive(:new).with(json_attribs, Chef::Config[:shell_config]).and_return(@client) @session.json_configuration = json_attribs @session.send(:rebuild_node) diff --git a/spec/unit/version_class_spec.rb b/spec/unit/version_class_spec.rb index c6848491ee..9c2150806f 100644 --- a/spec/unit/version_class_spec.rb +++ b/spec/unit/version_class_spec.rb @@ -161,8 +161,10 @@ describe Chef::Version do [ "1.2.2", :<, "1.2.1", false ], ].each do |spec| it "(#{spec.first(3).join(" ")}) should be #{spec[3]}" do - got = Chef::Version.new(spec[0]).send(spec[1], - Chef::Version.new(spec[2])) + got = Chef::Version.new(spec[0]).send( + spec[1], + Chef::Version.new(spec[2]) + ) expect(got).to eq(spec[3]) end end |
