diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-07-05 11:44:16 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2019-07-05 12:41:14 -0700 |
commit | 7bf98ad06b30b7feb4ea3fbbe45a5b733467a5d3 (patch) | |
tree | b0995ded1a63654d3f54140bd880c69f86afd52f | |
parent | 9802d7c075c8b7dae42dbcecd92d492f7fa128ac (diff) | |
download | chef-7bf98ad06b30b7feb4ea3fbbe45a5b733467a5d3.tar.gz |
Style/RegexpLiteral
given how many regexps we have with /'s in the match this seems like
a very good one.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
58 files changed, 149 insertions, 149 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index 88ce6216c4..ac7e9caaab 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -134,7 +134,7 @@ module ChefConfig # @return [Boolean] is the URL valid def self.is_valid_url?(uri) url = uri.to_s.strip - /^http:\/\// =~ url || /^https:\/\// =~ url || /^chefzero:/ =~ url + %r{^http://} =~ url || %r{^https://} =~ url || /^chefzero:/ =~ url end # Override the config dispatch to set the value of multiple server options simultaneously @@ -403,7 +403,7 @@ module ChefConfig default :repo_mode do if local_mode && !chef_zero.osc_compat "hosted_everything" - elsif chef_server_url =~ /\/+organizations\/.+/ + elsif chef_server_url =~ %r{/+organizations/.+} "hosted_everything" else "everything" @@ -459,7 +459,7 @@ module ChefConfig default(:chef_server_root) do # if the chef_server_url is a path to an organization, aka # 'some_url.../organizations/*' then remove the '/organization/*' by default - if configuration[:chef_server_url] =~ /\/organizations\/\S*$/ + if configuration[:chef_server_url] =~ %r{/organizations/\S*$} configuration[:chef_server_url].split("/")[0..-3].join("/") elsif configuration[:chef_server_url] # default to whatever chef_server_url is configuration[:chef_server_url] @@ -1074,7 +1074,7 @@ module ChefConfig # proxy before parsing. The regex /^.*:\/\// matches, for example, http://. Reusing proxy # here since we are really just trying to get the string built correctly. proxy = unless proxy_env_var.empty? - if proxy_env_var =~ /^.*:\/\// + if proxy_env_var =~ %r{^.*://} URI.parse(proxy_env_var) else URI.parse("#{scheme}://#{proxy_env_var}") diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb index 0da696c05c..29ba1971e1 100644 --- a/lib/chef/application/solo.rb +++ b/lib/chef/application/solo.rb @@ -272,7 +272,7 @@ class Chef::Application::Solo < Chef::Application Chef::Application.fatal!(unforked_interval_error_message) if !Chef::Config[:client_fork] && Chef::Config[:interval] if Chef::Config[:recipe_url] - cookbooks_path = Array(Chef::Config[:cookbook_path]).detect { |e| Pathname.new(e).cleanpath.to_s =~ /\/cookbooks\/*$/ } + cookbooks_path = Array(Chef::Config[:cookbook_path]).detect { |e| Pathname.new(e).cleanpath.to_s =~ %r{/cookbooks/*$} } recipes_path = File.expand_path(File.join(cookbooks_path, "..")) if Chef::Config[:delete_entire_chef_repo] diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index e0df23371c..8a942103f1 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -307,7 +307,7 @@ class Chef begin case config[:config_file] - when /^(http|https):\/\// + when %r{^(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) } diff --git a/lib/chef/chef_fs/config.rb b/lib/chef/chef_fs/config.rb index 48ebe75e27..83e82bfa0c 100644 --- a/lib/chef/chef_fs/config.rb +++ b/lib/chef/chef_fs/config.rb @@ -164,7 +164,7 @@ class Chef attr_reader :cookbook_version def is_hosted? - @chef_config[:chef_server_url] =~ /\/+organizations\/.+/ + @chef_config[:chef_server_url] =~ %r{/+organizations/.+} end def chef_fs diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index 6d1b3e1f61..0b62718ab9 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -52,7 +52,7 @@ class Chef @inferred_cookbook_name = File.basename( path ) @chefignore = chefignore @metadata = nil - @relative_path = /#{Regexp.escape(cookbook_path)}\/(.+)$/ + @relative_path = %r{#{Regexp.escape(cookbook_path)}/(.+)$} @metadata_loaded = false @cookbook_settings = { all_files: {}, diff --git a/lib/chef/cookbook/remote_file_vendor.rb b/lib/chef/cookbook/remote_file_vendor.rb index ebdb94ee54..e5270018fb 100644 --- a/lib/chef/cookbook/remote_file_vendor.rb +++ b/lib/chef/cookbook/remote_file_vendor.rb @@ -37,7 +37,7 @@ class Chef # Chef::Config.cookbook_path file hierarchy for the requested # file. def get_filename(filename) - if filename =~ /([^\/]+)\/(.+)$/ + if filename =~ %r{([^/]+)/(.+)$} segment = $1 else raise "get_filename: Cannot determine segment/filename for incoming filename #{filename}" diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb index b69e6b8212..342fc89f16 100644 --- a/lib/chef/cookbook/synchronizer.rb +++ b/lib/chef/cookbook/synchronizer.rb @@ -209,7 +209,7 @@ class Chef # (if we have an override run_list we may not want to do this) def remove_old_cookbooks cache.find(File.join(%w{cookbooks ** {*,.*}})).each do |cache_file| - cache_file =~ /^cookbooks\/([^\/]+)\// + cache_file =~ %r{^cookbooks/([^/]+)/} unless have_cookbook?($1) Chef::Log.info("Removing #{cache_file} from the cache; its cookbook is no longer needed on this client.") cache.delete(cache_file) @@ -221,7 +221,7 @@ class Chef # remove deleted files in cookbooks that are being used on the node def remove_deleted_files cache.find(File.join(%w{cookbooks ** {*,.*}})).each do |cache_file| - md = cache_file.match(/^cookbooks\/([^\/]+)\/([^\/]+)\/(.*)/) + md = cache_file.match(%r{^cookbooks/([^/]+)/([^/]+)/(.*)}) next unless md ( cookbook_name, segment, file ) = md[1..3] diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 959318a020..d546724fa0 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -296,9 +296,9 @@ class Chef # we're just going to make cookbook_files out of these and make the # cookbook find them by filespecificity again. but it's the shortest # path to "success" for now. - if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]*\/?#{Regexp.escape(dirname)})\/.+$/ + if manifest_record_path =~ %r{(#{Regexp.escape(segment.to_s)}/[^/]*/?#{Regexp.escape(dirname)})/.+$} specificity_dirname = $1 - non_specific_path = manifest_record_path[/#{Regexp.escape(segment.to_s)}\/[^\/]*\/?#{Regexp.escape(dirname)}\/(.+)$/, 1] + non_specific_path = manifest_record_path[%r{#{Regexp.escape(segment.to_s)}/[^/]*/?#{Regexp.escape(dirname)}/(.+)$}, 1] # Record the specificity_dirname only if it's in the list of # valid preferences if filenames_by_pref[specificity_dirname] @@ -326,7 +326,7 @@ class Chef manifest_record_path = manifest_record[:path] # extract the preference part from the path. - if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)})\/.+$/ + if manifest_record_path =~ %r{(#{Regexp.escape(segment.to_s)}/[^/]+/#{Regexp.escape(dirname)})/.+$} # Note the specificy_dirname includes the segment and # dirname argument as above, which is what # preferences_for_path returns. It could be diff --git a/lib/chef/encrypted_data_bag_item.rb b/lib/chef/encrypted_data_bag_item.rb index e8a979f7c0..d1928d195b 100644 --- a/lib/chef/encrypted_data_bag_item.rb +++ b/lib/chef/encrypted_data_bag_item.rb @@ -135,7 +135,7 @@ class Chef::EncryptedDataBagItem end secret = case path - when /^\w+:\/\// + when %r{^\w+://} # We have a remote key begin Kernel.open(path).read.strip diff --git a/lib/chef/http.rb b/lib/chef/http.rb index b5f6a91c5d..3cee587fd5 100644 --- a/lib/chef/http.rb +++ b/lib/chef/http.rb @@ -312,7 +312,7 @@ class Chef def create_url(path) return path if path.is_a?(URI) - if path =~ /^(http|https|chefzero):\/\//i + if path =~ %r{^(http|https|chefzero)://}i URI.parse(path) elsif path.nil? || path.empty? URI.parse(@url) diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 4be53af5c8..e892f1f2c9 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -663,7 +663,7 @@ class Chef def connection_protocol return @connection_protocol if @connection_protocol - from_url = host_descriptor =~ /^(.*):\/\// ? $1 : nil + from_url = host_descriptor =~ %r{^(.*)://} ? $1 : nil from_cli = config[:connection_protocol] from_knife = Chef::Config[:knife][:connection_protocol] @connection_protocol = from_url || from_cli || from_knife || "ssh" diff --git a/lib/chef/mixin/convert_to_class_name.rb b/lib/chef/mixin/convert_to_class_name.rb index a65fa87655..c5944c3985 100644 --- a/lib/chef/mixin/convert_to_class_name.rb +++ b/lib/chef/mixin/convert_to_class_name.rb @@ -25,7 +25,7 @@ class Chef def convert_to_class_name(str) str = normalize_snake_case_name(str) rname = nil - regexp = %r{^(.+?)(_(.+))?$} + regexp = /^(.+?)(_(.+))?$/ mn = str.match(regexp) if mn diff --git a/lib/chef/provider/cron.rb b/lib/chef/provider/cron.rb index ec810739ab..aad59d1eba 100644 --- a/lib/chef/provider/cron.rb +++ b/lib/chef/provider/cron.rb @@ -29,7 +29,7 @@ class Chef CRON_ATTRIBUTES = %i{minute hour day month weekday time command mailto path shell home environment}.freeze WEEKDAY_SYMBOLS = %i{sunday monday tuesday wednesday thursday friday saturday}.freeze - CRON_PATTERN = /\A([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+|[a-zA-Z]{3})\s([-0-9*,\/]+|[a-zA-Z]{3})\s(.*)/.freeze + CRON_PATTERN = %r{\A([-0-9*,/]+)\s([-0-9*,/]+)\s([-0-9*,/]+)\s([-0-9*,/]+|[a-zA-Z]{3})\s([-0-9*,/]+|[a-zA-Z]{3})\s(.*)}.freeze SPECIAL_PATTERN = /\A(@(#{SPECIAL_TIME_VALUES.join('|')}))\s(.*)/.freeze ENV_PATTERN = /\A(\S+)=(\S*)/.freeze ENVIRONMENT_PROPERTIES = %w{MAILTO PATH SHELL HOME}.freeze diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb index 3dd574c401..16d1e54408 100644 --- a/lib/chef/provider/git.rb +++ b/lib/chef/provider/git.rb @@ -51,7 +51,7 @@ class Chef end requirements.assert(:all_actions) do |a| - a.assertion { !(new_resource.revision =~ /^origin\//) } + a.assertion { !(new_resource.revision =~ %r{^origin/}) } a.failure_message Chef::Exceptions::InvalidRemoteGitReference, "Deploying remote branches is not supported. " + "Specify the remote branch as a local branch for " + diff --git a/lib/chef/provider/mount/aix.rb b/lib/chef/provider/mount/aix.rb index ca6ca4bd63..0a5e30447b 100644 --- a/lib/chef/provider/mount/aix.rb +++ b/lib/chef/provider/mount/aix.rb @@ -110,7 +110,7 @@ class Chef when /#{search_device}\s+#{Regexp.escape(@new_resource.mount_point)}/ mounted = true logger.trace("Special device #{device_logstring} mounted as #{@new_resource.mount_point}") - when /^[\/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+/ + when %r{^[/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+} mounted = false logger.trace("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab") end @@ -196,7 +196,7 @@ class Chef found_device = false ::File.open("/etc/filesystems", "r").each_line do |line| case line - when /^\/.+:\s*$/ + when %r{^/.+:\s*$} if line =~ /#{Regexp.escape(@new_resource.mount_point)}+:/ found_device = true else diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb index fe9a6ffc4f..4fdcc257da 100644 --- a/lib/chef/provider/mount/mount.rb +++ b/lib/chef/provider/mount/mount.rb @@ -71,7 +71,7 @@ class Chef @current_resource.pass($5.to_i) logger.trace("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/fstab") next - when /^[\/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+/ + when %r{^[/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+} enabled = false logger.trace("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab") end @@ -96,7 +96,7 @@ class Chef when /^#{device_mount_regex}\s+on\s+#{Regexp.escape(real_mount_point)}\s/ mounted = true logger.trace("Special device #{device_logstring} mounted as #{real_mount_point}") - when /^([\/\w])+\son\s#{Regexp.escape(real_mount_point)}\s+/ + when %r{^([/\w])+\son\s#{Regexp.escape(real_mount_point)}\s+} mounted = false logger.trace("Special device #{$~[1]} mounted as #{real_mount_point}") end @@ -201,7 +201,7 @@ class Chef end def network_device? - @new_resource.device =~ /:/ || @new_resource.device =~ /\/\// + @new_resource.device =~ /:/ || @new_resource.device =~ %r{//} end def device_should_exist? diff --git a/lib/chef/provider/mount/solaris.rb b/lib/chef/provider/mount/solaris.rb index 69659d4918..ae26d13117 100644 --- a/lib/chef/provider/mount/solaris.rb +++ b/lib/chef/provider/mount/solaris.rb @@ -158,7 +158,7 @@ class Chef when /^#{device_regex}\s+on\s+#{Regexp.escape(mount_point)}\s+/ logger.trace("Special device #{device} is mounted as #{mount_point}") mounted = true - when /^([\/\w]+)\son\s#{Regexp.escape(mount_point)}\s+/ + when %r{^([/\w]+)\son\s#{Regexp.escape(mount_point)}\s+} logger.trace("Special device #{Regexp.last_match[1]} is mounted as #{mount_point}") mounted = false end @@ -180,7 +180,7 @@ class Chef # solaris /etc/vfstab format: # device device mount FS fsck mount mount # to mount to fsck point type pass at boot options - when /^#{device_regex}\s+[-\/\w]+\s+#{Regexp.escape(mount_point)}\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/ + when %r{^#{device_regex}\s+[-/\w]+\s+#{Regexp.escape(mount_point)}\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)} enabled = true fstype = Regexp.last_match[1] options = Regexp.last_match[4] @@ -196,7 +196,7 @@ class Chef pass = (Regexp.last_match[2] == "-") ? 0 : Regexp.last_match[2].to_i logger.trace("Found mount #{device} to #{mount_point} in #{VFSTAB}") next - when /^[-\/\w]+\s+[-\/\w]+\s+#{Regexp.escape(mount_point)}\s+/ + when %r{^[-/\w]+\s+[-/\w]+\s+#{Regexp.escape(mount_point)}\s+} # if we find a mountpoint on top of our mountpoint, then we are not enabled enabled = false logger.trace("Found conflicting mount point #{mount_point} in #{VFSTAB}") diff --git a/lib/chef/provider/package/freebsd/base.rb b/lib/chef/provider/package/freebsd/base.rb index bfd828552c..70ca3f4a98 100644 --- a/lib/chef/provider/package/freebsd/base.rb +++ b/lib/chef/provider/package/freebsd/base.rb @@ -37,12 +37,12 @@ class Chef case port # When the package name starts with a '/' treat it as the full path to the ports directory. - when /^\// + when %r{^/} port # Otherwise if the package name contains a '/' not at the start (like 'www/wordpress') treat # as a relative path from /usr/ports. - when /\// + when %r{/} "/usr/ports/#{port}" # Otherwise look up the path to the ports directory using 'whereis' diff --git a/lib/chef/provider/package/freebsd/pkgng.rb b/lib/chef/provider/package/freebsd/pkgng.rb index a3d70ad9cd..fb79af617f 100644 --- a/lib/chef/provider/package/freebsd/pkgng.rb +++ b/lib/chef/provider/package/freebsd/pkgng.rb @@ -27,7 +27,7 @@ class Chef def install_package(name, version) unless current_resource.version case new_resource.source - when /^(http|ftp|\/)/ + when %r{^(http|ftp|/)} shell_out!("pkg", "add", options, new_resource.source, env: { "LC_ALL" => nil }).status logger.trace("#{new_resource} installed from: #{new_resource.source}") else diff --git a/lib/chef/provider/package/snap.rb b/lib/chef/provider/package/snap.rb index c9f9e1134f..cb639ff77f 100644 --- a/lib/chef/provider/package/snap.rb +++ b/lib/chef/provider/package/snap.rb @@ -190,7 +190,7 @@ class Chef def get_snap_version_from_source(path) body = { "context-id" => "get_snap_version_from_source_#{path}", - "args" => ["info", path,], + "args" => ["info", path], }.to_json # json = call_snap_api('POST', '/v2/snapctl', body) diff --git a/lib/chef/provider/package/windows/msi.rb b/lib/chef/provider/package/windows/msi.rb index a6807afc17..91b3d7a2b2 100644 --- a/lib/chef/provider/package/windows/msi.rb +++ b/lib/chef/provider/package/windows/msi.rb @@ -84,7 +84,7 @@ class Chef .map(&:uninstall_string).uniq.each do |uninstall_string| uninstall_string = "msiexec /x #{uninstall_string.match(/{.*}/)}" uninstall_string += expand_options(new_resource.options) - uninstall_string += " /q" unless uninstall_string.downcase =~ / \/q/ + uninstall_string += " /q" unless uninstall_string.downcase =~ %r{ /q} logger.trace("#{new_resource} removing MSI package version using '#{uninstall_string}'") shell_out!(uninstall_string, timeout: new_resource.timeout, returns: new_resource.returns) end diff --git a/lib/chef/provider/remote_file/fetcher.rb b/lib/chef/provider/remote_file/fetcher.rb index 85318b1df7..f007fe40db 100644 --- a/lib/chef/provider/remote_file/fetcher.rb +++ b/lib/chef/provider/remote_file/fetcher.rb @@ -49,7 +49,7 @@ class Chef def self.network_share?(source) case source when String - !!(%r{\A\\\\[A-Za-z0-9+\-\.]+} =~ source) + !!(/\A\\\\[A-Za-z0-9+\-\.]+/ =~ source) else false end diff --git a/lib/chef/provider/remote_file/local_file.rb b/lib/chef/provider/remote_file/local_file.rb index 14877806ce..d4b71e24fa 100644 --- a/lib/chef/provider/remote_file/local_file.rb +++ b/lib/chef/provider/remote_file/local_file.rb @@ -35,7 +35,7 @@ class Chef # CHEF-4472: Remove the leading slash from windows paths that we receive from a file:// URI def fix_windows_path(path) - path.gsub(/^\/([a-zA-Z]:)/, '\1') + path.gsub(%r{^/([a-zA-Z]:)}, '\1') end def source_path diff --git a/lib/chef/provider/service/aixinit.rb b/lib/chef/provider/service/aixinit.rb index 6469b6389c..05cdc2befe 100644 --- a/lib/chef/provider/service/aixinit.rb +++ b/lib/chef/provider/service/aixinit.rb @@ -22,7 +22,7 @@ class Chef class Provider class Service class AixInit < Chef::Provider::Service::Init - RC_D_SCRIPT_NAME = /\/etc\/rc.d\/rc2.d\/([SK])(\d\d|)/i.freeze + RC_D_SCRIPT_NAME = %r{/etc/rc.d/rc2.d/([SK])(\d\d|)}i.freeze def initialize(new_resource, run_context) super diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb index de76ed1416..9f48504d5e 100644 --- a/lib/chef/provider/service/debian.rb +++ b/lib/chef/provider/service/debian.rb @@ -26,8 +26,8 @@ class Chef Chef::Platform::ServiceHelpers.service_resource_providers.include?(:debian) end - UPDATE_RC_D_ENABLED_MATCHES = /\/rc[\dS].d\/S|not installed/i.freeze - UPDATE_RC_D_PRIORITIES = /\/rc([\dS]).d\/([SK])(\d\d)/i.freeze + UPDATE_RC_D_ENABLED_MATCHES = %r{/rc[\dS].d/S|not installed}i.freeze + UPDATE_RC_D_PRIORITIES = %r{/rc([\dS]).d/([SK])(\d\d)}i.freeze def self.supports?(resource, action) Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:initd) diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb index 5364053ba8..8b2db84f35 100644 --- a/lib/chef/provider/service/upstart.rb +++ b/lib/chef/provider/service/upstart.rb @@ -32,7 +32,7 @@ class Chef Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) end - UPSTART_STATE_FORMAT = /\S+ \(?(start|stop)?\)? ?[\/ ](\w+)/.freeze + UPSTART_STATE_FORMAT = %r{\S+ \(?(start|stop)?\)? ?[/ ](\w+)}.freeze # Returns true if the configs for the service name has upstart variable def self.supports?(resource, action) diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb index e1bdabce42..79ac2b1e29 100644 --- a/lib/chef/provider/service/windows.rb +++ b/lib/chef/provider/service/windows.rb @@ -307,7 +307,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service # remove characters that make for broken or wonky filenames. def clean_username_for_path(username) - username.gsub(/[\/\\. ]+/, "_") + username.gsub(%r{[/\\. ]+}, "_") end def canonicalize_username(username) diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index 147de19a65..e67aec974a 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -291,7 +291,7 @@ in 'password', with the associated 'salt' and 'iterations'.") end def validate_home_dir_specification! - unless new_resource.home =~ /^\// + unless new_resource.home =~ %r{^/} raise(Chef::Exceptions::InvalidHomeDirectory, "invalid path spec for User: '#{new_resource.username}', home directory: '#{new_resource.home}'") end end diff --git a/lib/chef/provider/zypper_repository.rb b/lib/chef/provider/zypper_repository.rb index 291a545843..764979cb3a 100644 --- a/lib/chef/provider/zypper_repository.rb +++ b/lib/chef/provider/zypper_repository.rb @@ -134,7 +134,7 @@ class Chef def key_fingerprint(key_path) so = shell_out!("gpg --with-fingerprint #{key_path}") # expected output and match: http://rubular.com/r/BpfMjxySQM - fingerprint = /pub\s*\S*\/(\S*)/.match(so.stdout)[1].downcase + fingerprint = %r{pub\s*\S*/(\S*)}.match(so.stdout)[1].downcase logger.trace("GPG fingerprint of key at #{key_path} is #{fingerprint}") fingerprint end diff --git a/lib/chef/resource/apt_repository.rb b/lib/chef/resource/apt_repository.rb index c70631253b..c73408807d 100644 --- a/lib/chef/resource/apt_repository.rb +++ b/lib/chef/resource/apt_repository.rb @@ -33,7 +33,7 @@ class Chef # defaults, but since we allowed users to pass nil here we need to continue # to allow that so don't refactor this however tempting it is property :repo_name, String, - regex: [/^[^\/]+$/], + regex: [%r{^[^/]+$}], description: "An optional property to set the repository name if it differs from the resource block's name. The value of this setting must not contain spaces.", validation_message: "repo_name property cannot contain a forward slash '/'", introduced: "14.1", name_property: true diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb index 71160e983e..dab599c272 100644 --- a/lib/chef/resource/hostname.rb +++ b/lib/chef/resource/hostname.rb @@ -203,7 +203,7 @@ class Chef declare_resource(:execute, "svccfg -s system/identity:node setprop config/nodename=\'#{new_resource.hostname}\'") do notifies :run, "execute[svcadm refresh]", :immediately notifies :run, "execute[svcadm restart]", :immediately - not_if { shell_out!("svccfg -s system/identity:node listprop config/nodename").stdout.chomp =~ /config\/nodename\s+astring\s+#{new_resource.hostname}/ } + not_if { shell_out!("svccfg -s system/identity:node listprop config/nodename").stdout.chomp =~ %r{config/nodename\s+astring\s+#{new_resource.hostname}} } end declare_resource(:execute, "svcadm refresh") do command "svcadm refresh system/identity:node" diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb index 0ce5bf2031..6220400069 100644 --- a/lib/chef/resource/windows_task.rb +++ b/lib/chef/resource/windows_task.rb @@ -31,7 +31,7 @@ class Chef allowed_actions :create, :delete, :run, :end, :enable, :disable, :change default_action :create - property :task_name, String, regex: [/\A[^\/\:\*\?\<\>\|]+\z/], + property :task_name, String, regex: [%r{\A[^/\:\*\?\<\>\|]+\z}], description: "An optional property to set the task name if it differs from the resource block's name. Example: 'Task Name' or '/Task Name'", name_property: true @@ -216,7 +216,7 @@ class Chef # make sure the start_day is in MM/DD/YYYY format: http://rubular.com/r/cgjHemtWl5 if start_day - raise ArgumentError, "`start_day` property must be in the MM/DD/YYYY format." unless /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$/ =~ start_day + raise ArgumentError, "`start_day` property must be in the MM/DD/YYYY format." unless %r{^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$} =~ start_day end end diff --git a/lib/chef/resource/yum_repository.rb b/lib/chef/resource/yum_repository.rb index 1883439da1..05639842af 100644 --- a/lib/chef/resource/yum_repository.rb +++ b/lib/chef/resource/yum_repository.rb @@ -142,7 +142,7 @@ class Chef property :report_instanceid, [TrueClass, FalseClass], description: "Determines whether to report the instance ID when using Amazon Linux AMIs and repositories." - property :repositoryid, String, regex: [/^[^\/]+$/], + property :repositoryid, String, regex: [%r{^[^/]+$}], description: "An optional property to set the repository name if it differs from the resource block's name.", validation_message: "repositoryid property cannot contain a forward slash '/'", name_property: true diff --git a/lib/chef/resource/zypper_repository.rb b/lib/chef/resource/zypper_repository.rb index 92ab012c66..447660e9ac 100644 --- a/lib/chef/resource/zypper_repository.rb +++ b/lib/chef/resource/zypper_repository.rb @@ -29,7 +29,7 @@ class Chef introduced "13.3" property :repo_name, String, - regex: [/^[^\/]+$/], + regex: [%r{^[^/]+$}], description: "An optional property to set the repository name if it differs from the resource block's name.", validation_message: "repo_name property cannot contain a forward slash '/'", name_property: true diff --git a/lib/chef/role.rb b/lib/chef/role.rb index 034e9484a4..8607833a55 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -249,8 +249,8 @@ class Chef paths = Array(Chef::Config[:role_path]) paths.each do |path| roles_files = Dir.glob(File.join(Chef::Util::PathHelper.escape_glob_dir(path), "**", "**")) - js_files = roles_files.select { |file| file.match(/\/#{name}\.json$/) } - rb_files = roles_files.select { |file| file.match(/\/#{name}\.rb$/) } + js_files = roles_files.select { |file| file.match(%r{/#{name}\.json$}) } + rb_files = roles_files.select { |file| file.match(%r{/#{name}\.rb$}) } if js_files.count > 1 || rb_files.count > 1 raise Chef::Exceptions::DuplicateRole, "Multiple roles of same type found named #{name}" end diff --git a/lib/chef/run_list/run_list_item.rb b/lib/chef/run_list/run_list_item.rb index f5aec6de5e..e9e4f85ce3 100644 --- a/lib/chef/run_list/run_list_item.rb +++ b/lib/chef/run_list/run_list_item.rb @@ -18,10 +18,10 @@ class Chef class RunList class RunListItem - QUALIFIED_RECIPE = %r{^recipe\[([^\]@]+)(@([0-9]+(\.[0-9]+){1,2}))?\]$}.freeze - QUALIFIED_ROLE = %r{^role\[([^\]]+)\]$}.freeze - VERSIONED_UNQUALIFIED_RECIPE = %r{^([^@]+)(@([0-9]+(\.[0-9]+){1,2}))$}.freeze - FALSE_FRIEND = %r{[\[\]]}.freeze + QUALIFIED_RECIPE = /^recipe\[([^\]@]+)(@([0-9]+(\.[0-9]+){1,2}))?\]$/.freeze + QUALIFIED_ROLE = /^role\[([^\]]+)\]$/.freeze + VERSIONED_UNQUALIFIED_RECIPE = /^([^@]+)(@([0-9]+(\.[0-9]+){1,2}))$/.freeze + FALSE_FRIEND = /[\[\]]/.freeze attr_reader :name, :type, :version diff --git a/spec/functional/knife/exec_spec.rb b/spec/functional/knife/exec_spec.rb index 7cdf1c93eb..010b89c4f4 100644 --- a/spec/functional/knife/exec_spec.rb +++ b/spec/functional/knife/exec_spec.rb @@ -49,7 +49,7 @@ describe Chef::Knife::Exec do code = "$output.puts nodes.all" @knife.config[:exec] = code @knife.run - expect($output.string).to match(%r{node\[ohai-world\]}) + expect($output.string).to match(/node\[ohai-world\]/) end end diff --git a/spec/functional/resource/remote_file_spec.rb b/spec/functional/resource/remote_file_spec.rb index 44a7a46d68..b7e482794c 100644 --- a/spec/functional/resource/remote_file_spec.rb +++ b/spec/functional/resource/remote_file_spec.rb @@ -134,7 +134,7 @@ describe Chef::Resource::RemoteFile do let(:smb_file_local_file_name) { "smb_file.txt" } let(:smb_file_local_path) { File.join( smb_share_root_directory, smb_file_local_file_name ) } let(:smb_share_name) { "chef_smb_test" } - let(:smb_remote_path) { File.join("//#{ENV['COMPUTERNAME']}", smb_share_name, smb_file_local_file_name).gsub(/\//, "\\") } + let(:smb_remote_path) { File.join("//#{ENV['COMPUTERNAME']}", smb_share_name, smb_file_local_file_name).gsub(%r{/}, "\\") } let(:smb_file_content) { "hellofun" } let(:local_destination_path) { File.join(Dir.tmpdir, make_tmpname("chef_remote_file")) } let(:windows_current_user) { ENV["USERNAME"] } @@ -155,7 +155,7 @@ describe Chef::Resource::RemoteFile do before do shell_out("net.exe share #{smb_share_name} /delete") File.write(smb_file_local_path, smb_file_content ) - shell_out!("net.exe share #{smb_share_name}=\"#{smb_share_root_directory.gsub(/\//, '\\')}\" /grant:\"authenticated users\",read") + shell_out!("net.exe share #{smb_share_name}=\"#{smb_share_root_directory.gsub(%r{/}, '\\')}\" /grant:\"authenticated users\",read") end after do diff --git a/spec/integration/knife/config_get_spec.rb b/spec/integration/knife/config_get_spec.rb index f34d096051..98fefd729f 100644 --- a/spec/integration/knife/config_get_spec.rb +++ b/spec/integration/knife/config_get_spec.rb @@ -143,7 +143,7 @@ describe "knife config get", :workstation do let(:cmd_args) { %w{node_name client_key} } before { file(".chef/credentials", "[default]\nclient_name = \"three\"\nclient_key = \"three.pem\"") } - it { is_expected.to match(/^client_key:\s+\S*\/.chef\/three.pem\nnode_name:\s+three\Z/) } + it { is_expected.to match(%r{^client_key:\s+\S*/.chef/three.pem\nnode_name:\s+three\Z}) } end context "with a dotted argument" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ee486e919c..875287a0a4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -52,7 +52,7 @@ require "chef/knife" Dir["lib/chef/knife/**/*.rb"] .map { |f| f.gsub("lib/", "") } - .map { |f| f.gsub(%r{\.rb$}, "") } + .map { |f| f.gsub(/\.rb$/, "") } .each { |f| require f } require "chef/resource_resolver" @@ -93,7 +93,7 @@ require "spec/support/shared/unit/mock_shellout" Dir["spec/support/**/*.rb"] .reject { |f| f =~ %r{^spec/support/platforms} } .reject { |f| f =~ %r{^spec/support/pedant} } - .map { |f| f.gsub(%r{.rb$}, "") } + .map { |f| f.gsub(/.rb$/, "") } .map { |f| f.gsub(%r{spec/}, "") } .each { |f| require f } diff --git a/spec/support/shared/functional/execute_resource.rb b/spec/support/shared/functional/execute_resource.rb index 1a14bb38c3..e5639f1614 100644 --- a/spec/support/shared/functional/execute_resource.rb +++ b/spec/support/shared/functional/execute_resource.rb @@ -58,7 +58,7 @@ shared_context "a command that can be executed as an alternate user" do include Chef::Mixin::ShellOut before do - shell_out!("icacls \"#{script_output_dir.gsub(/\//, '\\')}\" /grant \"authenticated users:(F)\"") + shell_out!("icacls \"#{script_output_dir.gsub(%r{/}, '\\')}\" /grant \"authenticated users:(F)\"") end after do diff --git a/spec/unit/config_fetcher_spec.rb b/spec/unit/config_fetcher_spec.rb index abaea6b2dc..8dadd9e681 100644 --- a/spec/unit/config_fetcher_spec.rb +++ b/spec/unit/config_fetcher_spec.rb @@ -7,7 +7,7 @@ describe Chef::ConfigFetcher do let(:http) { double("Chef::HTTP::Simple") } let(:config_location_regex) { Regexp.escape(config_location) } - let(:invalid_json_error_regex) { %r{Could not parse the provided JSON file \(#{config_location_regex}\)} } + let(:invalid_json_error_regex) { /Could not parse the provided JSON file \(#{config_location_regex}\)/ } let(:fetcher) { Chef::ConfigFetcher.new(config_location) } diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb index ba9f59c97b..c747f14dd0 100644 --- a/spec/unit/cookbook_loader_spec.rb +++ b/spec/unit/cookbook_loader_spec.rb @@ -113,19 +113,19 @@ describe Chef::CookbookLoader do it "should load different attribute files from deeper paths" do expect(full_paths_for_part(:openldap, "attributes").detect do |f| - f =~ /cookbooks\/openldap\/attributes\/smokey.rb/ + f =~ %r{cookbooks/openldap/attributes/smokey.rb} end).not_to eql(nil) end it "should load definition files from deeper paths" do expect(full_paths_for_part(:openldap, "definitions").detect do |f| - f =~ /cookbooks\/openldap\/definitions\/server.rb/ + f =~ %r{cookbooks/openldap/definitions/server.rb} end).not_to eql(nil) end it "should load recipe files from deeper paths" do expect(full_paths_for_part(:openldap, "recipes").detect do |f| - f =~ /cookbooks\/openldap\/recipes\/one.rb/ + f =~ %r{cookbooks/openldap/recipes/one.rb} end).not_to eql(nil) end @@ -134,8 +134,8 @@ describe Chef::CookbookLoader do f =~ /\.dotfile$/ end).to match(/\.dotfile$/) expect(full_paths_for_part(:openldap, "files").detect do |f| - f =~ /\.ssh\/id_rsa$/ - end).to match(/\.ssh\/id_rsa$/) + f =~ %r{\.ssh/id_rsa$} + end).to match(%r{\.ssh/id_rsa$}) end it "should load the metadata for the cookbook" do diff --git a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb index 0cdb06c3b3..7add65150a 100644 --- a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb @@ -60,7 +60,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do @trace = [ "/var/chef/cache/cookbooks/syntax-err/recipes/default.rb:14:in `from_file'", "/var/chef/cache/cookbooks/syntax-err/recipes/default.rb:11:in `from_file'", - "/usr/local/lib/ruby/gems/chef/lib/chef/client.rb:123:in `run'" # should not display + "/usr/local/lib/ruby/gems/chef/lib/chef/client.rb:123:in `run'", # should not display ] @exception = Chef::Exceptions::Package.new("No such package 'non-existing-package'") @exception.set_backtrace(@trace) @@ -122,7 +122,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do source_line = "C:/Users/btm/chef/chef/spec/unit/fake_file.rb:2: undefined local variable or method `non_existent' for main:Object (NameError)" @resource.source_line = source_line @inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @exception) - expect(@inspector.recipe_snippet).to match(/^# In C:\/Users\/btm/) + expect(@inspector.recipe_snippet).to match(%r{^# In C:/Users/btm}) end it "parses a Windows path" do @@ -136,7 +136,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do source_line = "/home/btm/src/chef/chef/spec/unit/fake_file.rb:2: undefined local variable or method `non_existent' for main:Object (NameError)" @resource.source_line = source_line @inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @exception) - expect(@inspector.recipe_snippet).to match(/^# In \/home\/btm/) + expect(@inspector.recipe_snippet).to match(%r{^# In /home/btm}) end context "when the recipe file does not exist" do diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index ee376e2bb4..ebc4e13ee5 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -107,7 +107,7 @@ describe Chef::Knife::Bootstrap do expect(knife).to receive(:read_secret).and_return("secrets") expect(rendered_template).to match("cat > /etc/chef/encrypted_data_bag_secret <<'EOP'") expect(rendered_template).to match('{"run_list":\[\]}') - expect(rendered_template).to match(%r{secrets}) + expect(rendered_template).to match(/secrets/) end end end @@ -127,7 +127,7 @@ describe Chef::Knife::Bootstrap do knife.render_template end it "configures the preinstall command in the bootstrap template correctly" do - expect(rendered_template).to match(%r{command}) + expect(rendered_template).to match(/command/) end end @@ -138,7 +138,7 @@ describe Chef::Knife::Bootstrap do knife.render_template end it "configures the https_proxy environment variable in the bootstrap template correctly" do - expect(rendered_template).to match(%r{https_proxy="1.1.1.1" export https_proxy}) + expect(rendered_template).to match(/https_proxy="1.1.1.1" export https_proxy/) end end @@ -149,7 +149,7 @@ describe Chef::Knife::Bootstrap do knife.render_template end it "configures the https_proxy environment variable in the bootstrap template correctly" do - expect(rendered_template).to match(%r{no_proxy="localserver" export no_proxy}) + expect(rendered_template).to match(/no_proxy="localserver" export no_proxy/) end end @@ -360,7 +360,7 @@ describe Chef::Knife::Bootstrap do it "should create a hint file when told to" do knife.parse_options(["--hint", "openstack"]) knife.merge_configs - expect(knife.render_template).to match(/\/etc\/chef\/ohai\/hints\/openstack.json/) + expect(knife.render_template).to match(%r{/etc/chef/ohai/hints/openstack.json}) end it "should populate a hint file with JSON when given a file to read" do @@ -393,7 +393,7 @@ describe Chef::Knife::Bootstrap do let(:setting) { "api.opscode.com" } it "renders the client.rb with a single FQDN no_proxy entry" do - expect(rendered_template).to match(%r{.*no_proxy\s*"api.opscode.com".*}) + expect(rendered_template).to match(/.*no_proxy\s*"api.opscode.com".*/) end end @@ -401,7 +401,7 @@ describe Chef::Knife::Bootstrap do let(:setting) { "api.opscode.com,172.16.10.*" } it "renders the client.rb with comma-separated FQDN and wildcard IP address no_proxy entries" do - expect(rendered_template).to match(%r{.*no_proxy\s*"api.opscode.com,172.16.10.\*".*}) + expect(rendered_template).to match(/.*no_proxy\s*"api.opscode.com,172.16.10.\*".*/) end end @@ -459,7 +459,7 @@ describe Chef::Knife::Bootstrap do it "creates a secret file" do expect(knife).to receive(:encryption_secret_provided_ignore_encrypt_flag?).and_return(true) expect(knife).to receive(:read_secret).and_return(secret) - expect(rendered_template).to match(%r{#{secret}}) + expect(rendered_template).to match(/#{secret}/) end it "renders the client.rb with an encrypted_data_bag_secret entry" do @@ -1730,7 +1730,7 @@ describe Chef::Knife::Bootstrap do before do Chef::Config[:validation_key] = "/blah" allow(vault_handler_mock).to receive(:doing_chef_vault?).and_return false - allow(File).to receive(:exist?).with(/\/blah/).and_return false + allow(File).to receive(:exist?).with(%r{/blah}).and_return false end it_behaves_like "creating the client locally" end @@ -1738,7 +1738,7 @@ describe Chef::Knife::Bootstrap do context "when a valid validation key is given and we're doing old-style client creation" do before do Chef::Config[:validation_key] = "/blah" - allow(File).to receive(:exist?).with(/\/blah/).and_return true + allow(File).to receive(:exist?).with(%r{/blah}).and_return true allow(vault_handler_mock).to receive(:doing_chef_vault?).and_return false end diff --git a/spec/unit/knife/configure_client_spec.rb b/spec/unit/knife/configure_client_spec.rb index c83ceed6cb..be76250e7c 100644 --- a/spec/unit/knife/configure_client_spec.rb +++ b/spec/unit/knife/configure_client_spec.rb @@ -58,7 +58,7 @@ describe Chef::Knife::ConfigureClient do it "should write out the config file" do allow(FileUtils).to receive(:mkdir_p) @knife.run - expect(@client_file.string).to match /chef_server_url\s+'https\:\/\/chef\.example\.com'/ + expect(@client_file.string).to match %r{chef_server_url\s+'https\://chef\.example\.com'} expect(@client_file.string).to match /validation_client_name\s+'chef-validator'/ end diff --git a/spec/unit/knife/configure_spec.rb b/spec/unit/knife/configure_spec.rb index 1cdad0cd0e..6b41e54778 100644 --- a/spec/unit/knife/configure_spec.rb +++ b/spec/unit/knife/configure_spec.rb @@ -159,7 +159,7 @@ describe Chef::Knife::Configure do @knife.run expect(config_file.string).to match(/^client_name[\s]+=[\s]+'#{Etc.getlogin}'$/) expect(config_file.string).to match(%r{^client_key[\s]+=[\s]+'/home/you/.chef/#{Etc.getlogin}.pem'$}) - expect(config_file.string).to match(%r{^chef_server_url\s+=[\s]+'#{default_server_url}'$}) + expect(config_file.string).to match(/^chef_server_url\s+=[\s]+'#{default_server_url}'$/) end it "creates a new client when given the --initial option" do diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb index 122c284b93..78dd20e2d2 100644 --- a/spec/unit/knife/cookbook_download_spec.rb +++ b/spec/unit/knife/cookbook_download_spec.rb @@ -112,7 +112,7 @@ describe Chef::Knife::CookbookDownload do it "should print an error and exit if the cookbook download directory already exists" do expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(true) - expect(@knife.ui).to receive(:fatal).with(/\/var\/tmp\/chef\/foobar-1\.0\.0 exists/i) + expect(@knife.ui).to receive(:fatal).with(%r{/var/tmp/chef/foobar-1\.0\.0 exists}i) expect { @knife.run }.to raise_error(SystemExit) end @@ -141,7 +141,7 @@ describe Chef::Knife::CookbookDownload do expect(@stderr.string).to match /downloading #{segment}/im end expect(@stderr.string).to match /downloading foobar cookbook version 1\.0\.0/im - expect(@stderr.string).to match /cookbook downloaded to \/var\/tmp\/chef\/foobar-1\.0\.0/im + expect(@stderr.string).to match %r{cookbook downloaded to /var/tmp/chef/foobar-1\.0\.0}im end describe "with -f or --force" do diff --git a/spec/unit/knife/cookbook_metadata_spec.rb b/spec/unit/knife/cookbook_metadata_spec.rb index c19fc5ae2d..04d851be6a 100644 --- a/spec/unit/knife/cookbook_metadata_spec.rb +++ b/spec/unit/knife/cookbook_metadata_spec.rb @@ -98,8 +98,8 @@ describe Chef::Knife::CookbookMetadata do it "should generate the metadata for each cookbook" do expect(Chef::CookbookLoader).to receive(:new).with(cookbook_dir).and_call_original knife.run - expect(stderr.string).to match /generating metadata for foo from #{cookbook_dir}\/foo\/metadata\.rb/im - expect(stderr.string).to match /generating metadata for bar from #{cookbook_dir}\/bar\/metadata\.rb/im + expect(stderr.string).to match %r{generating metadata for foo from #{cookbook_dir}/foo/metadata\.rb}im + expect(stderr.string).to match %r{generating metadata for bar from #{cookbook_dir}/bar/metadata\.rb}im end it "with -o or --cookbook_path should look in the provided path and generate cookbook metadata" do @@ -107,8 +107,8 @@ describe Chef::Knife::CookbookMetadata do knife.config[:cookbook_path] = cookbook_dir expect(Chef::CookbookLoader).to receive(:new).with(cookbook_dir).and_call_original knife.run - expect(stderr.string).to match /generating metadata for foo from #{cookbook_dir}\/foo\/metadata\.rb/im - expect(stderr.string).to match /generating metadata for bar from #{cookbook_dir}\/bar\/metadata\.rb/im + expect(stderr.string).to match %r{generating metadata for foo from #{cookbook_dir}/foo/metadata\.rb}im + expect(stderr.string).to match %r{generating metadata for bar from #{cookbook_dir}/bar/metadata\.rb}im end end diff --git a/spec/unit/knife/core/gem_glob_loader_spec.rb b/spec/unit/knife/core/gem_glob_loader_spec.rb index 689426de1b..c8bd34d4a9 100644 --- a/spec/unit/knife/core/gem_glob_loader_spec.rb +++ b/spec/unit/knife/core/gem_glob_loader_spec.rb @@ -34,7 +34,7 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do it "builds a list of the core subcommand file require paths" do expect(loader.subcommand_files).not_to be_empty loader.subcommand_files.each do |require_path| - expect(require_path).to match(/chef\/knife\/.*|plugins\/knife\/.*/) + expect(require_path).to match(%r{chef/knife/.*|plugins/knife/.*}) end end @@ -52,7 +52,7 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do expect($LOAD_PATH).to receive(:map).and_return([]) if Gem::Specification.respond_to? :latest_specs expect(Gem::Specification).to receive(:latest_specs).with(true).and_return(gems) - expect(gems[0]).to receive(:matches_for_glob).with(/chef\/knife\/\*\.rb\{(.*),\.rb,(.*)\}/).and_return(gem_files) + expect(gems[0]).to receive(:matches_for_glob).with(%r{chef/knife/\*\.rb\{(.*),\.rb,(.*)\}}).and_return(gem_files) else expect(Gem.source_index).to receive(:latest_specs).with(true).and_return(gems) expect(gems[0]).to receive(:require_paths).twice.and_return(["lib"]) @@ -185,7 +185,7 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do expect(Gem.source_index).to receive(:latest_specs).and_call_original end loader.subcommand_files.each do |require_path| - expect(require_path).to match(/chef\/knife\/.*|plugins\/knife\/.*/) + expect(require_path).to match(%r{chef/knife/.*|plugins/knife/.*}) end end @@ -201,7 +201,7 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do expect(Gem.source_index).to receive(:latest_specs).and_call_original end loader.subcommand_files.each do |require_path| - expect(require_path).to match(/chef\/knife\/.*|plugins\/knife\/.*/) + expect(require_path).to match(%r{chef/knife/.*|plugins/knife/.*}) end end end diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index d7943f0f8c..70e4091847 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -468,8 +468,8 @@ describe Chef::Knife do allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("403 Forbidden", response)) allow(knife).to receive(:username).and_return("sadpanda") knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action}) - expect(stderr.string).to match(%r{Response: y u no administrator}) + expect(stderr.string).to match(/ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action/) + expect(stderr.string).to match(/Response: y u no administrator/) end context "when proxy servers are set" do @@ -488,9 +488,9 @@ describe Chef::Knife do allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("403 Forbidden", response)) allow(knife).to receive(:username).and_return("sadpanda") knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action}) - expect(stderr.string).to match(%r{ERROR: There are proxy servers configured, your server url may need to be added to NO_PROXY.}) - expect(stderr.string).to match(%r{Response: y u no administrator}) + expect(stderr.string).to match(/ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action/) + expect(stderr.string).to match(/ERROR: There are proxy servers configured, your server url may need to be added to NO_PROXY./) + expect(stderr.string).to match(/Response: y u no administrator/) end end @@ -500,8 +500,8 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "y u search wrong")) allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("400 Bad Request", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: The data in your request was invalid}) - expect(stderr.string).to match(%r{Response: y u search wrong}) + expect(stderr.string).to match(/ERROR: The data in your request was invalid/) + expect(stderr.string).to match(/Response: y u search wrong/) end it "formats 404s nicely" do @@ -510,8 +510,8 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "nothing to see here")) allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("404 Not Found", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: The object you are looking for could not be found}) - expect(stderr.string).to match(%r{Response: nothing to see here}) + expect(stderr.string).to match(/ERROR: The object you are looking for could not be found/) + expect(stderr.string).to match(/Response: nothing to see here/) end it "formats 406s (non-supported API version error) nicely" do @@ -536,8 +536,8 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "sad trombone")) allow(knife).to receive(:run).and_raise(Net::HTTPFatalError.new("500 Internal Server Error", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: internal server error}) - expect(stderr.string).to match(%r{Response: sad trombone}) + expect(stderr.string).to match(/ERROR: internal server error/) + expect(stderr.string).to match(/Response: sad trombone/) end it "formats 502s nicely" do @@ -546,8 +546,8 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "sadder trombone")) allow(knife).to receive(:run).and_raise(Net::HTTPFatalError.new("502 Bad Gateway", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: bad gateway}) - expect(stderr.string).to match(%r{Response: sadder trombone}) + expect(stderr.string).to match(/ERROR: bad gateway/) + expect(stderr.string).to match(/Response: sadder trombone/) end it "formats 503s nicely" do @@ -556,8 +556,8 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "saddest trombone")) allow(knife).to receive(:run).and_raise(Net::HTTPFatalError.new("503 Service Unavailable", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: Service temporarily unavailable}) - expect(stderr.string).to match(%r{Response: saddest trombone}) + expect(stderr.string).to match(/ERROR: Service temporarily unavailable/) + expect(stderr.string).to match(/Response: saddest trombone/) end it "formats other HTTP errors nicely" do @@ -566,16 +566,16 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "nobugfixtillyoubuy")) allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("402 Payment Required", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: Payment Required}) - expect(stderr.string).to match(%r{Response: nobugfixtillyoubuy}) + expect(stderr.string).to match(/ERROR: Payment Required/) + expect(stderr.string).to match(/Response: nobugfixtillyoubuy/) end it "formats NameError and NoMethodError nicely" do allow(knife).to receive(:run).and_raise(NameError.new("Undefined constant FUUU")) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: .* encountered an unexpected error}) - expect(stderr.string).to match(%r{This may be a bug in the 'knife' .* command or plugin}) - expect(stderr.string).to match(%r{Exception: NameError: Undefined constant FUUU}) + expect(stderr.string).to match(/ERROR: .* encountered an unexpected error/) + expect(stderr.string).to match(/This may be a bug in the 'knife' .* command or plugin/) + expect(stderr.string).to match(/Exception: NameError: Undefined constant FUUU/) end it "formats missing private key errors nicely" do @@ -583,7 +583,7 @@ describe Chef::Knife do allow(knife).to receive(:api_key).and_return("/home/root/.chef/no-key-here.pem") knife.run_with_pretty_exceptions expect(stderr.string).to match(%r{ERROR: Your private key could not be loaded from /home/root/.chef/no-key-here.pem}) - expect(stderr.string).to match(%r{Check your configuration file and ensure that your private key is readable}) + expect(stderr.string).to match(/Check your configuration file and ensure that your private key is readable/) end it "formats connection refused errors nicely" do @@ -592,8 +592,8 @@ describe Chef::Knife do # Errno::ECONNREFUSED message differs by platform # *nix = Errno::ECONNREFUSED: Connection refused # win32: Errno::ECONNREFUSED: No connection could be made because the target machine actively refused it. - expect(stderr.string).to match(%r{ERROR: Network Error: .* - y u no shut up}) - expect(stderr.string).to match(%r{Check your .* configuration and network settings}) + expect(stderr.string).to match(/ERROR: Network Error: .* - y u no shut up/) + expect(stderr.string).to match(/Check your .* configuration and network settings/) end it "formats SSL errors nicely and suggests to use `knife ssl check` and `knife ssl fetch`" do diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index b2e992f8eb..50e15f4505 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -1052,19 +1052,19 @@ describe "Chef::Resource.property" do context "default ordering deprecation warnings" do it "emits an error for property :x, default: 10, #{name}: true" do expect { resource_class.property :x, :default => 10, name.to_sym => true }.to raise_error ArgumentError, - /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/ + %r{A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)} end it "emits an error for property :x, default: nil, #{name}: true" do expect { resource_class.property :x, :default => nil, name.to_sym => true }.to raise_error ArgumentError, - /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/ + %r{A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)} end it "emits an error for property :x, #{name}: true, default: 10" do expect { resource_class.property :x, name.to_sym => true, :default => 10 }.to raise_error ArgumentError, - /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/ + %r{A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)} end it "emits an error for property :x, #{name}: true, default: nil" do expect { resource_class.property :x, name.to_sym => true, :default => nil }.to raise_error ArgumentError, - /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/ + %r{A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)} end end end diff --git a/spec/unit/provider/package/bff_spec.rb b/spec/unit/provider/package/bff_spec.rb index 7606092762..b428ec0a72 100644 --- a/spec/unit/provider/package/bff_spec.rb +++ b/spec/unit/provider/package/bff_spec.rb @@ -81,7 +81,7 @@ describe Chef::Provider::Package::Bff do status = double("Status", stdout: info, exitstatus: 0) expect(@provider).to receive(:shell_out_compacted).with("installp", "-L", "-d", "/tmp/samba.base", timeout: 900).and_return(status) expect(@provider).to receive(:shell_out_compacted).with("lslpp", "-lcq", "samba.base", timeout: 900).and_return(@empty_status) - expect(logger).to receive(:warn).once.with(%r{bff package by product name}) + expect(logger).to receive(:warn).once.with(/bff package by product name/) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("samba.base") diff --git a/spec/unit/provider/package/windows/exe_spec.rb b/spec/unit/provider/package/windows/exe_spec.rb index 4f6a6121bd..6fa1747b03 100644 --- a/spec/unit/provider/package/windows/exe_spec.rb +++ b/spec/unit/provider/package/windows/exe_spec.rb @@ -117,7 +117,7 @@ describe Chef::Provider::Package::Windows::Exe do context "no version given and one package installed with unquoted uninstall string" do it "removes installed package and quotes uninstall string" do allow(::File).to receive(:exist?).with("uninst_dir/uninst_file").and_return(true) - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"uninst_dir\/uninst_file\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"uninst_dir/uninst_file\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.remove_package end end @@ -126,7 +126,7 @@ describe Chef::Provider::Package::Windows::Exe do it "removes installed package and quotes uninstall string" do new_resource.timeout = 300 allow(::File).to receive(:exist?).with("uninst_dir/uninst_file").and_return(true) - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"uninst_dir\/uninst_file\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, timeout: 300, returns: [0]) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"uninst_dir/uninst_file\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, timeout: 300, returns: [0]) provider.remove_package end end @@ -148,15 +148,15 @@ describe Chef::Provider::Package::Windows::Exe do context "version given and installed" do it "removes given version" do new_resource.version("v2") - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"uninst_dir2\/uninst_file2\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"uninst_dir2/uninst_file2\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.remove_package end end context "no version given" do it "removes both versions" do - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"uninst_dir1\/uninst_file1\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"uninst_dir2\/uninst_file2\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"uninst_dir1/uninst_file1\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"uninst_dir2/uninst_file2\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.remove_package end end @@ -167,7 +167,7 @@ describe Chef::Provider::Package::Windows::Exe do let(:provider) { Chef::Provider::Package::Windows::Exe.new(new_resource, :nsis, uninstall_entry) } it "calls installer with the correct flags" do - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"#{Regexp.quote(new_resource.source)}\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"#{Regexp.quote(new_resource.source)}\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.install_package end end @@ -176,7 +176,7 @@ describe Chef::Provider::Package::Windows::Exe do let(:provider) { Chef::Provider::Package::Windows::Exe.new(new_resource, :installshield, uninstall_entry) } it "calls installer with the correct flags" do - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"#{Regexp.quote(new_resource.source)}\" \/s \/sms & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"#{Regexp.quote(new_resource.source)}\" /s /sms & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.install_package end end @@ -185,7 +185,7 @@ describe Chef::Provider::Package::Windows::Exe do let(:provider) { Chef::Provider::Package::Windows::Exe.new(new_resource, :inno, uninstall_entry) } it "calls installer with the correct flags" do - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"#{Regexp.quote(new_resource.source)}\" \/VERYSILENT \/SUPPRESSMSGBOXES \/NORESTART & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"#{Regexp.quote(new_resource.source)}\" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.install_package end end @@ -194,7 +194,7 @@ describe Chef::Provider::Package::Windows::Exe do let(:provider) { Chef::Provider::Package::Windows::Exe.new(new_resource, :wise, uninstall_entry) } it "calls installer with the correct flags" do - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"#{Regexp.quote(new_resource.source)}\" \/s & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"#{Regexp.quote(new_resource.source)}\" /s & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.install_package end end diff --git a/spec/unit/provider/package/windows/msi_spec.rb b/spec/unit/provider/package/windows/msi_spec.rb index 0e939610db..d2902e1bb1 100644 --- a/spec/unit/provider/package/windows/msi_spec.rb +++ b/spec/unit/provider/package/windows/msi_spec.rb @@ -104,14 +104,14 @@ describe Chef::Provider::Package::Windows::MSI do describe "install_package" do it "calls msiexec /qn /i" do - expect(provider).to receive(:shell_out!).with(/msiexec \/qn \/i \"#{Regexp.quote(new_resource.source)}\"/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /qn /i \"#{Regexp.quote(new_resource.source)}\"}, kind_of(Hash)) provider.install_package end end describe "remove_package" do it "calls msiexec /qn /x" do - expect(provider).to receive(:shell_out!).with(/msiexec \/qn \/x \"#{Regexp.quote(new_resource.source)}\"/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /qn /x \"#{Regexp.quote(new_resource.source)}\"}, kind_of(Hash)) provider.remove_package end @@ -121,7 +121,7 @@ describe Chef::Provider::Package::Windows::MSI do end it "removes installed package" do - expect(provider).to receive(:shell_out!).with(/msiexec \/x {guid} \/q/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid} /q}, kind_of(Hash)) provider.remove_package end @@ -140,8 +140,8 @@ describe Chef::Provider::Package::Windows::MSI do end it "removes both installed package" do - expect(provider).to receive(:shell_out!).with(/msiexec \/x {guid} \/q/, kind_of(Hash)) - expect(provider).to receive(:shell_out!).with(/msiexec \/x {guid2} \/q/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid} /q}, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid2} /q}, kind_of(Hash)) provider.remove_package end end @@ -150,7 +150,7 @@ describe Chef::Provider::Package::Windows::MSI do before { new_resource.options("/Q") } it "does not duplicate quiet switch" do - expect(provider).to receive(:shell_out!).with(/msiexec \/x {guid} \/Q/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid} /Q}, kind_of(Hash)) provider.remove_package end end @@ -159,7 +159,7 @@ describe Chef::Provider::Package::Windows::MSI do before { new_resource.options("/qn") } it "does not duplicate quiet switch" do - expect(provider).to receive(:shell_out!).with(/msiexec \/x {guid} \/qn/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid} /qn}, kind_of(Hash)) provider.remove_package end end diff --git a/spec/unit/provider/registry_key_spec.rb b/spec/unit/provider/registry_key_spec.rb index 9a7dd9996e..2df2c917f9 100644 --- a/spec/unit/provider/registry_key_spec.rb +++ b/spec/unit/provider/registry_key_spec.rb @@ -322,7 +322,7 @@ describe Chef::Provider::RegistryKey do expect(@double_registry).to receive(:get_values).with(keyname).and_return( [ { name: "one", type: :string, data: "initial value" }, - { name: "two", type: :dword, data: 9001 } + { name: "two", type: :dword, data: 9001 }, ] ) end diff --git a/spec/unit/provider/route_spec.rb b/spec/unit/provider/route_spec.rb index 67311aa6f7..ad5223a04f 100644 --- a/spec/unit/provider/route_spec.rb +++ b/spec/unit/provider/route_spec.rb @@ -125,7 +125,7 @@ describe Chef::Provider::Route do @resource_add.action(:add) @provider.run_action(:add) expect(route_file.string.split("\n").size).to eq(1) - expect(route_file.string).to match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/) + expect(route_file.string).to match(%r{^192\.168\.1\.0/24 via 192\.168\.0\.1$}) end end @@ -150,12 +150,12 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "generate_command for action_add" do it "should include a netmask when a one is specified" do @new_resource.netmask("255.255.0.0") - expect(@provider.generate_command(:add).join(" ")).to match(/\/\d{1,2}/) + expect(@provider.generate_command(:add).join(" ")).to match(%r{/\d{1,2}}) end it "should not include a netmask when a one is specified" do @new_resource.netmask(nil) - expect(@provider.generate_command(:add).join(" ")).not_to match(/\/\d{1,2}/) + expect(@provider.generate_command(:add).join(" ")).not_to match(%r{/\d{1,2}}) end it "should include ' via $gateway ' when a gateway is specified" do @@ -176,12 +176,12 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "generate_command for action_delete" do it "should include a netmask when a one is specified" do @new_resource.netmask("255.255.0.0") - expect(@provider.generate_command(:delete).join(" ")).to match(/\/\d{1,2}/) + expect(@provider.generate_command(:delete).join(" ")).to match(%r{/\d{1,2}}) end it "should not include a netmask when a one is specified" do @new_resource.netmask(nil) - expect(@provider.generate_command(:delete).join(" ")).not_to match(/\/\d{1,2}/) + expect(@provider.generate_command(:delete).join(" ")).not_to match(%r{/\d{1,2}}) end it "should include ' via $gateway ' when a gateway is specified" do @@ -197,11 +197,11 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "config_file_contents for action_add" do it "should include a netmask when a one is specified" do @new_resource.netmask("255.255.0.0") - expect(@provider.config_file_contents(:add, target: @new_resource.target, netmask: @new_resource.netmask)).to match(/\/\d{1,2}.*\n$/) + expect(@provider.config_file_contents(:add, target: @new_resource.target, netmask: @new_resource.netmask)).to match(%r{/\d{1,2}.*\n$}) end it "should not include a netmask when a one is specified" do - expect(@provider.config_file_contents(:add, target: @new_resource.target)).not_to match(/\/\d{1,2}.*\n$/) + expect(@provider.config_file_contents(:add, target: @new_resource.target)).not_to match(%r{/\d{1,2}.*\n$}) end it "should include ' via $gateway ' when a gateway is specified" do @@ -261,10 +261,10 @@ describe Chef::Provider::Route do @provider.action = :add @provider.generate_config expect(route_file.string.split("\n").size).to eq(4) - expect(route_file.string).to match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/) - expect(route_file.string).to match(/^192\.168\.2\.0\/24 via 192\.168\.0\.1$/) - expect(route_file.string).to match(/^192\.168\.3\.0\/24 via 192\.168\.0\.1$/) - expect(route_file.string).to match(/^192\.168\.4\.0\/24 via 192\.168\.0\.1$/) + expect(route_file.string).to match(%r{^192\.168\.1\.0/24 via 192\.168\.0\.1$}) + expect(route_file.string).to match(%r{^192\.168\.2\.0/24 via 192\.168\.0\.1$}) + expect(route_file.string).to match(%r{^192\.168\.3\.0/24 via 192\.168\.0\.1$}) + expect(route_file.string).to match(%r{^192\.168\.4\.0/24 via 192\.168\.0\.1$}) end end end diff --git a/spec/unit/util/backup_spec.rb b/spec/unit/util/backup_spec.rb index 8bc68ec160..3a9a45b841 100644 --- a/spec/unit/util/backup_spec.rb +++ b/spec/unit/util/backup_spec.rb @@ -110,7 +110,7 @@ describe Chef::Util::Backup do end it "should strip the drive letter off for windows" do expect(@backup).to receive(:path).and_return('c:\a\b\c.txt') - expect(@backup.send(:backup_filename)).to match(%r|^\\a\\b\\c.txt.chef-\d{14}.\d{6}$|) + expect(@backup.send(:backup_filename)).to match(/^\\a\\b\\c.txt.chef-\d{14}.\d{6}$/) end it "should strip the drive letter off for windows (with forwardslashes)" do expect(@backup).to receive(:path).and_return("c:/a/b/c.txt") |