summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-07-05 11:44:16 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-07-05 12:41:14 -0700
commit7bf98ad06b30b7feb4ea3fbbe45a5b733467a5d3 (patch)
treeb0995ded1a63654d3f54140bd880c69f86afd52f /spec
parent9802d7c075c8b7dae42dbcecd92d492f7fa128ac (diff)
downloadchef-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>
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/knife/exec_spec.rb2
-rw-r--r--spec/functional/resource/remote_file_spec.rb4
-rw-r--r--spec/integration/knife/config_get_spec.rb2
-rw-r--r--spec/spec_helper.rb4
-rw-r--r--spec/support/shared/functional/execute_resource.rb2
-rw-r--r--spec/unit/config_fetcher_spec.rb2
-rw-r--r--spec/unit/cookbook_loader_spec.rb10
-rw-r--r--spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb6
-rw-r--r--spec/unit/knife/bootstrap_spec.rb20
-rw-r--r--spec/unit/knife/configure_client_spec.rb2
-rw-r--r--spec/unit/knife/configure_spec.rb2
-rw-r--r--spec/unit/knife/cookbook_download_spec.rb4
-rw-r--r--spec/unit/knife/cookbook_metadata_spec.rb8
-rw-r--r--spec/unit/knife/core/gem_glob_loader_spec.rb8
-rw-r--r--spec/unit/knife_spec.rb46
-rw-r--r--spec/unit/property_spec.rb8
-rw-r--r--spec/unit/provider/package/bff_spec.rb2
-rw-r--r--spec/unit/provider/package/windows/exe_spec.rb18
-rw-r--r--spec/unit/provider/package/windows/msi_spec.rb14
-rw-r--r--spec/unit/provider/registry_key_spec.rb2
-rw-r--r--spec/unit/provider/route_spec.rb22
-rw-r--r--spec/unit/util/backup_spec.rb2
22 files changed, 95 insertions, 95 deletions
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")