diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-11 16:12:49 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-11 16:12:49 -0800 |
commit | 002ef48ab082fc8f0767fb37c5b94471a8fd0185 (patch) | |
tree | 865e2a2758c93967f926110f3e0eebe93d303f81 | |
parent | 6ca21c9ce206f1ada1c12a02afb46e3f1625a321 (diff) | |
parent | 37e02399a6e1dd281808a556f1420f8cf6e846fd (diff) | |
download | chef-002ef48ab082fc8f0767fb37c5b94471a8fd0185.tar.gz |
Merge pull request #4541 from chef/lcg/chefstyle-batch
fix a batch of cops
175 files changed, 510 insertions, 510 deletions
diff --git a/bin/chef-shell b/bin/chef-shell index 9cc7651c70..f4e8307dd1 100755 --- a/bin/chef-shell +++ b/bin/chef-shell @@ -33,5 +33,5 @@ require "chef/shell" # On Windows only, enable irb --noreadline because of input problems -- # See CHEF-3284. -IRB.conf[:USE_READLINE] = false if Chef::Platform::windows? +IRB.conf[:USE_READLINE] = false if Chef::Platform.windows? Shell.start diff --git a/chef-config/lib/chef-config/package_task.rb b/chef-config/lib/chef-config/package_task.rb index 6c7a4d6f55..4f75af9c6c 100644 --- a/chef-config/lib/chef-config/package_task.rb +++ b/chef-config/lib/chef-config/package_task.rb @@ -189,7 +189,7 @@ end IO.write(version_rb_path, contents) end - Dir[File.expand_path("*gemspec", root_path)].reverse.each do |gemspec_path| + Dir[File.expand_path("*gemspec", root_path)].reverse_each do |gemspec_path| gemspec = eval(IO.read(gemspec_path)) Gem::PackageTask.new(gemspec) do |task| task.package_dir = full_package_dir @@ -212,7 +212,7 @@ end task :ship => [:clobber_package, :gem] do sh("git tag #{version}") sh("git push #{git_remote} --tags") - Dir[File.expand_path("*.gem", full_package_dir)].reverse.each do |built_gem| + Dir[File.expand_path("*.gem", full_package_dir)].reverse_each do |built_gem| sh("gem push #{built_gem}") end end diff --git a/chef-windows.gemspec b/chef-windows.gemspec index 2ebcc1ecf1..a4f086cfaf 100644 --- a/chef-windows.gemspec +++ b/chef-windows.gemspec @@ -1,6 +1,6 @@ gemspec = eval(IO.read(File.expand_path("../chef.gemspec", __FILE__))) -gemspec.platform = Gem::Platform.new(["universal", "mingw32"]) +gemspec.platform = Gem::Platform.new(%w{universal mingw32}) gemspec.add_dependency "ffi", "~> 1.9" gemspec.add_dependency "win32-api", "~> 1.5.3" diff --git a/lib/chef/application/knife.rb b/lib/chef/application/knife.rb index 849a011ab3..4a39ba5ba1 100644 --- a/lib/chef/application/knife.rb +++ b/lib/chef/application/knife.rb @@ -167,7 +167,7 @@ class Chef::Application::Knife < Chef::Application if no_command_given? print_help_and_exit(1, NO_COMMAND_GIVEN) elsif no_subcommand_given? - if (want_help? || want_version?) + if want_help? || want_version? print_help_and_exit(0) else print_help_and_exit(2, NO_COMMAND_GIVEN) diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index b955dd31b8..a9f7664e4f 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -74,7 +74,7 @@ class Chef # Set the initial timeout to splay sleep time timeout = rand Chef::Config[:splay] - while running? do + while running? # Grab the service_action_mutex to make a chef-client run @service_action_mutex.synchronize do begin @@ -310,7 +310,7 @@ class Chef when /^(http|https):\/\// Chef::HTTP.new("").streaming_request(config[:config_file]) { |f| apply_config(f.path) } else - ::File::open(config[:config_file]) { |f| apply_config(f.path) } + ::File.open(config[:config_file]) { |f| apply_config(f.path) } end rescue Errno::ENOENT => error Chef::Log.warn("*****************************************") diff --git a/lib/chef/audit/audit_event_proxy.rb b/lib/chef/audit/audit_event_proxy.rb index 667e1db592..c4d67fa8f4 100644 --- a/lib/chef/audit/audit_event_proxy.rb +++ b/lib/chef/audit/audit_event_proxy.rb @@ -70,7 +70,7 @@ class Chef # If the innermost block has a resource instead of a string, don't include it in context describe_groups.unshift(group[:description]) if described_class.nil? group = group[:parent_example_group] - while !group.nil? + until group.nil? describe_groups.unshift(group[:description]) group = group[:parent_example_group] end diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index 7cf7d5f8d9..2d3330088f 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -327,7 +327,7 @@ class Chef relative << path[1] end relative = relative + file[:path].split("/") - file["url"] = ChefZero::RestBase::build_uri(request.base_uri, relative) + file["url"] = ChefZero::RestBase.build_uri(request.base_uri, relative) end end end @@ -610,7 +610,7 @@ class Chef private def use_memory_store?(path) - return path[0] == "sandboxes" || path[0] == "file_store" && path[1] == "checksums" || path == [ "environments", "_default" ] + return path[0] == "sandboxes" || path[0] == "file_store" && path[1] == "checksums" || path == %w{environments _default} end def write_cookbook(path, data, *options) @@ -704,7 +704,7 @@ class Chef # /acls/containers|nodes|.../x.json # /acls/organization.json - if path.length == 3 || path == [ "acls", "organization" ] + if path.length == 3 || path == %w{acls organization} path = path.dup path[-1] = "#{path[-1]}.json" end diff --git a/lib/chef/chef_fs/file_pattern.rb b/lib/chef/chef_fs/file_pattern.rb index 5beec6dfdd..a308a0fe2c 100644 --- a/lib/chef/chef_fs/file_pattern.rb +++ b/lib/chef/chef_fs/file_pattern.rb @@ -72,11 +72,11 @@ class Chef def could_match_children?(path) return false if path == "" # Empty string is not a path - argument_is_absolute = Chef::ChefFS::PathUtils::is_absolute?(path) + argument_is_absolute = Chef::ChefFS::PathUtils.is_absolute?(path) return false if is_absolute != argument_is_absolute path = path[1, path.length - 1] if argument_is_absolute - path_parts = Chef::ChefFS::PathUtils::split(path) + path_parts = Chef::ChefFS::PathUtils.split(path) # If the pattern is shorter than the path (or same size), children will be larger than the pattern, and will not match. return false if regexp_parts.length <= path_parts.length && !has_double_star # If the path doesn't match up to this point, children won't match either. @@ -111,8 +111,8 @@ class Chef # # This method assumes +could_match_children?(path)+ is +true+. def exact_child_name_under(path) - path = path[1, path.length - 1] if Chef::ChefFS::PathUtils::is_absolute?(path) - dirs_in_path = Chef::ChefFS::PathUtils::split(path).length + path = path[1, path.length - 1] if Chef::ChefFS::PathUtils.is_absolute?(path) + dirs_in_path = Chef::ChefFS::PathUtils.split(path).length return nil if exact_parts.length <= dirs_in_path return exact_parts[dirs_in_path] end @@ -124,8 +124,8 @@ class Chef # abc/x\\yz.exact_path == 'abc/xyz' def exact_path return nil if has_double_star || exact_parts.any? { |part| part.nil? } - result = Chef::ChefFS::PathUtils::join(*exact_parts) - is_absolute ? Chef::ChefFS::PathUtils::join("", result) : result + result = Chef::ChefFS::PathUtils.join(*exact_parts) + is_absolute ? Chef::ChefFS::PathUtils.join("", result) : result end # Returns the normalized version of the pattern, with / as the directory @@ -149,7 +149,7 @@ class Chef # abc/*/def.match?('abc/foo/def') == true # abc/*/def.match?('abc/foo') == false def match?(path) - argument_is_absolute = Chef::ChefFS::PathUtils::is_absolute?(path) + argument_is_absolute = Chef::ChefFS::PathUtils.is_absolute?(path) return false if is_absolute != argument_is_absolute path = path[1, path.length - 1] if argument_is_absolute !!regexp.match(path) @@ -184,7 +184,7 @@ class Chef def calculate if !@regexp - @is_absolute = Chef::ChefFS::PathUtils::is_absolute?(@pattern) + @is_absolute = Chef::ChefFS::PathUtils.is_absolute?(@pattern) full_regexp_parts = [] normalized_parts = [] @@ -192,8 +192,8 @@ class Chef @exact_parts = [] @has_double_star = false - Chef::ChefFS::PathUtils::split(pattern).each do |part| - regexp, exact, has_double_star = FilePattern::pattern_to_regexp(part) + Chef::ChefFS::PathUtils.split(pattern).each do |part| + regexp, exact, has_double_star = FilePattern.pattern_to_regexp(part) if has_double_star @has_double_star = true end @@ -232,14 +232,14 @@ class Chef end end - @regexp = Regexp.new("^#{full_regexp_parts.join(Chef::ChefFS::PathUtils::regexp_path_separator)}$") + @regexp = Regexp.new("^#{full_regexp_parts.join(Chef::ChefFS::PathUtils.regexp_path_separator)}$") @normalized_pattern = Chef::ChefFS::PathUtils.join(*normalized_parts) @normalized_pattern = Chef::ChefFS::PathUtils.join("", @normalized_pattern) if @is_absolute end end def self.pattern_special_characters - if Chef::ChefFS::windows? + if Chef::ChefFS.windows? @pattern_special_characters ||= /(\*\*|\*|\?|[\*\?\.\|\(\)\[\]\{\}\+\\\\\^\$])/ else # Unix also supports character regexes and backslashes diff --git a/lib/chef/chef_fs/file_system.rb b/lib/chef/chef_fs/file_system.rb index 5865dd4b7c..415556300c 100644 --- a/lib/chef/chef_fs/file_system.rb +++ b/lib/chef/chef_fs/file_system.rb @@ -72,7 +72,7 @@ class Chef # Otherwise, go through all children and find any matches elsif entry.dir? - results = Parallelizer::parallelize(entry.children) { |child| Chef::ChefFS::FileSystem.list(child, pattern) } + results = Parallelizer.parallelize(entry.children) { |child| Chef::ChefFS::FileSystem.list(child, pattern) } results.flatten(1).each(&block) end end @@ -101,7 +101,7 @@ class Chef end result = entry - Chef::ChefFS::PathUtils::split(path).each do |part| + Chef::ChefFS::PathUtils.split(path).each do |part| result = result.child(part) end result diff --git a/lib/chef/chef_fs/file_system/base_fs_object.rb b/lib/chef/chef_fs/file_system/base_fs_object.rb index 19f98f2bdd..cf1aed552f 100644 --- a/lib/chef/chef_fs/file_system/base_fs_object.rb +++ b/lib/chef/chef_fs/file_system/base_fs_object.rb @@ -27,7 +27,7 @@ class Chef @parent = parent @name = name if parent - @path = Chef::ChefFS::PathUtils::join(parent.path, name) + @path = Chef::ChefFS::PathUtils.join(parent.path, name) else if name != "" raise ArgumentError, "Name of root object must be empty string: was '#{name}' instead" @@ -149,7 +149,7 @@ class Chef if parent_path == "." name else - Chef::ChefFS::PathUtils::join(parent.path_for_printing, name) + Chef::ChefFS::PathUtils.join(parent.path_for_printing, name) end else name diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb index a6a062ab3c..3a08768baf 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb @@ -153,7 +153,7 @@ class Chef return [ !exists?, nil, nil ] end are_same = true - Chef::ChefFS::CommandLine::diff_entries(self, other, nil, :name_only).each do |type, old_entry, new_entry| + Chef::ChefFS::CommandLine.diff_entries(self, other, nil, :name_only).each do |type, old_entry, new_entry| if [ :directory_to_file, :file_to_directory, :deleted, :added, :modified ].include?(type) are_same = false end diff --git a/lib/chef/chef_fs/knife.rb b/lib/chef/chef_fs/knife.rb index 399bf1c434..1731e19ce1 100644 --- a/lib/chef/chef_fs/knife.rb +++ b/lib/chef/chef_fs/knife.rb @@ -131,7 +131,7 @@ class Chef ui.error("Current working directory is '#{@chef_fs_config.cwd}'.") exit(1) else - inferred_path = Chef::ChefFS::PathUtils::join(@chef_fs_config.base_path, arg) + inferred_path = Chef::ChefFS::PathUtils.join(@chef_fs_config.base_path, arg) end Chef::ChefFS::FilePattern.new(inferred_path) end diff --git a/lib/chef/chef_fs/parallelizer.rb b/lib/chef/chef_fs/parallelizer.rb index 5d05f41e94..ccbf7ad96e 100644 --- a/lib/chef/chef_fs/parallelizer.rb +++ b/lib/chef/chef_fs/parallelizer.rb @@ -87,7 +87,7 @@ class Chef def worker_loop begin - while !@stop_thread[Thread.current] + until @stop_thread[Thread.current] begin task = @tasks.pop task.call diff --git a/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb b/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb index 8df6a76e13..9d02bbab78 100644 --- a/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb +++ b/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb @@ -157,7 +157,7 @@ class Chef @parent_task_queue.push(method(:process_one)) stop_processing_input = false - while !@unconsumed_output.empty? + until @unconsumed_output.empty? output, index, input, type = @unconsumed_output.pop yield output, index, input, type if type == :exception && @options[:stop_on_exception] @@ -178,13 +178,13 @@ class Chef end end - while !finished? + until finished? # yield thread to others (for 1.8.7) if @unconsumed_output.empty? sleep(0.01) end - while !@unconsumed_output.empty? + until @unconsumed_output.empty? yield @unconsumed_output.pop end diff --git a/lib/chef/chef_fs/path_utils.rb b/lib/chef/chef_fs/path_utils.rb index 8ec5c3df78..7b2de5e3e0 100644 --- a/lib/chef/chef_fs/path_utils.rb +++ b/lib/chef/chef_fs/path_utils.rb @@ -57,7 +57,7 @@ class Chef end def self.regexp_path_separator - Chef::ChefFS::windows? ? '[\/\\\\]' : "/" + Chef::ChefFS.windows? ? '[\/\\\\]' : "/" end # Given a server path, determines if it is absolute. @@ -83,7 +83,7 @@ class Chef # File.dirname happens to return the path as its own dirname if you're # at the root (such as at \\foo\bar, C:\ or /) - until parent_path == path do + until parent_path == path # This can occur if a path such as "C:" is given. Ruby gives the parent as "C:." # for reasons only it knows. raise ArgumentError "Invalid path segment #{path}" if parent_path.length > path.length @@ -101,7 +101,7 @@ class Chef # Compares two path fragments according to the case-sentitivity of the host platform. def self.os_path_eq?(left, right) - Chef::ChefFS::windows? ? left.casecmp(right) == 0 : left == right + Chef::ChefFS.windows? ? left.casecmp(right) == 0 : left == right end # Given two general OS-dependent file paths, determines the relative path of the diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index 7cc4be9f89..62e17d4f3b 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -485,7 +485,7 @@ class Chef :description => { :kind_of => String }, :choice => { :kind_of => [ Array ], :default => [] }, :calculated => { :equal_to => [ true, false ], :default => false }, - :type => { :equal_to => [ "string", "array", "hash", "symbol", "boolean", "numeric" ], :default => "string" }, + :type => { :equal_to => %w{string array hash symbol boolean numeric}, :default => "string" }, :required => { :equal_to => [ "required", "recommended", "optional", true, false ], :default => "optional" }, :recipes => { :kind_of => [ Array ], :default => [] }, :default => { :kind_of => [ String, Array, Hash, Symbol, Numeric, TrueClass, FalseClass ] }, diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb index aa6d756737..b286dad4e2 100644 --- a/lib/chef/environment.rb +++ b/lib/chef/environment.rb @@ -170,7 +170,7 @@ class Chef unless params[:cookbook_version].nil? params[:cookbook_version].each do |index, cookbook_constraint_spec| - unless (cookbook_constraint_spec.nil? || cookbook_constraint_spec.size == 0) + unless cookbook_constraint_spec.nil? || cookbook_constraint_spec.size == 0 valid = valid && update_cookbook_constraint_from_param(index, cookbook_constraint_spec) end end diff --git a/lib/chef/event_loggers/windows_eventlog.rb b/lib/chef/event_loggers/windows_eventlog.rb index 1d16b66087..84aa906dc7 100644 --- a/lib/chef/event_loggers/windows_eventlog.rb +++ b/lib/chef/event_loggers/windows_eventlog.rb @@ -38,11 +38,11 @@ class Chef SOURCE = "Chef" def self.available? - return Chef::Platform::windows? + return Chef::Platform.windows? end def initialize - @eventlog = ::Win32::EventLog::open("Application") + @eventlog = ::Win32::EventLog.open("Application") end def run_start(version) @@ -83,7 +83,7 @@ class Chef [@run_status.run_id, @run_status.elapsed_time.to_s] else - ["UNKNOWN", "UNKNOWN"] + %w{UNKNOWN UNKNOWN} end @eventlog.report_event( diff --git a/lib/chef/http/authenticator.rb b/lib/chef/http/authenticator.rb index 970c19cd62..b5e28cf54d 100644 --- a/lib/chef/http/authenticator.rb +++ b/lib/chef/http/authenticator.rb @@ -73,9 +73,9 @@ class Chef end def load_signing_key(key_file, raw_key = nil) - if (!!key_file) + if !!key_file @raw_key = IO.read(key_file).strip - elsif (!!raw_key) + elsif !!raw_key @raw_key = raw_key.strip else return nil diff --git a/lib/chef/http/http_request.rb b/lib/chef/http/http_request.rb index a1ef9b9ee2..6cd7dda251 100644 --- a/lib/chef/http/http_request.rb +++ b/lib/chef/http/http_request.rb @@ -169,7 +169,7 @@ class Chef raise ArgumentError, "You must provide :GET, :PUT, :POST, :DELETE or :HEAD as the method" end - @http_request.body = request_body if (request_body && @http_request.request_body_permitted?) + @http_request.body = request_body if request_body && @http_request.request_body_permitted? # Optionally handle HTTP Basic Authentication if url.user user = URI.unescape(url.user) diff --git a/lib/chef/http/ssl_policies.rb b/lib/chef/http/ssl_policies.rb index f49fca02f6..51db01c232 100644 --- a/lib/chef/http/ssl_policies.rb +++ b/lib/chef/http/ssl_policies.rb @@ -86,8 +86,8 @@ class Chef end def set_client_credentials - if (config[:ssl_client_cert] || config[:ssl_client_key]) - unless (config[:ssl_client_cert] && config[:ssl_client_key]) + if config[:ssl_client_cert] || config[:ssl_client_key] + unless config[:ssl_client_cert] && config[:ssl_client_key] raise Chef::Exceptions::ConfigurationError, "You must configure ssl_client_cert and ssl_client_key together" end unless ::File.exists?(config[:ssl_client_cert]) diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 7982c0f927..971257bf9e 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -220,7 +220,7 @@ class Chef :long => "--node-ssl-verify-mode [peer|none]", :description => "Whether or not to verify the SSL cert for all HTTPS requests.", :proc => Proc.new { |v| - valid_values = ["none", "peer"] + valid_values = %w{none peer} unless valid_values.include?(v) raise "Invalid value '#{v}' for --node-ssl-verify-mode. Valid values are: #{valid_values.join(", ")}" end diff --git a/lib/chef/knife/cookbook_metadata.rb b/lib/chef/knife/cookbook_metadata.rb index b13ab18a57..bfae9d8814 100644 --- a/lib/chef/knife/cookbook_metadata.rb +++ b/lib/chef/knife/cookbook_metadata.rb @@ -61,7 +61,7 @@ class Chef end def generate_metadata(cookbook) - Array(config[:cookbook_path]).reverse.each do |path| + Array(config[:cookbook_path]).reverse_each do |path| file = File.expand_path(File.join(path, cookbook, "metadata.rb")) if File.exists?(file) generate_metadata_from_file(cookbook, file) diff --git a/lib/chef/knife/cookbook_test.rb b/lib/chef/knife/cookbook_test.rb index ee42facf5e..1a5c9df74e 100644 --- a/lib/chef/knife/cookbook_test.rb +++ b/lib/chef/knife/cookbook_test.rb @@ -69,7 +69,7 @@ class Chef def test_cookbook(cookbook) ui.info("Running syntax check on #{cookbook}") - Array(config[:cookbook_path]).reverse.each do |path| + Array(config[:cookbook_path]).reverse_each do |path| syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cookbook, path) test_ruby(syntax_checker) test_templates(syntax_checker) diff --git a/lib/chef/knife/core/generic_presenter.rb b/lib/chef/knife/core/generic_presenter.rb index bbe0249b3d..61069cff48 100644 --- a/lib/chef/knife/core/generic_presenter.rb +++ b/lib/chef/knife/core/generic_presenter.rb @@ -81,7 +81,7 @@ class Chef Chef::JSONCompat.to_json_pretty(data) when :yaml require "yaml" - YAML::dump(data) + YAML.dump(data) when :pp require "stringio" # If you were looking for some attribute and there is only one match diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb index ee92127898..d6c21ee411 100644 --- a/lib/chef/knife/core/ui.rb +++ b/lib/chef/knife/core/ui.rb @@ -173,7 +173,7 @@ class Chef def edit_data(data, parse_output = true) output = Chef::JSONCompat.to_json_pretty(data) - if (!config[:disable_editing]) + if !config[:disable_editing] Tempfile.open([ "knife-edit-", ".json" ]) do |tf| tf.sync = true tf.puts output diff --git a/lib/chef/knife/edit.rb b/lib/chef/knife/edit.rb index 00358b2d09..cd2c1c741b 100644 --- a/lib/chef/knife/edit.rb +++ b/lib/chef/knife/edit.rb @@ -50,7 +50,7 @@ class Chef end def edit_text(text, extension) - if (!config[:disable_editing]) + if !config[:disable_editing] Tempfile.open([ "knife-edit-", extension ]) do |file| # Write the text to a temporary file file.write(text) diff --git a/lib/chef/knife/status.rb b/lib/chef/knife/status.rb index 7bf9abbd1b..e7a7165faa 100644 --- a/lib/chef/knife/status.rb +++ b/lib/chef/knife/status.rb @@ -97,7 +97,7 @@ class Chef end output(all_nodes.sort { |n1, n2| - if (config[:sort_reverse] || Chef::Config[:knife][:sort_status_reverse]) + if config[:sort_reverse] || Chef::Config[:knife][:sort_status_reverse] (n2["ohai_time"] or 0) <=> (n1["ohai_time"] or 0) else (n1["ohai_time"] or 0) <=> (n2["ohai_time"] or 0) diff --git a/lib/chef/log.rb b/lib/chef/log.rb index 8d4fed56aa..bfb5829be6 100644 --- a/lib/chef/log.rb +++ b/lib/chef/log.rb @@ -21,7 +21,7 @@ require "logger" require "chef/monologger" require "chef/exceptions" require "mixlib/log" -require "chef/log/syslog" unless (RUBY_PLATFORM =~ /mswin|mingw|windows/) +require "chef/log/syslog" unless RUBY_PLATFORM =~ /mswin|mingw|windows/ require "chef/log/winevt" class Chef diff --git a/lib/chef/log/winevt.rb b/lib/chef/log/winevt.rb index 04e24e3913..8411ad8af0 100644 --- a/lib/chef/log/winevt.rb +++ b/lib/chef/log/winevt.rb @@ -43,7 +43,7 @@ class Chef attr_accessor :sync, :formatter, :level def initialize(eventlog = nil) - @eventlog = eventlog || ::Win32::EventLog::open("Application") + @eventlog = eventlog || ::Win32::EventLog.open("Application") end def close diff --git a/lib/chef/mixin/command/unix.rb b/lib/chef/mixin/command/unix.rb index d930ee33e6..bfd507979f 100644 --- a/lib/chef/mixin/command/unix.rb +++ b/lib/chef/mixin/command/unix.rb @@ -109,7 +109,7 @@ class Chef Marshal.dump(e, ps.last) ps.last.flush end - ps.last.close unless (ps.last.closed?) + ps.last.close unless ps.last.closed? exit! } ensure diff --git a/lib/chef/mixin/windows_architecture_helper.rb b/lib/chef/mixin/windows_architecture_helper.rb index 5f8d3e3729..c55f92b362 100644 --- a/lib/chef/mixin/windows_architecture_helper.rb +++ b/lib/chef/mixin/windows_architecture_helper.rb @@ -98,13 +98,13 @@ class Chef end def disable_wow64_file_redirection( node ) - if ( ( node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows?) + if ( node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows? Chef::ReservedNames::Win32::System.wow64_disable_wow64_fs_redirection end end def restore_wow64_file_redirection( node, original_redirection_state ) - if ( (node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows?) + if (node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows? Chef::ReservedNames::Win32::System.wow64_revert_wow64_fs_redirection(original_redirection_state) end end diff --git a/lib/chef/mixin/windows_env_helper.rb b/lib/chef/mixin/windows_env_helper.rb index b2e08edc08..65b4b33cf0 100644 --- a/lib/chef/mixin/windows_env_helper.rb +++ b/lib/chef/mixin/windows_env_helper.rb @@ -43,12 +43,12 @@ class Chef flags = SMTO_BLOCK | SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG # for why two calls, see: # http://stackoverflow.com/questions/4968373/why-doesnt-sendmessagetimeout-update-the-environment-variables - if ( SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string("Environment").address, flags, 5000, nil) == 0 ) + 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( + if SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, FFI::MemoryPointer.from_string( utf8_to_wide("Environment") - ).address, flags, 5000, nil) == 0 ) + ).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 71bed2bb74..7880adb202 100644 --- a/lib/chef/monkey_patches/webrick-utils.rb +++ b/lib/chef/monkey_patches/webrick-utils.rb @@ -24,7 +24,7 @@ module WEBrick unless port 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 @@ -36,7 +36,7 @@ module WEBrick logger.debug("TCPServer.new(#{ai[3]}, #{port})") if logger sock = TCPServer.new(ai[3], port) port = sock.addr[1] if port == 0 - Utils::set_close_on_exec(sock) + Utils.set_close_on_exec(sock) sockets << sock rescue => ex logger.warn("TCPServer Error: #{ex}") if logger diff --git a/lib/chef/monologger.rb b/lib/chef/monologger.rb index 77ca54d7eb..49f744e314 100644 --- a/lib/chef/monologger.rb +++ b/lib/chef/monologger.rb @@ -64,7 +64,7 @@ class MonoLogger < Logger private def open_logfile(filename) - if (FileTest.exist?(filename)) + if FileTest.exist?(filename) open(filename, (File::WRONLY | File::APPEND)) else create_logfile(filename) diff --git a/lib/chef/node.rb b/lib/chef/node.rb index 1f72c86a8b..0471fe1171 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -685,7 +685,7 @@ class Chef def data_for_save data = for_json - ["automatic", "default", "normal", "override"].each do |level| + %w{automatic default normal override}.each do |level| whitelist_config_option = "#{level}_attribute_whitelist".to_sym whitelist = Chef::Config[whitelist_config_option] unless whitelist.nil? # nil => save everything diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb index f8a8dabb46..600da540e5 100644 --- a/lib/chef/provider/git.rb +++ b/lib/chef/provider/git.rb @@ -126,7 +126,7 @@ class Chef end def add_remotes - if (@new_resource.additional_remotes.length > 0) + if @new_resource.additional_remotes.length > 0 @new_resource.additional_remotes.each_pair do |remote_name, remote_url| converge_by("add remote #{remote_name} from #{remote_url}") do Chef::Log.info "#{@new_resource} adding git remote #{remote_name} = #{remote_url}" diff --git a/lib/chef/provider/group/groupmod.rb b/lib/chef/provider/group/groupmod.rb index 379d00e286..295d3b3425 100644 --- a/lib/chef/provider/group/groupmod.rb +++ b/lib/chef/provider/group/groupmod.rb @@ -25,7 +25,7 @@ class Chef def load_current_resource super - [ "group", "user" ].each do |binary| + %w{group user}.each do |binary| raise Chef::Exceptions::Group, "Could not find binary /usr/sbin/#{binary} for #{@new_resource}" unless ::File.exists?("/usr/sbin/#{binary}") end end diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb index f8b8684a1b..635a4f6ea2 100644 --- a/lib/chef/provider/mount/mount.rb +++ b/lib/chef/provider/mount/mount.rb @@ -42,7 +42,7 @@ class Chef def mountable? # only check for existence of non-remote devices - if (device_should_exist? && !::File.exists?(device_real) ) + if device_should_exist? && !::File.exists?(device_real) raise Chef::Exceptions::Mount, "Device #{@new_resource.device} does not exist" elsif( @new_resource.mount_point != "none" && !::File.exists?(@new_resource.mount_point) ) raise Chef::Exceptions::Mount, "Mount point #{@new_resource.mount_point} does not exist" diff --git a/lib/chef/provider/osx_profile.rb b/lib/chef/provider/osx_profile.rb index e93d29bd1f..1bef30d53b 100644 --- a/lib/chef/provider/osx_profile.rb +++ b/lib/chef/provider/osx_profile.rb @@ -234,7 +234,7 @@ class Chef end def read_plist(xml_file) - Plist::parse_xml(xml_file) + Plist.parse_xml(xml_file) end def profile_installed? diff --git a/lib/chef/provider/package/pacman.rb b/lib/chef/provider/package/pacman.rb index 22fa9c2307..fe321037bd 100644 --- a/lib/chef/provider/package/pacman.rb +++ b/lib/chef/provider/package/pacman.rb @@ -52,7 +52,7 @@ class Chef def candidate_version return @candidate_version if @candidate_version - repos = ["extra", "core", "community"] + repos = %w{extra core community} if(::File.exists?("/etc/pacman.conf")) pacman = ::File.read("/etc/pacman.conf") diff --git a/lib/chef/provider/package/rpm.rb b/lib/chef/provider/package/rpm.rb index c72c9559c8..777cc6d209 100644 --- a/lib/chef/provider/package/rpm.rb +++ b/lib/chef/provider/package/rpm.rb @@ -25,7 +25,7 @@ class Chef class Package class Rpm < Chef::Provider::Package - provides :rpm_package, os: [ "linux", "aix" ] + provides :rpm_package, os: %w{linux aix} include Chef::Mixin::GetSourceFromPackage diff --git a/lib/chef/provider/package/windows.rb b/lib/chef/provider/package/windows.rb index dc22de7ad5..f0c60db29e 100644 --- a/lib/chef/provider/package/windows.rb +++ b/lib/chef/provider/package/windows.rb @@ -105,7 +105,7 @@ class Chef return :nsis end - if (io.tell() < filesize) + if io.tell() < filesize io.seek(io.tell() - overlap) end end diff --git a/lib/chef/provider/package/windows/registry_uninstall_entry.rb b/lib/chef/provider/package/windows/registry_uninstall_entry.rb index 952a0f76b9..3fa00b6081 100644 --- a/lib/chef/provider/package/windows/registry_uninstall_entry.rb +++ b/lib/chef/provider/package/windows/registry_uninstall_entry.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require "win32/registry" if (RUBY_PLATFORM =~ /mswin|mingw32|windows/) +require "win32/registry" if RUBY_PLATFORM =~ /mswin|mingw32|windows/ class Chef class Provider diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb index aeecf3869e..858b430abe 100644 --- a/lib/chef/provider/package/yum.rb +++ b/lib/chef/provider/package/yum.rb @@ -128,7 +128,7 @@ class Chef y_pos_max = y.length - 1 y_comp = nil - while (x_pos <= x_pos_max and y_pos <= y_pos_max) + while x_pos <= x_pos_max and y_pos <= y_pos_max # first we skip over anything non alphanumeric while (x_pos <= x_pos_max) and (isalnum(x[x_pos]) == false) x_pos += 1 # +1 over pos_max if end of string diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb index 390330aed2..d716e44342 100644 --- a/lib/chef/provider/service.rb +++ b/lib/chef/provider/service.rb @@ -50,10 +50,10 @@ class Chef # XXX?: the #nil? check below will likely fail if this is a cloned resource or if # we just run multiple actions. def load_new_resource_state - if ( @new_resource.enabled.nil? ) + if @new_resource.enabled.nil? @new_resource.enabled(@current_resource.enabled) end - if ( @new_resource.running.nil? ) + if @new_resource.running.nil? @new_resource.running(@current_resource.running) end end diff --git a/lib/chef/provider/service/aixinit.rb b/lib/chef/provider/service/aixinit.rb index 6b451d649a..0234673474 100644 --- a/lib/chef/provider/service/aixinit.rb +++ b/lib/chef/provider/service/aixinit.rb @@ -97,7 +97,7 @@ class Chef priority = {} files.each do |file| - if (RC_D_SCRIPT_NAME =~ file) + if RC_D_SCRIPT_NAME =~ file priority[2] = [($1 == "S" ? :start : :stop), ($2.empty? ? "" : $2.to_i)] if $1 == "S" is_enabled = true diff --git a/lib/chef/provider/service/freebsd.rb b/lib/chef/provider/service/freebsd.rb index 7e475fc878..76d8c1d17b 100644 --- a/lib/chef/provider/service/freebsd.rb +++ b/lib/chef/provider/service/freebsd.rb @@ -27,7 +27,7 @@ class Chef attr_reader :enabled_state_found - provides :service, os: [ "freebsd", "netbsd" ] + provides :service, os: %w{freebsd netbsd} include Chef::Mixin::ShellOut diff --git a/lib/chef/provider/template.rb b/lib/chef/provider/template.rb index e12d465353..3c46a6eb7d 100644 --- a/lib/chef/provider/template.rb +++ b/lib/chef/provider/template.rb @@ -45,7 +45,7 @@ class Chef super requirements.assert(:create, :create_if_missing) do |a| - a.assertion { ::File::exists?(content.template_location) } + a.assertion { ::File.exists?(content.template_location) } a.failure_message "Template source #{content.template_location} could not be found." a.whyrun "Template source #{content.template_location} does not exist. Assuming it would have been created." a.block_action! diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index e81a01c764..8c282b0d7e 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -130,7 +130,7 @@ user password using shadow hash.") # Calling shell_out directly since we want to give an input stream shadow_hash_xml = convert_binary_plist_to_xml(shadow_hash_binary.string) - shadow_hash = Plist::parse_xml(shadow_hash_xml) + shadow_hash = Plist.parse_xml(shadow_hash_xml) if shadow_hash["SALTED-SHA512"] # Convert the shadow value from Base64 encoding to hex before consuming them @@ -212,7 +212,7 @@ user password using shadow hash.") # def dscl_set_uid # XXX: mutates the new resource - new_resource.uid(get_free_uid) if (new_resource.uid.nil? || new_resource.uid == "") + new_resource.uid(get_free_uid) if new_resource.uid.nil? || new_resource.uid == "" if uid_used?(new_resource.uid) raise(Chef::Exceptions::RequestedUIDUnavailable, "uid #{new_resource.uid} is already in use") @@ -410,7 +410,7 @@ user password using shadow hash.") salt = OpenSSL::Random.random_bytes(32) iterations = new_resource.iterations # Use the default if not specified by the user - entropy = OpenSSL::PKCS5::pbkdf2_hmac( + entropy = OpenSSL::PKCS5.pbkdf2_hmac( new_resource.password, salt, iterations, @@ -589,7 +589,7 @@ user password using shadow hash.") begin user_plist_file = "#{USER_PLIST_DIRECTORY}/#{new_resource.username}.plist" user_plist_info = run_plutil("convert xml1 -o - #{user_plist_file}") - user_info = Plist::parse_xml(user_plist_info) + user_info = Plist.parse_xml(user_plist_info) rescue Chef::Exceptions::PlistUtilCommandFailed end @@ -695,7 +695,7 @@ user password using shadow hash.") def salted_sha512_pbkdf2_password_match? salt = convert_to_binary(current_resource.salt) - OpenSSL::PKCS5::pbkdf2_hmac( + OpenSSL::PKCS5.pbkdf2_hmac( new_resource.password, salt, current_resource.iterations, diff --git a/lib/chef/provider/user/useradd.rb b/lib/chef/provider/user/useradd.rb index aabd4b5f68..e2f5b5897a 100644 --- a/lib/chef/provider/user/useradd.rb +++ b/lib/chef/provider/user/useradd.rb @@ -75,7 +75,7 @@ class Chef unless passwd_s.exitstatus == 0 raise_lock_error = false - if ["redhat", "centos"].include?(node[:platform]) + if %w{redhat centos}.include?(node[:platform]) passwd_version_check = shell_out!("rpm -q passwd") passwd_version = passwd_version_check.stdout.chomp diff --git a/lib/chef/resource/rpm_package.rb b/lib/chef/resource/rpm_package.rb index fdb5913db5..c93dfecaf5 100644 --- a/lib/chef/resource/rpm_package.rb +++ b/lib/chef/resource/rpm_package.rb @@ -23,7 +23,7 @@ class Chef class Resource class RpmPackage < Chef::Resource::Package resource_name :rpm_package - provides :rpm_package, os: [ "linux", "aix" ] + provides :rpm_package, os: %w{linux aix} property :allow_downgrade, [ true, false ], default: false, desired_state: false diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb index f2dd772d82..1f749b93c0 100644 --- a/lib/chef/resource/yum_package.rb +++ b/lib/chef/resource/yum_package.rb @@ -23,7 +23,7 @@ class Chef class Resource class YumPackage < Chef::Resource::Package resource_name :yum_package - provides :package, os: "linux", platform_family: [ "rhel", "fedora" ] + provides :package, os: "linux", platform_family: %w{rhel fedora} # Install a specific arch property :arch, [ String, Array ] diff --git a/lib/chef/role.rb b/lib/chef/role.rb index a5a33c28cf..bac054143e 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -70,7 +70,7 @@ class Chef end def run_list(*args) - if (args.length > 0) + if args.length > 0 @env_run_lists["_default"].reset!(args) end @env_run_lists["_default"] @@ -93,7 +93,7 @@ class Chef # Per environment run lists def env_run_lists(env_run_lists = nil) - if (!env_run_lists.nil?) + if !env_run_lists.nil? unless env_run_lists.key?("_default") msg = "_default key is required in env_run_lists.\n" msg << "(env_run_lists: #{env_run_lists.inspect})" @@ -108,7 +108,7 @@ class Chef alias :env_run_list :env_run_lists def env_run_lists_add(env_run_lists = nil) - if (!env_run_lists.nil?) + if !env_run_lists.nil? env_run_lists.each { |k, v| @env_run_lists[k] = Chef::RunList.new(*Array(v)) } end @env_run_lists diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb index ecb16c190d..cb3338d3de 100644 --- a/lib/chef/run_context.rb +++ b/lib/chef/run_context.rb @@ -541,12 +541,12 @@ ERROR_MESSAGE # 5. raise an exception on any second call. # 6. ? def request_reboot(reboot_info) - Chef::Log::info "Changing reboot status from #{self.reboot_info.inspect} to #{reboot_info.inspect}" + Chef::Log.info "Changing reboot status from #{self.reboot_info.inspect} to #{reboot_info.inspect}" @reboot_info = reboot_info end def cancel_reboot - Chef::Log::info "Changing reboot status from #{reboot_info.inspect} to {}" + Chef::Log.info "Changing reboot status from #{reboot_info.inspect} to {}" @reboot_info = {} end diff --git a/lib/chef/run_list/run_list_item.rb b/lib/chef/run_list/run_list_item.rb index 15e11b206e..0abfb106ff 100644 --- a/lib/chef/run_list/run_list_item.rb +++ b/lib/chef/run_list/run_list_item.rb @@ -32,7 +32,7 @@ class Chef assert_hash_is_valid_run_list_item!(item) @type = (item["type"] || item[:type]).to_sym @name = item["name"] || item[:name] - if (item.has_key?("version") || item.has_key?(:version)) + if item.has_key?("version") || item.has_key?(:version) @version = item["version"] || item[:version] end when String diff --git a/lib/chef/run_lock.rb b/lib/chef/run_lock.rb index be83494048..08d58fd164 100644 --- a/lib/chef/run_lock.rb +++ b/lib/chef/run_lock.rb @@ -63,7 +63,7 @@ class Chef def acquire if timeout_given? begin - Timeout::timeout(time_to_wait) do + Timeout.timeout(time_to_wait) do unless test if time_to_wait > 0.0 wait diff --git a/lib/chef/util/dsc/local_configuration_manager.rb b/lib/chef/util/dsc/local_configuration_manager.rb index 3b4eaa92a9..741c6a5898 100644 --- a/lib/chef/util/dsc/local_configuration_manager.rb +++ b/lib/chef/util/dsc/local_configuration_manager.rb @@ -81,11 +81,11 @@ EOH def log_what_if_exception(what_if_exception_output) if whatif_not_supported?(what_if_exception_output) # LCM returns an error if any of the resources do not support the opptional What-If - Chef::Log::warn("Received error while testing configuration due to resource not supporting 'WhatIf'") + Chef::Log.warn("Received error while testing configuration due to resource not supporting 'WhatIf'") elsif dsc_module_import_failure?(what_if_exception_output) - Chef::Log::warn("Received error while testing configuration due to a module for an imported resource possibly not being fully installed:\n#{what_if_exception_output.gsub(/\s+/, ' ')}") + Chef::Log.warn("Received error while testing configuration due to a module for an imported resource possibly not being fully installed:\n#{what_if_exception_output.gsub(/\s+/, ' ')}") else - Chef::Log::warn("Received error while testing configuration:\n#{what_if_exception_output.gsub(/\s+/, ' ')}") + Chef::Log.warn("Received error while testing configuration:\n#{what_if_exception_output.gsub(/\s+/, ' ')}") end end @@ -102,9 +102,9 @@ EOH def configuration_update_required?(what_if_output) Chef::Log.debug("DSC: DSC returned the following '-whatif' output from test operation:\n#{what_if_output}") begin - Parser::parse(what_if_output) + Parser.parse(what_if_output) rescue Chef::Exceptions::LCMParser => e - Chef::Log::warn("Could not parse LCM output: #{e}") + Chef::Log.warn("Could not parse LCM output: #{e}") [Chef::Util::DSC::ResourceInfo.new("Unknown DSC Resources", true, ["Unknown changes because LCM output was not parsable."])] end end diff --git a/lib/chef/util/windows/net_group.rb b/lib/chef/util/windows/net_group.rb index 6dd6e39f2b..0a351fbc6f 100644 --- a/lib/chef/util/windows/net_group.rb +++ b/lib/chef/util/windows/net_group.rb @@ -36,7 +36,7 @@ class Chef::Util::Windows::NetGroup def local_get_members begin - Chef::ReservedNames::Win32::NetUser::net_local_group_get_members(nil, groupname) + Chef::ReservedNames::Win32::NetUser.net_local_group_get_members(nil, groupname) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end @@ -44,7 +44,7 @@ class Chef::Util::Windows::NetGroup def local_add begin - Chef::ReservedNames::Win32::NetUser::net_local_group_add(nil, groupname) + Chef::ReservedNames::Win32::NetUser.net_local_group_add(nil, groupname) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end @@ -52,7 +52,7 @@ class Chef::Util::Windows::NetGroup def local_set_members(members) begin - Chef::ReservedNames::Win32::NetUser::net_local_group_set_members(nil, groupname, members) + Chef::ReservedNames::Win32::NetUser.net_local_group_set_members(nil, groupname, members) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end @@ -60,7 +60,7 @@ class Chef::Util::Windows::NetGroup def local_add_members(members) begin - Chef::ReservedNames::Win32::NetUser::net_local_group_add_members(nil, groupname, members) + Chef::ReservedNames::Win32::NetUser.net_local_group_add_members(nil, groupname, members) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end @@ -68,7 +68,7 @@ class Chef::Util::Windows::NetGroup def local_delete_members(members) begin - Chef::ReservedNames::Win32::NetUser::net_local_group_del_members(nil, groupname, members) + Chef::ReservedNames::Win32::NetUser.net_local_group_del_members(nil, groupname, members) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end @@ -76,7 +76,7 @@ class Chef::Util::Windows::NetGroup def local_delete begin - Chef::ReservedNames::Win32::NetUser::net_local_group_del(nil, groupname) + Chef::ReservedNames::Win32::NetUser.net_local_group_del(nil, groupname) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end diff --git a/lib/chef/util/windows/net_user.rb b/lib/chef/util/windows/net_user.rb index f2edeacf17..b0a779e44a 100644 --- a/lib/chef/util/windows/net_user.rb +++ b/lib/chef/util/windows/net_user.rb @@ -79,7 +79,7 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows def set_info(args) begin - rc = NetUser::net_user_set_info_l3(nil, @username, transform_usri3(args)) + rc = NetUser.net_user_set_info_l3(nil, @username, transform_usri3(args)) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end @@ -96,7 +96,7 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows #XXX for an extra painful alternative, see: http://support.microsoft.com/kb/180548 def validate_credentials(passwd) begin - token = Security::logon_user(@username, nil, passwd, + token = Security.logon_user(@username, nil, passwd, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT) return true rescue Chef::Exceptions::Win32APIError @@ -106,7 +106,7 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows def get_info begin - ui3 = NetUser::net_user_get_info_l3(nil, @username) + ui3 = NetUser.net_user_get_info_l3(nil, @username) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end @@ -115,8 +115,8 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows def add(args) transformed_args = transform_usri3(args) - NetUser::net_user_add_l3(nil, transformed_args) - NetUser::net_local_group_add_member(nil, "Users", args[:name]) + NetUser.net_user_add_l3(nil, transformed_args) + NetUser.net_local_group_add_member(nil, "Users", args[:name]) end def user_modify(&proc) @@ -137,7 +137,7 @@ class Chef::Util::Windows::NetUser < Chef::Util::Windows def delete begin - NetUser::net_user_del(nil, @username) + NetUser.net_user_del(nil, @username) rescue Chef::Exceptions::Win32APIError => e raise ArgumentError, e end diff --git a/lib/chef/win32/eventlog.rb b/lib/chef/win32/eventlog.rb index 0562f0c10e..723b43fc44 100644 --- a/lib/chef/win32/eventlog.rb +++ b/lib/chef/win32/eventlog.rb @@ -16,7 +16,7 @@ # limitations under the License. # -if Chef::Platform::windows? and not Chef::Platform::windows_server_2003? +if Chef::Platform.windows? and not Chef::Platform.windows_server_2003? if !defined? Chef::Win32EventLogLoaded if defined? Windows::Constants [:INFINITE, :WAIT_FAILED, :FORMAT_MESSAGE_IGNORE_INSERTS, :ERROR_INSUFFICIENT_BUFFER].each do |c| diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb index 19b17b7d7c..94a771c3ba 100644 --- a/lib/chef/win32/file.rb +++ b/lib/chef/win32/file.rb @@ -76,7 +76,7 @@ class Chef is_symlink = false path = encode_path(file_name) if ::File.exists?(file_name) - if ((GetFileAttributesW(path) & FILE_ATTRIBUTE_REPARSE_POINT) > 0) + if (GetFileAttributesW(path) & FILE_ATTRIBUTE_REPARSE_POINT) > 0 file_search_handle(file_name) do |handle, find_data| if find_data[:dw_reserved_0] == IO_REPARSE_TAG_SYMLINK is_symlink = true diff --git a/lib/chef/win32/security/sid.rb b/lib/chef/win32/security/sid.rb index 4d2d252dd3..665cba8880 100644 --- a/lib/chef/win32/security/sid.rb +++ b/lib/chef/win32/security/sid.rb @@ -46,7 +46,7 @@ class Chef end def self.from_string_sid(string_sid) - Chef::ReservedNames::Win32::Security::convert_string_sid_to_sid(string_sid) + Chef::ReservedNames::Win32::Security.convert_string_sid_to_sid(string_sid) end def ==(other) @@ -275,10 +275,10 @@ class Chef status = ERROR_MORE_DATA - while(status == ERROR_MORE_DATA) do + while(status == ERROR_MORE_DATA) status = NetUserEnum(servername, level, filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle) - if (status == NERR_Success || status == ERROR_MORE_DATA) + if status == NERR_Success || status == ERROR_MORE_DATA entriesread.read_long.times.collect do |i| user_info = USER_INFO_3.new(bufptr.read_pointer + i * USER_INFO_3.size) # Check if the account is the Administrator account diff --git a/lib/chef/win32/security/token.rb b/lib/chef/win32/security/token.rb index f8b6790d44..38ef03b33c 100644 --- a/lib/chef/win32/security/token.rb +++ b/lib/chef/win32/security/token.rb @@ -55,7 +55,7 @@ class Chef def adjust_privileges(privileges_struct) if privileges_struct[:PrivilegeCount] > 0 - Chef::ReservedNames::Win32::Security::adjust_token_privileges(self, privileges_struct) + Chef::ReservedNames::Win32::Security.adjust_token_privileges(self, privileges_struct) end end diff --git a/lib/chef/win32/unicode.rb b/lib/chef/win32/unicode.rb index b0fcf6492d..d531463be0 100644 --- a/lib/chef/win32/unicode.rb +++ b/lib/chef/win32/unicode.rb @@ -38,7 +38,7 @@ module FFI # Find the length of the string length = 0 last_char = nil - while last_char != "\000\000" do + while last_char != "\000\000" length += 1 last_char = self.get_bytes(0, length * 2)[-2..-1] end diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb index a18211b8c6..85a2744645 100644 --- a/lib/chef/win32/version.rb +++ b/lib/chef/win32/version.rb @@ -76,7 +76,7 @@ class Chef # Obtain sku information for the purpose of identifying # datacenter, cluster, and core skus, the latter 2 only # exist in releases after Windows Server 2003 - if ! Chef::Platform::windows_server_2003? + if ! Chef::Platform.windows_server_2003? @sku = get_product_info(@major_version, @minor_version, @sp_major_version, @sp_minor_version) else # The get_product_info API is not supported on Win2k3, diff --git a/spec/functional/event_loggers/windows_eventlog_spec.rb b/spec/functional/event_loggers/windows_eventlog_spec.rb index 031405f718..69874ef677 100644 --- a/spec/functional/event_loggers/windows_eventlog_spec.rb +++ b/spec/functional/event_loggers/windows_eventlog_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" require "securerandom" require "chef/event_loggers/windows_eventlog" -if Chef::Platform.windows? and not Chef::Platform::windows_server_2003? +if Chef::Platform.windows? and not Chef::Platform.windows_server_2003? require "win32/eventlog" include Win32 end diff --git a/spec/functional/resource/cookbook_file_spec.rb b/spec/functional/resource/cookbook_file_spec.rb index cd678e5e13..d127413c73 100644 --- a/spec/functional/resource/cookbook_file_spec.rb +++ b/spec/functional/resource/cookbook_file_spec.rb @@ -70,7 +70,7 @@ describe Chef::Resource::CookbookFile do let(:path) { File.join(windows_non_temp_dir, make_tmpname(file_base)) } before do - FileUtils::mkdir_p(windows_non_temp_dir) if Chef::Platform.windows? + FileUtils.mkdir_p(windows_non_temp_dir) if Chef::Platform.windows? end after do diff --git a/spec/functional/resource/cron_spec.rb b/spec/functional/resource/cron_spec.rb index 2906715f7a..3380eccb0d 100644 --- a/spec/functional/resource/cron_spec.rb +++ b/spec/functional/resource/cron_spec.rb @@ -104,7 +104,7 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do end end - exclude_solaris = ["solaris", "opensolaris", "solaris2", "omnios"].include?(ohai[:platform]) + exclude_solaris = %w{solaris opensolaris solaris2 omnios}.include?(ohai[:platform]) describe "create action with various attributes", :external => exclude_solaris do def create_and_validate_with_attribute(resource, attribute, value) if ohai[:platform] == "aix" @@ -117,7 +117,7 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do end def cron_attribute_should_exists(cron_name, attribute, value) - return if ["aix", "solaris"].include?(ohai[:platform]) + return if %w{aix solaris}.include?(ohai[:platform]) # Test if the attribute exists on newly created cron cron_should_exists(cron_name, "") expect(shell_out("crontab -l -u #{new_resource.user} | grep \"#{attribute.upcase}=#{value}\"").exitstatus).to eq(0) diff --git a/spec/functional/resource/deploy_revision_spec.rb b/spec/functional/resource/deploy_revision_spec.rb index 4772067949..ee98832180 100644 --- a/spec/functional/resource/deploy_revision_spec.rb +++ b/spec/functional/resource/deploy_revision_spec.rb @@ -45,7 +45,7 @@ describe Chef::Resource::DeployRevision, :unix_only => true do before(:all) do @ohai = Ohai::System.new - @ohai.all_plugins(["platform", "os"]) + @ohai.all_plugins(%w{platform os}) end let(:node) do diff --git a/spec/functional/resource/dsc_script_spec.rb b/spec/functional/resource/dsc_script_spec.rb index 5f264fdca1..921638bcf8 100644 --- a/spec/functional/resource/dsc_script_spec.rb +++ b/spec/functional/resource/dsc_script_spec.rb @@ -280,7 +280,7 @@ EOH end let(:test_registry_data) { test_registry_data1 } - let(:dsc_parameterized_env_param_value) { "val" + Random::rand.to_s } + let(:dsc_parameterized_env_param_value) { "val" + Random.rand.to_s } it "should have a default value of nil for the configuration_data attribute" do expect(dsc_test_resource.configuration_data).to eql(nil) diff --git a/spec/functional/resource/execute_spec.rb b/spec/functional/resource/execute_spec.rb index 1ceeb70590..dd0f68bebb 100644 --- a/spec/functional/resource/execute_spec.rb +++ b/spec/functional/resource/execute_spec.rb @@ -145,7 +145,7 @@ describe Chef::Resource::Execute do # Timeout::timeout should be longer than resource.timeout, but less than the resource.command ruby sleep timer, # so we fail if we finish on resource.command instead of resource.timeout, but raise CommandTimeout anyway (#2175). it "times out when a timeout is set on the resource" do - Timeout::timeout(30) do + Timeout.timeout(30) do resource.command %{ruby -e 'sleep 300'} resource.timeout 0.1 expect { resource.run_action(:run) }.to raise_error(Mixlib::ShellOut::CommandTimeout) diff --git a/spec/functional/resource/git_spec.rb b/spec/functional/resource/git_spec.rb index 7174a99451..92c2dd2074 100644 --- a/spec/functional/resource/git_spec.rb +++ b/spec/functional/resource/git_spec.rb @@ -92,7 +92,7 @@ E before(:all) do @ohai = Ohai::System.new - @ohai.all_plugins(["platform", "os"]) + @ohai.all_plugins(%w{platform os}) end context "working with pathes with special characters" do diff --git a/spec/functional/resource/group_spec.rb b/spec/functional/resource/group_spec.rb index 063b5d9004..521c8e887d 100644 --- a/spec/functional/resource/group_spec.rb +++ b/spec/functional/resource/group_spec.rb @@ -31,8 +31,8 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte def group_should_exist(group) case ohai[:platform_family] when "debian", "fedora", "rhel", "suse", "gentoo", "slackware", "arch" - expect { Etc::getgrnam(group) }.not_to raise_error - expect(group).to eq(Etc::getgrnam(group).name) + expect { Etc.getgrnam(group) }.not_to raise_error + expect(group).to eq(Etc.getgrnam(group).name) when "windows" expect { Chef::Util::Windows::NetGroup.new(group).local_get_members }.not_to raise_error end @@ -49,21 +49,21 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte members.shift # Get rid of GroupMembership: string members.include?(user) else - Etc::getgrnam(group_name).mem.include?(user) + Etc.getgrnam(group_name).mem.include?(user) end end def group_should_not_exist(group) case ohai[:platform_family] when "debian", "fedora", "rhel", "suse", "gentoo", "slackware", "arch" - expect { Etc::getgrnam(group) }.to raise_error(ArgumentError, "can't find group for #{group}") + expect { Etc.getgrnam(group) }.to raise_error(ArgumentError, "can't find group for #{group}") when "windows" expect { Chef::Util::Windows::NetGroup.new(group).local_get_members }.to raise_error(ArgumentError, /The group name could not be found./) end end def compare_gid(resource, gid) - return resource.gid == Etc::getgrnam(resource.name).gid if unix? + return resource.gid == Etc.getgrnam(resource.name).gid if unix? end def sid_string_from_user(user) @@ -361,7 +361,7 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" } end describe "group modify action", :not_supported_on_solaris do - let(:spec_members) { ["mnou5sdz", "htulrvwq", "x4c3g1lu"] } + let(:spec_members) { %w{mnou5sdz htulrvwq x4c3g1lu} } let(:included_members) { [spec_members[0], spec_members[1]] } let(:excluded_members) { [spec_members[2]] } let(:tested_action) { :modify } @@ -389,7 +389,7 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" } end describe "group manage action", :not_supported_on_solaris do - let(:spec_members) { ["mnou5sdz", "htulrvwq", "x4c3g1lu"] } + let(:spec_members) { %w{mnou5sdz htulrvwq x4c3g1lu} } let(:included_members) { [spec_members[0], spec_members[1]] } let(:excluded_members) { [spec_members[2]] } let(:tested_action) { :manage } @@ -443,7 +443,7 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" } end describe "when append is not set" do - let(:included_members) { ["gordon", "eric"] } + let(:included_members) { %w{gordon eric} } before(:each) do group_resource.append(false) diff --git a/spec/functional/resource/ifconfig_spec.rb b/spec/functional/resource/ifconfig_spec.rb index cac6d96981..a30dcff641 100644 --- a/spec/functional/resource/ifconfig_spec.rb +++ b/spec/functional/resource/ifconfig_spec.rb @@ -20,7 +20,7 @@ require "functional/resource/base" require "chef/mixin/shell_out" # run this test only for following platforms. -include_flag = !(["ubuntu", "centos", "aix"].include?(ohai[:platform])) +include_flag = !(%w{ubuntu centos aix}.include?(ohai[:platform])) describe Chef::Resource::Ifconfig, :requires_root, :skip_travis, :external => include_flag do # This test does not work in travis because there is no eth0 diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb index 9b9d696979..f55b9fca1e 100644 --- a/spec/functional/resource/link_spec.rb +++ b/spec/functional/resource/link_spec.rb @@ -38,11 +38,11 @@ describe Chef::Resource::Link do end before do - FileUtils::mkdir_p(test_file_dir) + FileUtils.mkdir_p(test_file_dir) end after do - FileUtils::rm_rf(test_file_dir) + FileUtils.rm_rf(test_file_dir) end let(:to) do @@ -559,7 +559,7 @@ describe Chef::Resource::Link do end context "and the link does not yet exist" do it "links to the target file" do - skip("OS X/FreeBSD/AIX symlink? and readlink working on hard links to symlinks") if (os_x? or freebsd? or aix?) + skip("OS X/FreeBSD/AIX symlink? and readlink working on hard links to symlinks") if os_x? or freebsd? or aix? resource.run_action(:create) expect(File.exists?(target_file)).to be_truthy # OS X gets angry about this sort of link. Bug in OS X, IMO. @@ -578,7 +578,7 @@ describe Chef::Resource::Link do end context "and the link does not yet exist" do it "links to the target file" do - skip("OS X/FreeBSD/AIX fails to create hardlinks to broken symlinks") if (os_x? or freebsd? or aix?) + skip("OS X/FreeBSD/AIX fails to create hardlinks to broken symlinks") if os_x? or freebsd? or aix? resource.run_action(:create) # Windows and Unix have different definitions of exists? here, and that's OK. if windows? diff --git a/spec/functional/resource/mount_spec.rb b/spec/functional/resource/mount_spec.rb index 7f088891e3..c756b0d3d4 100644 --- a/spec/functional/resource/mount_spec.rb +++ b/spec/functional/resource/mount_spec.rb @@ -22,7 +22,7 @@ require "chef/mixin/shell_out" require "tmpdir" # run this test only for following platforms. -include_flag = !(["ubuntu", "centos", "aix", "solaris2"].include?(ohai[:platform])) +include_flag = !(%w{ubuntu centos aix solaris2}.include?(ohai[:platform])) describe Chef::Resource::Mount, :requires_root, :skip_travis, :external => include_flag do # Disabled in travis because it refuses to let us mount a ramdisk. /dev/ramX does not diff --git a/spec/functional/resource/package_spec.rb b/spec/functional/resource/package_spec.rb index 36b106bf1c..1ab247a154 100644 --- a/spec/functional/resource/package_spec.rb +++ b/spec/functional/resource/package_spec.rb @@ -66,7 +66,7 @@ module AptServer @apt_server_thread = Thread.new do run_apt_server end - until tcp_test_port("localhost", 9000) do + until tcp_test_port("localhost", 9000) if @apt_server_thread.alive? sleep 1 else diff --git a/spec/functional/resource/registry_spec.rb b/spec/functional/resource/registry_spec.rb index 6cf8524883..e64b6697c5 100644 --- a/spec/functional/resource/registry_spec.rb +++ b/spec/functional/resource/registry_spec.rb @@ -78,7 +78,7 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do hive_class.create(key_parent + '\Opscode', Win32::Registry::KEY_WRITE | flag) hive_class.open(key_parent + '\Opscode', Win32::Registry::KEY_ALL_ACCESS | flag) do |reg| reg["Color", Win32::Registry::REG_SZ] = "Orange" - reg.write("Opscode", Win32::Registry::REG_MULTI_SZ, ["Seattle", "Washington"]) + reg.write("Opscode", Win32::Registry::REG_MULTI_SZ, %w{Seattle Washington}) reg["AKA", Win32::Registry::REG_SZ] = "OC" end hive_class.create(key_parent + '\ReportKey', Win32::Registry::KEY_WRITE | flag) @@ -179,12 +179,12 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do it "creates subkey if parent exists" do @new_resource.key(reg_child + '\OpscodeTest') - @new_resource.values([{ :name => "Chef", :type => :multi_string, :data => ["OpscodeOrange", "Rules"] }]) + @new_resource.values([{ :name => "Chef", :type => :multi_string, :data => %w{OpscodeOrange Rules} }]) @new_resource.recursive(false) @new_resource.run_action(:create) expect(@registry.key_exists?(reg_child + '\OpscodeTest')).to eq(true) - expect(@registry.value_exists?(reg_child + '\OpscodeTest', { :name => "Chef", :type => :multi_string, :data => ["OpscodeOrange", "Rules"] })).to eq(true) + expect(@registry.value_exists?(reg_child + '\OpscodeTest', { :name => "Chef", :type => :multi_string, :data => %w{OpscodeOrange Rules} })).to eq(true) end it "gives error if action create and parent does not exist and recursive is set to false" do @@ -312,12 +312,12 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do it "creates subkey if parent exists" do @new_resource.key(reg_child + '\Pyrovile') - @new_resource.values([{ :name => "Chef", :type => :multi_string, :data => ["OpscodeOrange", "Rules"] }]) + @new_resource.values([{ :name => "Chef", :type => :multi_string, :data => %w{OpscodeOrange Rules} }]) @new_resource.recursive(false) @new_resource.run_action(:create_if_missing) expect(@registry.key_exists?(reg_child + '\Pyrovile')).to eq(true) - expect(@registry.value_exists?(reg_child + '\Pyrovile', { :name => "Chef", :type => :multi_string, :data => ["OpscodeOrange", "Rules"] })).to eq(true) + expect(@registry.value_exists?(reg_child + '\Pyrovile', { :name => "Chef", :type => :multi_string, :data => %w{OpscodeOrange Rules} })).to eq(true) end it "gives error if action create and parent does not exist and recursive is set to false" do @@ -409,7 +409,7 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do expect(@registry.data_exists?(reg_parent + '\Opscode', { :name => "Color", :type => :string, :data => "Orange" })).to eq(true) @new_resource.key(reg_parent + '\Opscode') - @new_resource.values([{ :name => "LooksLike", :type => :multi_string, :data => ["SeattleGrey", "OCOrange"] }]) + @new_resource.values([{ :name => "LooksLike", :type => :multi_string, :data => %w{SeattleGrey OCOrange} }]) @new_resource.recursive(false) @new_resource.run_action(:delete) @@ -418,18 +418,18 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do it "deletes only specified values under a key path" do @new_resource.key(reg_parent + '\Opscode') - @new_resource.values([{ :name => "Opscode", :type => :multi_string, :data => ["Seattle", "Washington"] }, { :name => "AKA", :type => :string, :data => "OC" }]) + @new_resource.values([{ :name => "Opscode", :type => :multi_string, :data => %w{Seattle Washington} }, { :name => "AKA", :type => :string, :data => "OC" }]) @new_resource.recursive(false) @new_resource.run_action(:delete) expect(@registry.data_exists?(reg_parent + '\Opscode', { :name => "Color", :type => :string, :data => "Orange" })).to eq(true) expect(@registry.value_exists?(reg_parent + '\Opscode', { :name => "AKA", :type => :string, :data => "OC" })).to eq(false) - expect(@registry.value_exists?(reg_parent + '\Opscode', { :name => "Opscode", :type => :multi_string, :data => ["Seattle", "Washington"] })).to eq(false) + expect(@registry.value_exists?(reg_parent + '\Opscode', { :name => "Opscode", :type => :multi_string, :data => %w{Seattle Washington} })).to eq(false) end it "it deletes the values with the same name irrespective of it type and data" do @new_resource.key(reg_parent + '\Opscode') - @new_resource.values([{ :name => "Color", :type => :multi_string, :data => ["Black", "Orange"] }]) + @new_resource.values([{ :name => "Color", :type => :multi_string, :data => %w{Black Orange} }]) @new_resource.recursive(false) @new_resource.run_action(:delete) diff --git a/spec/functional/resource/rpm_spec.rb b/spec/functional/resource/rpm_spec.rb index 5e68c70d39..ce9332e4ed 100644 --- a/spec/functional/resource/rpm_spec.rb +++ b/spec/functional/resource/rpm_spec.rb @@ -21,7 +21,7 @@ require "functional/resource/base" require "chef/mixin/shell_out" # run this test only for following platforms. -exclude_test = !["aix", "centos", "redhat", "suse"].include?(ohai[:platform]) +exclude_test = !%w{aix centos redhat suse}.include?(ohai[:platform]) describe Chef::Resource::RpmPackage, :requires_root, :external => exclude_test do include Chef::Mixin::ShellOut diff --git a/spec/functional/resource/template_spec.rb b/spec/functional/resource/template_spec.rb index da8cbfc68a..f270043f2c 100644 --- a/spec/functional/resource/template_spec.rb +++ b/spec/functional/resource/template_spec.rb @@ -191,7 +191,7 @@ describe Chef::Resource::Template do describe "when template source contains windows style line endings" do include_context "diff disabled" - ["all", "some", "no"].each do |test_case| + %w{all some no}.each do |test_case| context "for #{test_case} lines" do let(:resource) do r = create_resource diff --git a/spec/functional/resource/user/dscl_spec.rb b/spec/functional/resource/user/dscl_spec.rb index 37f6047dfc..243471c3f7 100644 --- a/spec/functional/resource/user/dscl_spec.rb +++ b/spec/functional/resource/user/dscl_spec.rb @@ -168,7 +168,7 @@ c5adbbac718b7eb99463a7b679571e0f\ end describe "when a user is member of some groups" do - let(:groups) { ["staff", "operator"] } + let(:groups) { %w{staff operator} } before do existing_resource = user_resource.dup diff --git a/spec/functional/resource/windows_service_spec.rb b/spec/functional/resource/windows_service_spec.rb index 80faaece34..9353e92c24 100644 --- a/spec/functional/resource/windows_service_spec.rb +++ b/spec/functional/resource/windows_service_spec.rb @@ -68,7 +68,7 @@ describe Chef::Resource::WindowsService, :windows_only, :system_windows_service_ # the service executable has to be outside the current user's home # directory in order for the logon user to execute it. - FileUtils::copy_file(test_service[:service_file_path], global_service_file_path) + FileUtils.copy_file(test_service[:service_file_path], global_service_file_path) # if you don't make the file executable by the service user, you'll get # the not-very-helpful "service did not respond fast enough" error. diff --git a/spec/functional/run_lock_spec.rb b/spec/functional/run_lock_spec.rb index d380b19dc8..b0e52471db 100644 --- a/spec/functional/run_lock_spec.rb +++ b/spec/functional/run_lock_spec.rb @@ -47,7 +47,7 @@ describe Chef::RunLock do WAIT_ON_LOCK_TIME = 1.0 def wait_on_lock - Timeout::timeout(WAIT_ON_LOCK_TIME) do + Timeout.timeout(WAIT_ON_LOCK_TIME) do until File.exist?(lockfile) sleep 0.1 end @@ -346,7 +346,7 @@ describe Chef::RunLock do background_block.call if background_block # Wait until it gets there - Timeout::timeout(CLIENT_PROCESS_TIMEOUT) do + Timeout.timeout(CLIENT_PROCESS_TIMEOUT) do until @last_event == "after #{to_event}" got_event, time = read_from_process.gets.split("@") example.log_event("#{name}.last_event got #{got_event}") @@ -373,7 +373,7 @@ describe Chef::RunLock do def wait_for_exit example.log_event("#{name}.wait_for_exit (pid #{pid})") - Timeout::timeout(CLIENT_PROCESS_TIMEOUT) do + Timeout.timeout(CLIENT_PROCESS_TIMEOUT) do Process.wait(pid) if pid end example.log_event("#{name}.wait_for_exit finished (pid #{pid})") @@ -384,9 +384,9 @@ describe Chef::RunLock do example.log_event("#{name}.stop (pid #{pid})") begin # Send it the kill signal over and over until it dies - Timeout::timeout(CLIENT_PROCESS_TIMEOUT) do + Timeout.timeout(CLIENT_PROCESS_TIMEOUT) do Process.kill(:KILL, pid) - while !Process.waitpid2(pid, Process::WNOHANG) + until Process.waitpid2(pid, Process::WNOHANG) sleep(0.05) end end @@ -431,7 +431,7 @@ describe Chef::RunLock do example.log_event("#{name}.start") @pid = fork do begin - Timeout::timeout(CLIENT_PROCESS_TIMEOUT) do + Timeout.timeout(CLIENT_PROCESS_TIMEOUT) do run_lock = TestRunLock.new(example.lockfile) run_lock.client_process = self fire_event("started") diff --git a/spec/functional/win32/registry_spec.rb b/spec/functional/win32/registry_spec.rb index f0258ab3b9..4f9b742503 100644 --- a/spec/functional/win32/registry_spec.rb +++ b/spec/functional/win32/registry_spec.rb @@ -35,7 +35,7 @@ describe "Chef::Win32::Registry", :windows_only do reg["Strong", Win32::Registry::REG_SZ] = "bird nest" end ::Win32::Registry::HKEY_CURRENT_USER.open('Software\\Root\\Branch\\Flower', Win32::Registry::KEY_ALL_ACCESS) do |reg| - reg["Petals", Win32::Registry::REG_MULTI_SZ] = ["Pink", "Delicate"] + reg["Petals", Win32::Registry::REG_MULTI_SZ] = %w{Pink Delicate} end #Create the node with ohai data @@ -137,49 +137,49 @@ describe "Chef::Win32::Registry", :windows_only do describe "data_exists?" do it "throws an exception if the hive does not exist" do - expect { @registry.data_exists?("JKLM\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegHiveMissing) + expect { @registry.data_exists?("JKLM\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w{Pink Delicate} }) }.to raise_error(Chef::Exceptions::Win32RegHiveMissing) end it "throws an exception if the key does not exist" do - expect { @registry.data_exists?("HKCU\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegKeyMissing) + expect { @registry.data_exists?("HKCU\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w{Pink Delicate} }) }.to raise_error(Chef::Exceptions::Win32RegKeyMissing) end it "returns true if all the data matches" do - expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] })).to eq(true) + expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w{Pink Delicate} })).to eq(true) end it "returns true if all the data matches with a case mismatch on the data name" do - expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "petals", :type => :multi_string, :data => ["Pink", "Delicate"] })).to eq(true) + expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "petals", :type => :multi_string, :data => %w{Pink Delicate} })).to eq(true) end it "returns false if the name does not exist" do - expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "slateP", :type => :multi_string, :data => ["Pink", "Delicate"] })).to eq(false) + expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "slateP", :type => :multi_string, :data => %w{Pink Delicate} })).to eq(false) end it "returns false if the types do not match" do expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :string, :data => "Pink" })).to eq(false) end it "returns false if the data does not match" do - expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Mauve", "Delicate"] })).to eq(false) + expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w{Mauve Delicate} })).to eq(false) end end describe "data_exists!" do it "throws an exception if the hive does not exist" do - expect { @registry.data_exists!("JKLM\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegHiveMissing) + expect { @registry.data_exists!("JKLM\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w{Pink Delicate} }) }.to raise_error(Chef::Exceptions::Win32RegHiveMissing) end it "throws an exception if the key does not exist" do - expect { @registry.data_exists!("HKCU\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegKeyMissing) + expect { @registry.data_exists!("HKCU\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w{Pink Delicate} }) }.to raise_error(Chef::Exceptions::Win32RegKeyMissing) end it "returns true if all the data matches" do - expect(@registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] })).to eq(true) + expect(@registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w{Pink Delicate} })).to eq(true) end it "returns true if all the data matches with a case mismatch on the data name" do - expect(@registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "petals", :type => :multi_string, :data => ["Pink", "Delicate"] })).to eq(true) + expect(@registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "petals", :type => :multi_string, :data => %w{Pink Delicate} })).to eq(true) end it "throws an exception if the name does not exist" do - expect { @registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "slateP", :type => :multi_string, :data => ["Pink", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegDataMissing) + expect { @registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "slateP", :type => :multi_string, :data => %w{Pink Delicate} }) }.to raise_error(Chef::Exceptions::Win32RegDataMissing) end it "throws an exception if the types do not match" do expect { @registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :string, :data => "Pink" }) }.to raise_error(Chef::Exceptions::Win32RegDataMissing) end it "throws an exception if the data does not match" do - expect { @registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Mauve", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegDataMissing) + expect { @registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w{Mauve Delicate} }) }.to raise_error(Chef::Exceptions::Win32RegDataMissing) end end @@ -243,13 +243,13 @@ describe "Chef::Win32::Registry", :windows_only do end it "throws an exception when trying to cast an array to an int for a dword" do - expect { @registry.set_value("HKCU\\Software\\Root\\Branch\\Flower", { :name => "ShouldThrow", :type => :dword, :data => ["one", "two"] }) }.to raise_error + expect { @registry.set_value("HKCU\\Software\\Root\\Branch\\Flower", { :name => "ShouldThrow", :type => :dword, :data => %w{one two} }) }.to raise_error end # we are validating that the data gets .to_s called on it when type is a :string it "stores the string representation of an array into a string if you pass it an array" do - expect(@registry.set_value("HKCU\\Software\\Root\\Branch\\Flower", { :name => "ShouldBePainful", :type => :string, :data => ["one", "two"] })).to eq(true) + expect(@registry.set_value("HKCU\\Software\\Root\\Branch\\Flower", { :name => "ShouldBePainful", :type => :string, :data => %w{one two} })).to eq(true) expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "ShouldBePainful", :type => :string, :data => '["one", "two"]' })).to eq(true) end @@ -330,7 +330,7 @@ describe "Chef::Win32::Registry", :windows_only do before (:all) do ::Win32::Registry::HKEY_CURRENT_USER.create "Software\\Root\\Branch\\Fruit" ::Win32::Registry::HKEY_CURRENT_USER.open('Software\\Root\\Branch\\Fruit', Win32::Registry::KEY_ALL_ACCESS) do |reg| - reg["Apple", Win32::Registry::REG_MULTI_SZ] = ["Red", "Juicy"] + reg["Apple", Win32::Registry::REG_MULTI_SZ] = %w{Red Juicy} end ::Win32::Registry::HKEY_CURRENT_USER.create "Software\\Root\\Trunk\\Peck\\Woodpecker" ::Win32::Registry::HKEY_CURRENT_USER.open('Software\\Root\\Trunk\\Peck\\Woodpecker', Win32::Registry::KEY_ALL_ACCESS) do |reg| diff --git a/spec/functional/win32/service_manager_spec.rb b/spec/functional/win32/service_manager_spec.rb index 7f8e943367..8fff73396e 100644 --- a/spec/functional/win32/service_manager_spec.rb +++ b/spec/functional/win32/service_manager_spec.rb @@ -81,7 +81,7 @@ describe "Chef::Application::WindowsServiceManager", :windows_only, :system_wind end it "other actions => should say service doesn't exist" do - ["delete", "start", "stop", "pause", "resume", "uninstall"].each do |action| + %w{delete start stop pause resume uninstall}.each do |action| service_manager.run(["-a", action]) expect(@service_manager_output.grep(/doesn't exist on the system/).length).to be > 0 @service_manager_output = [ ] @@ -106,7 +106,7 @@ describe "Chef::Application::WindowsServiceManager", :windows_only, :system_wind end context "and service is stopped" do - ["delete", "uninstall"].each do |action| + %w{delete uninstall}.each do |action| it "#{action} => should remove the service", :volatile do service_manager.run(["-a", action]) expect(test_service_exists?).to be_falsey @@ -133,7 +133,7 @@ describe "Chef::Application::WindowsServiceManager", :windows_only, :system_wind expect(test_service_state).to eq("stopped") end - ["pause", "resume"].each do |action| + %w{pause resume}.each do |action| it "#{action} => should raise error" do expect { service_manager.run(["-a", action]) }.to raise_error(SystemCallError) end @@ -144,7 +144,7 @@ describe "Chef::Application::WindowsServiceManager", :windows_only, :system_wind service_manager.run(["-a", "start"]) end - ["delete", "uninstall"].each do |action| + %w{delete uninstall}.each do |action| it "#{action} => should remove the service", :volatile do service_manager.run(["-a", action]) expect(test_service_exists?).to be_falsey @@ -182,7 +182,7 @@ describe "Chef::Application::WindowsServiceManager", :windows_only, :system_wind service_manager.run(["-a", "pause"]) end - actions = ["delete", "uninstall"] + actions = %w{delete uninstall} actions.each do |action| it "#{action} => should remove the service" do service_manager.run(["-a", action]) diff --git a/spec/functional/win32/versions_spec.rb b/spec/functional/win32/versions_spec.rb index aee5bbbcd4..53fce39491 100644 --- a/spec/functional/win32/versions_spec.rb +++ b/spec/functional/win32/versions_spec.rb @@ -36,7 +36,7 @@ describe "Chef::ReservedNames::Win32::Version", :windows_only, :not_supported_on # from WMI contain extended characters such as registered # trademark on Win2k8 and Win2k3 that we're not using in our # library, so we have to set the expectation statically. - if Chef::Platform::windows_server_2003? + if Chef::Platform.windows_server_2003? @current_os_version = "Windows Server 2003 R2" elsif is_windows_server_2008?(host) @current_os_version = "Windows Server 2008" diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb index 6f8dce5ae7..5d136968dd 100644 --- a/spec/integration/knife/upload_spec.rb +++ b/spec/integration/knife/upload_spec.rb @@ -280,7 +280,7 @@ Created /data_bags/x/y.json EOM knife("diff --name-status /data_bags").should_succeed <<EOM EOM - expect(Chef::JSONCompat.parse(knife("raw /data/x/y").stdout, :create_additions => false).keys.sort).to eq([ "foo", "id" ]) + expect(Chef::JSONCompat.parse(knife("raw /data/x/y").stdout, :create_additions => false).keys.sort).to eq(%w{foo id}) end it "knife upload /data_bags/x /data_bags/x/y.json uploads x once" do @@ -304,7 +304,7 @@ Created /data_bags/x/y.json EOM knife("diff --name-status /data_bags").should_succeed "" result = Chef::JSONCompat.parse(knife("raw /data/x/y").stdout, :create_additions => false) - expect(result.keys.sort).to eq([ "chef_type", "data_bag", "id" ]) + expect(result.keys.sort).to eq(%w{chef_type data_bag id}) expect(result["chef_type"]).to eq("aaa") expect(result["data_bag"]).to eq("bbb") end @@ -1457,25 +1457,25 @@ EOM when_the_repository "wants to invite foo, bar and foobar" do before do - file "invitations.json", [ "foo", "bar", "foobar" ] + file "invitations.json", %w{foo bar foobar} end it "knife upload / emits a warning for bar and invites foobar" do knife("upload /").should_succeed "Updated /invitations.json\n", :stderr => "WARN: Could not invite bar to organization foo: User bar is already in organization foo\n" - expect(api.get("association_requests").map { |a| a["username"] }).to eq([ "foo", "foobar" ]) + expect(api.get("association_requests").map { |a| a["username"] }).to eq(%w{foo foobar}) expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar" ]) end end when_the_repository "wants to make foo, bar and foobar members" do before do - file "members.json", [ "foo", "bar", "foobar" ] + file "members.json", %w{foo bar foobar} end it "knife upload / emits a warning for bar and adds foo and foobar" do knife("upload /").should_succeed "Updated /members.json\n" expect(api.get("association_requests").map { |a| a["username"] }).to eq([ ]) - expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar", "foo", "foobar" ]) + expect(api.get("users").map { |a| a["user"]["username"] }).to eq(%w{bar foo foobar}) end end @@ -1498,12 +1498,12 @@ EOM when_the_repository "wants to invite foo and bar (different order)" do before do - file "invitations.json", [ "foo", "bar" ] + file "invitations.json", %w{foo bar} end it "knife upload / does nothing" do knife("upload /").should_succeed "" - expect(api.get("association_requests").map { |a| a["username"] }).to eq([ "bar", "foo" ]) + expect(api.get("association_requests").map { |a| a["username"] }).to eq(%w{bar foo}) expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ ]) end end @@ -1514,13 +1514,13 @@ EOM when_the_repository "wants to add foo and bar (different order)" do before do - file "members.json", [ "foo", "bar" ] + file "members.json", %w{foo bar} end it "knife upload / does nothing" do knife("upload /").should_succeed "" expect(api.get("association_requests").map { |a| a["username"] }).to eq([ ]) - expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar", "foo" ]) + expect(api.get("users").map { |a| a["user"]["username"] }).to eq(%w{bar foo}) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 47432f5a77..8ba4c8eb70 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -160,7 +160,7 @@ RSpec.configure do |config| config.filter_run_excluding :chef_gte_13_only => true unless chef_gte_13? config.filter_run_excluding :chef_lt_13_only => true unless chef_lt_13? config.filter_run_excluding :requires_root => true unless root? - config.filter_run_excluding :requires_root_or_running_windows => true unless (root? || windows?) + config.filter_run_excluding :requires_root_or_running_windows => true unless root? || windows? config.filter_run_excluding :requires_unprivileged_user => true if root? config.filter_run_excluding :uses_diff => true unless has_diff? config.filter_run_excluding :openssl_gte_101 => true unless openssl_gte_101? diff --git a/spec/stress/win32/security_spec.rb b/spec/stress/win32/security_spec.rb index e9da56620e..4fbd1dac9c 100644 --- a/spec/stress/win32/security_spec.rb +++ b/spec/stress/win32/security_spec.rb @@ -31,7 +31,7 @@ describe "Chef::ReservedNames::Win32::Security", :windows_only do end before :all do - @test_tempdir = File.join(Dir::tmpdir, "cheftests", "chef_win32_security") + @test_tempdir = File.join(Dir.tmpdir, "cheftests", "chef_win32_security") FileUtils.mkdir_p(@test_tempdir) @monkeyfoo = File.join(@test_tempdir, "monkeyfoo.txt") end diff --git a/spec/support/platforms/win32/spec_service.rb b/spec/support/platforms/win32/spec_service.rb index c196e13b6a..5548a79afc 100644 --- a/spec/support/platforms/win32/spec_service.rb +++ b/spec/support/platforms/win32/spec_service.rb @@ -24,7 +24,7 @@ class SpecService < ::Win32::Daemon end def service_main(*startup_parameters) - while running? do + while running? if !File.exists?(@test_service_file) File.open(@test_service_file, "wb") do |f| f.write("This file is created by SpecService") diff --git a/spec/support/shared/functional/directory_resource.rb b/spec/support/shared/functional/directory_resource.rb index 084cd43009..5e5e2bb360 100644 --- a/spec/support/shared/functional/directory_resource.rb +++ b/spec/support/shared/functional/directory_resource.rb @@ -163,11 +163,11 @@ shared_context Chef::Resource::Directory do end before do - FileUtils::mkdir_p(test_file_dir) + FileUtils.mkdir_p(test_file_dir) end after do - FileUtils::rm_rf(test_file_dir) + FileUtils.rm_rf(test_file_dir) end after(:each) do diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb index 5f34f1efe6..bb8db772be 100644 --- a/spec/support/shared/functional/file_resource.rb +++ b/spec/support/shared/functional/file_resource.rb @@ -781,11 +781,11 @@ shared_examples_for "a configured file resource" do let(:test_socket_dir) { File.join(Dir.tmpdir, "sockets") } before do - FileUtils::mkdir_p(test_socket_dir) + FileUtils.mkdir_p(test_socket_dir) end after do - FileUtils::rm_rf(test_socket_dir) + FileUtils.rm_rf(test_socket_dir) end let(:path) do @@ -1035,7 +1035,7 @@ shared_context Chef::Resource::File do end before do - FileUtils::mkdir_p(test_file_dir) + FileUtils.mkdir_p(test_file_dir) end after(:each) do @@ -1044,6 +1044,6 @@ shared_context Chef::Resource::File do end after do - FileUtils::rm_rf(test_file_dir) + FileUtils.rm_rf(test_file_dir) end end diff --git a/spec/support/shared/functional/windows_script.rb b/spec/support/shared/functional/windows_script.rb index 67a53306ba..908198add4 100644 --- a/spec/support/shared/functional/windows_script.rb +++ b/spec/support/shared/functional/windows_script.rb @@ -24,7 +24,7 @@ require "chef/platform/query_helpers" shared_context Chef::Resource::WindowsScript do before(:all) do @ohai_reader = Ohai::System.new - @ohai_reader.all_plugins(["platform", "kernel"]) + @ohai_reader.all_plugins(%w{platform kernel}) new_node = Chef::Node.new new_node.consume_external_attrs(@ohai_reader.data, {}) diff --git a/spec/support/shared/integration/app_server_support.rb b/spec/support/shared/integration/app_server_support.rb index c504c7ca99..8327caf1c9 100644 --- a/spec/support/shared/integration/app_server_support.rb +++ b/spec/support/shared/integration/app_server_support.rb @@ -27,12 +27,12 @@ module AppServerSupport Rack::Handler::WEBrick.run(app, :Port => 9018, :AccessLog => [], - :Logger => WEBrick::Log::new(StringIO.new, 7), + :Logger => WEBrick::Log.new(StringIO.new, 7), ) do |found_server| server = found_server end end - Timeout::timeout(30) do + Timeout.timeout(30) do until server && server.status == :Running sleep(0.01) end diff --git a/spec/support/shared/unit/platform_introspector.rb b/spec/support/shared/unit/platform_introspector.rb index 2e6f74fb14..7b9cc0f94e 100644 --- a/spec/support/shared/unit/platform_introspector.rb +++ b/spec/support/shared/unit/platform_introspector.rb @@ -26,7 +26,7 @@ shared_examples_for "a platform introspector" do "1.2.3" => "#{x}-1.2.3", } end - @platform_hash["debian"] = { ["5", "6"] => "debian-5/6", "default" => "debian" } + @platform_hash["debian"] = { %w{5 6} => "debian-5/6", "default" => "debian" } @platform_hash["default"] = "default" # The following @platform_hash keys are used for testing version constraints @platform_hash["exact_match"] = { "1.2.3" => "exact", ">= 1.0" => "not exact" } @@ -130,7 +130,7 @@ shared_examples_for "a platform introspector" do it "returns true if the node is a provided platform and platforms are provided as strings" do node.automatic_attrs[:platform] = "ubuntu" - expect(platform_introspector.platform?(["redhat", "ubuntu"])).to eq(true) + expect(platform_introspector.platform?(%w{redhat ubuntu})).to eq(true) end it "returns false if the node is not of the provided platforms" do @@ -148,7 +148,7 @@ shared_examples_for "a platform introspector" do it "returns true if the node is a provided platform and platforms are provided as strings" do node.automatic_attrs[:platform_family] = "rhel" - expect(platform_introspector.platform_family?(["rhel", "debian"])).to eq(true) + expect(platform_introspector.platform_family?(%w{rhel debian})).to eq(true) end it "returns false if the node is not of the provided platforms" do diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index 5e5fc058e7..7ddd51db80 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -142,7 +142,7 @@ shared_examples_for Chef::Provider::File do end after do - tempfile.close if (tempfile && !tempfile.closed?) + tempfile.close if tempfile && !tempfile.closed? File.unlink(tempfile.path) rescue nil end diff --git a/spec/support/shared/unit/provider/useradd_based_user_provider.rb b/spec/support/shared/unit/provider/useradd_based_user_provider.rb index 6694aa346c..6677a069ea 100644 --- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb +++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb @@ -315,7 +315,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option expect { provider.check_lock }.to raise_error(Chef::Exceptions::User) end - ["redhat", "centos"].each do |os| + %w{redhat centos}.each do |os| it "should not raise a Chef::Exceptions::User if passwd -S exits with 1 on #{os} and the passwd package is version 0.73-1" do @node.automatic_attrs[:platform] = os expect(passwd_s_status).to receive(:exitstatus).and_return(1) diff --git a/spec/unit/audit/control_group_data_spec.rb b/spec/unit/audit/control_group_data_spec.rb index f6935a4c75..a7c8850350 100644 --- a/spec/unit/audit/control_group_data_spec.rb +++ b/spec/unit/audit/control_group_data_spec.rb @@ -360,19 +360,19 @@ describe Chef::Audit::ControlGroupData do context "and it's the first audit" do include_examples "mixed audit results" do - let(:audit_results) { ["failure", "success", "success"] } + let(:audit_results) { %w{failure success success} } end end context "and it's an audit in the middle" do include_examples "mixed audit results" do - let(:audit_results) { ["success", "failure", "success"] } + let(:audit_results) { %w{success failure success} } end end context "and it's the last audit" do include_examples "mixed audit results" do - let(:audit_results) { ["success", "success", "failure"] } + let(:audit_results) { %w{success success failure} } end end end diff --git a/spec/unit/chef_class_spec.rb b/spec/unit/chef_class_spec.rb index 3c1200e04c..3c8411ef2a 100644 --- a/spec/unit/chef_class_spec.rb +++ b/spec/unit/chef_class_spec.rb @@ -61,14 +61,14 @@ describe "Chef class" do end context "#set_provider_priority_array" do it "should delegate to the provider_priority_map" do - expect(provider_priority_map).to receive(:set_priority_array).with(:http_request, ["a", "b"], platform: "debian").and_return("stuff") - expect(Chef.set_provider_priority_array(:http_request, ["a", "b"], platform: "debian")).to eql("stuff") + expect(provider_priority_map).to receive(:set_priority_array).with(:http_request, %w{a b}, platform: "debian").and_return("stuff") + expect(Chef.set_provider_priority_array(:http_request, %w{a b}, platform: "debian")).to eql("stuff") end end context "#set_priority_map_for_resource" do it "should delegate to the resource_priority_map" do - expect(resource_priority_map).to receive(:set_priority_array).with(:http_request, ["a", "b"], platform: "debian").and_return("stuff") - expect(Chef.set_resource_priority_array(:http_request, ["a", "b"], platform: "debian")).to eql("stuff") + expect(resource_priority_map).to receive(:set_priority_array).with(:http_request, %w{a b}, platform: "debian").and_return("stuff") + expect(Chef.set_resource_priority_array(:http_request, %w{a b}, platform: "debian")).to eql("stuff") end end end diff --git a/spec/unit/chef_fs/parallelizer.rb b/spec/unit/chef_fs/parallelizer.rb index da18117bbd..20edbcdcde 100644 --- a/spec/unit/chef_fs/parallelizer.rb +++ b/spec/unit/chef_fs/parallelizer.rb @@ -211,7 +211,7 @@ describe Chef::ChefFS::Parallelizer do occupying_job_finished[0] = true end.wait end - while !started + until started sleep(0.01) end end diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index ff18333e70..0107667fcd 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -460,7 +460,7 @@ describe Chef::Cookbook::Metadata do attrs = { "display_name" => "MySQL Databases", "description" => "Description of MySQL", - "choice" => ["dedicated", "shared"], + "choice" => %w{dedicated shared}, "calculated" => false, "type" => "string", "required" => "recommended", @@ -523,7 +523,7 @@ describe Chef::Cookbook::Metadata do it "should not accept anything but an array of strings for choice" do expect { - metadata.attribute("db/mysql/databases", :choice => ["dedicated", "shared"]) + metadata.attribute("db/mysql/databases", :choice => %w{dedicated shared}) }.not_to raise_error expect { metadata.attribute("db/mysql/databases", :choice => [10, "shared"]) @@ -651,7 +651,7 @@ describe Chef::Cookbook::Metadata do it "should limit the types allowed in the choice array" do options = { :type => "string", - :choice => [ "test1", "test2" ], + :choice => %w{test1 test2}, :default => "test1", } expect { @@ -706,15 +706,15 @@ describe Chef::Cookbook::Metadata do it "should allow a default that is a choice" do expect { attrs = { - :choice => [ "a", "b", "c"], + :choice => %w{a b c}, :default => "b", } metadata.attribute("db/mysql/databases", attrs) }.not_to raise_error expect { attrs = { - :choice => [ "a", "b", "c", "d", "e"], - :default => ["b", "d"], + :choice => %w{a b c d e}, + :default => %w{b d}, } metadata.attribute("db/mysql/databases", attrs) }.not_to raise_error @@ -723,15 +723,15 @@ describe Chef::Cookbook::Metadata do it "should error if default is not a choice" do expect { attrs = { - :choice => [ "a", "b", "c"], + :choice => %w{a b c}, :default => "d", } metadata.attribute("db/mysql/databases", attrs) }.to raise_error(ArgumentError) expect { attrs = { - :choice => [ "a", "b", "c", "d", "e"], - :default => ["b", "z"], + :choice => %w{a b c d e}, + :default => %w{b z}, } metadata.attribute("db/mysql/databases", attrs) }.to raise_error(ArgumentError) diff --git a/spec/unit/cookbook_spec.rb b/spec/unit/cookbook_spec.rb index f931b43eaa..33b4a3ccd8 100644 --- a/spec/unit/cookbook_spec.rb +++ b/spec/unit/cookbook_spec.rb @@ -39,7 +39,7 @@ describe Chef::CookbookVersion do it "should allow you to set the list of attribute files and create the mapping from short names to paths" do @cookbook.attribute_filenames = [ "attributes/one.rb", "attributes/two.rb" ] expect(@cookbook.attribute_filenames).to eq([ "attributes/one.rb", "attributes/two.rb" ]) - expect(@cookbook.attribute_filenames_by_short_filename.keys.sort).to eql(["one", "two"]) + expect(@cookbook.attribute_filenames_by_short_filename.keys.sort).to eql(%w{one two}) expect(@cookbook.attribute_filenames_by_short_filename["one"]).to eq("attributes/one.rb") expect(@cookbook.attribute_filenames_by_short_filename["two"]).to eq("attributes/two.rb") end @@ -47,7 +47,7 @@ describe Chef::CookbookVersion do it "should allow you to set the list of recipe files and create the mapping of recipe short name to filename" do @cookbook.recipe_filenames = [ "recipes/one.rb", "recipes/two.rb" ] expect(@cookbook.recipe_filenames).to eq([ "recipes/one.rb", "recipes/two.rb" ]) - expect(@cookbook.recipe_filenames_by_name.keys.sort).to eql(["one", "two"]) + expect(@cookbook.recipe_filenames_by_name.keys.sort).to eql(%w{one two}) expect(@cookbook.recipe_filenames_by_name["one"]).to eq("recipes/one.rb") expect(@cookbook.recipe_filenames_by_name["two"]).to eq("recipes/two.rb") end diff --git a/spec/unit/dsl/reboot_pending_spec.rb b/spec/unit/dsl/reboot_pending_spec.rb index 66f8b76d7f..5cd7c7794f 100644 --- a/spec/unit/dsl/reboot_pending_spec.rb +++ b/spec/unit/dsl/reboot_pending_spec.rb @@ -92,7 +92,7 @@ describe Chef::DSL::RebootPending do describe "in a resource" do it "responds to reboot_pending?" do - resource = Chef::Resource::new("Crackerjack::Timing", nil) + resource = Chef::Resource.new("Crackerjack::Timing", nil) expect(resource).to respond_to(:reboot_pending?) end end # describe in a resource diff --git a/spec/unit/dsl/regsitry_helper_spec.rb b/spec/unit/dsl/regsitry_helper_spec.rb index d6c2257003..45c7e73979 100644 --- a/spec/unit/dsl/regsitry_helper_spec.rb +++ b/spec/unit/dsl/regsitry_helper_spec.rb @@ -26,7 +26,7 @@ describe Chef::Resource::RegistryKey do node = Chef::Node.new node.consume_external_attrs(OHAI_SYSTEM.data, {}) run_context = Chef::RunContext.new(node, {}, events) - @resource = Chef::Resource::new("foo", run_context) + @resource = Chef::Resource.new("foo", run_context) end context "tests registry dsl" do diff --git a/spec/unit/encrypted_data_bag_item_spec.rb b/spec/unit/encrypted_data_bag_item_spec.rb index 14713682e7..e3b77852b7 100644 --- a/spec/unit/encrypted_data_bag_item_spec.rb +++ b/spec/unit/encrypted_data_bag_item_spec.rb @@ -112,7 +112,7 @@ describe Chef::EncryptedDataBagItem::Encryptor do it "includes the auth_tag in the envelope" do final_data = encryptor.for_encrypted_item - expect(final_data["auth_tag"]).to eq(Base64::encode64(encryptor.auth_tag)) + expect(final_data["auth_tag"]).to eq(Base64.encode64(encryptor.auth_tag)) end it "throws an error if auth tag is read before encrypting the data" do diff --git a/spec/unit/http/validate_content_length_spec.rb b/spec/unit/http/validate_content_length_spec.rb index c054529e48..c852d7b5c7 100644 --- a/spec/unit/http/validate_content_length_spec.rb +++ b/spec/unit/http/validate_content_length_spec.rb @@ -107,7 +107,7 @@ describe Chef::HTTP::ValidateContentLength do describe "without Content-Length header" do let(:response_headers) { {} } - [ "direct", "streaming" ].each do |req_type| + %w{direct streaming}.each do |req_type| describe "when running #{req_type} request" do let(:request_type) { req_type.to_sym } @@ -120,7 +120,7 @@ describe Chef::HTTP::ValidateContentLength do end describe "with correct Content-Length header" do - [ "direct", "streaming" ].each do |req_type| + %w{direct streaming}.each do |req_type| describe "when running #{req_type} request" do let(:request_type) { req_type.to_sym } @@ -134,7 +134,7 @@ describe Chef::HTTP::ValidateContentLength do describe "with wrong Content-Length header" do let(:content_length_value) { 25 } - [ "direct", "streaming" ].each do |req_type| + %w{direct streaming}.each do |req_type| describe "when running #{req_type} request" do let(:request_type) { req_type.to_sym } @@ -161,7 +161,7 @@ describe Chef::HTTP::ValidateContentLength do } } - [ "direct", "streaming" ].each do |req_type| + %w{direct streaming}.each do |req_type| describe "when running #{req_type} request" do let(:request_type) { req_type.to_sym } diff --git a/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb b/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb index ffc851e2b5..734b27216d 100644 --- a/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb +++ b/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb @@ -69,14 +69,14 @@ describe Chef::Knife::Bootstrap::ChefVaultHandler do end it "sets two items as an array" do - knife_config[:bootstrap_vault_item] = { "vault" => [ "item1", "item2" ] } + knife_config[:bootstrap_vault_item] = { "vault" => %w{item1 item2} } expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item2").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end it "sets two vaults from different hash keys" do - knife_config[:bootstrap_vault_item] = { "vault" => [ "item1", "item2" ], "vault2" => [ "item3" ] } + knife_config[:bootstrap_vault_item] = { "vault" => %w{item1 item2}, "vault2" => [ "item3" ] } expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item2").and_return(bootstrap_vault_item) expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault2", "item3").and_return(bootstrap_vault_item) diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index e8e75e43b5..3425b94c76 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -51,7 +51,7 @@ describe Chef::Knife::Bootstrap do context "with --bootstrap-vault-item" do let(:bootstrap_cli_options) { [ "--bootstrap-vault-item", "vault1:item1", "--bootstrap-vault-item", "vault1:item2", "--bootstrap-vault-item", "vault2:item1" ] } it "sets the knife config cli option correctly" do - expect(knife.config[:bootstrap_vault_item]).to eq({ "vault1" => ["item1", "item2"], "vault2" => ["item1"] }) + expect(knife.config[:bootstrap_vault_item]).to eq({ "vault1" => %w{item1 item2}, "vault2" => ["item1"] }) end end diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb index a8248a80b9..991abea776 100644 --- a/spec/unit/knife/cookbook_download_spec.rb +++ b/spec/unit/knife/cookbook_download_spec.rb @@ -119,7 +119,7 @@ describe Chef::Knife::CookbookDownload do it "should download the cookbook when the cookbook download directory doesn't exist" do expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(false) @knife.run - ["attributes", "recipes", "templates"].each do |segment| + %w{attributes recipes templates}.each do |segment| expect(@stderr.string).to match /downloading #{segment}/im end expect(@stderr.string).to match /downloading foobar cookbook version 1\.0\.0/im diff --git a/spec/unit/knife/cookbook_list_spec.rb b/spec/unit/knife/cookbook_list_spec.rb index 668f9afa4b..fce6bc9593 100644 --- a/spec/unit/knife/cookbook_list_spec.rb +++ b/spec/unit/knife/cookbook_list_spec.rb @@ -23,7 +23,7 @@ describe Chef::Knife::CookbookList do @knife = Chef::Knife::CookbookList.new @rest_mock = double("rest") allow(@knife).to receive(:rest).and_return(@rest_mock) - @cookbook_names = ["apache2", "mysql"] + @cookbook_names = %w{apache2 mysql} @base_url = "https://server.example.com/cookbooks" @cookbook_data = {} @cookbook_names.each do |item| diff --git a/spec/unit/knife/cookbook_site_install_spec.rb b/spec/unit/knife/cookbook_site_install_spec.rb index b0b1e8aec2..d60443d779 100644 --- a/spec/unit/knife/cookbook_site_install_spec.rb +++ b/spec/unit/knife/cookbook_site_install_spec.rb @@ -71,7 +71,7 @@ describe Chef::Knife::CookbookSiteInstall do end it "raises an error if more than two arguments are given" do - knife.name_args = ["foo", "bar", "baz"] + knife.name_args = %w{foo bar baz} expect(knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.") expect { knife.run }.to raise_error(SystemExit) end diff --git a/spec/unit/knife/cookbook_site_share_spec.rb b/spec/unit/knife/cookbook_site_share_spec.rb index 662b53dd29..d5e3915896 100644 --- a/spec/unit/knife/cookbook_site_share_spec.rb +++ b/spec/unit/knife/cookbook_site_share_spec.rb @@ -27,7 +27,7 @@ describe Chef::Knife::CookbookSiteShare do @knife = Chef::Knife::CookbookSiteShare.new # Merge default settings in. @knife.merge_configs - @knife.name_args = ["cookbook_name", "AwesomeSausage"] + @knife.name_args = %w{cookbook_name AwesomeSausage} @cookbook = Chef::CookbookVersion.new("cookbook_name") diff --git a/spec/unit/knife/cookbook_test_spec.rb b/spec/unit/knife/cookbook_test_spec.rb index abb88fe739..f8b212e271 100644 --- a/spec/unit/knife/cookbook_test_spec.rb +++ b/spec/unit/knife/cookbook_test_spec.rb @@ -45,7 +45,7 @@ describe Chef::Knife::CookbookTest do it "should test multiple cookbooks when provided" do allow(@knife).to receive(:test_cookbook).and_return(true) - @knife.name_args = ["tats", "jimmy_johns"] + @knife.name_args = %w{tats jimmy_johns} expect(@knife).to receive(:test_cookbook).with("tats") expect(@knife).to receive(:test_cookbook).with("jimmy_johns") expect(@knife).not_to receive(:test_cookbook).with("central_market") @@ -56,7 +56,7 @@ describe Chef::Knife::CookbookTest do it "should test both ruby and templates" do @knife.name_args = ["example"] expect(@knife.config[:cookbook_path]).not_to be_empty - Array(@knife.config[:cookbook_path]).reverse.each do |path| + Array(@knife.config[:cookbook_path]).reverse_each do |path| expect(@knife).to receive(:test_ruby).with(an_instance_of(Chef::Cookbook::SyntaxCheck)) expect(@knife).to receive(:test_templates).with(an_instance_of(Chef::Cookbook::SyntaxCheck)) end diff --git a/spec/unit/knife/cookbook_upload_spec.rb b/spec/unit/knife/cookbook_upload_spec.rb index dc55a709b7..277da14011 100644 --- a/spec/unit/knife/cookbook_upload_spec.rb +++ b/spec/unit/knife/cookbook_upload_spec.rb @@ -96,7 +96,7 @@ describe Chef::Knife::CookbookUpload do describe "when specifying the same cookbook name twice" do it "should upload the cookbook only once" do - knife.name_args = ["test_cookbook", "test_cookbook"] + knife.name_args = %w{test_cookbook test_cookbook} expect(knife).to receive(:upload).once knife.run end @@ -181,10 +181,10 @@ E it "should upload all dependencies once" do knife.config[:depends] = true - allow(knife).to receive(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2", "test_cookbook3"]) + allow(knife).to receive(:cookbook_names).and_return(%w{test_cookbook1 test_cookbook2 test_cookbook3}) expect(knife).to receive(:upload).exactly(3).times expect do - Timeout::timeout(5) do + Timeout.timeout(5) do knife.run end end.not_to raise_error @@ -200,7 +200,7 @@ E { "test_cookbook" => cookbook, "dependency" => cookbook_dependency }[ckbk] end - allow(knife).to receive(:cookbook_names).and_return(["cookbook_dependency", "test_cookbook"]) + allow(knife).to receive(:cookbook_names).and_return(%w{cookbook_dependency test_cookbook}) @stdout, @stderr, @stdin = StringIO.new, StringIO.new, StringIO.new knife.ui = Chef::Knife::UI.new(@stdout, @stderr, @stdin, {}) end @@ -227,7 +227,7 @@ E "dependency" => cookbook_dependency, "dependency2" => cookbook_dependency2 }[ckbk] end - allow(knife).to receive(:cookbook_names).and_return(["dependency", "dependency2", "test_cookbook"]) + allow(knife).to receive(:cookbook_names).and_return(%w{dependency dependency2 test_cookbook}) expect { knife.run }.to raise_error(SystemExit) expect(@stderr.string).to include("Cookbook test_cookbook depends on cookbooks which are not currently") expect(@stderr.string).to include("being uploaded and cannot be found on the server.") @@ -253,7 +253,7 @@ E @test_cookbook1 = Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah") @test_cookbook2 = Chef::CookbookVersion.new("test_cookbook2", "/tmp/blah") allow(cookbook_loader).to receive(:each).and_yield("test_cookbook1", @test_cookbook1).and_yield("test_cookbook2", @test_cookbook2) - allow(cookbook_loader).to receive(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2"]) + allow(cookbook_loader).to receive(:cookbook_names).and_return(%w{test_cookbook1 test_cookbook2}) end it "should upload all cookbooks" do diff --git a/spec/unit/knife/core/hashed_command_loader_spec.rb b/spec/unit/knife/core/hashed_command_loader_spec.rb index d9f5e5761c..4ae046cc09 100644 --- a/spec/unit/knife/core/hashed_command_loader_spec.rb +++ b/spec/unit/knife/core/hashed_command_loader_spec.rb @@ -83,7 +83,7 @@ describe Chef::Knife::SubcommandLoader::HashedCommandLoader do end it "finds the right subcommand even when _'s are elided" do - expect(loader.subcommand_for_args(["cooler", "b"])).to eq("cooler_b") + expect(loader.subcommand_for_args(%w{cooler b})).to eq("cooler_b") end it "returns nil if the the subcommand isn't in our manifest" do diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb index d2381f60cb..37974821d7 100644 --- a/spec/unit/knife/core/ui_spec.rb +++ b/spec/unit/knife/core/ui_spec.rb @@ -205,7 +205,7 @@ EOM end it "formats arrays appropriately" do - @ui.output([ "a", "b" ]) + @ui.output(%w{a b}) expect(@out.string).to eq <<EOM a b @@ -228,7 +228,7 @@ EOM end it "formats nested arrays appropriately" do - @ui.output([ [ "a", "b" ], [ "c", "d" ]]) + @ui.output([ %w{a b}, %w{c d}]) expect(@out.string).to eq <<EOM a b @@ -239,7 +239,7 @@ EOM end it "formats nested arrays with single- and empty subarrays appropriately" do - @ui.output([ [ "a", "b" ], [ "c" ], [], [ "d", "e" ]]) + @ui.output([ %w{a b}, [ "c" ], [], %w{d e}]) expect(@out.string).to eq <<EOM a b @@ -282,7 +282,7 @@ EOM end it "formats hashes with array members appropriately" do - @ui.output({ "a" => [ "foo", "bar" ], "b" => "c" }) + @ui.output({ "a" => %w{foo bar}, "b" => "c" }) expect(@out.string).to eq <<EOM a: foo @@ -301,7 +301,7 @@ EOM end it "formats hashes with nested array values appropriately" do - @ui.output({ "a" => [ [ "foo", "bar" ], [ "baz", "bjork" ] ], "b" => "c" }) + @ui.output({ "a" => [ %w{foo bar}, %w{baz bjork} ], "b" => "c" }) # XXX: using a HEREDOC at this point results in a line with required spaces which auto-whitespace removal settings # on editors will remove and will break this test. expect(@out.string).to eq("a:\n foo\n bar\n \n baz\n bjork\nb: c\n") @@ -353,7 +353,7 @@ EOM it "should return multiple attributes" do input = { "gi" => "go", "hi" => "ho", "id" => "sample-data-bag-item" } - @ui.config[:attribute] = ["gi", "hi"] + @ui.config[:attribute] = %w{gi hi} expect(@ui.format_for_display(input)).to eq({ "sample-data-bag-item" => { "gi" => "go", "hi" => "ho" } }) end @@ -545,7 +545,7 @@ EOM end end - ["Y", "y"].each do |answer| + %w{Y y}.each do |answer| describe "with answer #{answer}" do let(:answer) { answer } @@ -553,7 +553,7 @@ EOM end end - ["N", "n"].each do |answer| + %w{N n}.each do |answer| describe "with answer #{answer}" do let(:answer) { answer } diff --git a/spec/unit/knife/environment_compare_spec.rb b/spec/unit/knife/environment_compare_spec.rb index 7a341192be..863cdd4e6e 100644 --- a/spec/unit/knife/environment_compare_spec.rb +++ b/spec/unit/knife/environment_compare_spec.rb @@ -42,7 +42,7 @@ describe Chef::Knife::EnvironmentCompare do @rest_double = double("rest") allow(@knife).to receive(:rest).and_return(@rest_double) - @cookbook_names = ["apache2", "mysql", "foo", "bar", "dummy", "chef_handler"] + @cookbook_names = %w{apache2 mysql foo bar dummy chef_handler} @base_url = "https://server.example.com/cookbooks" @cookbook_data = {} @cookbook_names.each do |item| diff --git a/spec/unit/knife/node_environment_set_spec.rb b/spec/unit/knife/node_environment_set_spec.rb index 13dd3762a2..03fc764fd8 100644 --- a/spec/unit/knife/node_environment_set_spec.rb +++ b/spec/unit/knife/node_environment_set_spec.rb @@ -22,7 +22,7 @@ describe Chef::Knife::NodeEnvironmentSet do before(:each) do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::NodeEnvironmentSet.new - @knife.name_args = [ "adam", "bar" ] + @knife.name_args = %w{adam bar} allow(@knife).to receive(:output).and_return(true) @node = Chef::Node.new() @node.name("knifetest-node") diff --git a/spec/unit/knife/node_list_spec.rb b/spec/unit/knife/node_list_spec.rb index ab17a45795..b94101ef7a 100644 --- a/spec/unit/knife/node_list_spec.rb +++ b/spec/unit/knife/node_list_spec.rb @@ -40,7 +40,7 @@ describe Chef::Knife::NodeList do it "should pretty print the list" do expect(Chef::Node).to receive(:list).and_return(@list) - expect(@knife).to receive(:output).with([ "bar", "foo" ]) + expect(@knife).to receive(:output).with(%w{bar foo}) @knife.run end diff --git a/spec/unit/knife/node_run_list_remove_spec.rb b/spec/unit/knife/node_run_list_remove_spec.rb index e741f513eb..4f753d7991 100644 --- a/spec/unit/knife/node_run_list_remove_spec.rb +++ b/spec/unit/knife/node_run_list_remove_spec.rb @@ -96,7 +96,7 @@ describe Chef::Knife::NodeRunListRemove do it "should warn even more when the thing to remove is not in the runlist and unqualified" do @node.run_list << "role[blah]" @node.run_list << "recipe[duck::type]" - @knife.name_args = [ "adam", "blork" ] + @knife.name_args = %w{adam blork} expect(@knife.ui).to receive(:warn).with("blork is not in the run list") expect(@knife.ui).to receive(:warn).with(/did you forget recipe\[\] or role\[\]/) @knife.run diff --git a/spec/unit/knife/role_env_run_list_clear_spec.rb b/spec/unit/knife/role_env_run_list_clear_spec.rb index 1fb2f1f1c7..b7af9b7d57 100644 --- a/spec/unit/knife/role_env_run_list_clear_spec.rb +++ b/spec/unit/knife/role_env_run_list_clear_spec.rb @@ -30,7 +30,7 @@ describe Chef::Knife::RoleEnvRunListClear do @knife.config = { :print_after => nil } - @knife.name_args = [ "will", "QA" ] + @knife.name_args = %w{will QA} allow(@knife).to receive(:output).and_return(true) @role = Chef::Role.new() @@ -79,7 +79,7 @@ describe Chef::Knife::RoleEnvRunListClear do @setup.run @setup.name_args = [ "will", "PRD", "recipe[orange::chicken]", "role[monkey]", "recipe[duck::type]", "role[person]", "role[bird]", "role[town]" ] @setup.run - @knife.name_args = [ "will", "QA" ] + @knife.name_args = %w{will QA} @knife.run expect(@role.run_list_for("QA")[0]).to be_nil expect(@role.run_list_for("PRD")[0]).to eq("recipe[orange::chicken]") diff --git a/spec/unit/knife/role_list_spec.rb b/spec/unit/knife/role_list_spec.rb index bfbba30288..30743fdc02 100644 --- a/spec/unit/knife/role_list_spec.rb +++ b/spec/unit/knife/role_list_spec.rb @@ -38,7 +38,7 @@ describe Chef::Knife::RoleList do it "should pretty print the list" do expect(Chef::Role).to receive(:list).and_return(@list) - expect(@knife).to receive(:output).with([ "bar", "foo" ]) + expect(@knife).to receive(:output).with(%w{bar foo}) @knife.run end diff --git a/spec/unit/knife/tag_delete_spec.rb b/spec/unit/knife/tag_delete_spec.rb index 3095eda191..5c932706af 100644 --- a/spec/unit/knife/tag_delete_spec.rb +++ b/spec/unit/knife/tag_delete_spec.rb @@ -16,7 +16,7 @@ describe Chef::Knife::TagDelete do describe "run" do it "can delete tags on a node" do - expect(@node.tags).to eq(["sadtag", "happytag"]) + expect(@node.tags).to eq(%w{sadtag happytag}) @knife.run expect(@node.tags).to eq(["happytag"]) expect(@stderr.string).to match /deleted.+sadtag/i diff --git a/spec/unit/knife/user_create_spec.rb b/spec/unit/knife/user_create_spec.rb index 5ab77d2df6..806e8cf400 100644 --- a/spec/unit/knife/user_create_spec.rb +++ b/spec/unit/knife/user_create_spec.rb @@ -79,7 +79,7 @@ describe Chef::Knife::UserCreate do context "when FIRST_NAME isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ["some_user", "some_display_name"] } + let(:name_args) { %w{some_user some_display_name} } let(:fieldname) { "first name" } end end @@ -87,7 +87,7 @@ describe Chef::Knife::UserCreate do context "when LAST_NAME isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ["some_user", "some_display_name", "some_first_name"] } + let(:name_args) { %w{some_user some_display_name some_first_name} } let(:fieldname) { "last name" } end end @@ -95,7 +95,7 @@ describe Chef::Knife::UserCreate do context "when EMAIL isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ["some_user", "some_display_name", "some_first_name", "some_last_name"] } + let(:name_args) { %w{some_user some_display_name some_first_name some_last_name} } let(:fieldname) { "email" } end end @@ -103,14 +103,14 @@ describe Chef::Knife::UserCreate do context "when PASSWORD isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ["some_user", "some_display_name", "some_first_name", "some_last_name", "some_email"] } + let(:name_args) { %w{some_user some_display_name some_first_name some_last_name some_email} } let(:fieldname) { "password" } end end context "when all mandatory fields are validly specified" do before do - knife.name_args = ["some_user", "some_display_name", "some_first_name", "some_last_name", "some_email", "some_password"] + knife.name_args = %w{some_user some_display_name some_first_name some_last_name some_email some_password} allow(knife).to receive(:edit_data).and_return(knife.user.to_hash) allow(knife).to receive(:create_user_from_hash).and_return(knife.user) end diff --git a/spec/unit/mixin/deep_merge_spec.rb b/spec/unit/mixin/deep_merge_spec.rb index 2850193eb6..2122008616 100644 --- a/spec/unit/mixin/deep_merge_spec.rb +++ b/spec/unit/mixin/deep_merge_spec.rb @@ -41,7 +41,7 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do end it "tests merging an hash w/array into blank hash" do - hash_src = { "region" => { "id" => ["227", "2"] } } + hash_src = { "region" => { "id" => %w{227 2} } } hash_dst = {} @dm.deep_merge!(hash_src, hash_dst) expect(hash_dst).to eq(hash_src) @@ -49,16 +49,16 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do it "tests merge from empty hash" do hash_src = {} - hash_dst = { "property" => ["2", "4"] } + hash_dst = { "property" => %w{2 4} } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => ["2", "4"] }) + expect(hash_dst).to eq({ "property" => %w{2 4} }) end it "tests merge to empty hash" do - hash_src = { "property" => ["2", "4"] } + hash_src = { "property" => %w{2 4} } hash_dst = {} @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => ["2", "4"] }) + expect(hash_dst).to eq({ "property" => %w{2 4} }) end it "tests simple string overwrite" do @@ -76,36 +76,36 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do end it "tests hashes holding array" do - hash_src = { "property" => ["1", "3"] } - hash_dst = { "property" => ["2", "4"] } + hash_src = { "property" => %w{1 3} } + hash_dst = { "property" => %w{2 4} } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => ["2", "4", "1", "3"] }) + expect(hash_dst).to eq({ "property" => %w{2 4 1 3} }) end it "tests hashes holding hashes holding arrays (array with duplicate elements is merged with dest then src" do - hash_src = { "property" => { "bedroom_count" => ["1", "2"], "bathroom_count" => ["1", "4+"] } } - hash_dst = { "property" => { "bedroom_count" => ["3", "2"], "bathroom_count" => ["2"] } } + hash_src = { "property" => { "bedroom_count" => %w{1 2}, "bathroom_count" => ["1", "4+"] } } + hash_dst = { "property" => { "bedroom_count" => %w{3 2}, "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => { "bedroom_count" => ["3", "2", "1"], "bathroom_count" => ["2", "1", "4+"] } }) + expect(hash_dst).to eq({ "property" => { "bedroom_count" => %w{3 2 1}, "bathroom_count" => ["2", "1", "4+"] } }) end it "tests hash holding hash holding array v string (string is overwritten by array)" do - hash_src = { "property" => { "bedroom_count" => ["1", "2"], "bathroom_count" => ["1", "4+"] } } + hash_src = { "property" => { "bedroom_count" => %w{1 2}, "bathroom_count" => ["1", "4+"] } } hash_dst = { "property" => { "bedroom_count" => "3", "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => { "bedroom_count" => ["1", "2"], "bathroom_count" => ["2", "1", "4+"] } }) + expect(hash_dst).to eq({ "property" => { "bedroom_count" => %w{1 2}, "bathroom_count" => ["2", "1", "4+"] } }) end it "tests hash holding hash holding string v array (array is overwritten by string)" do hash_src = { "property" => { "bedroom_count" => "3", "bathroom_count" => ["1", "4+"] } } - hash_dst = { "property" => { "bedroom_count" => ["1", "2"], "bathroom_count" => ["2"] } } + hash_dst = { "property" => { "bedroom_count" => %w{1 2}, "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) expect(hash_dst).to eq({ "property" => { "bedroom_count" => "3", "bathroom_count" => ["2", "1", "4+"] } }) end it "tests hash holding hash holding hash v array (array is overwritten by hash)" do hash_src = { "property" => { "bedroom_count" => { "king_bed" => 3, "queen_bed" => 1 }, "bathroom_count" => ["1", "4+"] } } - hash_dst = { "property" => { "bedroom_count" => ["1", "2"], "bathroom_count" => ["2"] } } + hash_dst = { "property" => { "bedroom_count" => %w{1 2}, "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) expect(hash_dst).to eq({ "property" => { "bedroom_count" => { "king_bed" => 3, "queen_bed" => 1 }, "bathroom_count" => ["2", "1", "4+"] } }) end @@ -142,21 +142,21 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do hash_src = { "property" => { "bedroom_count" => { "king_bed" => 3, "queen_bed" => [1] }, "bathroom_count" => ["1"] } } hash_dst = { "property" => { "bedroom_count" => { "king_bed" => [2], "queen_bed" => [4] }, "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => { "bedroom_count" => { "king_bed" => 3, "queen_bed" => [4, 1] }, "bathroom_count" => ["2", "1"] } }) + expect(hash_dst).to eq({ "property" => { "bedroom_count" => { "king_bed" => 3, "queen_bed" => [4, 1] }, "bathroom_count" => %w{2 1} } }) end it "tests 3 hash layers holding arrays of int, but source is incomplete." do hash_src = { "property" => { "bedroom_count" => { "king_bed" => [3] }, "bathroom_count" => ["1"] } } hash_dst = { "property" => { "bedroom_count" => { "king_bed" => [2], "queen_bed" => [4] }, "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => { "bedroom_count" => { "king_bed" => [2, 3], "queen_bed" => [4] }, "bathroom_count" => ["2", "1"] } }) + expect(hash_dst).to eq({ "property" => { "bedroom_count" => { "king_bed" => [2, 3], "queen_bed" => [4] }, "bathroom_count" => %w{2 1} } }) end it "tests 3 hash layers holding arrays of int, but source is shorter and has new 2nd level ints." do hash_src = { "property" => { "bedroom_count" => { 2 => 3, "king_bed" => [3] }, "bathroom_count" => ["1"] } } hash_dst = { "property" => { "bedroom_count" => { "king_bed" => [2], "queen_bed" => [4] }, "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => { "bedroom_count" => { 2 => 3, "king_bed" => [2, 3], "queen_bed" => [4] }, "bathroom_count" => ["2", "1"] } }) + expect(hash_dst).to eq({ "property" => { "bedroom_count" => { 2 => 3, "king_bed" => [2, 3], "queen_bed" => [4] }, "bathroom_count" => %w{2 1} } }) end it "tests 3 hash layers holding arrays of int, but source is empty" do @@ -174,10 +174,10 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do end it "tests hash holding arrays of arrays" do - hash_src = { ["1", "2", "3"] => ["1", "2"] } - hash_dst = { ["4", "5"] => ["3"] } + hash_src = { %w{1 2 3} => %w{1 2} } + hash_dst = { %w{4 5} => ["3"] } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ ["1", "2", "3"] => ["1", "2"], ["4", "5"] => ["3"] }) + expect(hash_dst).to eq({ %w{1 2 3} => %w{1 2}, %w{4 5} => ["3"] }) end it "tests merging of hash with blank hash, and make sure that source array split does not function when turned off" do @@ -253,7 +253,7 @@ describe Chef::Mixin::DeepMerge do it "should merge a nested hash into an empty hash" do hash_dst = {} - hash_src = { "region" => { "id" => ["227", "2"] } } + hash_src = { "region" => { "id" => %w{227 2} } } expect(@dm.merge(hash_dst, hash_src)).to eq(hash_src) end @@ -264,9 +264,9 @@ describe Chef::Mixin::DeepMerge do end it "should merge arrays within hashes" do - hash_dst = { "property" => ["2", "4"] } - hash_src = { "property" => ["1", "3"] } - expect(@dm.merge(hash_dst, hash_src)).to eq({ "property" => ["2", "4", "1", "3"] }) + hash_dst = { "property" => %w{2 4} } + hash_src = { "property" => %w{1 3} } + expect(@dm.merge(hash_dst, hash_src)).to eq({ "property" => %w{2 4 1 3} }) end it "should merge deeply nested hashes" do @@ -276,12 +276,12 @@ describe Chef::Mixin::DeepMerge do end it "should not modify the source or destination during the merge" do - hash_dst = { "property" => ["1", "2", "3"] } - hash_src = { "property" => ["4", "5", "6"] } + hash_dst = { "property" => %w{1 2 3} } + hash_src = { "property" => %w{4 5 6} } ret = @dm.merge(hash_dst, hash_src) - expect(hash_dst).to eq({ "property" => ["1", "2", "3"] }) - expect(hash_src).to eq({ "property" => ["4", "5", "6"] }) - expect(ret).to eq({ "property" => ["1", "2", "3", "4", "5", "6"] }) + expect(hash_dst).to eq({ "property" => %w{1 2 3} }) + expect(hash_src).to eq({ "property" => %w{4 5 6} }) + expect(ret).to eq({ "property" => %w{1 2 3 4 5 6} }) end it "should not error merging un-dupable objects" do diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb index 259b89032e..b3bd7af159 100644 --- a/spec/unit/mixin/params_validate_spec.rb +++ b/spec/unit/mixin/params_validate_spec.rb @@ -144,7 +144,7 @@ describe Chef::Mixin::ParamsValidate do { :one => @vo }, { :one => { - :respond_to => ["validate", "music"] + :respond_to => %w{validate music} } }, ) @@ -155,7 +155,7 @@ describe Chef::Mixin::ParamsValidate do { :one => @vo }, { :one => { - :respond_to => ["monkey", "validate"] + :respond_to => %w{monkey validate} } }, ) diff --git a/spec/unit/mixin/properties_spec.rb b/spec/unit/mixin/properties_spec.rb index 00e339a221..1af0bc7abd 100644 --- a/spec/unit/mixin/properties_spec.rb +++ b/spec/unit/mixin/properties_spec.rb @@ -9,8 +9,8 @@ module ChefMixinPropertiesSpec class A include Chef::Mixin::Properties property :a, "a", default: "a" - property :ab, ["a", "b"], default: "a" - property :ac, ["a", "c"], default: "a" + property :ab, %w{a b}, default: "a" + property :ac, %w{a c}, default: "a" end context "and a module B with properties b, ab and bc" do @@ -18,7 +18,7 @@ module ChefMixinPropertiesSpec include Chef::Mixin::Properties property :b, "b", default: "b" property :ab, default: "b" - property :bc, ["b", "c"], default: "c" + property :bc, %w{b c}, default: "c" end context "and a derived class C < A with properties c, ac and bc" do @@ -32,22 +32,22 @@ module ChefMixinPropertiesSpec it "A.properties has a, ab, and ac with types 'a', ['a', 'b'], and ['b', 'c']" do expect(A.properties.keys).to eq [ :a, :ab, :ac ] expect(A.properties[:a].validation_options[:is]).to eq "a" - expect(A.properties[:ab].validation_options[:is]).to eq [ "a", "b" ] - expect(A.properties[:ac].validation_options[:is]).to eq [ "a", "c" ] + expect(A.properties[:ab].validation_options[:is]).to eq %w{a b} + expect(A.properties[:ac].validation_options[:is]).to eq %w{a c} end it "B.properties has b, ab, and bc with types 'b', nil and ['b', 'c']" do expect(B.properties.keys).to eq [ :b, :ab, :bc ] expect(B.properties[:b].validation_options[:is]).to eq "b" expect(B.properties[:ab].validation_options[:is]).to be_nil - expect(B.properties[:bc].validation_options[:is]).to eq [ "b", "c" ] + expect(B.properties[:bc].validation_options[:is]).to eq %w{b c} end it "C.properties has a, b, c, ac and bc with merged types" do expect(C.properties.keys).to eq [ :a, :ab, :ac, :b, :bc, :c ] expect(C.properties[:a].validation_options[:is]).to eq "a" expect(C.properties[:b].validation_options[:is]).to eq "b" expect(C.properties[:c].validation_options[:is]).to eq "c" - expect(C.properties[:ac].validation_options[:is]).to eq [ "a", "c" ] - expect(C.properties[:bc].validation_options[:is]).to eq [ "b", "c" ] + expect(C.properties[:ac].validation_options[:is]).to eq %w{a c} + expect(C.properties[:bc].validation_options[:is]).to eq %w{b c} end it "C.properties has ab with a non-merged type (from B)" do expect(C.properties[:ab].validation_options[:is]).to be_nil diff --git a/spec/unit/mixin/template_spec.rb b/spec/unit/mixin/template_spec.rb index 48150f7198..ab7ed5bc5a 100644 --- a/spec/unit/mixin/template_spec.rb +++ b/spec/unit/mixin/template_spec.rb @@ -209,7 +209,7 @@ describe Chef::Mixin::Template, "render_template" do def render_template_from_string end end - ["node", "render", "render_template", "render_template_from_string"].each do |method_name| + %w{node render render_template render_template_from_string}.each do |method_name| expect(Chef::Log).to receive(:warn).with(/^Core template method `#{method_name}' overridden by extension module/) end @template_context._extend_modules([mod]) diff --git a/spec/unit/mixin/windows_architecture_helper_spec.rb b/spec/unit/mixin/windows_architecture_helper_spec.rb index aaf9fa4b2b..4559702e1c 100644 --- a/spec/unit/mixin/windows_architecture_helper_spec.rb +++ b/spec/unit/mixin/windows_architecture_helper_spec.rb @@ -59,14 +59,14 @@ describe Chef::Mixin::WindowsArchitectureHelper do it "returns true only for supported desired architecture passed to node_supports_windows_architecture" do with_node_architecture_combinations do |node, desired_arch| - expect(node_supports_windows_architecture?(node, desired_arch)).to be true if (node_windows_architecture(node) == :x86_64 || desired_arch == :i386 ) - expect(node_supports_windows_architecture?(node, desired_arch)).to be false if (node_windows_architecture(node) == :i386 && desired_arch == :x86_64 ) + expect(node_supports_windows_architecture?(node, desired_arch)).to be true if node_windows_architecture(node) == :x86_64 || desired_arch == :i386 + expect(node_supports_windows_architecture?(node, desired_arch)).to be false if node_windows_architecture(node) == :i386 && desired_arch == :x86_64 end end it "returns true only when forced_32bit_override_required? has 64-bit node architecture and 32-bit desired architecture" do with_node_architecture_combinations do |node, desired_arch| - expect(forced_32bit_override_required?(node, desired_arch)).to be true if ((node_windows_architecture(node) == :x86_64) && (desired_arch == :i386) && !is_i386_process_on_x86_64_windows?) + expect(forced_32bit_override_required?(node, desired_arch)).to be true if (node_windows_architecture(node) == :x86_64) && (desired_arch == :i386) && !is_i386_process_on_x86_64_windows? expect(forced_32bit_override_required?(node, desired_arch)).to be false if ! ((node_windows_architecture(node) == :x86_64) && (desired_arch == :i386)) end end diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb index c69748ac49..7170f62efb 100644 --- a/spec/unit/node/attribute_spec.rb +++ b/spec/unit/node/attribute_spec.rb @@ -29,7 +29,7 @@ describe Chef::Node::Attribute do "platform" => "mac_os_x", "ipaddress" => "192.168.0.117", "network" => { "default_interface" => "en1", - "interfaces" => { "vmnet1" => { "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "interfaces" => { "vmnet1" => { "flags" => %w{UP BROADCAST SMART RUNNING SIMPLEX MULTICAST}, "number" => "1", "addresses" => { "00:50:56:c0:00:01" => { "family" => "lladdr" }, "192.168.110.1" => { "broadcast" => "192.168.110.255", @@ -45,7 +45,7 @@ describe Chef::Node::Attribute do "mtu" => "1280", "type" => "stf", "encapsulation" => "6to4" }, - "lo0" => { "flags" => ["UP", "LOOPBACK", "RUNNING", "MULTICAST"], + "lo0" => { "flags" => %w{UP LOOPBACK RUNNING MULTICAST}, "number" => "0", "addresses" => { "::1" => { "scope" => "Node", "prefixlen" => "128", "family" => "inet6" }, "127.0.0.1" => { "netmask" => "255.0.0.0", "family" => "inet" }, @@ -53,13 +53,13 @@ describe Chef::Node::Attribute do "mtu" => "16384", "type" => "lo", "encapsulation" => "Loopback" }, - "gif0" => { "flags" => ["POINTOPOINT", "MULTICAST"], + "gif0" => { "flags" => %w{POINTOPOINT MULTICAST}, "number" => "0", "addresses" => {}, "mtu" => "1280", "type" => "gif", "encapsulation" => "IPIP" }, - "vmnet8" => { "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "vmnet8" => { "flags" => %w{UP BROADCAST SMART RUNNING SIMPLEX MULTICAST}, "number" => "8", "addresses" => { "192.168.4.1" => { "broadcast" => "192.168.4.255", "netmask" => "255.255.255.0", @@ -70,7 +70,7 @@ describe Chef::Node::Attribute do "arp" => { "192.168.4.255" => "ff:ff:ff:ff:ff:ff" }, "encapsulation" => "Ethernet" }, "en0" => { "status" => "inactive", - "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "flags" => %w{UP BROADCAST SMART RUNNING SIMPLEX MULTICAST}, "number" => "0", "addresses" => { "00:23:32:b0:32:f2" => { "family" => "lladdr" } }, "mtu" => "1500", @@ -83,7 +83,7 @@ describe Chef::Node::Attribute do "type" => "en", "encapsulation" => "Ethernet" }, "en1" => { "status" => "active", - "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "flags" => %w{UP BROADCAST SMART RUNNING SIMPLEX MULTICAST}, "number" => "1", "addresses" => { "fe80::223:6cff:fe7f:676c" => { "scope" => "Link", "prefixlen" => "64", "family" => "inet6" }, "00:23:6c:7f:67:6c" => { "family" => "lladdr" }, @@ -102,7 +102,7 @@ describe Chef::Node::Attribute do "192.168.0.152" => "0:26:8:7d:2:4c" }, "encapsulation" => "Ethernet" }, "en2" => { "status" => "active", - "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "flags" => %w{UP BROADCAST SMART RUNNING SIMPLEX MULTICAST}, "number" => "2", "addresses" => { "169.254.206.152" => { "broadcast" => "169.254.255.255", "netmask" => "255.255.0.0", @@ -115,7 +115,7 @@ describe Chef::Node::Attribute do "type" => "en", "encapsulation" => "Ethernet" }, "fw0" => { "status" => "inactive", - "flags" => ["BROADCAST", "SIMPLEX", "MULTICAST"], + "flags" => %w{BROADCAST SIMPLEX MULTICAST}, "number" => "0", "addresses" => { "00:23:32:ff:fe:b0:32:f2" => { "family" => "lladdr" } }, "mtu" => "4078", @@ -124,7 +124,7 @@ describe Chef::Node::Attribute do "type" => "fw", "encapsulation" => "1394" }, "en3" => { "status" => "active", - "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "flags" => %w{UP BROADCAST SMART RUNNING SIMPLEX MULTICAST}, "number" => "3", "addresses" => { "169.254.206.152" => { "broadcast" => "169.254.255.255", "netmask" => "255.255.0.0", @@ -219,16 +219,16 @@ describe Chef::Node::Attribute do it "gives the value at each level of precedence for a path spec" do expected = [["set_unless_enabled?", false], - ["default", "default"], - ["env_default", "env_default"], - ["role_default", "role_default"], - ["force_default", "force_default"], - ["normal", "normal"], - ["override", "override"], - ["role_override", "role_override"], - ["env_override", "env_override"], - ["force_override", "force_override"], - ["automatic", "automatic"], + %w{default default}, + %w{env_default env_default}, + %w{role_default role_default}, + %w{force_default force_default}, + %w{normal normal}, + %w{override override}, + %w{role_override role_override}, + %w{env_override env_override}, + %w{force_override force_override}, + %w{automatic automatic}, ] expect(@attributes.debug_value(:foo, :bar)).to eq(expected) end @@ -457,7 +457,7 @@ describe Chef::Node::Attribute do hash = @attributes["foo"].to_hash expect(hash).to eql({ "bar" => [ "fizz" ] }) hash["bar"].push("buzz") - expect(hash).to eql({ "bar" => [ "fizz", "buzz" ] }) + expect(hash).to eql({ "bar" => %w{fizz buzz} }) expect(@attributes.default["foo"]).to eql({ "bar" => [ "fizz" ] }) end @@ -537,8 +537,8 @@ describe Chef::Node::Attribute do end it "should allow the last method to set a value if it has an = sign on the end" do - @attributes.normal.music.mastodon = [ "dream", "still", "shining" ] - expect(@attributes.normal.music.mastodon).to eq([ "dream", "still", "shining" ]) + @attributes.normal.music.mastodon = %w{dream still shining} + expect(@attributes.normal.music.mastodon).to eq(%w{dream still shining}) end end @@ -999,9 +999,9 @@ describe Chef::Node::Attribute do it "should return a new array of k,v pairs for which the block returns true" do expect(@attributes.select { true }.sort).to eq( [ - ["hut", "three"], - ["one", "six"], - ["snack", "cookies"], + %w{hut three}, + %w{one six}, + %w{snack cookies}, ["snakes", "on a plane"], ] ) diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index d3c58c6f6a..5304ac9f92 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -291,9 +291,9 @@ describe Chef::Node do end it "should let you use tag as a convience method for the tags attribute" do - node.normal["tags"] = ["one", "two"] + node.normal["tags"] = %w{one two} node.tag("three", "four") - expect(node["tags"]).to eq(["one", "two", "three", "four"]) + expect(node["tags"]).to eq(%w{one two three four}) end end @@ -766,15 +766,15 @@ describe Chef::Node do end it "should overwrites the run list with the run list it consumes" do - node.consume_run_list "recipes" => [ "one", "two" ] + node.consume_run_list "recipes" => %w{one two} node.consume_run_list "recipes" => [ "three" ] expect(node.run_list).to eq([ "three" ]) end it "should not add duplicate recipes from the json attributes" do node.run_list << "one" - node.consume_run_list "recipes" => [ "one", "two", "three" ] - expect(node.run_list).to eq([ "one", "two", "three" ]) + node.consume_run_list "recipes" => %w{one two three} + expect(node.run_list).to eq(%w{one two three}) end it "doesn't change the run list if no run_list is specified in the json" do @@ -887,7 +887,7 @@ describe Chef::Node do it "sets the 'roles' automatic attribute to the expanded role list" do @expansion.instance_variable_set(:@applied_roles, { "arf" => nil, "countersnark" => nil }) node.expand! - expect(node.automatic_attrs[:roles].sort).to eq(["arf", "countersnark"]) + expect(node.automatic_attrs[:roles].sort).to eq(%w{arf countersnark}) end it "applies default attributes from the environment as environment defaults" do diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb index 6b71b4d43e..40f4daaf76 100644 --- a/spec/unit/policy_builder/policyfile_spec.rb +++ b/spec/unit/policy_builder/policyfile_spec.rb @@ -660,7 +660,7 @@ describe Chef::PolicyBuilder::Policyfile do expect_any_instance_of(Chef::CookbookCollection).to receive(:validate!) run_context = policy_builder.setup_run_context expect(run_context.node).to eq(node) - expect(run_context.cookbook_collection.keys).to match_array(["example1", "example2"]) + expect(run_context.cookbook_collection.keys).to match_array(%w{example1 example2}) end it "makes the run context available via static method on Chef" do diff --git a/spec/unit/property/validation_spec.rb b/spec/unit/property/validation_spec.rb index 0b2a8e0bc9..db3c9fe4f6 100644 --- a/spec/unit/property/validation_spec.rb +++ b/spec/unit/property/validation_spec.rb @@ -292,7 +292,7 @@ describe "Chef::Resource.property validation" do # Regex validation_test "is: /abc/", - [ "abc", "wowabcwow" ], + %w{abc wowabcwow}, [ "", "abac" ] # Property @@ -427,17 +427,17 @@ describe "Chef::Resource.property validation" do :nil_is_valid validation_test "regex: [ /abc/, /z/ ]", - [ "xabcy", "aza" ], + %w{xabcy aza}, [ "gbh", 123 ], :nil_is_valid validation_test "regex: [ /z/, /abc/ ]", - [ "xabcy", "aza" ], + %w{xabcy aza}, [ "gbh", 123 ], :nil_is_valid validation_test "regex: [ [ /z/, /abc/ ], [ /n/ ] ]", - [ "xabcy", "aza", "ana" ], + %w{xabcy aza ana}, [ "gbh", 123 ], :nil_is_valid diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index ecea666072..f5eb361426 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -985,7 +985,7 @@ describe "Chef::Resource.property" do end end - [ "name_attribute", "name_property" ].each do |name| + %w{name_attribute name_property}.each do |name| context "Chef::Resource::Property##{name}" do with_property ":x, #{name}: true" do it "defaults x to resource.name" do diff --git a/spec/unit/provider/file/content_spec.rb b/spec/unit/provider/file/content_spec.rb index ebef4faa09..9ebcf10dcc 100644 --- a/spec/unit/provider/file/content_spec.rb +++ b/spec/unit/provider/file/content_spec.rb @@ -66,13 +66,13 @@ describe Chef::Provider::File::Content do it "returns a tempfile in the tempdir when :file_staging_uses_destdir is not set" do Chef::Config[:file_staging_uses_destdir] = false - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_truthy + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be_truthy expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_falsey end it "returns a tempfile in the destdir when :file_deployment_uses_destdir is set" do Chef::Config[:file_staging_uses_destdir] = true - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_falsey + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be_falsey expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_truthy end @@ -83,7 +83,7 @@ describe Chef::Provider::File::Content do it "returns a tempfile in the tempdir when :file_deployment_uses_destdir is set to :auto" do Chef::Config[:file_staging_uses_destdir] = :auto - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_truthy + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be_truthy expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_falsey end @@ -93,7 +93,7 @@ describe Chef::Provider::File::Content do end it "returns a tempfile in the tempdir when :file_desployment_uses_destdir is not set" do - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_truthy + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be_truthy expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_falsey end end diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb index 52aff87dc5..bc69d7580e 100644 --- a/spec/unit/provider/group/dscl_spec.rb +++ b/spec/unit/provider/group/dscl_spec.rb @@ -184,7 +184,7 @@ describe Chef::Provider::Group::Dscl do before do allow(@new_resource).to receive(:members).and_return([]) allow(@new_resource).to receive(:append).and_return(false) - allow(@current_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(@current_resource).to receive(:members).and_return(%w{all your base}) end it "should log an appropriate message" do @@ -201,7 +201,7 @@ describe Chef::Provider::Group::Dscl do describe "with supplied members in the new resource" do before do - @new_resource.members(["all", "your", "base"]) + @new_resource.members(%w{all your base}) @current_resource.members([]) end @@ -326,6 +326,6 @@ EOF end it "should parse members properly" do allow(File).to receive(:exists?).and_return(true) - expect(@current_resource.members).to eq(["waka", "bar"]) + expect(@current_resource.members).to eq(%w{waka bar}) end end diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb index b4295c9dff..87ab3c3493 100644 --- a/spec/unit/provider/group/groupadd_spec.rb +++ b/spec/unit/provider/group/groupadd_spec.rb @@ -25,12 +25,12 @@ describe Chef::Provider::Group::Groupadd, "set_options" do @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Group.new("aj") @new_resource.gid(50) - @new_resource.members(["root", "aj"]) + @new_resource.members(%w{root aj}) @new_resource.system false @new_resource.non_unique false @current_resource = Chef::Resource::Group.new("aj") @current_resource.gid(50) - @current_resource.members(["root", "aj"]) + @current_resource.members(%w{root aj}) @current_resource.system false @current_resource.non_unique false @provider = Chef::Provider::Group::Groupadd.new(@new_resource, @run_context) diff --git a/spec/unit/provider/group/pw_spec.rb b/spec/unit/provider/group/pw_spec.rb index 2c563750f3..97ffcb3c31 100644 --- a/spec/unit/provider/group/pw_spec.rb +++ b/spec/unit/provider/group/pw_spec.rb @@ -26,11 +26,11 @@ describe Chef::Provider::Group::Pw do @new_resource = Chef::Resource::Group.new("wheel") @new_resource.gid 50 - @new_resource.members [ "root", "aj"] + @new_resource.members %w{root aj} @current_resource = Chef::Resource::Group.new("aj") @current_resource.gid 50 - @current_resource.members [ "root", "aj"] + @current_resource.members %w{root aj} @provider = Chef::Provider::Group::Pw.new(@new_resource, @run_context) @provider.current_resource = @current_resource end @@ -89,7 +89,7 @@ describe Chef::Provider::Group::Pw do describe "with an empty members array in the new resource and existing members in the current resource" do before do allow(@new_resource).to receive(:members).and_return([]) - allow(@current_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(@current_resource).to receive(:members).and_return(%w{all your base}) end it "should log an appropriate message" do @@ -104,7 +104,7 @@ describe Chef::Provider::Group::Pw do describe "with supplied members array in the new resource and an empty members array in the current resource" do before do - allow(@new_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(@new_resource).to receive(:members).and_return(%w{all your base}) allow(@current_resource).to receive(:members).and_return([]) end diff --git a/spec/unit/provider/group/usermod_spec.rb b/spec/unit/provider/group/usermod_spec.rb index 1a718b1d40..7bd45c4f1b 100644 --- a/spec/unit/provider/group/usermod_spec.rb +++ b/spec/unit/provider/group/usermod_spec.rb @@ -24,7 +24,7 @@ describe Chef::Provider::Group::Usermod do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Group.new("wheel") - @new_resource.members [ "all", "your", "base" ] + @new_resource.members %w{all your base} @new_resource.excluded_members [ ] @provider = Chef::Provider::Group::Usermod.new(@new_resource, @run_context) allow(@provider).to receive(:run_command) @@ -56,7 +56,7 @@ describe Chef::Provider::Group::Usermod do } before do - allow(@new_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(@new_resource).to receive(:members).and_return(%w{all your base}) allow(File).to receive(:exists?).and_return(true) end diff --git a/spec/unit/provider/group/windows_spec.rb b/spec/unit/provider/group/windows_spec.rb index c331e2b021..c424e35e0e 100644 --- a/spec/unit/provider/group/windows_spec.rb +++ b/spec/unit/provider/group/windows_spec.rb @@ -50,7 +50,7 @@ describe Chef::Provider::Group::Windows do before do @new_resource.members([ "us" ]) @current_resource = Chef::Resource::Group.new("staff") - @current_resource.members [ "all", "your", "base" ] + @current_resource.members %w{all your base} allow(Chef::Util::Windows::NetGroup).to receive(:new).and_return(@net_group) allow(@net_group).to receive(:local_add_members) diff --git a/spec/unit/provider/group_spec.rb b/spec/unit/provider/group_spec.rb index d41b0689ee..f056114d89 100644 --- a/spec/unit/provider/group_spec.rb +++ b/spec/unit/provider/group_spec.rb @@ -39,7 +39,7 @@ describe Chef::Provider::User do @pw_group = double("Struct::Group", :name => "wheel", :gid => 20, - :mem => [ "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/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb index 50ed356049..52be15b2a8 100644 --- a/spec/unit/provider/mount/mount_spec.rb +++ b/spec/unit/provider/mount/mount_spec.rb @@ -107,7 +107,7 @@ describe Chef::Provider::Mount::Mount do expect { @provider.load_current_resource();@provider.mountable? }.to raise_error(Chef::Exceptions::Mount) end - [ "tmpfs", "fuse", "cgroup" ].each do |fstype| + %w{tmpfs fuse cgroup}.each do |fstype| it "does not expect the device to exist for #{fstype}" do @new_resource.fstype(fstype) @new_resource.device("whatever") diff --git a/spec/unit/provider/mount/solaris_spec.rb b/spec/unit/provider/mount/solaris_spec.rb index a6d0620df6..51ace83470 100644 --- a/spec/unit/provider/mount/solaris_spec.rb +++ b/spec/unit/provider/mount/solaris_spec.rb @@ -316,7 +316,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end it "should set the options field on the current_resource" do - expect(provider.current_resource.options).to eql(["rw", "soft"]) + expect(provider.current_resource.options).to eql(%w{rw soft}) end it "should set the pass field on the current_resource" do diff --git a/spec/unit/provider/package/chocolatey_spec.rb b/spec/unit/provider/package/chocolatey_spec.rb index aeb420fa7a..a347aa7ebd 100644 --- a/spec/unit/provider/package/chocolatey_spec.rb +++ b/spec/unit/provider/package/chocolatey_spec.rb @@ -95,26 +95,26 @@ munin-node|1.6.1.20130823 end it "should set the candidate_version correctly when there are two packages to install" do - allow_remote_list(["ConEmu", "chocolatey"]) - new_resource.package_name(["ConEmu", "chocolatey"]) + allow_remote_list(%w{ConEmu chocolatey}) + new_resource.package_name(%w{ConEmu chocolatey}) expect(provider.candidate_version).to eql(["15.10.25.1", "0.9.9.11"]) end it "should set the candidate_version correctly when only the first is installable" do - allow_remote_list(["ConEmu", "vim"]) - new_resource.package_name(["ConEmu", "vim"]) + allow_remote_list(%w{ConEmu vim}) + new_resource.package_name(%w{ConEmu vim}) expect(provider.candidate_version).to eql(["15.10.25.1", nil]) end it "should set the candidate_version correctly when only the last is installable" do - allow_remote_list(["vim", "chocolatey"]) - new_resource.package_name(["vim", "chocolatey"]) + allow_remote_list(%w{vim chocolatey}) + new_resource.package_name(%w{vim chocolatey}) expect(provider.candidate_version).to eql([nil, "0.9.9.11"]) end it "should set the candidate_version correctly when neither are is installable" do - allow_remote_list(["vim", "ruby"]) - new_resource.package_name(["vim", "ruby"]) + allow_remote_list(%w{vim ruby}) + new_resource.package_name(%w{vim ruby}) expect(provider.candidate_version).to eql([nil, nil]) end end @@ -156,25 +156,25 @@ munin-node|1.6.1.20130823 end it "should set the current_resource.version when there are two packages that are installed" do - new_resource.package_name(["ConEmu", "chocolatey"]) + new_resource.package_name(%w{ConEmu chocolatey}) provider.load_current_resource expect(provider.current_resource.version).to eql(["15.10.25.0", "0.9.9.11"]) end it "should set the current_resource.version correctly when only the first is installed" do - new_resource.package_name(["ConEmu", "git"]) + new_resource.package_name(%w{ConEmu git}) provider.load_current_resource expect(provider.current_resource.version).to eql(["15.10.25.0", nil]) end it "should set the current_resource.version correctly when only the last is installed" do - new_resource.package_name(["git", "chocolatey"]) + new_resource.package_name(%w{git chocolatey}) provider.load_current_resource expect(provider.current_resource.version).to eql([nil, "0.9.9.11"]) end it "should set the current_resource.version correctly when none are installed" do - new_resource.package_name(["git", "vim"]) + new_resource.package_name(%w{git vim}) provider.load_current_resource expect(provider.current_resource.version).to eql([nil, nil]) end @@ -233,8 +233,8 @@ munin-node|1.6.1.20130823 # chocolatey will be pruned by the superclass out of the args to install_package and we # implicitly test that we correctly pick up new_resource.version[1] instead of # new_version.resource[0] - allow_remote_list(["chocolatey", "ConEmu"]) - new_resource.package_name(["chocolatey", "ConEmu"]) + allow_remote_list(%w{chocolatey ConEmu}) + new_resource.package_name(%w{chocolatey ConEmu}) new_resource.version([nil, "15.10.25.1"]) provider.load_current_resource expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -version 15.10.25.1 conemu", { :timeout => timeout }).and_return(double) @@ -253,8 +253,8 @@ munin-node|1.6.1.20130823 end it "should split up commands when given two packages, one with a version pin" do - allow_remote_list(["ConEmu", "git"]) - new_resource.package_name(["ConEmu", "git"]) + allow_remote_list(%w{ConEmu git}) + new_resource.package_name(%w{ConEmu git}) new_resource.version(["15.10.25.1", nil]) provider.load_current_resource expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -version 15.10.25.1 conemu", { :timeout => timeout }).and_return(double) @@ -371,8 +371,8 @@ munin-node|1.6.1.20130823 end it "upgrading multiple packages uses a single command" do - allow_remote_list(["conemu", "git"]) - new_resource.package_name(["conemu", "git"]) + allow_remote_list(%w{conemu git}) + new_resource.package_name(%w{conemu git}) expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y conemu git", { :timeout => timeout }).and_return(double) provider.run_action(:upgrade) expect(new_resource).to be_updated_by_last_action @@ -441,8 +441,8 @@ munin-node|1.6.1.20130823 it "removes a single package when its the only one installed" do pending "this is a bug in the superclass" - allow_remote_list(["git", "conemu"]) - new_resource.package_name(["git", "conemu"]) + allow_remote_list(%w{git conemu}) + new_resource.package_name(%w{git conemu}) provider.load_current_resource expect(provider).to receive(:shell_out!).with("#{choco_exe} uninstall -y conemu", { :timeout => timeout }).and_return(double) provider.run_action(:remove) diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index 98fe9551a6..2b3048bc19 100644 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -987,7 +987,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do end it "tests isalnum good input" do - [ "a", "z", "A", "Z", "0", "9" ].each do |t| + %w{a z A Z 0 9}.each do |t| expect(@rpmutils.isalnum(t)).to eq(true) end end @@ -999,7 +999,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do end it "tests isalpha good input" do - [ "a", "z", "A", "Z" ].each do |t| + %w{a z A Z}.each do |t| expect(@rpmutils.isalpha(t)).to eq(true) end end @@ -1011,7 +1011,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do end it "tests isdigit good input" do - [ "0", "9" ].each do |t| + %w{0 9}.each do |t| expect(@rpmutils.isdigit(t)).to eq(true) end end @@ -1119,8 +1119,8 @@ describe Chef::Provider::Package::Yum::RPMVersion do "3.3-15.el5" ], [ "alpha9.8", "beta9.8" ], - [ "14jpp", - "15jpp" ], + %w{14jpp +15jpp}, [ "0.9.0-0.6", "0.9.0-0.7" ], [ "0:1.9", @@ -1297,8 +1297,8 @@ describe Chef::Provider::Package::Yum::RPMPackage do "B-test" ], [ "Aa-test", "aA-test" ], - [ "1test", - "2test" ], + %w{1test +2test}, ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMPackage.new(smaller, "0:0.0.1-1", "x86_64", []) lg = Chef::Provider::Package::Yum::RPMPackage.new(larger, "0:0.0.1-1", "x86_64", []) @@ -1310,12 +1310,12 @@ describe Chef::Provider::Package::Yum::RPMPackage do it "should sort alphabetically based on package arch" do [ - [ "i386", - "x86_64" ], - [ "i386", - "noarch" ], - [ "noarch", - "x86_64" ], + %w{i386 +x86_64}, + %w{i386 +noarch}, + %w{noarch +x86_64}, ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "0:0.0.1-1", smaller, []) lg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "0:0.0.1-1", larger, []) @@ -2113,7 +2113,7 @@ describe "Chef::Provider::Package::Yum - Multi" do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) - @new_resource = Chef::Resource::Package.new(["cups", "vim"]) + @new_resource = Chef::Resource::Package.new(%w{cups vim}) @status = double("Status", :exitstatus => 0) @yum_cache = double( "Chef::Provider::Yum::YumCache", @@ -2142,7 +2142,7 @@ describe "Chef::Provider::Package::Yum - Multi" do it "should set the current resources package name to the new resources package name" do @provider.load_current_resource - expect(@provider.current_resource.package_name).to eq(["cups", "vim"]) + expect(@provider.current_resource.package_name).to eq(%w{cups vim}) end it "should set the installed version to nil on the current resource if no installed package" do @@ -2196,9 +2196,9 @@ describe "Chef::Provider::Package::Yum - Multi" do expect(Chef::Log).to receive(:debug).exactly(1).times.with(%r{candidate version: \["1.2.4-11.18.el5_2.3", "24.4"\]}) expect(Chef::Log).to receive(:debug).at_least(2).times.with(%r{checking yum info}) @provider.load_current_resource - expect(@provider.new_resource.package_name).to eq(["cups", "emacs"]) + expect(@provider.new_resource.package_name).to eq(%w{cups emacs}) expect(@provider.new_resource.version).to eq(["1.2.4-11.18.el5_2.3", "24.4"]) - expect(@provider.send(:package_name_array)).to eq(["cups", "emacs"]) + expect(@provider.send(:package_name_array)).to eq(%w{cups emacs}) expect(@provider.send(:new_version_array)).to eq(["1.2.4-11.18.el5_2.3", "24.4"]) end end @@ -2213,7 +2213,7 @@ describe "Chef::Provider::Package::Yum - Multi" do expect(@provider).to receive(:yum_command).with( "-d0 -e0 -y install cups-1.2.4-11.19.el5 vim-1.0" ) - @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", "1.0"]) + @provider.install_package(%w{cups vim}, ["1.2.4-11.19.el5", "1.0"]) end it "should run yum install with the package name, version and arch" do @@ -2223,7 +2223,7 @@ describe "Chef::Provider::Package::Yum - Multi" do expect(@provider).to receive(:yum_command).with( "-d0 -e0 -y install cups-1.2.4-11.19.el5.i386 vim-1.0.i386" ) - @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", "1.0"]) + @provider.install_package(%w{cups vim}, ["1.2.4-11.19.el5", "1.0"]) end it "installs the package with the options given in the resource" do @@ -2235,7 +2235,7 @@ describe "Chef::Provider::Package::Yum - Multi" do "-d0 -e0 -y --disablerepo epmd install cups-1.2.4-11.19.el5 vim-1.0" ) allow(@new_resource).to receive(:options).and_return("--disablerepo epmd") - @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", "1.0"]) + @provider.install_package(%w{cups vim}, ["1.2.4-11.19.el5", "1.0"]) end it "should run yum install with the package name and version when name has arch" do @@ -2260,7 +2260,7 @@ describe "Chef::Provider::Package::Yum - Multi" do expect(@provider).to receive(:yum_command).with( "-d0 -e0 -y install cups-1.2.4-11.19.el5.x86_64 vim-1.0" ) - @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", "1.0"]) + @provider.install_package(%w{cups vim}, ["1.2.4-11.19.el5", "1.0"]) end end diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb index c998c93d6e..df0a1da9a2 100644 --- a/spec/unit/provider/package/zypper_spec.rb +++ b/spec/unit/provider/package/zypper_spec.rb @@ -254,7 +254,7 @@ describe Chef::Provider::Package::Zypper do shell_out_expectation!( "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0 vim=2.0" ) - provider.install_package(["emacs", "vim"], ["1.0", "2.0"]) + provider.install_package(%w{emacs vim}, ["1.0", "2.0"]) end it "should remove an array of package names and versions" do @@ -262,7 +262,7 @@ describe Chef::Provider::Package::Zypper do shell_out_expectation!( "zypper --non-interactive --no-gpg-checks remove emacs=1.0 vim=2.0" ) - provider.remove_package(["emacs", "vim"], ["1.0", "2.0"]) + provider.remove_package(%w{emacs vim}, ["1.0", "2.0"]) end end end diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb index 50016c623d..9f2b019a84 100644 --- a/spec/unit/provider/package_spec.rb +++ b/spec/unit/provider/package_spec.rb @@ -44,7 +44,7 @@ describe Chef::Provider::Package do end it "raises a Chef::Exceptions::InvalidResourceSpecification if both multipackage and source are provided" do - new_resource.package_name(["a", "b"]) + new_resource.package_name(%w{a b}) new_resource.source("foo") expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::InvalidResourceSpecification) end @@ -563,8 +563,8 @@ describe "Chef::Provider::Package - Multi" do let(:node) { Chef::Node.new } let(:events) { Chef::EventDispatch::Dispatcher.new } let(:run_context) { Chef::RunContext.new(node, {}, events) } - let(:new_resource) { Chef::Resource::Package.new(["emacs", "vi"]) } - let(:current_resource) { Chef::Resource::Package.new(["emacs", "vi"]) } + let(:new_resource) { Chef::Resource::Package.new(%w{emacs vi}) } + let(:current_resource) { Chef::Resource::Package.new(%w{emacs vi}) } let(:candidate_version) { [ "1.0", "6.2" ] } let(:provider) do provider = Chef::Provider::Package.new(new_resource, run_context) @@ -581,7 +581,7 @@ describe "Chef::Provider::Package - Multi" do it "installs the candidate versions when none are installed" do expect(provider).to receive(:install_package).with( - ["emacs", "vi"], + %w{emacs vi}, ["1.0", "6.2"], ).and_return(true) provider.run_action(:install) @@ -731,7 +731,7 @@ describe "Chef::Provider::Package - Multi" do it "should remove the packages if all are installed" do expect(provider).to be_removing_package - expect(provider).to receive(:remove_package).with(["emacs", "vi"], nil) + expect(provider).to receive(:remove_package).with(%w{emacs vi}, nil) provider.run_action(:remove) expect(new_resource).to be_updated expect(new_resource).to be_updated_by_last_action @@ -740,7 +740,7 @@ describe "Chef::Provider::Package - Multi" do it "should remove the packages if some are installed" do current_resource.version ["1.0", nil] expect(provider).to be_removing_package - expect(provider).to receive(:remove_package).with(["emacs", "vi"], nil) + expect(provider).to receive(:remove_package).with(%w{emacs vi}, nil) provider.run_action(:remove) expect(new_resource).to be_updated expect(new_resource).to be_updated_by_last_action @@ -749,7 +749,7 @@ describe "Chef::Provider::Package - Multi" do it "should remove the packages at a specific version if they are installed at that version" do new_resource.version ["1.0", "6.2"] expect(provider).to be_removing_package - expect(provider).to receive(:remove_package).with(["emacs", "vi"], ["1.0", "6.2"]) + expect(provider).to receive(:remove_package).with(%w{emacs vi}, ["1.0", "6.2"]) provider.run_action(:remove) expect(new_resource).to be_updated_by_last_action end @@ -757,7 +757,7 @@ describe "Chef::Provider::Package - Multi" do it "should remove the packages at a specific version any are is installed at that version" do new_resource.version ["0.5", "6.2"] expect(provider).to be_removing_package - expect(provider).to receive(:remove_package).with(["emacs", "vi"], ["0.5", "6.2"]) + expect(provider).to receive(:remove_package).with(%w{emacs vi}, ["0.5", "6.2"]) provider.run_action(:remove) expect(new_resource).to be_updated_by_last_action end @@ -787,7 +787,7 @@ describe "Chef::Provider::Package - Multi" do it "should purge the packages if all are installed" do expect(provider).to be_removing_package - expect(provider).to receive(:purge_package).with(["emacs", "vi"], nil) + expect(provider).to receive(:purge_package).with(%w{emacs vi}, nil) provider.run_action(:purge) expect(new_resource).to be_updated expect(new_resource).to be_updated_by_last_action @@ -796,7 +796,7 @@ describe "Chef::Provider::Package - Multi" do it "should purge the packages if some are installed" do current_resource.version ["1.0", nil] expect(provider).to be_removing_package - expect(provider).to receive(:purge_package).with(["emacs", "vi"], nil) + expect(provider).to receive(:purge_package).with(%w{emacs vi}, nil) provider.run_action(:purge) expect(new_resource).to be_updated expect(new_resource).to be_updated_by_last_action @@ -805,7 +805,7 @@ describe "Chef::Provider::Package - Multi" do it "should purge the packages at a specific version if they are installed at that version" do new_resource.version ["1.0", "6.2"] expect(provider).to be_removing_package - expect(provider).to receive(:purge_package).with(["emacs", "vi"], ["1.0", "6.2"]) + expect(provider).to receive(:purge_package).with(%w{emacs vi}, ["1.0", "6.2"]) provider.run_action(:purge) expect(new_resource).to be_updated_by_last_action end @@ -813,7 +813,7 @@ describe "Chef::Provider::Package - Multi" do it "should purge the packages at a specific version any are is installed at that version" do new_resource.version ["0.5", "6.2"] expect(provider).to be_removing_package - expect(provider).to receive(:purge_package).with(["emacs", "vi"], ["0.5", "6.2"]) + expect(provider).to receive(:purge_package).with(%w{emacs vi}, ["0.5", "6.2"]) provider.run_action(:purge) expect(new_resource).to be_updated_by_last_action end diff --git a/spec/unit/provider/service/arch_service_spec.rb b/spec/unit/provider/service/arch_service_spec.rb index 47f874cc0e..506a1616c5 100644 --- a/spec/unit/provider/service/arch_service_spec.rb +++ b/spec/unit/provider/service/arch_service_spec.rb @@ -180,7 +180,7 @@ RUNNING_PS it "should add chef to DAEMONS array" do allow(::File).to receive(:read).with("/etc/rc.conf").and_return("DAEMONS=(network)") - expect(@provider).to receive(:update_daemons).with(["network", "chef"]) + expect(@provider).to receive(:update_daemons).with(%w{network chef}) @provider.enable_service() end end diff --git a/spec/unit/provider/service/freebsd_service_spec.rb b/spec/unit/provider/service/freebsd_service_spec.rb index e64aa517e2..68d4d63991 100644 --- a/spec/unit/provider/service/freebsd_service_spec.rb +++ b/spec/unit/provider/service/freebsd_service_spec.rb @@ -495,7 +495,7 @@ EOF allow(provider).to receive(:service_enable_variable_name).and_return("#{new_resource.service_name}_enable") end - [ "start", "reload", "restart", "enable" ].each do |action| + %w{start reload restart enable}.each do |action| it "should raise an exception when the action is #{action}" do provider.define_resource_requirements provider.action = action @@ -503,7 +503,7 @@ EOF end end - [ "stop", "disable" ].each do |action| + %w{stop disable}.each do |action| it "should not raise an error when the action is #{action}" do provider.define_resource_requirements provider.action = action @@ -518,7 +518,7 @@ EOF allow(provider).to receive(:service_enable_variable_name).and_return(nil) end - [ "start", "reload", "restart", "enable" ].each do |action| + %w{start reload restart enable}.each do |action| it "should raise an exception when the action is #{action}" do provider.action = action provider.define_resource_requirements @@ -526,7 +526,7 @@ EOF end end - [ "stop", "disable" ].each do |action| + %w{stop disable}.each do |action| it "should not raise an error when the action is #{action}" do provider.action = action provider.define_resource_requirements @@ -558,7 +558,7 @@ EOF it "should enable the service if it is not enabled and not already specified in the rc.conf file" do allow(current_resource).to receive(:enabled).and_return(false) - expect(provider).to receive(:read_rc_conf).and_return([ "foo", "bar" ]) + expect(provider).to receive(:read_rc_conf).and_return(%w{foo bar}) expect(provider).to receive(:write_rc_conf).with(["foo", "bar", "#{new_resource.service_name}_enable=\"YES\""]) provider.enable_service() end diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 29ebf2da11..12f97431ba 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -58,7 +58,7 @@ describe Chef::Provider::Service::Macosx do </plist> XML - ["Daemon", "Agent"].each do |service_type| + %w{Daemon Agent}.each do |service_type| ["redis-server", "io.redis.redis-server"].each do |service_name| ["10.9", "10.10", "10.11"].each do |platform_version| let(:plist) { "/Library/LaunchDaemons/io.redis.redis-server.plist" } diff --git a/spec/unit/provider/service/openbsd_service_spec.rb b/spec/unit/provider/service/openbsd_service_spec.rb index 7b64214e65..b11015a63a 100644 --- a/spec/unit/provider/service/openbsd_service_spec.rb +++ b/spec/unit/provider/service/openbsd_service_spec.rb @@ -338,7 +338,7 @@ describe Chef::Provider::Service::Openbsd do allow(provider).to receive(:builtin_service_enable_variable_name).and_return("#{new_resource.service_name}_enable") end - [ "start", "reload", "restart", "enable" ].each do |action| + %w{start reload restart enable}.each do |action| it "should raise an exception when the action is #{action}" do provider.define_resource_requirements provider.action = action @@ -346,7 +346,7 @@ describe Chef::Provider::Service::Openbsd do end end - [ "stop", "disable" ].each do |action| + %w{stop disable}.each do |action| it "should not raise an error when the action is #{action}" do provider.define_resource_requirements provider.action = action @@ -360,7 +360,7 @@ describe Chef::Provider::Service::Openbsd do allow(provider).to receive(:builtin_service_enable_variable_name).and_return(nil) end - [ "start", "reload", "restart", "enable" ].each do |action| + %w{start reload restart enable}.each do |action| it "should raise an exception when the action is #{action}" do provider.action = action provider.define_resource_requirements @@ -368,7 +368,7 @@ describe Chef::Provider::Service::Openbsd do end end - [ "stop", "disable" ].each do |action| + %w{stop disable}.each do |action| it "should not raise an error when the action is #{action}" do provider.action = action provider.define_resource_requirements diff --git a/spec/unit/provider/service/redhat_spec.rb b/spec/unit/provider/service/redhat_spec.rb index 5d03c688fc..9b878abcd6 100644 --- a/spec/unit/provider/service/redhat_spec.rb +++ b/spec/unit/provider/service/redhat_spec.rb @@ -150,14 +150,14 @@ describe "Chef::Provider::Service::Redhat" do @provider.define_resource_requirements end - [ "start", "reload", "restart", "enable" ].each do |action| + %w{start reload restart enable}.each do |action| it "should raise an error when the action is #{action}" do @provider.action = action expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end - [ "stop", "disable" ].each do |action| + %w{stop disable}.each do |action| it "should not raise an error when the action is #{action}" do @provider.action = action expect { @provider.process_resource_requirements }.not_to raise_error diff --git a/spec/unit/provider/template/content_spec.rb b/spec/unit/provider/template/content_spec.rb index 4f7b4c256c..0f936c8f11 100644 --- a/spec/unit/provider/template/content_spec.rb +++ b/spec/unit/provider/template/content_spec.rb @@ -91,7 +91,7 @@ describe Chef::Provider::Template::Content do it "returns a tempfile in the tempdir when :file_staging_uses_destdir is not set" do Chef::Config[:file_staging_uses_destdir] = false - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be true + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be true expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be false end @@ -107,7 +107,7 @@ describe Chef::Provider::Template::Content do it "returns a tempfile in the tempdir when :file_deployment_uses_destdir is set to :auto" do Chef::Config[:file_staging_uses_destdir] = :auto - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be true + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be true expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be false end @@ -117,7 +117,7 @@ describe Chef::Provider::Template::Content do end it "returns a tempfile in the tempdir when :file_desployment_uses_destdir is not set" do - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be true + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be true expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be false end end diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb index 0794ce0328..1cdbe462f7 100644 --- a/spec/unit/provider/user_spec.rb +++ b/spec/unit/provider/user_spec.rb @@ -192,13 +192,13 @@ describe Chef::Provider::User do describe "compare_user" do let(:mapping) { { - "username" => ["adam", "Adam"], + "username" => %w{adam Adam}, "comment" => ["Adam Jacob", "adam jacob"], "uid" => [1000, 1001], "gid" => [1000, 1001], "home" => ["/home/adam", "/Users/adam"], "shell" => ["/usr/bin/zsh", "/bin/bash"], - "password" => ["abcd", "12345"], + "password" => %w{abcd 12345}, } } diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 8f43d0cbca..f9b4bd9b9c 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -100,7 +100,7 @@ describe Chef::Recipe do end end - expect(run_context.resource_collection.map { |r| r.name }).to eql(["monkey", "dog", "cat"]) + expect(run_context.resource_collection.map { |r| r.name }).to eql(%w{monkey dog cat}) end it "should return the new resource after creating it" do diff --git a/spec/unit/resource/chocolatey_package_spec.rb b/spec/unit/resource/chocolatey_package_spec.rb index dfd6a3e679..e43803a65f 100644 --- a/spec/unit/resource/chocolatey_package_spec.rb +++ b/spec/unit/resource/chocolatey_package_spec.rb @@ -42,13 +42,13 @@ describe Chef::Resource::ChocolateyPackage do end it "the package_name setter should accept arrays" do - resource.package_name(["git", "unzip"]) - expect(resource.package_name).to eql(["git", "unzip"]) + resource.package_name(%w{git unzip}) + expect(resource.package_name).to eql(%w{git unzip}) end it "the name should accept arrays" do - resource = Chef::Resource::ChocolateyPackage.new(["git", "unzip"]) - expect(resource.package_name).to eql(["git", "unzip"]) + resource = Chef::Resource::ChocolateyPackage.new(%w{git unzip}) + expect(resource.package_name).to eql(%w{git unzip}) end it "the default version should be nil" do diff --git a/spec/unit/resource/cron_spec.rb b/spec/unit/resource/cron_spec.rb index 037bbaf733..6e867b75e1 100644 --- a/spec/unit/resource/cron_spec.rb +++ b/spec/unit/resource/cron_spec.rb @@ -106,19 +106,19 @@ describe Chef::Resource::Cron do end it "should allow * for all time and date values" do - [ "minute", "hour", "day", "month", "weekday" ].each do |x| + %w{minute hour day month weekday}.each do |x| expect(@resource.send(x, "*")).to eql("*") end end it "should allow ranges for all time and date values" do - [ "minute", "hour", "day", "month", "weekday" ].each do |x| + %w{minute hour day month weekday}.each do |x| expect(@resource.send(x, "1-2,5")).to eql("1-2,5") end end it "should have a default value of * for all time and date values" do - [ "minute", "hour", "day", "month", "weekday" ].each do |x| + %w{minute hour day month weekday}.each do |x| expect(@resource.send(x)).to eql("*") end end @@ -153,7 +153,7 @@ describe Chef::Resource::Cron do end it "should convert integer schedule values to a string" do - [ "minute", "hour", "day", "month", "weekday" ].each do |x| + %w{minute hour day month weekday}.each do |x| expect(@resource.send(x, 5)).to eql("5") end end diff --git a/spec/unit/resource/dsc_script_spec.rb b/spec/unit/resource/dsc_script_spec.rb index 55473e3146..4892049884 100644 --- a/spec/unit/resource/dsc_script_spec.rb +++ b/spec/unit/resource/dsc_script_spec.rb @@ -77,7 +77,7 @@ describe Chef::Resource::DscScript do context "when calling imports" do let(:module_name) { "FooModule" } let(:module_name_b) { "BarModule" } - let(:dsc_resources) { ["ResourceA", "ResourceB"] } + let(:dsc_resources) { %w{ResourceA ResourceB} } it "allows an arbitrary number of resources to be set for a module to be set" do dsc_test_resource.imports module_name, *dsc_resources diff --git a/spec/unit/resource/group_spec.rb b/spec/unit/resource/group_spec.rb index 7cfec23365..2bb4b57e26 100644 --- a/spec/unit/resource/group_spec.rb +++ b/spec/unit/resource/group_spec.rb @@ -111,8 +111,8 @@ describe Chef::Resource::Group, "members" do end it "(#{method}) should allow an array" do - @resource.send(method, [ "aj", "adam" ]) - expect(@resource.send(method)).to eql( ["aj", "adam"] ) + @resource.send(method, %w{aj adam}) + expect(@resource.send(method)).to eql( %w{aj adam} ) end it "(#{method}) should not allow a hash" do @@ -142,12 +142,12 @@ describe Chef::Resource::Group, "append" do describe "when it has members" do before do @resource.group_name("pokemon") - @resource.members(["blastoise", "pikachu"]) + @resource.members(%w{blastoise pikachu}) end it "describes its state" do state = @resource.state - expect(state[:members]).to eql(["blastoise", "pikachu"]) + expect(state[:members]).to eql(%w{blastoise pikachu}) end it "returns the group name as its identity" do diff --git a/spec/unit/resource/mdadm_spec.rb b/spec/unit/resource/mdadm_spec.rb index 6a446a2815..8eceed733e 100644 --- a/spec/unit/resource/mdadm_spec.rb +++ b/spec/unit/resource/mdadm_spec.rb @@ -82,14 +82,14 @@ describe Chef::Resource::Mdadm do describe "when it has devices, level, and chunk" do before do @resource.raid_device("raider") - @resource.devices(["device1", "device2"]) + @resource.devices(%w{device1 device2}) @resource.level(1) @resource.chunk(42) end it "describes its state" do state = @resource.state - expect(state[:devices]).to eql(["device1", "device2"]) + expect(state[:devices]).to eql(%w{device1 device2}) expect(state[:level]).to eq(1) expect(state[:chunk]).to eq(42) end diff --git a/spec/unit/resource/mount_spec.rb b/spec/unit/resource/mount_spec.rb index ea20511990..188eaa67d6 100644 --- a/spec/unit/resource/mount_spec.rb +++ b/spec/unit/resource/mount_spec.rb @@ -87,19 +87,19 @@ describe Chef::Resource::Mount do end it "should allow options attribute as an array" do - @resource.options ["ro", "nosuid"] + @resource.options %w{ro nosuid} expect(@resource.options).to be_a_kind_of(Array) end it "should allow options to be sent as a delayed evaluator" do - @resource.options Chef::DelayedEvaluator.new { ["rw", "noexec"] } - expect(@resource.options).to eql(["rw", "noexec"]) + @resource.options Chef::DelayedEvaluator.new { %w{rw noexec} } + expect(@resource.options).to eql(%w{rw noexec}) end it "should allow options to be sent as a delayed evaluator, and convert to array" do @resource.options Chef::DelayedEvaluator.new { "rw,noexec" } expect(@resource.options).to be_a_kind_of(Array) - expect(@resource.options).to eql(["rw", "noexec"]) + expect(@resource.options).to eql(%w{rw noexec}) end it "should accept true for mounted" do diff --git a/spec/unit/resource/resource_notification_spec.rb b/spec/unit/resource/resource_notification_spec.rb index 5bb3ba95ea..e141e01fcf 100644 --- a/spec/unit/resource/resource_notification_spec.rb +++ b/spec/unit/resource/resource_notification_spec.rb @@ -100,7 +100,7 @@ describe Chef::Resource::Notification do end it "raises a RuntimeError if you try to reference multiple resources" do - notification.resource = { :cat => ["keyboard_cat", "cheez_cat"] } + notification.resource = { :cat => %w{keyboard_cat cheez_cat} } @keyboard_cat = Chef::Resource::Cat.new("keyboard_cat") @cheez_cat = Chef::Resource::Cat.new("cheez_cat") @resource_collection = Chef::ResourceCollection.new @@ -112,7 +112,7 @@ describe Chef::Resource::Notification do end it "raises a RuntimeError if you try to reference multiple notifying resources" do - notification.notifying_resource = { :cat => ["long_cat", "cheez_cat"] } + notification.notifying_resource = { :cat => %w{long_cat cheez_cat} } @long_cat = Chef::Resource::Cat.new("long_cat") @cheez_cat = Chef::Resource::Cat.new("cheez_cat") @resource_collection = Chef::ResourceCollection.new diff --git a/spec/unit/resource_collection/resource_set_spec.rb b/spec/unit/resource_collection/resource_set_spec.rb index 2f8ba0e1aa..20f6f70911 100644 --- a/spec/unit/resource_collection/resource_set_spec.rb +++ b/spec/unit/resource_collection/resource_set_spec.rb @@ -84,7 +84,7 @@ describe Chef::ResourceCollection::ResourceSet do it "should find a resource by type symbol and array of names with custom names" do 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 => %w{name1 name2}), zen_master_name, zen_master2_name) end it "should find resources of multiple kinds (:zen_master => a, :zen_follower => b)" do @@ -98,7 +98,7 @@ 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"]), + check_by_names(collection.find(:zzz => %w{name1 name2}, :yyy => ["name3"]), zen_master_name, zen_follower_name, zen_master2_name) end diff --git a/spec/unit/resource_collection_spec.rb b/spec/unit/resource_collection_spec.rb index 178d58b303..a6ad895c51 100644 --- a/spec/unit/resource_collection_spec.rb +++ b/spec/unit/resource_collection_spec.rb @@ -171,7 +171,7 @@ describe Chef::ResourceCollection do it "should find a resource by symbol and array of names (:zen_master => [a,b])" do load_up_resources - results = rc.resources(:zen_master => [ "monkey", "dog" ]) + results = rc.resources(:zen_master => %w{monkey dog}) expect(results.length).to eql(2) check_by_names(results, "monkey", "dog") end diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 1297ed6f04..1c3a825ea1 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -205,7 +205,7 @@ describe Chef::Resource do end it "coerces arrays to names" do - expect(resource.name ["a", "b"]).to eql("a, b") + expect(resource.name %w{a b}).to eql("a, b") end it "should coerce objects to a string" do @@ -270,7 +270,7 @@ describe Chef::Resource do end it "notifies a resource with an array for its name via its prettified string name" do - run_context.resource_collection << Chef::Resource::ZenMaster.new(["coffee", "tea"]) + run_context.resource_collection << Chef::Resource::ZenMaster.new(%w{coffee tea}) resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee, tea") expect(resource.delayed_notifications.detect { |e| e.resource.name == "coffee, tea" && e.action == :reload }).not_to be_nil end @@ -859,9 +859,9 @@ describe Chef::Resource do it "adds mappings for multiple platforms" do expect(Chef.resource_handler_map).to receive(:set).with( - :energy, Chef::Resource::Klz, { platform: ["autobots", "decepticons"] } + :energy, Chef::Resource::Klz, { platform: %w{autobots decepticons} } ) - klz.provides :energy, platform: ["autobots", "decepticons"] + klz.provides :energy, platform: %w{autobots decepticons} end it "adds mappings for all platforms" do diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb index 1ff76d7207..1bbbc4c7b0 100644 --- a/spec/unit/role_spec.rb +++ b/spec/unit/role_spec.rb @@ -85,12 +85,12 @@ describe Chef::Role do describe "using the old #recipes API" do it "should let you set the recipe array" do - expect(@role.recipes([ "one", "two" ])).to eq([ "one", "two" ]) + expect(@role.recipes(%w{one two})).to eq(%w{one two}) end it "should let you return the recipe array" do - @role.recipes([ "one", "two" ]) - expect(@role.recipes).to eq([ "one", "two" ]) + @role.recipes(%w{one two}) + expect(@role.recipes).to eq(%w{one two}) end it "should not list roles in the recipe array" do diff --git a/spec/unit/run_list/run_list_expansion_spec.rb b/spec/unit/run_list/run_list_expansion_spec.rb index b0cb978bb1..e1af112dbf 100644 --- a/spec/unit/run_list/run_list_expansion_spec.rb +++ b/spec/unit/run_list/run_list_expansion_spec.rb @@ -119,7 +119,7 @@ describe Chef::RunList::RunListExpansion do it "has the list of all roles applied" do # this is the correct order, but 1.8 hash order is not stable - expect(@expansion.roles).to match_array(["rage", "mollusk"]) + expect(@expansion.roles).to match_array(%w{rage mollusk}) end end diff --git a/spec/unit/run_list/versioned_recipe_list_spec.rb b/spec/unit/run_list/versioned_recipe_list_spec.rb index 2b1c6edebc..8bbd816956 100644 --- a/spec/unit/run_list/versioned_recipe_list_spec.rb +++ b/spec/unit/run_list/versioned_recipe_list_spec.rb @@ -43,23 +43,23 @@ describe Chef::RunList::VersionedRecipeList do it "should append the recipe to the end of the list" do list.add_recipe "rails" - expect(list).to eq(["apt", "god", "apache2", "rails"]) + expect(list).to eq(%w{apt god apache2 rails}) end it "should not duplicate entries" do list.add_recipe "apt" - expect(list).to eq(["apt", "god", "apache2"]) + expect(list).to eq(%w{apt god apache2}) end it "should allow you to specify a version" do list.add_recipe "rails", "1.0.0" - expect(list).to eq(["apt", "god", "apache2", "rails"]) + expect(list).to eq(%w{apt god apache2 rails}) expect(list.with_versions).to include({ :name => "rails", :version => "1.0.0" }) end it "should allow you to specify a version for a recipe that already exists" do list.add_recipe "apt", "1.2.3" - expect(list).to eq(["apt", "god", "apache2"]) + expect(list).to eq(%w{apt god apache2}) expect(list.with_versions).to include({ :name => "apt", :version => "1.2.3" }) end diff --git a/spec/unit/run_list_spec.rb b/spec/unit/run_list_spec.rb index 6d17e654cd..0dcd349ced 100644 --- a/spec/unit/run_list_spec.rb +++ b/spec/unit/run_list_spec.rb @@ -95,7 +95,7 @@ describe Chef::RunList do it "should believe a RunList is equal to an array named after it's members" do @run_list << "foo" @run_list << "baz" - expect(@run_list).to eq([ "foo", "baz" ]) + expect(@run_list).to eq(%w{foo baz}) end end @@ -199,7 +199,7 @@ describe Chef::RunList do it "should load the role from the chef server" do #@rest.should_receive(:get).with("roles/stubby") expansion = @run_list.expand("_default", "server") - expect(expansion.recipes).to eq(["one", "two", "kitty"]) + expect(expansion.recipes).to eq(%w{one two kitty}) end it "should default to expanding from the server" do diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb index 9652d69783..b23f0277d6 100644 --- a/spec/unit/search/query_spec.rb +++ b/spec/unit/search/query_spec.rb @@ -30,7 +30,7 @@ describe Chef::Search::Query do let(:filter_hash) { { "env" => [ "chef_environment" ], - "ruby_plat" => [ "languages", "ruby", "platform" ], + "ruby_plat" => %w{languages ruby platform}, } } let(:response) { diff --git a/spec/unit/util/backup_spec.rb b/spec/unit/util/backup_spec.rb index 3454e07692..8bc68ec160 100644 --- a/spec/unit/util/backup_spec.rb +++ b/spec/unit/util/backup_spec.rb @@ -76,7 +76,7 @@ describe Chef::Util::Backup do end it "should keep only 1 backup copy" do - expect(@backup).to receive(:sorted_backup_files).and_return(["a", "b", "c"]) + expect(@backup).to receive(:sorted_backup_files).and_return(%w{a b c}) expect(@backup).to receive(:delete_backup).with("b") expect(@backup).to receive(:delete_backup).with("c") @backup.backup! @@ -89,13 +89,13 @@ describe Chef::Util::Backup do end it "should not delete anything if we only have one other backup" do - expect(@backup).to receive(:sorted_backup_files).and_return(["a", "b"]) + expect(@backup).to receive(:sorted_backup_files).and_return(%w{a b}) expect(@backup).not_to receive(:delete_backup) @backup.backup! end it "should keep only 2 backup copies" do - expect(@backup).to receive(:sorted_backup_files).and_return(["a", "b", "c", "d"]) + expect(@backup).to receive(:sorted_backup_files).and_return(%w{a b c d}) expect(@backup).to receive(:delete_backup).with("c") expect(@backup).to receive(:delete_backup).with("d") @backup.backup! diff --git a/spec/unit/util/dsc/configuration_generator_spec.rb b/spec/unit/util/dsc/configuration_generator_spec.rb index d59423e1e5..12f62deb5a 100644 --- a/spec/unit/util/dsc/configuration_generator_spec.rb +++ b/spec/unit/util/dsc/configuration_generator_spec.rb @@ -151,7 +151,7 @@ describe Chef::Util::DSC::ConfigurationGenerator do allow(File).to receive(:join) do |a, b| [a, b].join("++") end - allow(Dir).to receive(:entries).with("tmp++hello") { ["f1", "f2", "f3"] } + allow(Dir).to receive(:entries).with("tmp++hello") { %w{f1 f2 f3} } expect(conf_man.send(:find_configuration_document, "hello")).to be_nil end end @@ -179,12 +179,12 @@ describe Chef::Util::DSC::ConfigurationGenerator do end it "should import specific resources when a module has list without * that is not empty" do - dsc = conf_man.send(:configuration_code, "archive{}", "hello", { "FooModule" => ["FooResource", "BarResource"] }) + dsc = conf_man.send(:configuration_code, "archive{}", "hello", { "FooModule" => %w{FooResource BarResource} }) expect(dsc).to match(/Import-DscResource -ModuleName FooModule -Name FooResource,BarResource/) end it "should import multiple modules with multiple import statements" do - dsc = conf_man.send(:configuration_code, "archive{}", "hello", { "FooModule" => ["FooResource", "BarResource"], "BazModule" => [] }) + dsc = conf_man.send(:configuration_code, "archive{}", "hello", { "FooModule" => %w{FooResource BarResource}, "BazModule" => [] }) expect(dsc).to match(/Import-DscResource -ModuleName FooModule -Name FooResource,BarResource/) expect(dsc).to match(/Import-DscResource -ModuleName BazModule\s*\n/) end diff --git a/spec/unit/util/dsc/lcm_output_parser_spec.rb b/spec/unit/util/dsc/lcm_output_parser_spec.rb index 69eb8724ea..d59497de6f 100644 --- a/spec/unit/util/dsc/lcm_output_parser_spec.rb +++ b/spec/unit/util/dsc/lcm_output_parser_spec.rb @@ -24,11 +24,11 @@ describe Chef::Util::DSC::LocalConfigurationManager::Parser do str = <<-EOF EOF - expect { Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) }.to raise_error(Chef::Exceptions::LCMParser) + expect { Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) }.to raise_error(Chef::Exceptions::LCMParser) end it "raises an exception for a nil input" do - expect { Chef::Util::DSC::LocalConfigurationManager::Parser::parse(nil) }.to raise_error(Chef::Exceptions::LCMParser) + expect { Chef::Util::DSC::LocalConfigurationManager::Parser.parse(nil) }.to raise_error(Chef::Exceptions::LCMParser) end end @@ -40,7 +40,7 @@ logtype: [machinename]: LCM: [ Start Resource ] [name] logtype: [machinename]: LCM: [ End Resource ] [name] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources.length).to eq(1) expect(resources[0].name).to eq("[name]") end @@ -54,7 +54,7 @@ logtype: [machinename]: LCM: [ End Set ] [name] logtype: [machinename]: LCM: [ End Resource ] [name] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].changes_state?).to be_truthy end @@ -68,7 +68,7 @@ logtype: [machinename]: LCM: [ End Set ] [name] logtype: [machinename]: LCM: [ End Resource ] [name] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].change_log).to match_array(["[name]", "[message]", "[name]"]) end @@ -80,7 +80,7 @@ logtype: [machinename]: LCM: [ Skip Set ] [name] logtype: [machinename]: LCM: [ End Resource ] [name] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].changes_state?).to be_falsey end @@ -92,7 +92,7 @@ logtype: [machinename]: LCM: [ Skip Set ] [name] logtype: [machinename]: LCM: [ End Resource ] [name] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].change_log).to be_empty end end @@ -114,7 +114,7 @@ logtype: [machinename]: LCM: [ End Set ] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].changes_state?).to be_falsey expect(resources[1].changes_state?).to be_truthy end @@ -135,7 +135,7 @@ logtype: [machinename]: LCM: [ End Resource ] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].changes_state?).to be_falsey expect(resources[1].changes_state?).to be_truthy end @@ -154,7 +154,7 @@ logtype: [machinename]: LCM: [ End Set ] logtype: [machinename]: LCM: [ End Resource ] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].changes_state?).to be_truthy expect(resources[0].name).to eql("[name]") expect(resources[1].changes_state?).to be_truthy diff --git a/spec/unit/util/editor_spec.rb b/spec/unit/util/editor_spec.rb index 9db7e85931..7a0ec91533 100644 --- a/spec/unit/util/editor_spec.rb +++ b/spec/unit/util/editor_spec.rb @@ -16,7 +16,7 @@ describe Chef::Util::Editor do end subject(:editor) { described_class.new(input_lines) } - let(:input_lines) { ["one", "two", "two", "three"] } + let(:input_lines) { %w{one two two three} } describe '#append_line_after' do context "when there is no match" do @@ -34,7 +34,7 @@ describe Chef::Util::Editor do it("returns the number of added lines") { is_expected.to eq(2) } it "adds a line after each match" do execute - expect(editor.lines).to be == ["one", "two", "new", "two", "new", "three"] + expect(editor.lines).to be == %w{one two new two new three} end end @@ -51,7 +51,7 @@ describe Chef::Util::Editor do it("returns the number of added lines") { is_expected.to eq(1) } it "adds a line to the end" do execute - expect(editor.lines).to be == ["one", "two", "two", "three", "new"] + expect(editor.lines).to be == %w{one two two three new} end end @@ -86,7 +86,7 @@ describe Chef::Util::Editor do it("returns the number of removed lines") { is_expected.to eq(2) } it "removes the matching lines" do execute - expect(editor.lines).to be == ["one", "three"] + expect(editor.lines).to be == %w{one three} end end @@ -112,14 +112,14 @@ describe Chef::Util::Editor do it("returns the number of changed lines") { is_expected.to eq(2) } it "replaces the matching portions" do execute - expect(editor.lines).to be == ["one", "new", "new", "three"] + expect(editor.lines).to be == %w{one new new three} end end it "matches a Regexp" do expect(editor.replace(/^ee/, "new")).to be == 0 expect(editor.replace(/ee$/, "new")).to be == 1 - expect(editor.lines).to be == ["one", "two", "two", "thrnew"] + expect(editor.lines).to be == %w{one two two thrnew} end end @@ -139,14 +139,14 @@ describe Chef::Util::Editor do it("returns the number of replaced lines") { is_expected.to eq(2) } it "replaces the matching line" do execute - expect(editor.lines).to be == ["one", "new", "new", "three"] + expect(editor.lines).to be == %w{one new new three} end end it "matches a Regexp" do expect(editor.replace_lines(/^ee/, "new")).to be == 0 expect(editor.replace_lines(/ee$/, "new")).to be == 1 - expect(editor.lines).to be == ["one", "two", "two", "new"] + expect(editor.lines).to be == %w{one two two new} end end end |