diff options
Diffstat (limited to 'spec/unit/knife')
102 files changed, 1029 insertions, 1029 deletions
diff --git a/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb b/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb index 75e0ff6b00..4bdd994906 100644 --- a/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb +++ b/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::Bootstrap::ChefVaultHandler do @@ -57,29 +57,29 @@ describe Chef::Knife::Bootstrap::ChefVaultHandler do context "from knife_config[:bootstrap_vault_item]" do it "sets a single item as a scalar" do - knife_config[:bootstrap_vault_item] = { 'vault' => 'item1' } - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) + knife_config[:bootstrap_vault_item] = { "vault" => "item1" } + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end it "sets a single item as an array" do - knife_config[:bootstrap_vault_item] = { 'vault' => [ 'item1' ] } - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) + knife_config[:bootstrap_vault_item] = { "vault" => [ "item1" ] } + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end it "sets two items as an array" do - knife_config[:bootstrap_vault_item] = { 'vault' => [ 'item1', 'item2' ] } - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item2').and_return(bootstrap_vault_item) + knife_config[:bootstrap_vault_item] = { "vault" => [ "item1", "item2" ] } + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item2").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end it "sets two vaults from different hash keys" do - knife_config[:bootstrap_vault_item] = { 'vault' => [ 'item1', 'item2' ], 'vault2' => [ 'item3' ] } - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item2').and_return(bootstrap_vault_item) - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault2', 'item3').and_return(bootstrap_vault_item) + knife_config[:bootstrap_vault_item] = { "vault" => [ "item1", "item2" ], "vault2" => [ "item3" ] } + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item2").and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault2", "item3").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end end @@ -87,28 +87,28 @@ describe Chef::Knife::Bootstrap::ChefVaultHandler do context "from knife_config[:bootstrap_vault_json]" do it "sets a single item as a scalar" do knife_config[:bootstrap_vault_json] = '{ "vault": "item1" }' - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end it "sets a single item as an array" do knife_config[:bootstrap_vault_json] = '{ "vault": [ "item1" ] }' - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end it "sets two items as an array" do knife_config[:bootstrap_vault_json] = '{ "vault": [ "item1", "item2" ] }' - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item2').and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item2").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end it "sets two vaults from different hash keys" do knife_config[:bootstrap_vault_json] = '{ "vault": [ "item1", "item2" ], "vault2": [ "item3" ] }' - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item2').and_return(bootstrap_vault_item) - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault2', 'item3').and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item2").and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault2", "item3").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end end @@ -123,28 +123,28 @@ describe Chef::Knife::Bootstrap::ChefVaultHandler do it "sets a single item as a scalar" do setup_file_contents('{ "vault": "item1" }') - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end it "sets a single item as an array" do setup_file_contents('{ "vault": [ "item1" ] }') - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end it "sets two items as an array" do setup_file_contents('{ "vault": [ "item1", "item2" ] }') - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item2').and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item2").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end it "sets two vaults from different hash keys" do setup_file_contents('{ "vault": [ "item1", "item2" ], "vault2": [ "item3" ] }') - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item1').and_return(bootstrap_vault_item) - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault', 'item2').and_return(bootstrap_vault_item) - expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with('vault2', 'item3').and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item2").and_return(bootstrap_vault_item) + expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault2", "item3").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end end diff --git a/spec/unit/knife/bootstrap/client_builder_spec.rb b/spec/unit/knife/bootstrap/client_builder_spec.rb index 6812a24c91..791b84b9c3 100644 --- a/spec/unit/knife/bootstrap/client_builder_spec.rb +++ b/spec/unit/knife/bootstrap/client_builder_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::Bootstrap::ClientBuilder do @@ -42,7 +42,7 @@ describe Chef::Knife::Bootstrap::ClientBuilder do } context "#sanity_check!" do - let(:response_404) { OpenStruct.new(:code => '404') } + let(:response_404) { OpenStruct.new(:code => "404") } let(:exception_404) { Net::HTTPServerException.new("404 not found", response_404) } context "in cases where the prompting fails" do @@ -54,14 +54,14 @@ describe Chef::Knife::Bootstrap::ClientBuilder do it "exits when the node exists and the user does not want to delete" do expect(rest).to receive(:get).with("nodes/#{node_name}") - expect(ui.stdin).to receive(:readline).and_return('n') + expect(ui.stdin).to receive(:readline).and_return("n") expect { client_builder.run }.to raise_error(SystemExit) end it "exits when the client exists and the user does not want to delete" do expect(rest).to receive(:get).with("nodes/#{node_name}").and_raise(exception_404) expect(rest).to receive(:get).with("clients/#{node_name}") - expect(ui.stdin).to receive(:readline).and_return('n') + expect(ui.stdin).to receive(:readline).and_return("n") expect { client_builder.run }.to raise_error(SystemExit) end end @@ -81,7 +81,7 @@ describe Chef::Knife::Bootstrap::ClientBuilder do it "when we are allowed to delete an old node" do expect(rest).to receive(:get).with("nodes/#{node_name}") - expect(ui.stdin).to receive(:readline).and_return('y') + expect(ui.stdin).to receive(:readline).and_return("y") expect(rest).to receive(:get).with("clients/#{node_name}").and_raise(exception_404) expect(rest).to receive(:delete).with("nodes/#{node_name}") expect { client_builder.run }.not_to raise_error @@ -90,7 +90,7 @@ describe Chef::Knife::Bootstrap::ClientBuilder do it "when we are allowed to delete an old client" do expect(rest).to receive(:get).with("nodes/#{node_name}").and_raise(exception_404) expect(rest).to receive(:get).with("clients/#{node_name}") - expect(ui.stdin).to receive(:readline).and_return('y') + expect(ui.stdin).to receive(:readline).and_return("y") expect(rest).to receive(:delete).with("clients/#{node_name}") expect { client_builder.run }.not_to raise_error end @@ -98,7 +98,7 @@ describe Chef::Knife::Bootstrap::ClientBuilder do it "when we are are allowed to delete both an old client and node" do expect(rest).to receive(:get).with("nodes/#{node_name}") expect(rest).to receive(:get).with("clients/#{node_name}") - expect(ui.stdin).to receive(:readline).twice.and_return('y') + expect(ui.stdin).to receive(:readline).twice.and_return("y") expect(rest).to receive(:delete).with("nodes/#{node_name}") expect(rest).to receive(:delete).with("clients/#{node_name}") expect { client_builder.run }.not_to raise_error diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index b4babdc14f..c64b2e49ea 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -16,10 +16,10 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" Chef::Knife::Bootstrap.load_deps -require 'net/ssh' +require "net/ssh" describe Chef::Knife::Bootstrap do before do @@ -102,7 +102,7 @@ describe Chef::Knife::Bootstrap do context "when :bootstrap_template config is set to a template name" do let(:bootstrap_template) { "example" } - let(:builtin_template_path) { File.expand_path(File.join(File.dirname(__FILE__), '../../../lib/chef/knife/bootstrap/templates', "example.erb"))} + let(:builtin_template_path) { File.expand_path(File.join(File.dirname(__FILE__), "../../../lib/chef/knife/bootstrap/templates", "example.erb"))} let(:chef_config_dir_template_path) { "/knife/chef/config/bootstrap/example.erb" } @@ -237,7 +237,7 @@ describe Chef::Knife::Bootstrap do context "with bootstrap_attribute options" do let(:jsonfile) { - file = Tempfile.new (['node', '.json']) + file = Tempfile.new (["node", ".json"]) File.open(file.path, "w") {|f| f.puts '{"foo":{"bar":"baz"}}' } file } @@ -385,7 +385,7 @@ describe Chef::Knife::Bootstrap do end describe "when transferring trusted certificates" do - let(:trusted_certs_dir) { Chef::Util::PathHelper.cleanpath(File.join(File.dirname(__FILE__), '../../data/trusted_certs')) } + let(:trusted_certs_dir) { Chef::Util::PathHelper.cleanpath(File.join(File.dirname(__FILE__), "../../data/trusted_certs")) } let(:rendered_template) do knife.merge_configs @@ -509,15 +509,15 @@ describe Chef::Knife::Bootstrap do end it "configures the ssh user" do - expect(knife_ssh.config[:ssh_user]).to eq('rooty') + expect(knife_ssh.config[:ssh_user]).to eq("rooty") end it "configures the ssh password" do - expect(knife_ssh.config[:ssh_password]).to eq('open_sesame') + expect(knife_ssh.config[:ssh_password]).to eq("open_sesame") end it "configures the ssh port" do - expect(knife_ssh.config[:ssh_port]).to eq('4001') + expect(knife_ssh.config[:ssh_port]).to eq("4001") end it "configures the ssh agent forwarding" do @@ -525,7 +525,7 @@ describe Chef::Knife::Bootstrap do end it "configures the ssh identity file" do - expect(knife_ssh.config[:ssh_identity_file]).to eq('~/.ssh/me.rsa') + expect(knife_ssh.config[:ssh_identity_file]).to eq("~/.ssh/me.rsa") end end @@ -537,8 +537,8 @@ describe Chef::Knife::Bootstrap do it "use_sudo_password contains description and long params for help" do expect(knife.options).to have_key(:use_sudo_password) \ - and expect(knife.options[:use_sudo_password][:description].to_s).not_to eq('')\ - and expect(knife.options[:use_sudo_password][:long].to_s).not_to eq('') + and expect(knife.options[:use_sudo_password][:description].to_s).not_to eq("")\ + and expect(knife.options[:use_sudo_password][:long].to_s).not_to eq("") end it "uses the password from --ssh-password for sudo when --use-sudo-password is set" do @@ -570,11 +570,11 @@ describe Chef::Knife::Bootstrap do end it "configures the ssh user" do - expect(knife_ssh.config[:ssh_user]).to eq('curiosity') + expect(knife_ssh.config[:ssh_user]).to eq("curiosity") end it "configures the ssh port" do - expect(knife_ssh.config[:ssh_port]).to eq('2430') + expect(knife_ssh.config[:ssh_port]).to eq("2430") end it "configures the ssh agent forwarding" do @@ -582,11 +582,11 @@ describe Chef::Knife::Bootstrap do end it "configures the ssh identity file" do - expect(knife_ssh.config[:ssh_identity_file]).to eq('~/.ssh/you.rsa') + expect(knife_ssh.config[:ssh_identity_file]).to eq("~/.ssh/you.rsa") end it "configures the ssh gateway" do - expect(knife_ssh.config[:ssh_gateway]).to eq('towel.blinkenlights.nl') + expect(knife_ssh.config[:ssh_gateway]).to eq("towel.blinkenlights.nl") end it "configures the host key verify mode" do @@ -601,13 +601,13 @@ describe Chef::Knife::Bootstrap do knife.config[:ssh_identity_file] = "~/.ssh/me.rsa" allow(knife).to receive(:render_template).and_return("") k = knife.knife_ssh - allow(k).to receive(:get_password).and_return('typed_in_password') + allow(k).to receive(:get_password).and_return("typed_in_password") allow(knife).to receive(:knife_ssh).and_return(k) knife.knife_ssh_with_password_auth end it "prompts the user for a password " do - expect(knife_ssh_with_password_auth.config[:ssh_password]).to eq('typed_in_password') + expect(knife_ssh_with_password_auth.config[:ssh_password]).to eq("typed_in_password") end it "configures knife not to use the identity file that didn't work previously" do diff --git a/spec/unit/knife/client_bulk_delete_spec.rb b/spec/unit/knife/client_bulk_delete_spec.rb index 1a6317ac00..30bd8b5b97 100644 --- a/spec/unit/knife/client_bulk_delete_spec.rb +++ b/spec/unit/knife/client_bulk_delete_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::ClientBulkDelete do let(:stdout_io) { StringIO.new } diff --git a/spec/unit/knife/client_create_spec.rb b/spec/unit/knife/client_create_spec.rb index 9066505dfd..359271672e 100644 --- a/spec/unit/knife/client_create_spec.rb +++ b/spec/unit/knife/client_create_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" Chef::Knife::ClientCreate.load_deps @@ -61,13 +61,13 @@ describe Chef::Knife::ClientCreate do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do let(:name_args) { [] } - let(:fieldname) { 'client name' } + let(:fieldname) { "client name" } end end context "when clientname is passed" do before do - knife.name_args = ['adam'] + knife.name_args = ["adam"] end context "when public_key and prevent_keygen are passed" do @@ -131,7 +131,7 @@ describe Chef::Knife::ClientCreate do it "should write the private key to a file" do knife.config[:file] = "/tmp/monkeypants" filehandle = double("Filehandle") - expect(filehandle).to receive(:print).with('woot') + expect(filehandle).to receive(:print).with("woot") expect(File).to receive(:open).with("/tmp/monkeypants", "w").and_yield(filehandle) knife.run end @@ -150,14 +150,14 @@ describe Chef::Knife::ClientCreate do describe "with -p or --public-key" do before do - knife.config[:public_key] = 'some_key' - allow(File).to receive(:read).and_return('some_key') + knife.config[:public_key] = "some_key" + allow(File).to receive(:read).and_return("some_key") allow(File).to receive(:expand_path) end it "sets the public key" do knife.run - expect(client.public_key).to eq('some_key') + expect(client.public_key).to eq("some_key") end end diff --git a/spec/unit/knife/client_delete_spec.rb b/spec/unit/knife/client_delete_spec.rb index 619009979b..e08a9c59c8 100644 --- a/spec/unit/knife/client_delete_spec.rb +++ b/spec/unit/knife/client_delete_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::ClientDelete do before(:each) do @@ -25,16 +25,16 @@ describe Chef::Knife::ClientDelete do @knife.config = { :delete_validators => false } - @knife.name_args = [ 'adam' ] + @knife.name_args = [ "adam" ] end - describe 'run' do - it 'should delete the client' do - expect(@knife).to receive(:delete_object).with(Chef::ApiClientV1, 'adam', 'client') + describe "run" do + it "should delete the client" do + expect(@knife).to receive(:delete_object).with(Chef::ApiClientV1, "adam", "client") @knife.run end - it 'should print usage and exit when a client name is not provided' do + it "should print usage and exit when a client name is not provided" do @knife.name_args = [] expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal) @@ -42,7 +42,7 @@ describe Chef::Knife::ClientDelete do end end - describe 'with a validator' do + describe "with a validator" do before(:each) do allow(Chef::Knife::UI).to receive(:confirm).and_return(true) allow(@knife).to receive(:confirm).and_return(true) @@ -50,7 +50,7 @@ describe Chef::Knife::ClientDelete do expect(Chef::ApiClientV1).to receive(:load).and_return(@client) end - it 'should delete non-validator client if --delete-validators is not set' do + it "should delete non-validator client if --delete-validators is not set" do @knife.config[:delete_validators] = false expect(@client).to receive(:destroy).and_return(@client) expect(@knife).to receive(:msg) @@ -58,7 +58,7 @@ describe Chef::Knife::ClientDelete do @knife.run end - it 'should delete non-validator client if --delete-validators is set' do + it "should delete non-validator client if --delete-validators is set" do @knife.config[:delete_validators] = true expect(@client).to receive(:destroy).and_return(@client) expect(@knife).to receive(:msg) @@ -66,13 +66,13 @@ describe Chef::Knife::ClientDelete do @knife.run end - it 'should not delete validator client if --delete-validators is not set' do + it "should not delete validator client if --delete-validators is not set" do @client.validator(true) expect(@knife.ui).to receive(:fatal) expect { @knife.run}.to raise_error(SystemExit) end - it 'should delete validator client if --delete-validators is set' do + it "should delete validator client if --delete-validators is set" do @knife.config[:delete_validators] = true expect(@client).to receive(:destroy).and_return(@client) expect(@knife).to receive(:msg) diff --git a/spec/unit/knife/client_edit_spec.rb b/spec/unit/knife/client_edit_spec.rb index 75b0ef8c92..876dfc5770 100644 --- a/spec/unit/knife/client_edit_spec.rb +++ b/spec/unit/knife/client_edit_spec.rb @@ -16,17 +16,17 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/api_client_v1' +require "spec_helper" +require "chef/api_client_v1" describe Chef::Knife::ClientEdit do before(:each) do @knife = Chef::Knife::ClientEdit.new - @knife.name_args = [ 'adam' ] + @knife.name_args = [ "adam" ] @knife.config[:disable_editing] = true end - describe 'run' do + describe "run" do let(:data) { { "name" => "adam", @@ -37,13 +37,13 @@ describe Chef::Knife::ClientEdit do } } - it 'should edit the client' do - allow(Chef::ApiClientV1).to receive(:load).with('adam').and_return(data) + it "should edit the client" do + allow(Chef::ApiClientV1).to receive(:load).with("adam").and_return(data) expect(@knife).to receive(:edit_data).with(data).and_return(data) @knife.run end - it 'should print usage and exit when a client name is not provided' do + it "should print usage and exit when a client name is not provided" do @knife.name_args = [] expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal) diff --git a/spec/unit/knife/client_list_spec.rb b/spec/unit/knife/client_list_spec.rb index ce0fa4f5e8..03d87022db 100644 --- a/spec/unit/knife/client_list_spec.rb +++ b/spec/unit/knife/client_list_spec.rb @@ -16,16 +16,16 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::ClientList do before(:each) do @knife = Chef::Knife::ClientList.new - @knife.name_args = [ 'adam' ] + @knife.name_args = [ "adam" ] end - describe 'run' do - it 'should list the clients' do + describe "run" do + it "should list the clients" do expect(Chef::ApiClientV1).to receive(:list) expect(@knife).to receive(:format_list_for_display) @knife.run diff --git a/spec/unit/knife/client_reregister_spec.rb b/spec/unit/knife/client_reregister_spec.rb index 7e763242e4..da1f4314b6 100644 --- a/spec/unit/knife/client_reregister_spec.rb +++ b/spec/unit/knife/client_reregister_spec.rb @@ -16,13 +16,13 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::ClientReregister do before(:each) do @knife = Chef::Knife::ClientReregister.new - @knife.name_args = [ 'adam' ] - @client_mock = double('client_mock', :private_key => "foo_key") + @knife.name_args = [ "adam" ] + @client_mock = double("client_mock", :private_key => "foo_key") @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) end @@ -32,28 +32,28 @@ describe Chef::Knife::ClientReregister do @knife.name_args = [] end - it 'should print usage and exit when a client name is not provided' do + it "should print usage and exit when a client name is not provided" do expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal) expect { @knife.run }.to raise_error(SystemExit) end end - context 'when not configured for file output' do - it 'reregisters the client and prints the key' do - expect(Chef::ApiClientV1).to receive(:reregister).with('adam').and_return(@client_mock) + context "when not configured for file output" do + it "reregisters the client and prints the key" do + expect(Chef::ApiClientV1).to receive(:reregister).with("adam").and_return(@client_mock) @knife.run expect(@stdout.string).to match( /foo_key/ ) end end - context 'when configured for file output' do - it 'should write the private key to a file' do - expect(Chef::ApiClientV1).to receive(:reregister).with('adam').and_return(@client_mock) + context "when configured for file output" do + it "should write the private key to a file" do + expect(Chef::ApiClientV1).to receive(:reregister).with("adam").and_return(@client_mock) - @knife.config[:file] = '/tmp/monkeypants' + @knife.config[:file] = "/tmp/monkeypants" filehandle = StringIO.new - expect(File).to receive(:open).with('/tmp/monkeypants', 'w').and_yield(filehandle) + expect(File).to receive(:open).with("/tmp/monkeypants", "w").and_yield(filehandle) @knife.run expect(filehandle.string).to eq("foo_key") end diff --git a/spec/unit/knife/client_show_spec.rb b/spec/unit/knife/client_show_spec.rb index 73a876cee0..96a7653d92 100644 --- a/spec/unit/knife/client_show_spec.rb +++ b/spec/unit/knife/client_show_spec.rb @@ -16,33 +16,33 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::ClientShow do before(:each) do @knife = Chef::Knife::ClientShow.new - @knife.name_args = [ 'adam' ] - @client_mock = double('client_mock') + @knife.name_args = [ "adam" ] + @client_mock = double("client_mock") end - describe 'run' do - it 'should list the client' do - expect(Chef::ApiClientV1).to receive(:load).with('adam').and_return(@client_mock) + describe "run" do + it "should list the client" do + expect(Chef::ApiClientV1).to receive(:load).with("adam").and_return(@client_mock) expect(@knife).to receive(:format_for_display).with(@client_mock) @knife.run end - it 'should pretty print json' do - @knife.config[:format] = 'json' + it "should pretty print json" do + @knife.config[:format] = "json" @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) fake_client_contents = {"foo"=>"bar", "baz"=>"qux"} - expect(Chef::ApiClientV1).to receive(:load).with('adam').and_return(fake_client_contents) + expect(Chef::ApiClientV1).to receive(:load).with("adam").and_return(fake_client_contents) @knife.run expect(@stdout.string).to eql("{\n \"foo\": \"bar\",\n \"baz\": \"qux\"\n}\n") end - it 'should print usage and exit when a client name is not provided' do + it "should print usage and exit when a client name is not provided" do @knife.name_args = [] expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal) diff --git a/spec/unit/knife/configure_client_spec.rb b/spec/unit/knife/configure_client_spec.rb index 363743f8cc..a825384785 100644 --- a/spec/unit/knife/configure_client_spec.rb +++ b/spec/unit/knife/configure_client_spec.rb @@ -16,21 +16,21 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::ConfigureClient do before do @knife = Chef::Knife::ConfigureClient.new - Chef::Config[:chef_server_url] = 'https://chef.example.com' - Chef::Config[:validation_client_name] = 'chef-validator' - Chef::Config[:validation_key] = '/etc/chef/validation.pem' + Chef::Config[:chef_server_url] = "https://chef.example.com" + Chef::Config[:validation_client_name] = "chef-validator" + Chef::Config[:validation_key] = "/etc/chef/validation.pem" @stderr = StringIO.new allow(@knife.ui).to receive(:stderr).and_return(@stderr) end - describe 'run' do - it 'should print usage and exit when a directory is not provided' do + describe "run" do + it "should print usage and exit when a directory is not provided" do expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal).with(/must provide the directory/) expect { @@ -38,24 +38,24 @@ describe Chef::Knife::ConfigureClient do }.to raise_error SystemExit end - describe 'when specifing a directory' do + describe "when specifing a directory" do before do - @knife.name_args = ['/home/bob/.chef'] + @knife.name_args = ["/home/bob/.chef"] @client_file = StringIO.new @validation_file = StringIO.new - expect(File).to receive(:open).with('/home/bob/.chef/client.rb', 'w'). + expect(File).to receive(:open).with("/home/bob/.chef/client.rb", "w"). and_yield(@client_file) - expect(File).to receive(:open).with('/home/bob/.chef/validation.pem', 'w'). + expect(File).to receive(:open).with("/home/bob/.chef/validation.pem", "w"). and_yield(@validation_file) - expect(IO).to receive(:read).and_return('foo_bar_baz') + expect(IO).to receive(:read).and_return("foo_bar_baz") end - it 'should recursively create the directory' do - expect(FileUtils).to receive(:mkdir_p).with('/home/bob/.chef') + it "should recursively create the directory" do + expect(FileUtils).to receive(:mkdir_p).with("/home/bob/.chef") @knife.run end - it 'should write out the config file' do + it "should write out the config file" do allow(FileUtils).to receive(:mkdir_p) @knife.run expect(@client_file.string).to match /log_level\s+\:info/ @@ -64,13 +64,13 @@ describe Chef::Knife::ConfigureClient do expect(@client_file.string).to match /validation_client_name\s+'chef-validator'/ end - it 'should write out the validation.pem file' do + it "should write out the validation.pem file" do allow(FileUtils).to receive(:mkdir_p) @knife.run expect(@validation_file.string).to match /foo_bar_baz/ end - it 'should print information on what is being configured' do + it "should print information on what is being configured" do allow(FileUtils).to receive(:mkdir_p) @knife.run expect(@stderr.string).to match /creating client configuration/i diff --git a/spec/unit/knife/configure_spec.rb b/spec/unit/knife/configure_spec.rb index 89874cfdf9..6c1d98c2f5 100644 --- a/spec/unit/knife/configure_spec.rb +++ b/spec/unit/knife/configure_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Chef::Knife::Configure do before do @@ -11,7 +11,7 @@ describe Chef::Knife::Configure do @out = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@out) - @knife.config[:config_file] = '/home/you/.chef/knife.rb' + @knife.config[:config_file] = "/home/you/.chef/knife.rb" @in = StringIO.new("\n" * 7) allow(@knife.ui).to receive(:stdin).and_return(@in) @@ -58,11 +58,11 @@ describe Chef::Knife::Configure do it "should not ask the user for the clientname they want for the new client if -i and --node_name are specified" do @knife.config[:initial] = true - @knife.config[:node_name] = 'testnode' + @knife.config[:node_name] = "testnode" allow(Etc).to receive(:getlogin).and_return("a-new-user") @knife.ask_user_for_config expect(@out.string).not_to match(Regexp.escape("Please enter a name for the new user")) - expect(@knife.new_client_name).to eq('testnode') + expect(@knife.new_client_name).to eq("testnode") end it "asks the user for the existing API username or clientname if -i is not specified" do @@ -76,21 +76,21 @@ describe Chef::Knife::Configure do @knife.config[:initial] = true @knife.ask_user_for_config expect(@out.string).to match(Regexp.escape("Please enter the existing admin name: [admin]")) - expect(@knife.admin_client_name).to eq('admin') + expect(@knife.admin_client_name).to eq("admin") end it "should not ask the user for the existing admin client's name if -i and --admin-client_name are specified" do @knife.config[:initial] = true - @knife.config[:admin_client_name] = 'my-webui' + @knife.config[:admin_client_name] = "my-webui" @knife.ask_user_for_config expect(@out.string).not_to match(Regexp.escape("Please enter the existing admin:")) - expect(@knife.admin_client_name).to eq('my-webui') + expect(@knife.admin_client_name).to eq("my-webui") end it "should not ask the user for the existing admin client's name if -i is not specified" do @knife.ask_user_for_config expect(@out.string).not_to match(Regexp.escape("Please enter the existing admin: [admin]")) - expect(@knife.admin_client_name).not_to eq('admin') + expect(@knife.admin_client_name).not_to eq("admin") end it "asks the user for the location of the existing admin key if -i is specified" do @@ -106,13 +106,13 @@ describe Chef::Knife::Configure do it "should not ask the user for the location of the existing admin key if -i and --admin_client_key are specified" do @knife.config[:initial] = true - @knife.config[:admin_client_key] = '/home/you/.chef/my-webui.pem' + @knife.config[:admin_client_key] = "/home/you/.chef/my-webui.pem" @knife.ask_user_for_config expect(@out.string).not_to match(Regexp.escape("Please enter the location of the existing admin client's private key:")) if windows? expect(@knife.admin_client_key).to match %r{^[A-Za-z]:/home/you/\.chef/my-webui\.pem$} else - expect(@knife.admin_client_key).to eq('/home/you/.chef/my-webui.pem') + expect(@knife.admin_client_key).to eq("/home/you/.chef/my-webui.pem") end end @@ -129,20 +129,20 @@ describe Chef::Knife::Configure do it "asks the user for the location of a chef repo" do @knife.ask_user_for_config expect(@out.string).to match(Regexp.escape("Please enter the path to a chef repository (or leave blank):")) - expect(@knife.chef_repo).to eq('') + expect(@knife.chef_repo).to eq("") end it "asks the users for the name of the validation client" do @knife.ask_user_for_config expect(@out.string).to match(Regexp.escape("Please enter the validation clientname: [chef-validator]")) - expect(@knife.validation_client_name).to eq('chef-validator') + expect(@knife.validation_client_name).to eq("chef-validator") end it "should not ask the users for the name of the validation client if --validation_client_name is specified" do - @knife.config[:validation_client_name] = 'my-validator' + @knife.config[:validation_client_name] = "my-validator" @knife.ask_user_for_config expect(@out.string).not_to match(Regexp.escape("Please enter the validation clientname:")) - expect(@knife.validation_client_name).to eq('my-validator') + expect(@knife.validation_client_name).to eq("my-validator") end it "asks the users for the location of the validation key" do @@ -156,45 +156,45 @@ describe Chef::Knife::Configure do end it "should not ask the users for the location of the validation key if --validation_key is specified" do - @knife.config[:validation_key] = '/home/you/.chef/my-validation.pem' + @knife.config[:validation_key] = "/home/you/.chef/my-validation.pem" @knife.ask_user_for_config expect(@out.string).not_to match(Regexp.escape("Please enter the location of the validation key:")) if windows? expect(@knife.validation_key).to match %r{^[A-Za-z]:/home/you/\.chef/my-validation\.pem$} else - expect(@knife.validation_key).to eq('/home/you/.chef/my-validation.pem') + expect(@knife.validation_key).to eq("/home/you/.chef/my-validation.pem") end end it "should not ask the user for anything if -i and all other properties are specified" do @knife.config[:initial] = true - @knife.config[:chef_server_url] = 'http://localhost:5000' - @knife.config[:node_name] = 'testnode' - @knife.config[:admin_client_name] = 'my-webui' - @knife.config[:admin_client_key] = '/home/you/.chef/my-webui.pem' - @knife.config[:validation_client_name] = 'my-validator' - @knife.config[:validation_key] = '/home/you/.chef/my-validation.pem' - @knife.config[:repository] = '' - @knife.config[:client_key] = '/home/you/a-new-user.pem' - allow(Etc).to receive(:getlogin).and_return('a-new-user') + @knife.config[:chef_server_url] = "http://localhost:5000" + @knife.config[:node_name] = "testnode" + @knife.config[:admin_client_name] = "my-webui" + @knife.config[:admin_client_key] = "/home/you/.chef/my-webui.pem" + @knife.config[:validation_client_name] = "my-validator" + @knife.config[:validation_key] = "/home/you/.chef/my-validation.pem" + @knife.config[:repository] = "" + @knife.config[:client_key] = "/home/you/a-new-user.pem" + allow(Etc).to receive(:getlogin).and_return("a-new-user") @knife.ask_user_for_config expect(@out.string).to match(/\s*/) - expect(@knife.new_client_name).to eq('testnode') - expect(@knife.chef_server).to eq('http://localhost:5000') - expect(@knife.admin_client_name).to eq('my-webui') + expect(@knife.new_client_name).to eq("testnode") + expect(@knife.chef_server).to eq("http://localhost:5000") + expect(@knife.admin_client_name).to eq("my-webui") if windows? expect(@knife.admin_client_key).to match %r{^[A-Za-z]:/home/you/\.chef/my-webui\.pem$} expect(@knife.validation_key).to match %r{^[A-Za-z]:/home/you/\.chef/my-validation\.pem$} expect(@knife.new_client_key).to match %r{^[A-Za-z]:/home/you/a-new-user\.pem$} else - expect(@knife.admin_client_key).to eq('/home/you/.chef/my-webui.pem') - expect(@knife.validation_key).to eq('/home/you/.chef/my-validation.pem') - expect(@knife.new_client_key).to eq('/home/you/a-new-user.pem') + expect(@knife.admin_client_key).to eq("/home/you/.chef/my-webui.pem") + expect(@knife.validation_key).to eq("/home/you/.chef/my-validation.pem") + expect(@knife.new_client_key).to eq("/home/you/a-new-user.pem") end - expect(@knife.validation_client_name).to eq('my-validator') - expect(@knife.chef_repo).to eq('') + expect(@knife.validation_client_name).to eq("my-validator") + expect(@knife.chef_repo).to eq("") end it "writes the new data to a config file" do @@ -205,7 +205,7 @@ describe Chef::Knife::Configure do expect(FileUtils).to receive(:mkdir_p).with("/home/you/.chef") config_file = StringIO.new expect(::File).to receive(:open).with("/home/you/.chef/knife.rb", "w").and_yield config_file - @knife.config[:repository] = '/home/you/chef-repo' + @knife.config[:repository] = "/home/you/chef-repo" @knife.run expect(config_file.string).to match(/^node_name[\s]+'#{Etc.getlogin}'$/) expect(config_file.string).to match(%r{^client_key[\s]+'/home/you/.chef/#{Etc.getlogin}.pem'$}) diff --git a/spec/unit/knife/cookbook_bulk_delete_spec.rb b/spec/unit/knife/cookbook_bulk_delete_spec.rb index 7d6e851589..6ef01bc0bb 100644 --- a/spec/unit/knife/cookbook_bulk_delete_spec.rb +++ b/spec/unit/knife/cookbook_bulk_delete_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::CookbookBulkDelete do before(:each) do @@ -48,12 +48,12 @@ describe Chef::Knife::CookbookBulkDelete do describe "when there are several cookbooks on the server" do before do - @cheezburger = {'cheezburger' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-cheez", "version" => "1.0.0"}]}} - allow(@rest).to receive(:get).with('cookbooks/cheezburger').and_return(@cheezburger) - @pizza = {'pizza' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-pizza", "version" => "2.0.0"}]}} - allow(@rest).to receive(:get).with('cookbooks/pizza').and_return(@pizza) - @lasagna = {'lasagna' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-lasagna", "version" => "3.0.0"}]}} - allow(@rest).to receive(:get).with('cookbooks/lasagna').and_return(@lasagna) + @cheezburger = {"cheezburger" => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-cheez", "version" => "1.0.0"}]}} + allow(@rest).to receive(:get).with("cookbooks/cheezburger").and_return(@cheezburger) + @pizza = {"pizza" => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-pizza", "version" => "2.0.0"}]}} + allow(@rest).to receive(:get).with("cookbooks/pizza").and_return(@pizza) + @lasagna = {"lasagna" => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-lasagna", "version" => "3.0.0"}]}} + allow(@rest).to receive(:get).with("cookbooks/lasagna").and_return(@lasagna) end it "should print the cookbooks you are about to delete" do @@ -68,7 +68,7 @@ describe Chef::Knife::CookbookBulkDelete do end it "should delete each cookbook" do - {"cheezburger" => "1.0.0", "pizza" => "2.0.0", "lasagna" => '3.0.0'}.each do |cookbook_name, version| + {"cheezburger" => "1.0.0", "pizza" => "2.0.0", "lasagna" => "3.0.0"}.each do |cookbook_name, version| expect(@rest).to receive(:delete).with("cookbooks/#{cookbook_name}/#{version}") end @knife.run @@ -76,7 +76,7 @@ describe Chef::Knife::CookbookBulkDelete do it "should only delete cookbooks that match the regex" do @knife.name_args = ["cheezburger"] - expect(@rest).to receive(:delete).with('cookbooks/cheezburger/1.0.0') + expect(@rest).to receive(:delete).with("cookbooks/cheezburger/1.0.0") @knife.run end end diff --git a/spec/unit/knife/cookbook_create_spec.rb b/spec/unit/knife/cookbook_create_spec.rb index 8619c8f64b..27bdc303c2 100644 --- a/spec/unit/knife/cookbook_create_spec.rb +++ b/spec/unit/knife/cookbook_create_spec.rb @@ -16,8 +16,8 @@ # limitations under the License. # -require 'spec_helper' -require 'tmpdir' +require "spec_helper" +require "tmpdir" describe Chef::Knife::CookbookCreate do before(:each) do diff --git a/spec/unit/knife/cookbook_delete_spec.rb b/spec/unit/knife/cookbook_delete_spec.rb index e9085e9512..aed5f197b9 100644 --- a/spec/unit/knife/cookbook_delete_spec.rb +++ b/spec/unit/knife/cookbook_delete_spec.rb @@ -16,51 +16,51 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::CookbookDelete do before(:each) do @knife = Chef::Knife::CookbookDelete.new - @knife.name_args = ['foobar'] - @knife.cookbook_name = 'foobar' + @knife.name_args = ["foobar"] + @knife.cookbook_name = "foobar" @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) @stderr = StringIO.new allow(@knife.ui).to receive(:stderr).and_return(@stderr) end - describe 'run' do - it 'should print usage and exit when a cookbook name is not provided' do + describe "run" do + it "should print usage and exit when a cookbook name is not provided" do @knife.name_args = [] expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal) expect { @knife.run }.to raise_error(SystemExit) end - describe 'when specifying a cookbook name' do - it 'should delete the cookbook without a specific version' do + describe "when specifying a cookbook name" do + it "should delete the cookbook without a specific version" do expect(@knife).to receive(:delete_without_explicit_version) @knife.run end - describe 'and a version' do - it 'should delete the specific version of the cookbook' do - @knife.name_args << '1.0.0' + describe "and a version" do + it "should delete the specific version of the cookbook" do + @knife.name_args << "1.0.0" expect(@knife).to receive(:delete_explicit_version) @knife.run end end - describe 'with -a or --all' do - it 'should delete all versions of the cookbook' do + describe "with -a or --all" do + it "should delete all versions of the cookbook" do @knife.config[:all] = true expect(@knife).to receive(:delete_all_versions) @knife.run end end - describe 'with -p or --purge' do - it 'should prompt to purge the files' do + describe "with -p or --purge" do + it "should prompt to purge the files" do @knife.config[:purge] = true expect(@knife).to receive(:confirm). with(/.+Are you sure you want to purge files.+/) @@ -71,30 +71,30 @@ describe Chef::Knife::CookbookDelete do end end - describe 'delete_explicit_version' do - it 'should delete the specific cookbook version' do - @knife.cookbook_name = 'foobar' - @knife.version = '1.0.0' + describe "delete_explicit_version" do + it "should delete the specific cookbook version" do + @knife.cookbook_name = "foobar" + @knife.version = "1.0.0" expect(@knife).to receive(:delete_object).with(Chef::CookbookVersion, - 'foobar version 1.0.0', - 'cookbook').and_yield() - expect(@knife).to receive(:delete_request).with('cookbooks/foobar/1.0.0') + "foobar version 1.0.0", + "cookbook").and_yield() + expect(@knife).to receive(:delete_request).with("cookbooks/foobar/1.0.0") @knife.delete_explicit_version end end - describe 'delete_all_versions' do - it 'should prompt to delete all versions of the cookbook' do - @knife.cookbook_name = 'foobar' - expect(@knife).to receive(:confirm).with('Do you really want to delete all versions of foobar') + describe "delete_all_versions" do + it "should prompt to delete all versions of the cookbook" do + @knife.cookbook_name = "foobar" + expect(@knife).to receive(:confirm).with("Do you really want to delete all versions of foobar") expect(@knife).to receive(:delete_all_without_confirmation) @knife.delete_all_versions end end - describe 'delete_all_without_confirmation' do - it 'should delete all versions without confirmation' do - versions = ['1.0.0', '1.1.0'] + describe "delete_all_without_confirmation" do + it "should delete all versions without confirmation" do + versions = ["1.0.0", "1.1.0"] expect(@knife).to receive(:available_versions).and_return(versions) versions.each do |v| expect(@knife).to receive(:delete_version_without_confirmation).with(v) @@ -103,43 +103,43 @@ describe Chef::Knife::CookbookDelete do end end - describe 'delete_without_explicit_version' do - it 'should exit if there are no available versions' do + describe "delete_without_explicit_version" do + it "should exit if there are no available versions" do expect(@knife).to receive(:available_versions).and_return(nil) expect { @knife.delete_without_explicit_version }.to raise_error(SystemExit) end - it 'should delete the version if only one is found' do - expect(@knife).to receive(:available_versions).at_least(:once).and_return(['1.0.0']) + it "should delete the version if only one is found" do + expect(@knife).to receive(:available_versions).at_least(:once).and_return(["1.0.0"]) expect(@knife).to receive(:delete_explicit_version) @knife.delete_without_explicit_version end - it 'should ask which version(s) to delete if multiple are found' do - expect(@knife).to receive(:available_versions).at_least(:once).and_return(['1.0.0', '1.1.0']) - expect(@knife).to receive(:ask_which_versions_to_delete).and_return(['1.0.0', '1.1.0']) - expect(@knife).to receive(:delete_versions_without_confirmation).with(['1.0.0', '1.1.0']) + it "should ask which version(s) to delete if multiple are found" do + expect(@knife).to receive(:available_versions).at_least(:once).and_return(["1.0.0", "1.1.0"]) + expect(@knife).to receive(:ask_which_versions_to_delete).and_return(["1.0.0", "1.1.0"]) + expect(@knife).to receive(:delete_versions_without_confirmation).with(["1.0.0", "1.1.0"]) @knife.delete_without_explicit_version end end - describe 'available_versions' do + describe "available_versions" do before(:each) do - @rest_mock = double('rest') + @rest_mock = double("rest") expect(@knife).to receive(:rest).and_return(@rest_mock) - @cookbook_data = { 'foobar' => { 'versions' => [{'version' => '1.0.0'}, - {'version' => '1.1.0'}, - {'version' => '2.0.0'} ]} + @cookbook_data = { "foobar" => { "versions" => [{"version" => "1.0.0"}, + {"version" => "1.1.0"}, + {"version" => "2.0.0"} ]} } end - it 'should return the list of versions of the cookbook' do - expect(@rest_mock).to receive(:get).with('cookbooks/foobar').and_return(@cookbook_data) - expect(@knife.available_versions).to eq(['1.0.0', '1.1.0', '2.0.0']) + it "should return the list of versions of the cookbook" do + expect(@rest_mock).to receive(:get).with("cookbooks/foobar").and_return(@cookbook_data) + expect(@knife.available_versions).to eq(["1.0.0", "1.1.0", "2.0.0"]) end - it 'should raise if an error other than HTTP 404 is returned' do - exception = Net::HTTPServerException.new('500 Internal Server Error', '500') + it "should raise if an error other than HTTP 404 is returned" do + exception = Net::HTTPServerException.new("500 Internal Server Error", "500") expect(@rest_mock).to receive(:get).and_raise(exception) expect { @knife.available_versions }.to raise_error Net::HTTPServerException end @@ -147,88 +147,88 @@ describe Chef::Knife::CookbookDelete do describe "if the cookbook can't be found" do before(:each) do expect(@rest_mock).to receive(:get). - and_raise(Net::HTTPServerException.new('404 Not Found', '404')) + and_raise(Net::HTTPServerException.new("404 Not Found", "404")) end - it 'should print an error' do + it "should print an error" do @knife.available_versions expect(@stderr.string).to match /error.+cannot find a cookbook named foobar/i end - it 'should return nil' do + it "should return nil" do expect(@knife.available_versions).to eq(nil) end end end - describe 'ask_which_version_to_delete' do + describe "ask_which_version_to_delete" do before(:each) do - allow(@knife).to receive(:available_versions).and_return(['1.0.0', '1.1.0', '2.0.0']) + allow(@knife).to receive(:available_versions).and_return(["1.0.0", "1.1.0", "2.0.0"]) end - it 'should prompt the user to select a version' do + it "should prompt the user to select a version" do prompt = /Which version\(s\) do you want to delete\?.+1\. foobar 1\.0\.0.+2\. foobar 1\.1\.0.+3\. foobar 2\.0\.0.+4\. All versions.+/m - expect(@knife).to receive(:ask_question).with(prompt).and_return('1') + expect(@knife).to receive(:ask_question).with(prompt).and_return("1") @knife.ask_which_versions_to_delete end it "should print an error and exit if a version wasn't specified" do - expect(@knife).to receive(:ask_question).and_return('') + expect(@knife).to receive(:ask_question).and_return("") expect(@knife.ui).to receive(:error).with(/no versions specified/i) expect { @knife.ask_which_versions_to_delete }.to raise_error(SystemExit) end - it 'should print an error if an invalid choice was selected' do - expect(@knife).to receive(:ask_question).and_return('100') + it "should print an error if an invalid choice was selected" do + expect(@knife).to receive(:ask_question).and_return("100") expect(@knife.ui).to receive(:error).with(/100 is not a valid choice/i) @knife.ask_which_versions_to_delete end - it 'should return the selected versions' do - expect(@knife).to receive(:ask_question).and_return('1, 3') - expect(@knife.ask_which_versions_to_delete).to eq(['1.0.0', '2.0.0']) + it "should return the selected versions" do + expect(@knife).to receive(:ask_question).and_return("1, 3") + expect(@knife.ask_which_versions_to_delete).to eq(["1.0.0", "2.0.0"]) end it "should return all of the versions if 'all' was selected" do - expect(@knife).to receive(:ask_question).and_return('4') + expect(@knife).to receive(:ask_question).and_return("4") expect(@knife.ask_which_versions_to_delete).to eq([:all]) end end - describe 'delete_version_without_confirmation' do - it 'should delete the cookbook version' do - expect(@knife).to receive(:delete_request).with('cookbooks/foobar/1.0.0') - @knife.delete_version_without_confirmation('1.0.0') + describe "delete_version_without_confirmation" do + it "should delete the cookbook version" do + expect(@knife).to receive(:delete_request).with("cookbooks/foobar/1.0.0") + @knife.delete_version_without_confirmation("1.0.0") end - it 'should output that the cookbook was deleted' do + it "should output that the cookbook was deleted" do allow(@knife).to receive(:delete_request) - @knife.delete_version_without_confirmation('1.0.0') + @knife.delete_version_without_confirmation("1.0.0") expect(@stderr.string).to match /deleted cookbook\[foobar\]\[1.0.0\]/im end - describe 'with --print-after' do - it 'should display the cookbook data' do - object = '' + describe "with --print-after" do + it "should display the cookbook data" do + object = "" @knife.config[:print_after] = true allow(@knife).to receive(:delete_request).and_return(object) expect(@knife).to receive(:format_for_display).with(object) - @knife.delete_version_without_confirmation('1.0.0') + @knife.delete_version_without_confirmation("1.0.0") end end end - describe 'delete_versions_without_confirmation' do - it 'should delete each version without confirmation' do - versions = ['1.0.0', '1.1.0'] + describe "delete_versions_without_confirmation" do + it "should delete each version without confirmation" do + versions = ["1.0.0", "1.1.0"] versions.each do |v| expect(@knife).to receive(:delete_version_without_confirmation).with(v) end @knife.delete_versions_without_confirmation(versions) end - describe 'with -a or --all' do - it 'should delete all versions without confirmation' do + describe "with -a or --all" do + it "should delete all versions without confirmation" do versions = [:all] expect(@knife).to receive(:delete_all_without_confirmation) @knife.delete_versions_without_confirmation(versions) diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb index 64b754d173..baa8acc6f4 100644 --- a/spec/unit/knife/cookbook_download_spec.rb +++ b/spec/unit/knife/cookbook_download_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::CookbookDownload do before(:each) do @@ -25,66 +25,66 @@ describe Chef::Knife::CookbookDownload do allow(@knife.ui).to receive(:stderr).and_return(@stderr) end - describe 'run' do - it 'should print usage and exit when a cookbook name is not provided' do + describe "run" do + it "should print usage and exit when a cookbook name is not provided" do @knife.name_args = [] expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal).with(/must specify a cookbook name/) expect { @knife.run }.to raise_error(SystemExit) end - it 'should exit with a fatal error when there is no cookbook on the server' do - @knife.name_args = ['foobar', nil] + it "should exit with a fatal error when there is no cookbook on the server" do + @knife.name_args = ["foobar", nil] expect(@knife).to receive(:determine_version).and_return(nil) - expect(@knife.ui).to receive(:fatal).with('No such cookbook found') + expect(@knife.ui).to receive(:fatal).with("No such cookbook found") expect { @knife.run }.to raise_error(SystemExit) end - describe 'with a cookbook name' do + describe "with a cookbook name" do before(:each) do - @knife.name_args = ['foobar'] - @knife.config[:download_directory] = '/var/tmp/chef' - @rest_mock = double('rest') + @knife.name_args = ["foobar"] + @knife.config[:download_directory] = "/var/tmp/chef" + @rest_mock = double("rest") allow(@knife).to receive(:rest).and_return(@rest_mock) @manifest_data = { :recipes => [ - {'path' => 'recipes/foo.rb', - 'url' => 'http://example.org/files/foo.rb'}, - {'path' => 'recipes/bar.rb', - 'url' => 'http://example.org/files/bar.rb'}, + {"path" => "recipes/foo.rb", + "url" => "http://example.org/files/foo.rb"}, + {"path" => "recipes/bar.rb", + "url" => "http://example.org/files/bar.rb"}, ], :templates => [ - {'path' => 'templates/default/foo.erb', - 'url' => 'http://example.org/files/foo.erb'}, - {'path' => 'templates/default/bar.erb', - 'url' => 'http://example.org/files/bar.erb'}, + {"path" => "templates/default/foo.erb", + "url" => "http://example.org/files/foo.erb"}, + {"path" => "templates/default/bar.erb", + "url" => "http://example.org/files/bar.erb"}, ], :attributes => [ - {'path' => 'attributes/default.rb', - 'url' => 'http://example.org/files/default.rb'}, + {"path" => "attributes/default.rb", + "url" => "http://example.org/files/default.rb"}, ], } - @cookbook_mock = double('cookbook') - allow(@cookbook_mock).to receive(:version).and_return('1.0.0') + @cookbook_mock = double("cookbook") + allow(@cookbook_mock).to receive(:version).and_return("1.0.0") allow(@cookbook_mock).to receive(:manifest).and_return(@manifest_data) expect(Chef::CookbookVersion).to receive(:load).with("foobar", "1.0.0"). and_return(@cookbook_mock) end - it 'should determine which version if one was not explicitly specified'do + it "should determine which version if one was not explicitly specified"do allow(@cookbook_mock).to receive(:manifest).and_return({}) - expect(@knife).to receive(:determine_version).and_return('1.0.0') - expect(File).to receive(:exists?).with('/var/tmp/chef/foobar-1.0.0').and_return(false) + expect(@knife).to receive(:determine_version).and_return("1.0.0") + expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(false) allow(Chef::CookbookVersion).to receive(:COOKBOOK_SEGEMENTS).and_return([]) @knife.run end - describe 'and a version' do + describe "and a version" do before(:each) do - @knife.name_args << '1.0.0' - @files = @manifest_data.values.map { |v| v.map { |i| i['path'] } }.flatten.uniq + @knife.name_args << "1.0.0" + @files = @manifest_data.values.map { |v| v.map { |i| i["path"] } }.flatten.uniq @files_mocks = {} @files.map { |f| File.basename(f) }.flatten.uniq.each do |f| @files_mocks[f] = double("#{f}_mock") @@ -92,13 +92,13 @@ describe Chef::Knife::CookbookDownload do end end - 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) + 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.run }.to raise_error(SystemExit) end - describe 'when downloading the cookbook' do + describe "when downloading the cookbook" do before(:each) do @files.map { |f| File.dirname(f) }.flatten.uniq.each do |dir| expect(FileUtils).to receive(:mkdir_p).with("/var/tmp/chef/foobar-1.0.0/#{dir}"). @@ -117,20 +117,20 @@ describe Chef::Knife::CookbookDownload do end it "should download the cookbook when the cookbook download directory doesn't exist" do - expect(File).to receive(:exists?).with('/var/tmp/chef/foobar-1.0.0').and_return(false) + expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(false) @knife.run - ['attributes', 'recipes', 'templates'].each do |segment| + ["attributes", "recipes", "templates"].each do |segment| expect(@stderr.string).to match /downloading #{segment}/im end expect(@stderr.string).to match /downloading foobar cookbook version 1\.0\.0/im expect(@stderr.string).to match /cookbook downloaded to \/var\/tmp\/chef\/foobar-1\.0\.0/im end - describe 'with -f or --force' do - it 'should remove the existing the cookbook download directory if it exists' do + describe "with -f or --force" do + it "should remove the existing the cookbook download directory if it exists" do @knife.config[:force] = true - expect(File).to receive(:exists?).with('/var/tmp/chef/foobar-1.0.0').and_return(true) - expect(FileUtils).to receive(:rm_rf).with('/var/tmp/chef/foobar-1.0.0') + expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(true) + expect(FileUtils).to receive(:rm_rf).with("/var/tmp/chef/foobar-1.0.0") @knife.run end end @@ -141,94 +141,94 @@ describe Chef::Knife::CookbookDownload do end - describe 'determine_version' do + describe "determine_version" do - it 'should return nil if there are no versions' do + it "should return nil if there are no versions" do expect(@knife).to receive(:available_versions).and_return(nil) expect(@knife.determine_version).to eq(nil) expect(@knife.version).to eq(nil) end - it 'should return and set the version if there is only one version' do - expect(@knife).to receive(:available_versions).at_least(:once).and_return(['1.0.0']) - expect(@knife.determine_version).to eq('1.0.0') - expect(@knife.version).to eq('1.0.0') + it "should return and set the version if there is only one version" do + expect(@knife).to receive(:available_versions).at_least(:once).and_return(["1.0.0"]) + expect(@knife.determine_version).to eq("1.0.0") + expect(@knife.version).to eq("1.0.0") end - it 'should ask which version to download and return it if there is more than one' do - expect(@knife).to receive(:available_versions).at_least(:once).and_return(['1.0.0', '2.0.0']) - expect(@knife).to receive(:ask_which_version).and_return('1.0.0') - expect(@knife.determine_version).to eq('1.0.0') + it "should ask which version to download and return it if there is more than one" do + expect(@knife).to receive(:available_versions).at_least(:once).and_return(["1.0.0", "2.0.0"]) + expect(@knife).to receive(:ask_which_version).and_return("1.0.0") + expect(@knife.determine_version).to eq("1.0.0") end - describe 'with -N or --latest' do - it 'should return and set the version to the latest version' do + describe "with -N or --latest" do + it "should return and set the version to the latest version" do @knife.config[:latest] = true expect(@knife).to receive(:available_versions).at_least(:once). - and_return(['1.0.0', '1.1.0', '2.0.0']) + and_return(["1.0.0", "1.1.0", "2.0.0"]) @knife.determine_version - expect(@knife.version.to_s).to eq('2.0.0') + expect(@knife.version.to_s).to eq("2.0.0") end end end - describe 'available_versions' do + describe "available_versions" do before(:each) do - @knife.cookbook_name = 'foobar' + @knife.cookbook_name = "foobar" end - it 'should return nil if there are no versions' do + it "should return nil if there are no versions" do expect(Chef::CookbookVersion).to receive(:available_versions). - with('foobar'). + with("foobar"). and_return(nil) expect(@knife.available_versions).to eq(nil) end - it 'should return the available versions' do + it "should return the available versions" do expect(Chef::CookbookVersion).to receive(:available_versions). - with('foobar'). - and_return(['1.1.0', '2.0.0', '1.0.0']) - expect(@knife.available_versions).to eq([Chef::Version.new('1.0.0'), - Chef::Version.new('1.1.0'), - Chef::Version.new('2.0.0')]) + with("foobar"). + and_return(["1.1.0", "2.0.0", "1.0.0"]) + expect(@knife.available_versions).to eq([Chef::Version.new("1.0.0"), + Chef::Version.new("1.1.0"), + Chef::Version.new("2.0.0")]) end - it 'should avoid multiple API calls to the server' do + it "should avoid multiple API calls to the server" do expect(Chef::CookbookVersion).to receive(:available_versions). once. - with('foobar'). - and_return(['1.1.0', '2.0.0', '1.0.0']) + with("foobar"). + and_return(["1.1.0", "2.0.0", "1.0.0"]) @knife.available_versions @knife.available_versions end end - describe 'ask_which_version' do + describe "ask_which_version" do before(:each) do - @knife.cookbook_name = 'foobar' - allow(@knife).to receive(:available_versions).and_return(['1.0.0', '1.1.0', '2.0.0']) + @knife.cookbook_name = "foobar" + allow(@knife).to receive(:available_versions).and_return(["1.0.0", "1.1.0", "2.0.0"]) end - it 'should prompt the user to select a version' do + it "should prompt the user to select a version" do prompt = /Which version do you want to download\?.+1\. foobar 1\.0\.0.+2\. foobar 1\.1\.0.+3\. foobar 2\.0\.0.+/m - expect(@knife).to receive(:ask_question).with(prompt).and_return('1') + expect(@knife).to receive(:ask_question).with(prompt).and_return("1") @knife.ask_which_version end it "should set the version to the user's selection" do - expect(@knife).to receive(:ask_question).and_return('1') + expect(@knife).to receive(:ask_question).and_return("1") @knife.ask_which_version - expect(@knife.version).to eq('1.0.0') + expect(@knife.version).to eq("1.0.0") end it "should print an error and exit if a version wasn't specified" do - expect(@knife).to receive(:ask_question).and_return('') + expect(@knife).to receive(:ask_question).and_return("") expect(@knife.ui).to receive(:error).with(/is not a valid value/i) expect { @knife.ask_which_version }.to raise_error(SystemExit) end - it 'should print an error if an invalid choice was selected' do - expect(@knife).to receive(:ask_question).and_return('100') + it "should print an error if an invalid choice was selected" do + expect(@knife).to receive(:ask_question).and_return("100") expect(@knife.ui).to receive(:error).with(/'100' is not a valid value/i) expect { @knife.ask_which_version }.to raise_error(SystemExit) end diff --git a/spec/unit/knife/cookbook_list_spec.rb b/spec/unit/knife/cookbook_list_spec.rb index fc07c8af3f..124c4bca8e 100644 --- a/spec/unit/knife/cookbook_list_spec.rb +++ b/spec/unit/knife/cookbook_list_spec.rb @@ -16,28 +16,28 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::CookbookList do before do @knife = Chef::Knife::CookbookList.new - @rest_mock = double('rest') + @rest_mock = double("rest") allow(@knife).to receive(:rest).and_return(@rest_mock) - @cookbook_names = ['apache2', 'mysql'] - @base_url = 'https://server.example.com/cookbooks' + @cookbook_names = ["apache2", "mysql"] + @base_url = "https://server.example.com/cookbooks" @cookbook_data = {} @cookbook_names.each do |item| - @cookbook_data[item] = {'url' => "#{@base_url}/#{item}", - 'versions' => [{'version' => '1.0.1', - 'url' => "#{@base_url}/#{item}/1.0.1"}]} + @cookbook_data[item] = {"url" => "#{@base_url}/#{item}", + "versions" => [{"version" => "1.0.1", + "url" => "#{@base_url}/#{item}/1.0.1"}]} end @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) end - describe 'run' do - it 'should display the latest version of the cookbooks' do - expect(@rest_mock).to receive(:get).with('/cookbooks?num_versions=1'). + describe "run" do + it "should display the latest version of the cookbooks" do + expect(@rest_mock).to receive(:get).with("/cookbooks?num_versions=1"). and_return(@cookbook_data) @knife.run @cookbook_names.each do |item| @@ -45,16 +45,16 @@ describe Chef::Knife::CookbookList do end end - it 'should query cookbooks for the configured environment' do - @knife.config[:environment] = 'production' + it "should query cookbooks for the configured environment" do + @knife.config[:environment] = "production" expect(@rest_mock).to receive(:get). - with('/environments/production/cookbooks?num_versions=1'). + with("/environments/production/cookbooks?num_versions=1"). and_return(@cookbook_data) @knife.run end - describe 'with -w or --with-uri' do - it 'should display the cookbook uris' do + describe "with -w or --with-uri" do + it "should display the cookbook uris" do @knife.config[:with_uri] = true allow(@rest_mock).to receive(:get).and_return(@cookbook_data) @knife.run @@ -65,17 +65,17 @@ describe Chef::Knife::CookbookList do end end - describe 'with -a or --all' do + describe "with -a or --all" do before do @cookbook_names.each do |item| - @cookbook_data[item]['versions'] << {'version' => '1.0.0', - 'url' => "#{@base_url}/#{item}/1.0.0"} + @cookbook_data[item]["versions"] << {"version" => "1.0.0", + "url" => "#{@base_url}/#{item}/1.0.0"} end end - it 'should display all versions of the cookbooks' do + it "should display all versions of the cookbooks" do @knife.config[:all_versions] = true - expect(@rest_mock).to receive(:get).with('/cookbooks?num_versions=all'). + expect(@rest_mock).to receive(:get).with("/cookbooks?num_versions=all"). and_return(@cookbook_data) @knife.run @cookbook_names.each do |item| diff --git a/spec/unit/knife/cookbook_metadata_from_file_spec.rb b/spec/unit/knife/cookbook_metadata_from_file_spec.rb index 456e378ca2..852258e8a0 100644 --- a/spec/unit/knife/cookbook_metadata_from_file_spec.rb +++ b/spec/unit/knife/cookbook_metadata_from_file_spec.rb @@ -18,7 +18,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::CookbookMetadataFromFile do before(:each) do diff --git a/spec/unit/knife/cookbook_metadata_spec.rb b/spec/unit/knife/cookbook_metadata_spec.rb index bd54d4278b..1dcc840611 100644 --- a/spec/unit/knife/cookbook_metadata_spec.rb +++ b/spec/unit/knife/cookbook_metadata_spec.rb @@ -16,12 +16,12 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::CookbookMetadata do before(:each) do @knife = Chef::Knife::CookbookMetadata.new - @knife.name_args = ['foobar'] + @knife.name_args = ["foobar"] @cookbook_dir = Dir.mktmpdir @json_data = '{ "version": "1.0.0" }' @stdout = StringIO.new @@ -30,50 +30,50 @@ describe Chef::Knife::CookbookMetadata do allow(@knife.ui).to receive(:stderr).and_return(@stderr) end - describe 'run' do - it 'should print an error and exit if a cookbook name was not provided' do + describe "run" do + it "should print an error and exit if a cookbook name was not provided" do @knife.name_args = [] expect(@knife.ui).to receive(:error).with(/you must specify the cookbook.+use the --all/i) expect { @knife.run }.to raise_error(SystemExit) end - it 'should print an error and exit if an empty cookbook name was provided' do - @knife.name_args = [''] + it "should print an error and exit if an empty cookbook name was provided" do + @knife.name_args = [""] expect(@knife.ui).to receive(:error).with(/you must specify the cookbook.+use the --all/i) expect { @knife.run }.to raise_error(SystemExit) end - it 'should generate the metadata for the cookbook' do - expect(@knife).to receive(:generate_metadata).with('foobar') + it "should generate the metadata for the cookbook" do + expect(@knife).to receive(:generate_metadata).with("foobar") @knife.run end - describe 'with -a or --all' do + describe "with -a or --all" do before(:each) do @knife.config[:all] = true - @foo = Chef::CookbookVersion.new('foo', '/tmp/blah') - @foo.version = '1.0.0' - @bar = Chef::CookbookVersion.new('bar', '/tmp/blah') - @bar.version = '2.0.0' + @foo = Chef::CookbookVersion.new("foo", "/tmp/blah") + @foo.version = "1.0.0" + @bar = Chef::CookbookVersion.new("bar", "/tmp/blah") + @bar.version = "2.0.0" @cookbook_loader = { "foo" => @foo, "bar" => @bar, } expect(@cookbook_loader).to receive(:load_cookbooks).and_return(@cookbook_loader) - expect(@knife).to receive(:generate_metadata).with('foo') - expect(@knife).to receive(:generate_metadata).with('bar') + expect(@knife).to receive(:generate_metadata).with("foo") + expect(@knife).to receive(:generate_metadata).with("bar") end - it 'should generate the metadata for each cookbook' do + it "should generate the metadata for each cookbook" do Chef::Config[:cookbook_path] = @cookbook_dir expect(Chef::CookbookLoader).to receive(:new).with(@cookbook_dir).and_return(@cookbook_loader) @knife.run end - describe 'and with -o or --cookbook-path' do - it 'should look in the provided path and generate cookbook metadata' do - @knife.config[:cookbook_path] = '/opt/chef/cookbooks' - expect(Chef::CookbookLoader).to receive(:new).with('/opt/chef/cookbooks').and_return(@cookbook_loader) + describe "and with -o or --cookbook-path" do + it "should look in the provided path and generate cookbook metadata" do + @knife.config[:cookbook_path] = "/opt/chef/cookbooks" + expect(Chef::CookbookLoader).to receive(:new).with("/opt/chef/cookbooks").and_return(@cookbook_loader) @knife.run end end @@ -81,55 +81,55 @@ describe Chef::Knife::CookbookMetadata do end - describe 'generate_metadata' do + describe "generate_metadata" do before(:each) do @knife.config[:cookbook_path] = @cookbook_dir allow(File).to receive(:expand_path).with("#{@cookbook_dir}/foobar/metadata.rb"). and_return("#{@cookbook_dir}/foobar/metadata.rb") end - it 'should generate the metadata from metadata.rb if it exists' do + it "should generate the metadata from metadata.rb if it exists" do expect(File).to receive(:exists?).with("#{@cookbook_dir}/foobar/metadata.rb"). and_return(true) - expect(@knife).to receive(:generate_metadata_from_file).with('foobar', "#{@cookbook_dir}/foobar/metadata.rb") + expect(@knife).to receive(:generate_metadata_from_file).with("foobar", "#{@cookbook_dir}/foobar/metadata.rb") @knife.run end - it 'should validate the metadata json if metadata.rb does not exist' do + it "should validate the metadata json if metadata.rb does not exist" do expect(File).to receive(:exists?).with("#{@cookbook_dir}/foobar/metadata.rb"). and_return(false) - expect(@knife).to receive(:validate_metadata_json).with(@cookbook_dir, 'foobar') + expect(@knife).to receive(:validate_metadata_json).with(@cookbook_dir, "foobar") @knife.run end end - describe 'generate_metadata_from_file' do + describe "generate_metadata_from_file" do before(:each) do - @metadata_mock = double('metadata') - @json_file_mock = double('json_file') + @metadata_mock = double("metadata") + @json_file_mock = double("json_file") end - it 'should generate the metatdata json from metatdata.rb' do + it "should generate the metatdata json from metatdata.rb" do allow(Chef::Cookbook::Metadata).to receive(:new).and_return(@metadata_mock) - expect(@metadata_mock).to receive(:name).with('foobar') + expect(@metadata_mock).to receive(:name).with("foobar") expect(@metadata_mock).to receive(:from_file).with("#{@cookbook_dir}/foobar/metadata.rb") - expect(File).to receive(:open).with("#{@cookbook_dir}/foobar/metadata.json", 'w'). + expect(File).to receive(:open).with("#{@cookbook_dir}/foobar/metadata.json", "w"). and_yield(@json_file_mock) expect(@json_file_mock).to receive(:write).with(@json_data) expect(Chef::JSONCompat).to receive(:to_json_pretty).with(@metadata_mock). and_return(@json_data) - @knife.generate_metadata_from_file('foobar', "#{@cookbook_dir}/foobar/metadata.rb") + @knife.generate_metadata_from_file("foobar", "#{@cookbook_dir}/foobar/metadata.rb") expect(@stderr.string).to match /generating metadata for foobar from #{@cookbook_dir}\/foobar\/metadata\.rb/im end - { Chef::Exceptions::ObsoleteDependencySyntax => 'obsolote dependency', - Chef::Exceptions::InvalidVersionConstraint => 'invalid version constraint', + { Chef::Exceptions::ObsoleteDependencySyntax => "obsolote dependency", + Chef::Exceptions::InvalidVersionConstraint => "invalid version constraint", }.each_pair do |klass, description| it "should print an error and exit when an #{description} syntax exception is encountered" do exception = klass.new("#{description} blah") allow(Chef::Cookbook::Metadata).to receive(:new).and_raise(exception) expect { - @knife.generate_metadata_from_file('foobar', "#{@cookbook_dir}/foobar/metadata.rb") + @knife.generate_metadata_from_file("foobar", "#{@cookbook_dir}/foobar/metadata.rb") }.to raise_error(SystemExit) expect(@stderr.string).to match /error: the cookbook 'foobar' contains invalid or obsolete metadata syntax/im expect(@stderr.string).to match /in #{@cookbook_dir}\/foobar\/metadata\.rb/im @@ -138,26 +138,26 @@ describe Chef::Knife::CookbookMetadata do end end - describe 'validate_metadata_json' do - it 'should validate the metadata json' do + describe "validate_metadata_json" do + it "should validate the metadata json" do expect(File).to receive(:exist?).with("#{@cookbook_dir}/foobar/metadata.json"). and_return(true) expect(IO).to receive(:read).with("#{@cookbook_dir}/foobar/metadata.json"). and_return(@json_data) expect(Chef::Cookbook::Metadata).to receive(:validate_json).with(@json_data) - @knife.validate_metadata_json(@cookbook_dir, 'foobar') + @knife.validate_metadata_json(@cookbook_dir, "foobar") end - it 'should not try to validate the metadata json if the file does not exist' do + it "should not try to validate the metadata json if the file does not exist" do expect(File).to receive(:exist?).with("#{@cookbook_dir}/foobar/metadata.json"). and_return(false) expect(IO).not_to receive(:read) expect(Chef::Cookbook::Metadata).not_to receive(:validate_json) - @knife.validate_metadata_json(@cookbook_dir, 'foobar') + @knife.validate_metadata_json(@cookbook_dir, "foobar") end - { Chef::Exceptions::ObsoleteDependencySyntax => 'obsolote dependency', - Chef::Exceptions::InvalidVersionConstraint => 'invalid version constraint', + { Chef::Exceptions::ObsoleteDependencySyntax => "obsolote dependency", + Chef::Exceptions::InvalidVersionConstraint => "invalid version constraint", }.each_pair do |klass, description| it "should print an error and exit when an #{description} syntax exception is encountered" do expect(File).to receive(:exist?).with("#{@cookbook_dir}/foobar/metadata.json"). @@ -167,7 +167,7 @@ describe Chef::Knife::CookbookMetadata do exception = klass.new("#{description} blah") allow(Chef::Cookbook::Metadata).to receive(:validate_json).and_raise(exception) expect { - @knife.validate_metadata_json(@cookbook_dir, 'foobar') + @knife.validate_metadata_json(@cookbook_dir, "foobar") }.to raise_error(SystemExit) expect(@stderr.string).to match /error: the cookbook 'foobar' contains invalid or obsolete metadata syntax/im expect(@stderr.string).to match /in #{@cookbook_dir}\/foobar\/metadata\.json/im diff --git a/spec/unit/knife/cookbook_show_spec.rb b/spec/unit/knife/cookbook_show_spec.rb index 6c77db013f..bde33b0689 100644 --- a/spec/unit/knife/cookbook_show_spec.rb +++ b/spec/unit/knife/cookbook_show_spec.rb @@ -17,7 +17,7 @@ # # rename to cookbook not coookbook -require 'spec_helper' +require "spec_helper" describe Chef::Knife::CookbookShow do before(:each) do @@ -33,7 +33,7 @@ describe Chef::Knife::CookbookShow do describe "run" do describe "with 0 arguments: help" do - it 'should should print usage and exit when given no arguments' do + it "should should print usage and exit when given no arguments" do @knife.name_args = [] expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal) diff --git a/spec/unit/knife/cookbook_site_download_spec.rb b/spec/unit/knife/cookbook_site_download_spec.rb index 35c6544d58..52e82a7f0b 100644 --- a/spec/unit/knife/cookbook_site_download_spec.rb +++ b/spec/unit/knife/cookbook_site_download_spec.rb @@ -16,22 +16,22 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') +require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") describe Chef::Knife::CookbookSiteDownload do - describe 'run' do + describe "run" do before do @knife = Chef::Knife::CookbookSiteDownload.new - @knife.name_args = ['apache2'] - @noauth_rest = double('no auth rest') + @knife.name_args = ["apache2"] + @noauth_rest = double("no auth rest") @stderr = StringIO.new - @cookbook_api_url = 'https://supermarket.chef.io/api/v1/cookbooks' - @version = '1.0.2' - @version_us = @version.gsub '.', '_' - @current_data = { 'deprecated' => false, - 'latest_version' => "#{@cookbook_api_url}/apache2/versions/#{@version_us}", - 'replacement' => 'other_apache2' } + @cookbook_api_url = "https://supermarket.chef.io/api/v1/cookbooks" + @version = "1.0.2" + @version_us = @version.gsub ".", "_" + @current_data = { "deprecated" => false, + "latest_version" => "#{@cookbook_api_url}/apache2/versions/#{@version_us}", + "replacement" => "other_apache2" } allow(@knife.ui).to receive(:stderr).and_return(@stderr) allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest) @@ -40,12 +40,12 @@ describe Chef::Knife::CookbookSiteDownload do and_return(@current_data) end - context 'when the cookbook is deprecated and not forced' do + context "when the cookbook is deprecated and not forced" do before do - @current_data['deprecated'] = true + @current_data["deprecated"] = true end - it 'should warn with info about the replacement' do + it "should warn with info about the replacement" do expect(@knife.ui).to receive(:warn). with(/.+deprecated.+replaced by other_apache2.+/i) expect(@knife.ui).to receive(:warn). @@ -54,33 +54,33 @@ describe Chef::Knife::CookbookSiteDownload do end end - context 'when' do + context "when" do before do - @cookbook_data = { 'version' => @version, - 'file' => "http://example.com/apache2_#{@version_us}.tgz" } + @cookbook_data = { "version" => @version, + "file" => "http://example.com/apache2_#{@version_us}.tgz" } @temp_file = double( :path => "/tmp/apache2_#{@version_us}.tgz" ) @file = File.join(Dir.pwd, "apache2-#{@version}.tar.gz") expect(@noauth_rest).to receive(:sign_on_redirect=).with(false) end - context 'downloading the latest version' do + context "downloading the latest version" do before do expect(@noauth_rest).to receive(:get). - with(@current_data['latest_version']). + with(@current_data["latest_version"]). and_return(@cookbook_data) expect(@noauth_rest).to receive(:get). - with(@cookbook_data['file'], true). + with(@cookbook_data["file"], true). and_return(@temp_file) end - context 'and it is deprecated and with --force' do + context "and it is deprecated and with --force" do before do - @current_data['deprecated'] = true + @current_data["deprecated"] = true @knife.config[:force] = true end - it 'should download the latest version' do + it "should download the latest version" do expect(@knife.ui).to receive(:warn). with(/.+deprecated.+replaced by other_apache2.+/i) expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) @@ -91,51 +91,51 @@ describe Chef::Knife::CookbookSiteDownload do end - it 'should download the latest version' do + it "should download the latest version" do expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) @knife.run expect(@stderr.string).to match /downloading apache2.+version.+#{Regexp.escape(@version)}/i expect(@stderr.string).to match /cookbook save.+#{Regexp.escape(@file)}/i end - context 'with -f or --file' do + context "with -f or --file" do before do - @file = '/opt/chef/cookbooks/apache2.tar.gz' + @file = "/opt/chef/cookbooks/apache2.tar.gz" @knife.config[:file] = @file expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) end - it 'should download the cookbook to the desired file' do + it "should download the cookbook to the desired file" do @knife.run expect(@stderr.string).to match /downloading apache2.+version.+#{Regexp.escape(@version)}/i expect(@stderr.string).to match /cookbook save.+#{Regexp.escape(@file)}/i end end - it 'should provide an accessor to the version' do + it "should provide an accessor to the version" do allow(FileUtils).to receive(:cp).and_return(true) expect(@knife.version).to eq(@version) @knife.run end end - context 'downloading a cookbook of a specific version' do + context "downloading a cookbook of a specific version" do before do - @version = '1.0.1' - @version_us = @version.gsub '.', '_' - @cookbook_data = { 'version' => @version, - 'file' => "http://example.com/apache2_#{@version_us}.tgz" } + @version = "1.0.1" + @version_us = @version.gsub ".", "_" + @cookbook_data = { "version" => @version, + "file" => "http://example.com/apache2_#{@version_us}.tgz" } @temp_file = double(:path => "/tmp/apache2_#{@version_us}.tgz") @file = File.join(Dir.pwd, "apache2-#{@version}.tar.gz") @knife.name_args << @version end - it 'should download the desired version' do + it "should download the desired version" do expect(@noauth_rest).to receive(:get). with("#{@cookbook_api_url}/apache2/versions/#{@version_us}"). and_return(@cookbook_data) expect(@noauth_rest).to receive(:get). - with(@cookbook_data['file'], true). + with(@cookbook_data["file"], true). and_return(@temp_file) expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) @knife.run diff --git a/spec/unit/knife/cookbook_site_install_spec.rb b/spec/unit/knife/cookbook_site_install_spec.rb index 9779de4a64..c2ffe4bb14 100644 --- a/spec/unit/knife/cookbook_site_install_spec.rb +++ b/spec/unit/knife/cookbook_site_install_spec.rb @@ -28,14 +28,14 @@ describe Chef::Knife::CookbookSiteInstall do :merge_updates_from => true) } let(:install_path) { if Chef::Platform.windows? - 'C:/tmp/chef' + "C:/tmp/chef" else - '/var/tmp/chef' + "/var/tmp/chef" end } before(:each) do - require 'chef/knife/core/cookbook_scm_repo' + require "chef/knife/core/cookbook_scm_repo" allow(knife.ui).to receive(:stdout).and_return(stdout) knife.config = {} diff --git a/spec/unit/knife/cookbook_site_share_spec.rb b/spec/unit/knife/cookbook_site_share_spec.rb index 14ade10e09..5cd90bc0c4 100644 --- a/spec/unit/knife/cookbook_site_share_spec.rb +++ b/spec/unit/knife/cookbook_site_share_spec.rb @@ -16,10 +16,10 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" -require 'chef/cookbook_uploader' -require 'chef/cookbook_site_streaming_uploader' +require "chef/cookbook_uploader" +require "chef/cookbook_site_streaming_uploader" describe Chef::Knife::CookbookSiteShare do @@ -27,11 +27,11 @@ describe Chef::Knife::CookbookSiteShare do @knife = Chef::Knife::CookbookSiteShare.new # Merge default settings in. @knife.merge_configs - @knife.name_args = ['cookbook_name', 'AwesomeSausage'] + @knife.name_args = ["cookbook_name", "AwesomeSausage"] - @cookbook = Chef::CookbookVersion.new('cookbook_name') + @cookbook = Chef::CookbookVersion.new("cookbook_name") - @cookbook_loader = double('Chef::CookbookLoader') + @cookbook_loader = double("Chef::CookbookLoader") allow(@cookbook_loader).to receive(:cookbook_exists?).and_return(true) allow(@cookbook_loader).to receive(:[]).and_return(@cookbook) allow(Chef::CookbookLoader).to receive(:new).and_return(@cookbook_loader) @@ -39,7 +39,7 @@ describe Chef::Knife::CookbookSiteShare do @noauth_rest = double(Chef::ServerAPI) allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest) - @cookbook_uploader = Chef::CookbookUploader.new('herpderp', :rest => "norest") + @cookbook_uploader = Chef::CookbookUploader.new("herpderp", :rest => "norest") allow(Chef::CookbookUploader).to receive(:new).and_return(@cookbook_uploader) allow(@cookbook_uploader).to receive(:validate_cookbooks).and_return(true) allow(Chef::CookbookSiteStreamingUploader).to receive(:create_build_dir).and_return(Dir.mktmpdir) @@ -49,7 +49,7 @@ describe Chef::Knife::CookbookSiteShare do allow(@knife.ui).to receive(:stdout).and_return(@stdout) end - describe 'run' do + describe "run" do before(:each) do allow(@knife).to receive(:do_upload).and_return(true) @@ -65,39 +65,39 @@ describe Chef::Knife::CookbookSiteShare do } end - it 'should set true to config[:dry_run] as default' do + it "should set true to config[:dry_run] as default" do expect(@knife.config[:dry_run]).to be_falsey end - it 'should should print usage and exit when given no arguments' do + it "should should print usage and exit when given no arguments" do @knife.name_args = [] expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal) expect { @knife.run }.to raise_error(SystemExit) end - it 'should not fail when given only 1 argument and can determine category' do - @knife.name_args = ['cookbook_name'] + it "should not fail when given only 1 argument and can determine category" do + @knife.name_args = ["cookbook_name"] expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@category_response) expect(@knife).to receive(:do_upload) @knife.run end - it 'should print error and exit when given only 1 argument and cannot determine category' do - @knife.name_args = ['cookbook_name'] + it "should print error and exit when given only 1 argument and cannot determine category" do + @knife.name_args = ["cookbook_name"] expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@bad_category_response) expect(@knife.ui).to receive(:fatal) expect { @knife.run }.to raise_error(SystemExit) end - it 'should print error and exit when given only 1 argument and Chef::ServerAPI throws an exception' do - @knife.name_args = ['cookbook_name'] + it "should print error and exit when given only 1 argument and Chef::ServerAPI throws an exception" do + @knife.name_args = ["cookbook_name"] expect(@noauth_rest).to receive(:get).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name") { raise Errno::ECONNREFUSED, "Connection refused" } expect(@knife.ui).to receive(:fatal) expect { @knife.run }.to raise_error(SystemExit) end - it 'should check if the cookbook exists' do + it "should check if the cookbook exists" do expect(@cookbook_loader).to receive(:cookbook_exists?) @knife.run end @@ -108,15 +108,15 @@ describe Chef::Knife::CookbookSiteShare do expect { @knife.run }.to raise_error(SystemExit) end - if File.exists?('/usr/bin/gnutar') || File.exists?('/bin/gnutar') - it 'should use gnutar to make a tarball of the cookbook' do + if File.exists?("/usr/bin/gnutar") || File.exists?("/bin/gnutar") + it "should use gnutar to make a tarball of the cookbook" do expect(@knife).to receive(:shell_out!) do |args| expect(args.to_s).to match(/gnutar -czf/) end @knife.run end else - it 'should make a tarball of the cookbook' do + it "should make a tarball of the cookbook" do expect(@knife).to receive(:shell_out!) do |args| expect(args.to_s).to match(/tar -czf/) end @@ -124,13 +124,13 @@ describe Chef::Knife::CookbookSiteShare do end end - it 'should exit and log to error when the tarball creation fails' do + it "should exit and log to error when the tarball creation fails" do allow(@knife).to receive(:shell_out!).and_raise(Chef::Exceptions::Exec) expect(@knife.ui).to receive(:error) expect { @knife.run }.to raise_error(SystemExit) end - it 'should upload the cookbook and clean up the tarball' do + it "should upload the cookbook and clean up the tarball" do expect(@knife).to receive(:do_upload) expect(FileUtils).to receive(:rm_rf) @knife.run @@ -140,7 +140,7 @@ describe Chef::Knife::CookbookSiteShare do before do allow(Chef::CookbookSiteStreamingUploader).to receive(:create_build_dir).and_return("/var/tmp/dummy") @knife.config = { :dry_run => true } - allow(@knife).to receive_message_chain(:shell_out!, :stdout).and_return('file') + allow(@knife).to receive_message_chain(:shell_out!, :stdout).and_return("file") end it "should list files in the tarball" do @@ -158,10 +158,10 @@ describe Chef::Knife::CookbookSiteShare do end end - describe 'do_upload' do + describe "do_upload" do before(:each) do - @upload_response = double('Net::HTTPResponse') + @upload_response = double("Net::HTTPResponse") allow(Chef::CookbookSiteStreamingUploader).to receive(:post).and_return(@upload_response) @stdout = StringIO.new @@ -172,22 +172,22 @@ describe Chef::Knife::CookbookSiteShare do end it 'should post the cookbook to "https://supermarket.chef.io"' do - response_text = Chef::JSONCompat.to_json({:uri => 'https://supermarket.chef.io/cookbooks/cookbook_name'}) + response_text = Chef::JSONCompat.to_json({:uri => "https://supermarket.chef.io/cookbooks/cookbook_name"}) allow(@upload_response).to receive(:body).and_return(response_text) allow(@upload_response).to receive(:code).and_return(201) expect(Chef::CookbookSiteStreamingUploader).to receive(:post).with(/supermarket\.chef\.io/, anything(), anything(), anything()) @knife.run end - it 'should alert the user when a version already exists' do - response_text = Chef::JSONCompat.to_json({:error_messages => ['Version already exists']}) + it "should alert the user when a version already exists" do + response_text = Chef::JSONCompat.to_json({:error_messages => ["Version already exists"]}) allow(@upload_response).to receive(:body).and_return(response_text) allow(@upload_response).to receive(:code).and_return(409) expect { @knife.run }.to raise_error(SystemExit) expect(@stderr.string).to match(/ERROR(.+)cookbook already exists/) end - it 'should pass any errors on to the user' do + it "should pass any errors on to the user" do response_text = Chef::JSONCompat.to_json({:error_messages => ["You're holding it wrong"]}) allow(@upload_response).to receive(:body).and_return(response_text) allow(@upload_response).to receive(:code).and_return(403) @@ -195,7 +195,7 @@ describe Chef::Knife::CookbookSiteShare do expect(@stderr.string).to match("ERROR(.*)You're holding it wrong") end - it 'should print the body if no errors are exposed on failure' do + it "should print the body if no errors are exposed on failure" do response_text = Chef::JSONCompat.to_json({:system_error => "Your call was dropped", :reason => "There's a map for that"}) allow(@upload_response).to receive(:body).and_return(response_text) allow(@upload_response).to receive(:code).and_return(500) diff --git a/spec/unit/knife/cookbook_site_unshare_spec.rb b/spec/unit/knife/cookbook_site_unshare_spec.rb index aafb7c1507..d8c67aae20 100644 --- a/spec/unit/knife/cookbook_site_unshare_spec.rb +++ b/spec/unit/knife/cookbook_site_unshare_spec.rb @@ -17,26 +17,26 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::CookbookSiteUnshare do before(:each) do @knife = Chef::Knife::CookbookSiteUnshare.new - @knife.name_args = ['cookbook_name'] + @knife.name_args = ["cookbook_name"] allow(@knife).to receive(:confirm).and_return(true) - @rest = double('Chef::ServerAPI') + @rest = double("Chef::ServerAPI") allow(@rest).to receive(:delete).and_return(true) allow(@knife).to receive(:rest).and_return(@rest) @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) end - describe 'run' do + describe "run" do - describe 'with no cookbook argument' do - it 'should print the usage and exit' do + describe "with no cookbook argument" do + it "should print the usage and exit" do @knife.name_args = [] expect(@knife.ui).to receive(:fatal) expect(@knife).to receive(:show_usage) @@ -44,30 +44,30 @@ describe Chef::Knife::CookbookSiteUnshare do end end - it 'should confirm you want to unshare the cookbook' do + it "should confirm you want to unshare the cookbook" do expect(@knife).to receive(:confirm) @knife.run end - it 'should send a delete request to the cookbook site' do + it "should send a delete request to the cookbook site" do expect(@rest).to receive(:delete) @knife.run end - it 'should log an error and exit when forbidden' do - exception = double('403 "Forbidden"', :code => '403') + it "should log an error and exit when forbidden" do + exception = double('403 "Forbidden"', :code => "403") allow(@rest).to receive(:delete).and_raise(Net::HTTPServerException.new('403 "Forbidden"', exception)) expect(@knife.ui).to receive(:error) expect { @knife.run }.to raise_error(SystemExit) end - it 'should re-raise any non-forbidden errors on delete' do - exception = double('500 "Application Error"', :code => '500') + it "should re-raise any non-forbidden errors on delete" do + exception = double('500 "Application Error"', :code => "500") allow(@rest).to receive(:delete).and_raise(Net::HTTPServerException.new('500 "Application Error"', exception)) expect { @knife.run }.to raise_error(Net::HTTPServerException) end - it 'should log a success message' do + it "should log a success message" do expect(@knife.ui).to receive(:info) @knife.run end diff --git a/spec/unit/knife/cookbook_test_spec.rb b/spec/unit/knife/cookbook_test_spec.rb index ce74bcaa5d..3587de0c78 100644 --- a/spec/unit/knife/cookbook_test_spec.rb +++ b/spec/unit/knife/cookbook_test_spec.rb @@ -18,14 +18,14 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" Chef::Knife::CookbookTest.load_deps describe Chef::Knife::CookbookTest do before(:each) do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::CookbookTest.new - @knife.config[:cookbook_path] = File.join(CHEF_SPEC_DATA,'cookbooks') + @knife.config[:cookbook_path] = File.join(CHEF_SPEC_DATA,"cookbooks") allow(@knife.cookbook_loader).to receive(:cookbook_exists?).and_return(true) @cookbooks = [] %w{tats central_market jimmy_johns pho}.each do |cookbook_name| diff --git a/spec/unit/knife/cookbook_upload_spec.rb b/spec/unit/knife/cookbook_upload_spec.rb index ecee34f308..666974a817 100644 --- a/spec/unit/knife/cookbook_upload_spec.rb +++ b/spec/unit/knife/cookbook_upload_spec.rb @@ -19,11 +19,11 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) -require 'chef/cookbook_uploader' -require 'timeout' +require "chef/cookbook_uploader" +require "timeout" describe Chef::Knife::CookbookUpload do - let(:cookbook) { Chef::CookbookVersion.new('test_cookbook', '/tmp/blah.txt') } + let(:cookbook) { Chef::CookbookVersion.new("test_cookbook", "/tmp/blah.txt") } let(:cookbooks_by_name) do {cookbook.name => cookbook} @@ -40,7 +40,7 @@ describe Chef::Knife::CookbookUpload do let(:output) { StringIO.new } - let(:name_args) { ['test_cookbook'] } + let(:name_args) { ["test_cookbook"] } let(:knife) do k = Chef::Knife::CookbookUpload.new @@ -54,11 +54,11 @@ describe Chef::Knife::CookbookUpload do allow(Chef::CookbookLoader).to receive(:new).and_return(cookbook_loader) end - describe 'with --concurrency' do - it 'should upload cookbooks with predefined concurrency' do + describe "with --concurrency" do + it "should upload cookbooks with predefined concurrency" do allow(Chef::CookbookVersion).to receive(:list_all_versions).and_return({}) knife.config[:concurrency] = 3 - test_cookbook = Chef::CookbookVersion.new('test_cookbook', '/tmp/blah') + test_cookbook = Chef::CookbookVersion.new("test_cookbook", "/tmp/blah") allow(cookbook_loader).to receive(:each).and_yield("test_cookbook", test_cookbook) allow(cookbook_loader).to receive(:cookbook_names).and_return(["test_cookbook"]) expect(Chef::CookbookUploader).to receive(:new). @@ -68,35 +68,35 @@ describe Chef::Knife::CookbookUpload do end end - describe 'run' do + describe "run" do before(:each) do allow(Chef::CookbookUploader).to receive_messages(:new => cookbook_uploader) allow(Chef::CookbookVersion).to receive(:list_all_versions).and_return({}) end - it 'should print usage and exit when a cookbook name is not provided' do + it "should print usage and exit when a cookbook name is not provided" do knife.name_args = [] expect(knife).to receive(:show_usage) expect(knife.ui).to receive(:fatal) expect { knife.run }.to raise_error(SystemExit) end - describe 'when specifying a cookbook name' do - it 'should upload the cookbook' do + describe "when specifying a cookbook name" do + it "should upload the cookbook" do expect(knife).to receive(:upload).once knife.run end - it 'should report on success' do + it "should report on success" do expect(knife).to receive(:upload).once expect(knife.ui).to receive(:info).with(/Uploaded 1 cookbook/) knife.run end end - describe 'when specifying the same cookbook name twice' do - it 'should upload the cookbook only once' do - knife.name_args = ['test_cookbook', 'test_cookbook'] + describe "when specifying the same cookbook name twice" do + it "should upload the cookbook only once" do + knife.name_args = ["test_cookbook", "test_cookbook"] expect(knife).to receive(:upload).once knife.run end @@ -105,9 +105,9 @@ describe Chef::Knife::CookbookUpload do context "when uploading a cookbook that uses deprecated overlays" do before do - allow(cookbook_loader).to receive(:merged_cookbooks).and_return(['test_cookbook']) + allow(cookbook_loader).to receive(:merged_cookbooks).and_return(["test_cookbook"]) allow(cookbook_loader).to receive(:merged_cookbook_paths). - and_return({'test_cookbook' => %w{/path/one/test_cookbook /path/two/test_cookbook}}) + and_return({"test_cookbook" => %w{/path/one/test_cookbook /path/two/test_cookbook}}) end it "emits a warning" do @@ -127,19 +127,19 @@ E end end - describe 'when specifying a cookbook name among many' do - let(:name_args) { ['test_cookbook1'] } + describe "when specifying a cookbook name among many" do + let(:name_args) { ["test_cookbook1"] } let(:cookbooks_by_name) do { - 'test_cookbook1' => Chef::CookbookVersion.new('test_cookbook1', '/tmp/blah'), - 'test_cookbook2' => Chef::CookbookVersion.new('test_cookbook2', '/tmp/blah'), - 'test_cookbook3' => Chef::CookbookVersion.new('test_cookbook3', '/tmp/blah'), + "test_cookbook1" => Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah"), + "test_cookbook2" => Chef::CookbookVersion.new("test_cookbook2", "/tmp/blah"), + "test_cookbook3" => Chef::CookbookVersion.new("test_cookbook3", "/tmp/blah"), } end it "should read only one cookbook" do - expect(cookbook_loader).to receive(:[]).once.with('test_cookbook1').and_call_original + expect(cookbook_loader).to receive(:[]).once.with("test_cookbook1").and_call_original knife.run end @@ -155,7 +155,7 @@ E end # This is testing too much. We should break it up. - describe 'when specifying a cookbook name with dependencies' do + describe "when specifying a cookbook name with dependencies" do let(:name_args) { ["test_cookbook2"] } let(:cookbooks_by_name) do @@ -164,16 +164,16 @@ E "test_cookbook3" => test_cookbook3 } end - let(:test_cookbook1) { Chef::CookbookVersion.new('test_cookbook1', '/tmp/blah') } + let(:test_cookbook1) { Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah") } let(:test_cookbook2) do - c = Chef::CookbookVersion.new('test_cookbook2') + c = Chef::CookbookVersion.new("test_cookbook2") c.metadata.depends("test_cookbook3") c end let(:test_cookbook3) do - c = Chef::CookbookVersion.new('test_cookbook3') + c = Chef::CookbookVersion.new("test_cookbook3") c.metadata.depends("test_cookbook1") c.metadata.depends("test_cookbook2") c @@ -191,8 +191,8 @@ E end end - describe 'when specifying a cookbook name with missing dependencies' do - let(:cookbook_dependency) { Chef::CookbookVersion.new('dependency', '/tmp/blah') } + describe "when specifying a cookbook name with missing dependencies" do + let(:cookbook_dependency) { Chef::CookbookVersion.new("dependency", "/tmp/blah") } before(:each) do cookbook.metadata.depends("dependency") @@ -205,22 +205,22 @@ E knife.ui = Chef::Knife::UI.new(@stdout, @stderr, @stdin, {}) end - it 'should exit and not upload the cookbook' do - expect(cookbook_loader).to receive(:[]).once.with('test_cookbook') + it "should exit and not upload the cookbook" do + expect(cookbook_loader).to receive(:[]).once.with("test_cookbook") expect(cookbook_loader).not_to receive(:load_cookbooks) expect(cookbook_uploader).not_to receive(:upload_cookbooks) expect {knife.run}.to raise_error(SystemExit) end - it 'should output a message for a single missing dependency' do + it "should output a message for a single missing dependency" do expect {knife.run}.to raise_error(SystemExit) - expect(@stderr.string).to include('Cookbook test_cookbook depends on cookbooks which are not currently') - expect(@stderr.string).to include('being uploaded and cannot be found on the server.') + expect(@stderr.string).to include("Cookbook test_cookbook depends on cookbooks which are not currently") + expect(@stderr.string).to include("being uploaded and cannot be found on the server.") expect(@stderr.string).to include("The missing cookbook(s) are: 'dependency' version '>= 0.0.0'") end - it 'should output a message for a multiple missing dependencies which are concatenated' do - cookbook_dependency2 = Chef::CookbookVersion.new('dependency2') + it "should output a message for a multiple missing dependencies which are concatenated" do + cookbook_dependency2 = Chef::CookbookVersion.new("dependency2") cookbook.metadata.depends("dependency2") allow(cookbook_loader).to receive(:[]) do |ckbk| { "test_cookbook" => cookbook, @@ -229,8 +229,8 @@ E end allow(knife).to receive(:cookbook_names).and_return(["dependency", "dependency2", "test_cookbook"]) expect {knife.run}.to raise_error(SystemExit) - expect(@stderr.string).to include('Cookbook test_cookbook depends on cookbooks which are not currently') - expect(@stderr.string).to include('being uploaded and cannot be found on the server.') + expect(@stderr.string).to include("Cookbook test_cookbook depends on cookbooks which are not currently") + expect(@stderr.string).to include("being uploaded and cannot be found on the server.") expect(@stderr.string).to include("The missing cookbook(s) are:") expect(@stderr.string).to include("'dependency' version '>= 0.0.0'") expect(@stderr.string).to include("'dependency2' version '>= 0.0.0'") @@ -243,31 +243,31 @@ E knife.run end - describe 'with -a or --all' do + describe "with -a or --all" do before(:each) do knife.config[:all] = true end - context 'when cookbooks exist in the cookbook path' do + context "when cookbooks exist in the cookbook path" do before(:each) do - @test_cookbook1 = Chef::CookbookVersion.new('test_cookbook1', '/tmp/blah') - @test_cookbook2 = Chef::CookbookVersion.new('test_cookbook2', '/tmp/blah') + @test_cookbook1 = Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah") + @test_cookbook2 = Chef::CookbookVersion.new("test_cookbook2", "/tmp/blah") allow(cookbook_loader).to receive(:each).and_yield("test_cookbook1", @test_cookbook1).and_yield("test_cookbook2", @test_cookbook2) allow(cookbook_loader).to receive(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2"]) end - it 'should upload all cookbooks' do + it "should upload all cookbooks" do expect(knife).to receive(:upload).once knife.run end - it 'should report on success' do + it "should report on success" do expect(knife).to receive(:upload).once expect(knife.ui).to receive(:info).with(/Uploaded all cookbooks/) knife.run end - it 'should update the version constraints for an environment' do + it "should update the version constraints for an environment" do allow(knife).to receive(:assert_environment_valid!).and_return(true) knife.config[:environment] = "production" expect(knife).to receive(:update_version_constraints).once @@ -275,28 +275,28 @@ E end end - context 'when no cookbooks exist in the cookbook path' do + context "when no cookbooks exist in the cookbook path" do before(:each) do allow(cookbook_loader).to receive(:each) end - it 'should not upload any cookbooks' do + it "should not upload any cookbooks" do expect(knife).to_not receive(:upload) knife.run end - context 'when cookbook path is an array' do - it 'should warn users that no cookbooks exist' do - knife.config[:cookbook_path] = ['/chef-repo/cookbooks', '/home/user/cookbooks'] + context "when cookbook path is an array" do + it "should warn users that no cookbooks exist" do + knife.config[:cookbook_path] = ["/chef-repo/cookbooks", "/home/user/cookbooks"] expect(knife.ui).to receive(:warn).with( /Could not find any cookbooks in your cookbook path: #{knife.config[:cookbook_path].join(', ')}\. Use --cookbook-path to specify the desired path\./) knife.run end end - context 'when cookbook path is a string' do - it 'should warn users that no cookbooks exist' do - knife.config[:cookbook_path] = '/chef-repo/cookbooks' + context "when cookbook path is a string" do + it "should warn users that no cookbooks exist" do + knife.config[:cookbook_path] = "/chef-repo/cookbooks" expect(knife.ui).to receive(:warn).with( /Could not find any cookbooks in your cookbook path: #{knife.config[:cookbook_path]}\. Use --cookbook-path to specify the desired path\./) knife.run @@ -305,8 +305,8 @@ E end end - describe 'when a frozen cookbook exists on the server' do - it 'should fail to replace it' do + describe "when a frozen cookbook exists on the server" do + it "should fail to replace it" do exception = Chef::Exceptions::CookbookFrozen.new expect(cookbook_uploader).to receive(:upload_cookbooks). and_raise(exception) @@ -315,7 +315,7 @@ E expect { knife.run }.to raise_error(SystemExit) end - it 'should not update the version constraints for an environment' do + it "should not update the version constraints for an environment" do allow(knife).to receive(:assert_environment_valid!).and_return(true) knife.config[:environment] = "production" allow(knife).to receive(:upload).and_raise(Chef::Exceptions::CookbookFrozen) diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb index 1d93f64e32..7ecade338a 100644 --- a/spec/unit/knife/core/bootstrap_context_spec.rb +++ b/spec/unit/knife/core/bootstrap_context_spec.rb @@ -16,17 +16,17 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/knife/core/bootstrap_context' +require "spec_helper" +require "chef/knife/core/bootstrap_context" describe Chef::Knife::Core::BootstrapContext do let(:config) { {:foo => :bar, :color => true} } - let(:run_list) { Chef::RunList.new('recipe[tmux]', 'role[base]') } + let(:run_list) { Chef::RunList.new("recipe[tmux]", "role[base]") } let(:chef_config) do { - :validation_key => File.join(CHEF_SPEC_DATA, 'ssl', 'private_key.pem'), - :chef_server_url => 'http://chef.example.com:4444', - :validation_client_name => 'chef-validator-testing', + :validation_key => File.join(CHEF_SPEC_DATA, "ssl", "private_key.pem"), + :chef_server_url => "http://chef.example.com:4444", + :validation_client_name => "chef-validator-testing", } end @@ -57,7 +57,7 @@ describe Chef::Knife::Core::BootstrapContext do end it "reads the validation key" do - expect(bootstrap_context.validation_key).to eq IO.read(File.join(CHEF_SPEC_DATA, 'ssl', 'private_key.pem')) + expect(bootstrap_context.validation_key).to eq IO.read(File.join(CHEF_SPEC_DATA, "ssl", "private_key.pem")) end it "generates the config file data" do @@ -75,23 +75,23 @@ EXPECTED end describe "alternate chef-client path" do - let(:chef_config){ {:chef_client_path => '/usr/local/bin/chef-client'} } + let(:chef_config){ {:chef_client_path => "/usr/local/bin/chef-client"} } it "runs chef-client from another path when specified" do expect(bootstrap_context.start_chef).to eq "/usr/local/bin/chef-client -j /etc/chef/first-boot.json" end end describe "validation key path that contains a ~" do - let(:chef_config){ {:validation_key => '~/my.key'} } + let(:chef_config){ {:validation_key => "~/my.key"} } it "reads the validation key when it contains a ~" do - expect(File).to receive(:exist?).with(File.expand_path("my.key", ENV['HOME'])).and_return(true) - expect(IO).to receive(:read).with(File.expand_path("my.key", ENV['HOME'])) + expect(File).to receive(:exist?).with(File.expand_path("my.key", ENV["HOME"])).and_return(true) + expect(IO).to receive(:read).with(File.expand_path("my.key", ENV["HOME"])) bootstrap_context.validation_key end end describe "when an explicit node name is given" do - let(:config){ {:chef_node_name => 'foobar.example.com' }} + let(:config){ {:chef_node_name => "foobar.example.com" }} it "sets the node name in the client.rb" do expect(bootstrap_context.config_content).to match(/node_name "foobar\.example\.com"/) end @@ -100,7 +100,7 @@ EXPECTED describe "when bootstrapping into a specific environment" do let(:config){ {:environment => "prodtastic", :color => true} } it "starts chef in the configured environment" do - expect(bootstrap_context.start_chef).to eq('chef-client -j /etc/chef/first-boot.json -E prodtastic') + expect(bootstrap_context.start_chef).to eq("chef-client -j /etc/chef/first-boot.json -E prodtastic") end end diff --git a/spec/unit/knife/core/cookbook_scm_repo_spec.rb b/spec/unit/knife/core/cookbook_scm_repo_spec.rb index 2d66df31c1..b29091188e 100644 --- a/spec/unit/knife/core/cookbook_scm_repo_spec.rb +++ b/spec/unit/knife/core/cookbook_scm_repo_spec.rb @@ -16,15 +16,15 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/knife/core/cookbook_scm_repo' +require "spec_helper" +require "chef/knife/core/cookbook_scm_repo" describe Chef::Knife::CookbookSCMRepo do before do - @repo_path = File.join(CHEF_SPEC_DATA, 'cookbooks') + @repo_path = File.join(CHEF_SPEC_DATA, "cookbooks") @stdout, @stderr, @stdin = StringIO.new, StringIO.new, StringIO.new @ui = Chef::Knife::UI.new(@stdout, @stderr, @stdin, {}) - @cookbook_repo = Chef::Knife::CookbookSCMRepo.new(@repo_path, @ui, :default_branch => 'master') + @cookbook_repo = Chef::Knife::CookbookSCMRepo.new(@repo_path, @ui, :default_branch => "master") @branch_list = Mixlib::ShellOut.new @branch_list.stdout.replace(<<-BRANCHES) @@ -43,7 +43,7 @@ BRANCHES end it "has a default branch" do - expect(@cookbook_repo.default_branch).to eq('master') + expect(@cookbook_repo.default_branch).to eq("master") end describe "when sanity checking the repo" do @@ -64,12 +64,12 @@ BRANCHES describe "and the repo is a git repo" do before do - allow(::File).to receive(:directory?).with(File.join(@repo_path, '.git')).and_return(true) + allow(::File).to receive(:directory?).with(File.join(@repo_path, ".git")).and_return(true) end it "exits when the default branch doesn't exist" do @nobranches = Mixlib::ShellOut.new.tap {|s|s.stdout.replace "\n"} - expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@nobranches) + expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@nobranches) expect {@cookbook_repo.sanity_check}.to raise_error(SystemExit) end @@ -85,14 +85,14 @@ BRANCHES @dirty_status.stdout.replace(<<-DIRTY) M chef/lib/chef/knife/cookbook_site_vendor.rb DIRTY - expect(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain', :cwd => @repo_path).and_return(@dirty_status) + expect(@cookbook_repo).to receive(:shell_out!).with("git status --porcelain", :cwd => @repo_path).and_return(@dirty_status) expect {@cookbook_repo.sanity_check}.to raise_error(SystemExit) end describe "and the repo is clean" do before do @clean_status = Mixlib::ShellOut.new.tap {|s| s.stdout.replace("\n")} - allow(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain', :cwd => @repo_path).and_return(@clean_status) + allow(@cookbook_repo).to receive(:shell_out!).with("git status --porcelain", :cwd => @repo_path).and_return(@clean_status) end it "passes the sanity check" do @@ -106,35 +106,35 @@ DIRTY end it "resets to default state by checking out the default branch" do - expect(@cookbook_repo).to receive(:shell_out!).with('git checkout master', :cwd => @repo_path) + expect(@cookbook_repo).to receive(:shell_out!).with("git checkout master", :cwd => @repo_path) @cookbook_repo.reset_to_default_state end it "determines if a the pristine copy branch exists" do - expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) + expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@branch_list) expect(@cookbook_repo.branch_exists?("chef-vendor-apache2")).to be_truthy - expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) + expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@branch_list) expect(@cookbook_repo.branch_exists?("chef-vendor-nginx")).to be_falsey end it "determines if a the branch not exists correctly without substring search" do - expect(@cookbook_repo).to receive(:shell_out!).twice.with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) + expect(@cookbook_repo).to receive(:shell_out!).twice.with("git branch --no-color", :cwd => @repo_path).and_return(@branch_list) expect(@cookbook_repo).not_to be_branch_exists("chef-vendor-absent") expect(@cookbook_repo).to be_branch_exists("chef-vendor-absent-new") end describe "when the pristine copy branch does not exist" do it "prepares for import by creating the pristine copy branch" do - expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) - expect(@cookbook_repo).to receive(:shell_out!).with('git checkout -b chef-vendor-nginx', :cwd => @repo_path) + expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@branch_list) + expect(@cookbook_repo).to receive(:shell_out!).with("git checkout -b chef-vendor-nginx", :cwd => @repo_path) @cookbook_repo.prepare_to_import("nginx") end end describe "when the pristine copy branch does exist" do it "prepares for import by checking out the pristine copy branch" do - expect(@cookbook_repo).to receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list) - expect(@cookbook_repo).to receive(:shell_out!).with('git checkout chef-vendor-apache2', :cwd => @repo_path) + expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@branch_list) + expect(@cookbook_repo).to receive(:shell_out!).with("git checkout chef-vendor-apache2", :cwd => @repo_path) @cookbook_repo.prepare_to_import("apache2") end end @@ -143,15 +143,15 @@ DIRTY before do @updates = Mixlib::ShellOut.new @updates.stdout.replace("\n") - allow(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates) + allow(@cookbook_repo).to receive(:shell_out!).with("git status --porcelain -- apache2", :cwd => @repo_path).and_return(@updates) end it "shows no changes in the pristine copy" do - expect(@cookbook_repo.updated?('apache2')).to be_falsey + expect(@cookbook_repo.updated?("apache2")).to be_falsey end it "does nothing to finalize the updates" do - expect(@cookbook_repo.finalize_updates_to('apache2', '1.2.3')).to be_falsey + expect(@cookbook_repo.finalize_updates_to("apache2", "1.2.3")).to be_falsey end end @@ -159,11 +159,11 @@ DIRTY before do @updates = Mixlib::ShellOut.new @updates.stdout.replace(" M cookbooks/apache2/recipes/default.rb\n") - allow(@cookbook_repo).to receive(:shell_out!).with('git status --porcelain -- apache2', :cwd => @repo_path).and_return(@updates) + allow(@cookbook_repo).to receive(:shell_out!).with("git status --porcelain -- apache2", :cwd => @repo_path).and_return(@updates) end it "shows changes in the pristine copy" do - expect(@cookbook_repo.updated?('apache2')).to be_truthy + expect(@cookbook_repo.updated?("apache2")).to be_truthy end it "commits the changes to the repo and tags the commit" do @@ -176,11 +176,11 @@ DIRTY describe "when a custom default branch is specified" do before do - @cookbook_repo = Chef::Knife::CookbookSCMRepo.new(@repo_path, @ui, :default_branch => 'develop') + @cookbook_repo = Chef::Knife::CookbookSCMRepo.new(@repo_path, @ui, :default_branch => "develop") end it "resets to default state by checking out the default branch" do - expect(@cookbook_repo).to receive(:shell_out!).with('git checkout develop', :cwd => @repo_path) + expect(@cookbook_repo).to receive(:shell_out!).with("git checkout develop", :cwd => @repo_path) @cookbook_repo.reset_to_default_state end end diff --git a/spec/unit/knife/core/custom_manifest_loader_spec.rb b/spec/unit/knife/core/custom_manifest_loader_spec.rb index 1edbedd3c8..f15710274c 100644 --- a/spec/unit/knife/core/custom_manifest_loader_spec.rb +++ b/spec/unit/knife/core/custom_manifest_loader_spec.rb @@ -15,7 +15,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::SubcommandLoader::CustomManifestLoader do let(:ec2_server_create_plugin) { "/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/ec2_server_create.rb" } @@ -30,7 +30,7 @@ describe Chef::Knife::SubcommandLoader::CustomManifestLoader do } end let(:loader) do - Chef::Knife::SubcommandLoader::CustomManifestLoader.new(File.join(CHEF_SPEC_DATA, 'knife-site-subcommands'), + Chef::Knife::SubcommandLoader::CustomManifestLoader.new(File.join(CHEF_SPEC_DATA, "knife-site-subcommands"), manifest_content) end diff --git a/spec/unit/knife/core/gem_glob_loader_spec.rb b/spec/unit/knife/core/gem_glob_loader_spec.rb index 89de9f98e4..671fabf695 100644 --- a/spec/unit/knife/core/gem_glob_loader_spec.rb +++ b/spec/unit/knife/core/gem_glob_loader_spec.rb @@ -15,12 +15,12 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::SubcommandLoader::GemGlobLoader do - let(:loader) { Chef::Knife::SubcommandLoader::GemGlobLoader.new(File.join(CHEF_SPEC_DATA, 'knife-site-subcommands')) } - let(:home) { File.join(CHEF_SPEC_DATA, 'knife-home') } - let(:plugin_dir) { File.join(home, '.chef', 'plugins', 'knife') } + let(:loader) { Chef::Knife::SubcommandLoader::GemGlobLoader.new(File.join(CHEF_SPEC_DATA, "knife-site-subcommands")) } + let(:home) { File.join(CHEF_SPEC_DATA, "knife-home") } + let(:plugin_dir) { File.join(home, ".chef", "plugins", "knife") } before do allow(ChefConfig).to receive(:windows?) { false } @@ -39,15 +39,15 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do end it "finds files installed via rubygems" do - expect(loader.find_subcommands_via_rubygems).to include('chef/knife/node_create') + expect(loader.find_subcommands_via_rubygems).to include("chef/knife/node_create") loader.find_subcommands_via_rubygems.each {|rel_path, abs_path| expect(abs_path).to match(%r[chef/knife/.+])} end it "finds files from latest version of installed gems" do - gems = [ double('knife-ec2-0.5.12') ] + gems = [ double("knife-ec2-0.5.12") ] gem_files = [ - '/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/ec2_base.rb', - '/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/ec2_otherstuff.rb', + "/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/ec2_base.rb", + "/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/ec2_otherstuff.rb", ] expect($LOAD_PATH).to receive(:map).and_return([]) if Gem::Specification.respond_to? :latest_specs @@ -55,26 +55,26 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do expect(gems[0]).to receive(:matches_for_glob).with(/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']) - expect(gems[0]).to receive(:full_gem_path).and_return('/usr/lib/ruby/gems/knife-ec2-0.5.12') - expect(Dir).to receive(:[]).with('/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/*.rb').and_return(gem_files) + expect(gems[0]).to receive(:require_paths).twice.and_return(["lib"]) + expect(gems[0]).to receive(:full_gem_path).and_return("/usr/lib/ruby/gems/knife-ec2-0.5.12") + expect(Dir).to receive(:[]).with("/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/*.rb").and_return(gem_files) end expect(loader).to receive(:find_subcommands_via_dirglob).and_return({}) expect(loader.subcommand_files.select { |file| file =~ /knife-ec2/ }.sort).to eq(gem_files) end it "finds files using a dirglob when rubygems is not available" do - expect(loader.find_subcommands_via_dirglob).to include('chef/knife/node_create') + expect(loader.find_subcommands_via_dirglob).to include("chef/knife/node_create") loader.find_subcommands_via_dirglob.each {|rel_path, abs_path| expect(abs_path).to match(%r[chef/knife/.+])} end it "finds user-specific subcommands in the user's ~/.chef directory" do - expected_command = File.join(home, '.chef', 'plugins', 'knife', 'example_home_subcommand.rb') + expected_command = File.join(home, ".chef", "plugins", "knife", "example_home_subcommand.rb") expect(loader.site_subcommands).to include(expected_command) end it "finds repo specific subcommands by searching for a .chef directory" do - expected_command = File.join(CHEF_SPEC_DATA, 'knife-site-subcommands', 'plugins', 'knife', 'example_subcommand.rb') + expected_command = File.join(CHEF_SPEC_DATA, "knife-site-subcommands", "plugins", "knife", "example_subcommand.rb") expect(loader.site_subcommands).to include(expected_command) end diff --git a/spec/unit/knife/core/hashed_command_loader_spec.rb b/spec/unit/knife/core/hashed_command_loader_spec.rb index 1a6c2f42b7..45ee377ac6 100644 --- a/spec/unit/knife/core/hashed_command_loader_spec.rb +++ b/spec/unit/knife/core/hashed_command_loader_spec.rb @@ -15,7 +15,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::SubcommandLoader::HashedCommandLoader do before do @@ -42,7 +42,7 @@ describe Chef::Knife::SubcommandLoader::HashedCommandLoader do } let(:loader) { Chef::Knife::SubcommandLoader::HashedCommandLoader.new( - File.join(CHEF_SPEC_DATA, 'knife-site-subcommands'), + File.join(CHEF_SPEC_DATA, "knife-site-subcommands"), plugin_manifest)} describe "#list_commands" do diff --git a/spec/unit/knife/core/node_editor_spec.rb b/spec/unit/knife/core/node_editor_spec.rb index 52e3aeadd5..2c1beb6ccb 100644 --- a/spec/unit/knife/core/node_editor_spec.rb +++ b/spec/unit/knife/core/node_editor_spec.rb @@ -16,34 +16,34 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/knife/core/node_editor' +require "spec_helper" +require "chef/knife/core/node_editor" describe Chef::Knife::NodeEditor do let(:node_data) do - { 'name' => 'test_node', - 'chef_environment' => 'production', - 'automatic' => { 'foo' => 'bar' }, - 'default' => { 'alpha' => { 'bravo' => 'charlie', 'delta' => 'echo' } }, - 'normal' => { 'alpha' => { 'bravo' => 'hotel' }, 'tags' => [] }, - 'override' => { 'alpha' => { 'bravo' => 'foxtrot', 'delta' => 'golf' } }, - 'policy_name' => nil, - 'policy_group' => nil, - 'run_list' => %w(role[comedy] role[drama] recipe[mystery]) + { "name" => "test_node", + "chef_environment" => "production", + "automatic" => { "foo" => "bar" }, + "default" => { "alpha" => { "bravo" => "charlie", "delta" => "echo" } }, + "normal" => { "alpha" => { "bravo" => "hotel" }, "tags" => [] }, + "override" => { "alpha" => { "bravo" => "foxtrot", "delta" => "golf" } }, + "policy_name" => nil, + "policy_group" => nil, + "run_list" => %w(role[comedy] role[drama] recipe[mystery]), } end let(:node) { Chef::Node.from_hash(node_data) } - let(:ui) { double 'ui' } - let(:base_config) { { editor: 'cat' } } + let(:ui) { double "ui" } + let(:base_config) { { editor: "cat" } } let(:config) { base_config.merge(all_attributes: false) } subject { described_class.new(node, ui, config) } describe '#view' do - it 'returns a Hash with only the name, chef_environment, normal, ' + - 'policy_name, policy_group, and run_list properties' do + it "returns a Hash with only the name, chef_environment, normal, " + + "policy_name, policy_group, and run_list properties" do expected = node_data.select do |key,| %w[ name chef_environment normal policy_name policy_group run_list ].include?(key) @@ -52,7 +52,7 @@ describe Chef::Knife::NodeEditor do expect(subject.view).to eq(expected) end - context 'when config[:all_attributes] == true' do + context "when config[:all_attributes] == true" do let(:config) { base_config.merge(all_attributes: true) } it 'returns a Hash with all of the node\'s properties' do @@ -62,49 +62,49 @@ describe Chef::Knife::NodeEditor do end describe '#apply_updates' do - context 'when the node name is changed' do + context "when the node name is changed" do before(:each) do allow(ui).to receive(:warn) allow(ui).to receive(:confirm).and_return(true) end - it 'emits a warning and prompts for confirmation' do - data = subject.view.merge('name' => 'foo_new_name_node') + it "emits a warning and prompts for confirmation" do + data = subject.view.merge("name" => "foo_new_name_node") updated_node = subject.apply_updates(data) expect(ui).to have_received(:warn) - .with 'Changing the name of a node results in a new node being ' + - 'created, test_node will not be modified or removed.' + .with "Changing the name of a node results in a new node being " + + "created, test_node will not be modified or removed." expect(ui).to have_received(:confirm) - .with('Proceed with creation of new node') + .with("Proceed with creation of new node") expect(updated_node).to be_a(Chef::Node) end end - context 'when config[:all_attributes] == false' do + context "when config[:all_attributes] == false" do let(:config) { base_config.merge(all_attributes: false) } let(:updated_data) do subject.view.merge( - 'normal' => { 'alpha' => { 'bravo' => 'hotel2' }, 'tags' => [ 'xyz' ] }, - 'policy_name' => 'mypolicy', - 'policy_group' => 'prod', - 'run_list' => %w(role[drama] recipe[mystery]) + "normal" => { "alpha" => { "bravo" => "hotel2" }, "tags" => [ "xyz" ] }, + "policy_name" => "mypolicy", + "policy_group" => "prod", + "run_list" => %w(role[drama] recipe[mystery]), ) end - it 'returns a node with run_list and normal_attrs changed' do + it "returns a node with run_list and normal_attrs changed" do updated_node = subject.apply_updates(updated_data) expect(updated_node).to be_a(Chef::Node) # Expected to have been changed - expect(updated_node.chef_environment).to eql(updated_data['chef_environment']) - expect(updated_node.normal_attrs).to eql(updated_data['normal']) - expect(updated_node.policy_name).to eql(updated_data['policy_name']) - expect(updated_node.policy_group).to eql(updated_data['policy_group']) - expect(updated_node.run_list.map(&:to_s)).to eql(updated_data['run_list']) + expect(updated_node.chef_environment).to eql(updated_data["chef_environment"]) + expect(updated_node.normal_attrs).to eql(updated_data["normal"]) + expect(updated_node.policy_name).to eql(updated_data["policy_name"]) + expect(updated_node.policy_group).to eql(updated_data["policy_group"]) + expect(updated_node.run_list.map(&:to_s)).to eql(updated_data["run_list"]) # Expected not to have changed expect(updated_node.default_attrs).to eql(node.default_attrs) @@ -113,57 +113,57 @@ describe Chef::Knife::NodeEditor do end end - context 'when config[:all_attributes] == true' do + context "when config[:all_attributes] == true" do let(:config) { base_config.merge(all_attributes: true) } let(:updated_data) do subject.view.merge( - 'default' => { 'alpha' => { 'bravo' => 'charlie2', 'delta' => 'echo2' } }, - 'normal' => { 'alpha' => { 'bravo' => 'hotel2' }, 'tags' => [ 'xyz' ] }, - 'override' => { 'alpha' => { 'bravo' => 'foxtrot2', 'delta' => 'golf2' } }, - 'policy_name' => 'mypolicy', - 'policy_group' => 'prod', - 'run_list' => %w(role[drama] recipe[mystery]) + "default" => { "alpha" => { "bravo" => "charlie2", "delta" => "echo2" } }, + "normal" => { "alpha" => { "bravo" => "hotel2" }, "tags" => [ "xyz" ] }, + "override" => { "alpha" => { "bravo" => "foxtrot2", "delta" => "golf2" } }, + "policy_name" => "mypolicy", + "policy_group" => "prod", + "run_list" => %w(role[drama] recipe[mystery]), ) end - it 'returns a node with all editable properties changed' do + it "returns a node with all editable properties changed" do updated_node = subject.apply_updates(updated_data) expect(updated_node).to be_a(Chef::Node) - expect(updated_node.chef_environment).to eql(updated_data['chef_environment']) - expect(updated_node.automatic_attrs).to eql(updated_data['automatic']) - expect(updated_node.normal_attrs).to eql(updated_data['normal']) - expect(updated_node.default_attrs).to eql(updated_data['default']) - expect(updated_node.override_attrs).to eql(updated_data['override']) - expect(updated_node.policy_name).to eql(updated_data['policy_name']) - expect(updated_node.policy_group).to eql(updated_data['policy_group']) - expect(updated_node.run_list.map(&:to_s)).to eql(updated_data['run_list']) + expect(updated_node.chef_environment).to eql(updated_data["chef_environment"]) + expect(updated_node.automatic_attrs).to eql(updated_data["automatic"]) + expect(updated_node.normal_attrs).to eql(updated_data["normal"]) + expect(updated_node.default_attrs).to eql(updated_data["default"]) + expect(updated_node.override_attrs).to eql(updated_data["override"]) + expect(updated_node.policy_name).to eql(updated_data["policy_name"]) + expect(updated_node.policy_group).to eql(updated_data["policy_group"]) + expect(updated_node.run_list.map(&:to_s)).to eql(updated_data["run_list"]) end end end describe '#updated?' do - context 'before the node has been edited' do - it 'returns false' do + context "before the node has been edited" do + it "returns false" do expect(subject.updated?).to be false end end - context 'after the node has been edited' do - context 'and changes were made' do + context "after the node has been edited" do + context "and changes were made" do let(:updated_data) do subject.view.merge( - 'default' => { 'alpha' => { 'bravo' => 'charlie2', 'delta' => 'echo2' } }, - 'normal' => { 'alpha' => { 'bravo' => 'hotel2' }, 'tags' => [ 'xyz' ] }, - 'override' => { 'alpha' => { 'bravo' => 'foxtrot2', 'delta' => 'golf2' } }, - 'policy_name' => 'mypolicy', - 'policy_group' => 'prod', - 'run_list' => %w(role[drama] recipe[mystery]) + "default" => { "alpha" => { "bravo" => "charlie2", "delta" => "echo2" } }, + "normal" => { "alpha" => { "bravo" => "hotel2" }, "tags" => [ "xyz" ] }, + "override" => { "alpha" => { "bravo" => "foxtrot2", "delta" => "golf2" } }, + "policy_name" => "mypolicy", + "policy_group" => "prod", + "run_list" => %w(role[drama] recipe[mystery]), ) end - context 'and changes affect only editable properties' do + context "and changes affect only editable properties" do before(:each) do allow(ui).to receive(:edit_data) .with(subject.view) @@ -172,14 +172,14 @@ describe Chef::Knife::NodeEditor do subject.edit_node end - it 'returns an array of the changed property names' do + it "returns an array of the changed property names" do expect(subject.updated?).to eql %w[ normal policy_name policy_group run_list ] end end - context 'and the changes include non-editable properties' do + context "and the changes include non-editable properties" do before(:each) do - data = updated_data.merge('bad_property' => 'bad_value') + data = updated_data.merge("bad_property" => "bad_value") allow(ui).to receive(:edit_data) .with(subject.view) @@ -189,13 +189,13 @@ describe Chef::Knife::NodeEditor do end it 'returns an array of property names that doesn\'t include ' + - 'the non-editable properties' do + "the non-editable properties" do expect(subject.updated?).to eql %w[ normal policy_name policy_group run_list ] end end end - context 'and changes were not made' do + context "and changes were not made" do before(:each) do allow(ui).to receive(:edit_data) .with(subject.view) diff --git a/spec/unit/knife/core/object_loader_spec.rb b/spec/unit/knife/core/object_loader_spec.rb index 0b572cc1f0..50f358379e 100644 --- a/spec/unit/knife/core/object_loader_spec.rb +++ b/spec/unit/knife/core/object_loader_spec.rb @@ -17,15 +17,15 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/knife/core/object_loader' +require "spec_helper" +require "chef/knife/core/object_loader" describe Chef::Knife::Core::ObjectLoader do before(:each) do @knife = Chef::Knife.new @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) - Dir.chdir(File.join(CHEF_SPEC_DATA, 'object_loader')) + Dir.chdir(File.join(CHEF_SPEC_DATA, "object_loader")) end shared_examples_for "Chef object" do |chef_class| @@ -34,14 +34,14 @@ describe Chef::Knife::Core::ObjectLoader do end it "should has a attribute 'name'" do - expect(@object.name).to eql('test') + expect(@object.name).to eql("test") end end { - 'nodes' => Chef::Node, - 'roles' => Chef::Role, - 'environments' => Chef::Environment, + "nodes" => Chef::Node, + "roles" => Chef::Role, + "environments" => Chef::Environment, }.each do |repo_location, chef_class| describe "when the file is a #{chef_class}" do @@ -51,7 +51,7 @@ describe Chef::Knife::Core::ObjectLoader do describe "when the file is a Ruby" do before do - @object = @loader.load_from(repo_location, 'test.rb') + @object = @loader.load_from(repo_location, "test.rb") end it_behaves_like "Chef object", chef_class @@ -61,7 +61,7 @@ describe Chef::Knife::Core::ObjectLoader do describe "when the file is a JSON" do describe "and it has defined 'json_class'" do before do - @object = @loader.load_from(repo_location, 'test_json_class.json') + @object = @loader.load_from(repo_location, "test_json_class.json") end it_behaves_like "Chef object", chef_class @@ -69,7 +69,7 @@ describe Chef::Knife::Core::ObjectLoader do describe "and it has not defined 'json_class'" do before do - @object = @loader.load_from(repo_location, 'test.json') + @object = @loader.load_from(repo_location, "test.json") end it_behaves_like "Chef object", chef_class diff --git a/spec/unit/knife/core/subcommand_loader_spec.rb b/spec/unit/knife/core/subcommand_loader_spec.rb index 2386465c75..c1712c297e 100644 --- a/spec/unit/knife/core/subcommand_loader_spec.rb +++ b/spec/unit/knife/core/subcommand_loader_spec.rb @@ -15,12 +15,12 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::SubcommandLoader do - let(:loader) { Chef::Knife::SubcommandLoader.new(File.join(CHEF_SPEC_DATA, 'knife-site-subcommands')) } - let(:home) { File.join(CHEF_SPEC_DATA, 'knife-home') } - let(:plugin_dir) { File.join(home, '.chef', 'plugins', 'knife') } + let(:loader) { Chef::Knife::SubcommandLoader.new(File.join(CHEF_SPEC_DATA, "knife-site-subcommands")) } + let(:home) { File.join(CHEF_SPEC_DATA, "knife-home") } + let(:plugin_dir) { File.join(home, ".chef", "plugins", "knife") } before do allow(ChefConfig).to receive(:windows?) { false } @@ -31,29 +31,29 @@ describe Chef::Knife::SubcommandLoader do Chef::Util::PathHelper.class_variable_set(:@@home_dir, nil) end - let(:config_dir) { File.join(CHEF_SPEC_DATA, 'knife-site-subcommands') } + let(:config_dir) { File.join(CHEF_SPEC_DATA, "knife-site-subcommands") } describe "#for_config" do context "when ~/.chef/plugin_manifest.json exists" do before do - allow(File).to receive(:exist?).with(File.join(home, '.chef', 'plugin_manifest.json')).and_return(true) + allow(File).to receive(:exist?).with(File.join(home, ".chef", "plugin_manifest.json")).and_return(true) end it "creates a HashedCommandLoader with the manifest has _autogenerated_command_paths" do - allow(File).to receive(:read).with(File.join(home, '.chef', 'plugin_manifest.json')).and_return("{ \"_autogenerated_command_paths\": {}}") + allow(File).to receive(:read).with(File.join(home, ".chef", "plugin_manifest.json")).and_return("{ \"_autogenerated_command_paths\": {}}") expect(Chef::Knife::SubcommandLoader.for_config(config_dir)).to be_a Chef::Knife::SubcommandLoader::HashedCommandLoader end it "creates a CustomManifestLoader with then manifest has a key other than _autogenerated_command_paths" do Chef::Config[:treat_deprecation_warnings_as_errors] = false - allow(File).to receive(:read).with(File.join(home, '.chef', 'plugin_manifest.json')).and_return("{ \"plugins\": {}}") + allow(File).to receive(:read).with(File.join(home, ".chef", "plugin_manifest.json")).and_return("{ \"plugins\": {}}") expect(Chef::Knife::SubcommandLoader.for_config(config_dir)).to be_a Chef::Knife::SubcommandLoader::CustomManifestLoader end end context "when ~/.chef/plugin_manifest.json does not exist" do before do - allow(File).to receive(:exist?).with(File.join(home, '.chef', 'plugin_manifest.json')).and_return(false) + allow(File).to receive(:exist?).with(File.join(home, ".chef", "plugin_manifest.json")).and_return(false) end it "creates a GemGlobLoader" do diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb index 2c3b067e4f..b5b6a0a179 100644 --- a/spec/unit/knife/core/ui_spec.rb +++ b/spec/unit/knife/core/ui_spec.rb @@ -19,7 +19,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::UI do before do @@ -33,10 +33,10 @@ describe Chef::Knife::UI do end describe "edit" do - ruby_for_json = { 'foo' => 'bar' } + ruby_for_json = { "foo" => "bar" } json_from_ruby = "{\n \"foo\": \"bar\"\n}" json_from_editor = "{\n \"bar\": \"foo\"\n}" - ruby_from_editor = { 'bar' => 'foo' } + ruby_from_editor = { "bar" => "foo" } my_editor = "veeeye" temp_path = "/tmp/bar/baz" @@ -66,12 +66,12 @@ describe Chef::Knife::UI do before do @ui.config[:disable_editing] = false @ui.config[:editor] = my_editor - @mock = double('Tempfile') + @mock = double("Tempfile") expect(@mock).to receive(:sync=).with(true) expect(@mock).to receive(:puts).with(json_from_ruby) expect(@mock).to receive(:close) expect(@mock).to receive(:path).at_least(:once).and_return(temp_path) - expect(Tempfile).to receive(:open).with([ 'knife-edit-', '.json' ]).and_yield(@mock) + expect(Tempfile).to receive(:open).with([ "knife-edit-", ".json" ]).and_yield(@mock) end context "and the editor works" do before do @@ -114,8 +114,8 @@ describe Chef::Knife::UI do before do @ui.config[:disable_editing] = false @ui.config[:editor] = my_editor - @tempfile = Tempfile.new([ 'knife-edit-', '.json' ]) - expect(Tempfile).to receive(:open).with([ 'knife-edit-', '.json' ]).and_yield(@tempfile) + @tempfile = Tempfile.new([ "knife-edit-", ".json" ]) + expect(Tempfile).to receive(:open).with([ "knife-edit-", ".json" ]).and_yield(@tempfile) end context "and the editor works" do @@ -192,7 +192,7 @@ describe Chef::Knife::UI do end it "formats hashes appropriately" do - @ui.output({'hi' => 'a', 'lo' => 'b' }) + @ui.output({"hi" => "a", "lo" => "b" }) expect(@out.string).to eq <<EOM hi: a lo: b @@ -205,7 +205,7 @@ EOM end it "formats arrays appropriately" do - @ui.output([ 'a', 'b' ]) + @ui.output([ "a", "b" ]) expect(@out.string).to eq <<EOM a b @@ -218,17 +218,17 @@ EOM end it "formats single-member arrays appropriately" do - @ui.output([ 'a' ]) + @ui.output([ "a" ]) expect(@out.string).to eq("a\n") end it "formats nested single-member arrays appropriately" do - @ui.output([ [ 'a' ] ]) + @ui.output([ [ "a" ] ]) expect(@out.string).to eq("a\n") end it "formats nested arrays appropriately" do - @ui.output([ [ 'a', 'b' ], [ 'c', 'd' ]]) + @ui.output([ [ "a", "b" ], [ "c", "d" ]]) expect(@out.string).to eq <<EOM a b @@ -239,7 +239,7 @@ EOM end it "formats nested arrays with single- and empty subarrays appropriately" do - @ui.output([ [ 'a', 'b' ], [ 'c' ], [], [ 'd', 'e' ]]) + @ui.output([ [ "a", "b" ], [ "c" ], [], [ "d", "e" ]]) expect(@out.string).to eq <<EOM a b @@ -253,7 +253,7 @@ EOM end it "formats arrays of hashes with extra lines in between for readability" do - @ui.output([ { 'a' => 'b', 'c' => 'd' }, { 'x' => 'y' }, { 'm' => 'n', 'o' => 'p' }]) + @ui.output([ { "a" => "b", "c" => "d" }, { "x" => "y" }, { "m" => "n", "o" => "p" }]) expect(@out.string).to eq <<EOM a: b c: d @@ -266,7 +266,7 @@ EOM end it "formats hashes with empty array members appropriately" do - @ui.output({ 'a' => [], 'b' => 'c' }) + @ui.output({ "a" => [], "b" => "c" }) expect(@out.string).to eq <<EOM a: b: c @@ -274,7 +274,7 @@ EOM end it "formats hashes with single-member array values appropriately" do - @ui.output({ 'a' => [ 'foo' ], 'b' => 'c' }) + @ui.output({ "a" => [ "foo" ], "b" => "c" }) expect(@out.string).to eq <<EOM a: foo b: c @@ -282,7 +282,7 @@ EOM end it "formats hashes with array members appropriately" do - @ui.output({ 'a' => [ 'foo', 'bar' ], 'b' => 'c' }) + @ui.output({ "a" => [ "foo", "bar" ], "b" => "c" }) expect(@out.string).to eq <<EOM a: foo @@ -292,7 +292,7 @@ EOM end it "formats hashes with single-member nested array values appropriately" do - @ui.output({ 'a' => [ [ 'foo' ] ], 'b' => 'c' }) + @ui.output({ "a" => [ [ "foo" ] ], "b" => "c" }) expect(@out.string).to eq <<EOM a: foo @@ -301,14 +301,14 @@ EOM end it "formats hashes with nested array values appropriately" do - @ui.output({ 'a' => [ [ 'foo', 'bar' ], [ 'baz', 'bjork' ] ], 'b' => 'c' }) + @ui.output({ "a" => [ [ "foo", "bar" ], [ "baz", "bjork" ] ], "b" => "c" }) # XXX: using a HEREDOC at this point results in a line with required spaces which auto-whitespace removal settings # on editors will remove and will break this test. expect(@out.string).to eq("a:\n foo\n bar\n \n baz\n bjork\nb: c\n") end it "formats hashes with hash values appropriately" do - @ui.output({ 'a' => { 'aa' => 'bb', 'cc' => 'dd' }, 'b' => 'c' }) + @ui.output({ "a" => { "aa" => "bb", "cc" => "dd" }, "b" => "c" }) expect(@out.string).to eq <<EOM a: aa: bb @@ -318,7 +318,7 @@ EOM end it "formats hashes with empty hash values appropriately" do - @ui.output({ 'a' => { }, 'b' => 'c' }) + @ui.output({ "a" => { }, "b" => "c" }) expect(@out.string).to eq <<EOM a: b: c @@ -432,7 +432,7 @@ EOM context "when running on Windows" do before(:each) do - stdout = double('StringIO', :tty? => true) + stdout = double("StringIO", :tty? => true) allow(@ui).to receive(:stdout).and_return(stdout) allow(ChefConfig).to receive(:windows?) { true } Chef::Config.reset @@ -464,7 +464,7 @@ EOM let(:output) {stdout.string} let(:question) { "monkeys rule" } - let(:answer) { 'y' } + let(:answer) { "y" } let(:default_choice) { nil } let(:append_instructions) { true } @@ -583,7 +583,7 @@ EOM out = StringIO.new allow(@ui).to receive(:stdout).and_return(out) allow(@ui).to receive(:stdin).and_return(StringIO.new(" \n")) - expect(@ui.ask_question("your chef server URL? ", :default => 'http://localhost:4000')).to eq("http://localhost:4000") + expect(@ui.ask_question("your chef server URL? ", :default => "http://localhost:4000")).to eq("http://localhost:4000") expect(out.string).to eq("your chef server URL? [http://localhost:4000] ") end end diff --git a/spec/unit/knife/data_bag_create_spec.rb b/spec/unit/knife/data_bag_create_spec.rb index d022cc7f7d..3cca61be6b 100644 --- a/spec/unit/knife/data_bag_create_spec.rb +++ b/spec/unit/knife/data_bag_create_spec.rb @@ -17,8 +17,8 @@ # limitations under the License. # -require 'spec_helper' -require 'tempfile' +require "spec_helper" +require "tempfile" describe Chef::Knife::DataBagCreate do let(:knife) do @@ -47,7 +47,7 @@ describe Chef::Knife::DataBagCreate do end it "tries to create a data bag with an invalid name when given one argument" do - knife.name_args = ['invalid&char'] + knife.name_args = ["invalid&char"] expect(Chef::DataBag).to receive(:validate_name!).with(knife.name_args[0]).and_raise(Chef::Exceptions::InvalidDataBagName) expect {knife.run}.to exit_with_code(1) end @@ -75,7 +75,7 @@ describe Chef::Knife::DataBagCreate do it "creates a data bag item" do expect(knife).to receive(:create_object).and_yield(raw_hash) expect(knife).to receive(:encryption_secret_provided?).and_return(false) - expect(rest).to receive(:post).with("data", {'name' => bag_name}).ordered + expect(rest).to receive(:post).with("data", {"name" => bag_name}).ordered expect(rest).to receive(:post).with("data/#{bag_name}", item).ordered knife.run diff --git a/spec/unit/knife/data_bag_edit_spec.rb b/spec/unit/knife/data_bag_edit_spec.rb index f1bcae990b..4e55a9386e 100644 --- a/spec/unit/knife/data_bag_edit_spec.rb +++ b/spec/unit/knife/data_bag_edit_spec.rb @@ -16,8 +16,8 @@ # limitations under the License. # -require 'spec_helper' -require 'tempfile' +require "spec_helper" +require "tempfile" describe Chef::Knife::DataBagEdit do before do diff --git a/spec/unit/knife/data_bag_from_file_spec.rb b/spec/unit/knife/data_bag_from_file_spec.rb index ddf877d9f7..387dfc7554 100644 --- a/spec/unit/knife/data_bag_from_file_spec.rb +++ b/spec/unit/knife/data_bag_from_file_spec.rb @@ -16,11 +16,11 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" -require 'chef/data_bag_item' -require 'chef/encrypted_data_bag_item' -require 'tempfile' +require "chef/data_bag_item" +require "chef/encrypted_data_bag_item" +require "tempfile" Chef::Knife::DataBagFromFile.load_deps diff --git a/spec/unit/knife/data_bag_secret_options_spec.rb b/spec/unit/knife/data_bag_secret_options_spec.rb index 0a2d8ca4bf..71a6bf7af5 100644 --- a/spec/unit/knife/data_bag_secret_options_spec.rb +++ b/spec/unit/knife/data_bag_secret_options_spec.rb @@ -16,10 +16,10 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/knife' -require 'chef/config' -require 'tempfile' +require "spec_helper" +require "chef/knife" +require "chef/config" +require "tempfile" class ExampleDataBagCommand < Chef::Knife include Chef::Knife::DataBagSecretOptions diff --git a/spec/unit/knife/data_bag_show_spec.rb b/spec/unit/knife/data_bag_show_spec.rb index 48a0071b49..427d3e4d1b 100644 --- a/spec/unit/knife/data_bag_show_spec.rb +++ b/spec/unit/knife/data_bag_show_spec.rb @@ -17,12 +17,12 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" -require 'chef/data_bag_item' -require 'chef/encrypted_data_bag_item' -require 'chef/json_compat' -require 'tempfile' +require "chef/data_bag_item" +require "chef/encrypted_data_bag_item" +require "chef/json_compat" +require "tempfile" describe Chef::Knife::DataBagShow do diff --git a/spec/unit/knife/environment_compare_spec.rb b/spec/unit/knife/environment_compare_spec.rb index 14dc5c52cf..bf2c2c15f0 100644 --- a/spec/unit/knife/environment_compare_spec.rb +++ b/spec/unit/knife/environment_compare_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::EnvironmentCompare do before(:each) do @@ -40,15 +40,15 @@ describe Chef::Knife::EnvironmentCompare do allow(@knife).to receive(:cookbook_list).and_return(@cookbooks) - @rest_double = double('rest') + @rest_double = double("rest") allow(@knife).to receive(:rest).and_return(@rest_double) - @cookbook_names = ['apache2', 'mysql', 'foo', 'bar', 'dummy', 'chef_handler'] - @base_url = 'https://server.example.com/cookbooks' + @cookbook_names = ["apache2", "mysql", "foo", "bar", "dummy", "chef_handler"] + @base_url = "https://server.example.com/cookbooks" @cookbook_data = {} @cookbook_names.each do |item| - @cookbook_data[item] = {'url' => "#{@base_url}/#{item}", - 'versions' => [{'version' => '1.0.1', - 'url' => "#{@base_url}/#{item}/1.0.1"}]} + @cookbook_data[item] = {"url" => "#{@base_url}/#{item}", + "versions" => [{"version" => "1.0.1", + "url" => "#{@base_url}/#{item}/1.0.1"}]} end allow(@rest_double).to receive(:get).with("/cookbooks?num_versions=1").and_return(@cookbook_data) @@ -57,25 +57,25 @@ describe Chef::Knife::EnvironmentCompare do allow(@knife.ui).to receive(:stdout).and_return(@stdout) end - describe 'run' do - it 'should display only cookbooks with version constraints' do - @knife.config[:format] = 'summary' + describe "run" do + it "should display only cookbooks with version constraints" do + @knife.config[:format] = "summary" @knife.run @environments.each do |item, url| expect(@stdout.string).to match /#{item}/ and expect(@stdout.string.lines.count).to be 4 end end - it 'should display 4 number of lines' do - @knife.config[:format] = 'summary' + it "should display 4 number of lines" do + @knife.config[:format] = "summary" @knife.run expect(@stdout.string.lines.count).to be 4 end end - describe 'with -m or --mismatch' do - it 'should display only cookbooks that have mismatching version constraints' do - @knife.config[:format] = 'summary' + describe "with -m or --mismatch" do + it "should display only cookbooks that have mismatching version constraints" do + @knife.config[:format] = "summary" @knife.config[:mismatch] = true @knife.run @constraints.each do |item, ver| @@ -83,17 +83,17 @@ describe Chef::Knife::EnvironmentCompare do end end - it 'should display 3 number of lines' do - @knife.config[:format] = 'summary' + it "should display 3 number of lines" do + @knife.config[:format] = "summary" @knife.config[:mismatch] = true @knife.run expect(@stdout.string.lines.count).to be 3 end end - describe 'with -a or --all' do - it 'should display all cookbooks' do - @knife.config[:format] = 'summary' + describe "with -a or --all" do + it "should display all cookbooks" do + @knife.config[:format] = "summary" @knife.config[:all] = true @knife.run @constraints.each do |item, ver| @@ -101,8 +101,8 @@ describe Chef::Knife::EnvironmentCompare do end end - it 'should display 8 number of lines' do - @knife.config[:format] = 'summary' + it "should display 8 number of lines" do + @knife.config[:format] = "summary" @knife.config[:all] = true @knife.run expect(@stdout.string.lines.count).to be 8 diff --git a/spec/unit/knife/environment_create_spec.rb b/spec/unit/knife/environment_create_spec.rb index 04e45048ef..7cee275499 100644 --- a/spec/unit/knife/environment_create_spec.rb +++ b/spec/unit/knife/environment_create_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::EnvironmentCreate do before(:each) do diff --git a/spec/unit/knife/environment_delete_spec.rb b/spec/unit/knife/environment_delete_spec.rb index 95df6e15fe..262c87dcc6 100644 --- a/spec/unit/knife/environment_delete_spec.rb +++ b/spec/unit/knife/environment_delete_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::EnvironmentDelete do before(:each) do diff --git a/spec/unit/knife/environment_edit_spec.rb b/spec/unit/knife/environment_edit_spec.rb index 61c2663a41..d23aa7234c 100644 --- a/spec/unit/knife/environment_edit_spec.rb +++ b/spec/unit/knife/environment_edit_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::EnvironmentEdit do before(:each) do diff --git a/spec/unit/knife/environment_from_file_spec.rb b/spec/unit/knife/environment_from_file_spec.rb index 11ad23c919..9ff2aceb6a 100644 --- a/spec/unit/knife/environment_from_file_spec.rb +++ b/spec/unit/knife/environment_from_file_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" Chef::Knife::EnvironmentFromFile.load_deps @@ -39,7 +39,7 @@ describe Chef::Knife::EnvironmentFromFile do describe "run" do it "loads the environment data from a file and saves it" do - expect(@knife.loader).to receive(:load_from).with('environments', 'spec.rb').and_return(@environment) + expect(@knife.loader).to receive(:load_from).with("environments", "spec.rb").and_return(@environment) expect(@environment).to receive(:save) @knife.run end diff --git a/spec/unit/knife/environment_list_spec.rb b/spec/unit/knife/environment_list_spec.rb index 1d5462257d..b01c0e57ed 100644 --- a/spec/unit/knife/environment_list_spec.rb +++ b/spec/unit/knife/environment_list_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::EnvironmentList do before(:each) do diff --git a/spec/unit/knife/environment_show_spec.rb b/spec/unit/knife/environment_show_spec.rb index caac958f8e..1c9d687d8c 100644 --- a/spec/unit/knife/environment_show_spec.rb +++ b/spec/unit/knife/environment_show_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::EnvironmentShow do before(:each) do diff --git a/spec/unit/knife/index_rebuild_spec.rb b/spec/unit/knife/index_rebuild_spec.rb index 6c1ff7b98e..187f77ee1c 100644 --- a/spec/unit/knife/index_rebuild_spec.rb +++ b/spec/unit/knife/index_rebuild_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::IndexRebuild do diff --git a/spec/unit/knife/key_create_spec.rb b/spec/unit/knife/key_create_spec.rb index 039dba7a44..4958f20321 100644 --- a/spec/unit/knife/key_create_spec.rb +++ b/spec/unit/knife/key_create_spec.rb @@ -16,11 +16,11 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/knife/user_key_create' -require 'chef/knife/client_key_create' -require 'chef/knife/key_create' -require 'chef/key' +require "spec_helper" +require "chef/knife/user_key_create" +require "chef/knife/client_key_create" +require "chef/knife/key_create" +require "chef/key" describe "key create commands that inherit knife" do shared_examples_for "a key create command" do diff --git a/spec/unit/knife/key_delete_spec.rb b/spec/unit/knife/key_delete_spec.rb index 1d4b9f825f..65250df69f 100644 --- a/spec/unit/knife/key_delete_spec.rb +++ b/spec/unit/knife/key_delete_spec.rb @@ -16,11 +16,11 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/knife/user_key_delete' -require 'chef/knife/client_key_delete' -require 'chef/knife/key_delete' -require 'chef/key' +require "spec_helper" +require "chef/knife/user_key_delete" +require "chef/knife/client_key_delete" +require "chef/knife/key_delete" +require "chef/key" describe "key delete commands that inherit knife" do shared_examples_for "a key delete command" do diff --git a/spec/unit/knife/key_edit_spec.rb b/spec/unit/knife/key_edit_spec.rb index 06b31ce71c..18f2cd45be 100644 --- a/spec/unit/knife/key_edit_spec.rb +++ b/spec/unit/knife/key_edit_spec.rb @@ -16,11 +16,11 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/knife/user_key_edit' -require 'chef/knife/client_key_edit' -require 'chef/knife/key_edit' -require 'chef/key' +require "spec_helper" +require "chef/knife/user_key_edit" +require "chef/knife/client_key_edit" +require "chef/knife/key_edit" +require "chef/key" describe "key edit commands that inherit knife" do shared_examples_for "a key edit command" do diff --git a/spec/unit/knife/key_helper.rb b/spec/unit/knife/key_helper.rb index 36ababc09a..6a972d1e7b 100644 --- a/spec/unit/knife/key_helper.rb +++ b/spec/unit/knife/key_helper.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" shared_examples_for "a knife key command" do let(:stderr) { StringIO.new } diff --git a/spec/unit/knife/key_list_spec.rb b/spec/unit/knife/key_list_spec.rb index 775a7cdfb1..70caa249bb 100644 --- a/spec/unit/knife/key_list_spec.rb +++ b/spec/unit/knife/key_list_spec.rb @@ -16,11 +16,11 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/knife/user_key_list' -require 'chef/knife/client_key_list' -require 'chef/knife/key_list' -require 'chef/key' +require "spec_helper" +require "chef/knife/user_key_list" +require "chef/knife/client_key_list" +require "chef/knife/key_list" +require "chef/key" describe "key list commands that inherit knife" do shared_examples_for "a key list command" do diff --git a/spec/unit/knife/key_show_spec.rb b/spec/unit/knife/key_show_spec.rb index f4923ef235..03b3062e62 100644 --- a/spec/unit/knife/key_show_spec.rb +++ b/spec/unit/knife/key_show_spec.rb @@ -16,11 +16,11 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/knife/user_key_show' -require 'chef/knife/client_key_show' -require 'chef/knife/key_show' -require 'chef/key' +require "spec_helper" +require "chef/knife/user_key_show" +require "chef/knife/client_key_show" +require "chef/knife/key_show" +require "chef/key" describe "key show commands that inherit knife" do shared_examples_for "a key show command" do @@ -113,14 +113,14 @@ describe Chef::Knife::KeyShow do context "when load_method is :load_by_user" do it_should_behave_like "key show run command" do let(:load_method) { :load_by_user } - let(:actor_field_name) { 'user' } + let(:actor_field_name) { "user" } end end context "when load_method is :load_by_client" do it_should_behave_like "key show run command" do let(:load_method) { :load_by_client } - let(:actor_field_name) { 'user' } + let(:actor_field_name) { "user" } end end end diff --git a/spec/unit/knife/knife_help.rb b/spec/unit/knife/knife_help.rb index 293bae17f4..d357239e6a 100644 --- a/spec/unit/knife/knife_help.rb +++ b/spec/unit/knife/knife_help.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::Help do before(:each) do diff --git a/spec/unit/knife/node_bulk_delete_spec.rb b/spec/unit/knife/node_bulk_delete_spec.rb index 57a8d0bf64..7106fdfc7b 100644 --- a/spec/unit/knife/node_bulk_delete_spec.rb +++ b/spec/unit/knife/node_bulk_delete_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::NodeBulkDelete do before(:each) do @@ -78,10 +78,10 @@ describe Chef::Knife::NodeBulkDelete do end it "should only delete nodes that match the regex" do - @knife.name_args = ['adam'] - expect(@inflatedish_list['adam']).to receive(:destroy) - expect(@inflatedish_list['brent']).not_to receive(:destroy) - expect(@inflatedish_list['jacob']).not_to receive(:destroy) + @knife.name_args = ["adam"] + expect(@inflatedish_list["adam"]).to receive(:destroy) + expect(@inflatedish_list["brent"]).not_to receive(:destroy) + expect(@inflatedish_list["jacob"]).not_to receive(:destroy) @knife.run end diff --git a/spec/unit/knife/node_delete_spec.rb b/spec/unit/knife/node_delete_spec.rb index 0941d850e5..b2fd54219c 100644 --- a/spec/unit/knife/node_delete_spec.rb +++ b/spec/unit/knife/node_delete_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::NodeDelete do before(:each) do diff --git a/spec/unit/knife/node_edit_spec.rb b/spec/unit/knife/node_edit_spec.rb index be42a15ee7..c7a99517a4 100644 --- a/spec/unit/knife/node_edit_spec.rb +++ b/spec/unit/knife/node_edit_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" Chef::Knife::NodeEdit.load_deps describe Chef::Knife::NodeEdit do @@ -30,7 +30,7 @@ describe Chef::Knife::NodeEdit do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::NodeEdit.new @knife.config = { - :editor => 'cat', + :editor => "cat", :attribute => nil, :print_after => nil, } diff --git a/spec/unit/knife/node_environment_set_spec.rb b/spec/unit/knife/node_environment_set_spec.rb index 10267915d7..0888af05e9 100644 --- a/spec/unit/knife/node_environment_set_spec.rb +++ b/spec/unit/knife/node_environment_set_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::NodeEnvironmentSet do before(:each) do @@ -39,7 +39,7 @@ describe Chef::Knife::NodeEnvironmentSet do it "should update the environment" do @knife.run - expect(@node.chef_environment).to eq('bar') + expect(@node.chef_environment).to eq("bar") end it "should save the node" do diff --git a/spec/unit/knife/node_from_file_spec.rb b/spec/unit/knife/node_from_file_spec.rb index 623904753e..19ee8b52ff 100644 --- a/spec/unit/knife/node_from_file_spec.rb +++ b/spec/unit/knife/node_from_file_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" Chef::Knife::NodeFromFile.load_deps @@ -39,7 +39,7 @@ describe Chef::Knife::NodeFromFile do describe "run" do it "should load from a file" do - expect(@knife.loader).to receive(:load_from).with('nodes', 'adam.rb').and_return(@node) + expect(@knife.loader).to receive(:load_from).with("nodes", "adam.rb").and_return(@node) @knife.run end diff --git a/spec/unit/knife/node_list_spec.rb b/spec/unit/knife/node_list_spec.rb index ec694cb040..c043d47b29 100644 --- a/spec/unit/knife/node_list_spec.rb +++ b/spec/unit/knife/node_list_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::NodeList do before(:each) do diff --git a/spec/unit/knife/node_run_list_add_spec.rb b/spec/unit/knife/node_run_list_add_spec.rb index 92fbfd23fe..e309878a22 100644 --- a/spec/unit/knife/node_run_list_add_spec.rb +++ b/spec/unit/knife/node_run_list_add_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::NodeRunListAdd do before(:each) do @@ -40,7 +40,7 @@ describe Chef::Knife::NodeRunListAdd do it "should add to the run list" do @knife.run - expect(@node.run_list[0]).to eq('role[monkey]') + expect(@node.run_list[0]).to eq("role[monkey]") end it "should save the node" do diff --git a/spec/unit/knife/node_run_list_remove_spec.rb b/spec/unit/knife/node_run_list_remove_spec.rb index a279a59635..f450dd8016 100644 --- a/spec/unit/knife/node_run_list_remove_spec.rb +++ b/spec/unit/knife/node_run_list_remove_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::NodeRunListRemove do before(:each) do @@ -43,7 +43,7 @@ describe Chef::Knife::NodeRunListRemove do it "should remove the item from the run list" do @knife.run - expect(@node.run_list[0]).not_to eq('role[monkey]') + expect(@node.run_list[0]).not_to eq("role[monkey]") end it "should save the node" do @@ -53,50 +53,50 @@ describe Chef::Knife::NodeRunListRemove do it "should print the run list" do @knife.config[:print_after] = true - expect(@knife.ui).to receive(:output).with({ "knifetest-node" => { 'run_list' => [] } }) + expect(@knife.ui).to receive(:output).with({ "knifetest-node" => { "run_list" => [] } }) @knife.run end describe "run with a list of roles and recipes" do it "should remove the items from the run list" do - @node.run_list << 'role[monkey]' - @node.run_list << 'recipe[duck::type]' - @knife.name_args = [ 'adam', 'role[monkey],recipe[duck::type]' ] + @node.run_list << "role[monkey]" + @node.run_list << "recipe[duck::type]" + @knife.name_args = [ "adam", "role[monkey],recipe[duck::type]" ] @knife.run - expect(@node.run_list).not_to include('role[monkey]') - expect(@node.run_list).not_to include('recipe[duck::type]') + expect(@node.run_list).not_to include("role[monkey]") + expect(@node.run_list).not_to include("recipe[duck::type]") end it "should remove the items from the run list when name args contains whitespace" do - @node.run_list << 'role[monkey]' - @node.run_list << 'recipe[duck::type]' - @knife.name_args = [ 'adam', 'role[monkey], recipe[duck::type]' ] + @node.run_list << "role[monkey]" + @node.run_list << "recipe[duck::type]" + @knife.name_args = [ "adam", "role[monkey], recipe[duck::type]" ] @knife.run - expect(@node.run_list).not_to include('role[monkey]') - expect(@node.run_list).not_to include('recipe[duck::type]') + expect(@node.run_list).not_to include("role[monkey]") + expect(@node.run_list).not_to include("recipe[duck::type]") end it "should remove the items from the run list when name args contains multiple run lists" do - @node.run_list << 'role[blah]' - @node.run_list << 'recipe[duck::type]' - @knife.name_args = [ 'adam', 'role[monkey], recipe[duck::type]', 'role[blah]' ] + @node.run_list << "role[blah]" + @node.run_list << "recipe[duck::type]" + @knife.name_args = [ "adam", "role[monkey], recipe[duck::type]", "role[blah]" ] @knife.run - expect(@node.run_list).not_to include('role[monkey]') - expect(@node.run_list).not_to include('recipe[duck::type]') + expect(@node.run_list).not_to include("role[monkey]") + expect(@node.run_list).not_to include("recipe[duck::type]") end it "should warn when the thing to remove is not in the runlist" do - @node.run_list << 'role[blah]' - @node.run_list << 'recipe[duck::type]' - @knife.name_args = [ 'adam', 'role[blork]' ] + @node.run_list << "role[blah]" + @node.run_list << "recipe[duck::type]" + @knife.name_args = [ "adam", "role[blork]" ] expect(@knife.ui).to receive(:warn).with("role[blork] is not in the run list") @knife.run end it "should warn even more when the thing to remove is not in the runlist and unqualified" do - @node.run_list << 'role[blah]' - @node.run_list << 'recipe[duck::type]' - @knife.name_args = [ 'adam', 'blork' ] + @node.run_list << "role[blah]" + @node.run_list << "recipe[duck::type]" + @knife.name_args = [ "adam", "blork" ] expect(@knife.ui).to receive(:warn).with("blork is not in the run list") expect(@knife.ui).to receive(:warn).with(/did you forget recipe\[\] or role\[\]/) @knife.run diff --git a/spec/unit/knife/node_run_list_set_spec.rb b/spec/unit/knife/node_run_list_set_spec.rb index 68daaafd70..75eecfeb27 100644 --- a/spec/unit/knife/node_run_list_set_spec.rb +++ b/spec/unit/knife/node_run_list_set_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::NodeRunListSet do before(:each) do @@ -38,7 +38,7 @@ describe Chef::Knife::NodeRunListSet do it "should set the run list" do @knife.run - expect(@node.run_list[0]).to eq('role[monkey]') + expect(@node.run_list[0]).to eq("role[monkey]") end it "should save the node" do diff --git a/spec/unit/knife/node_show_spec.rb b/spec/unit/knife/node_show_spec.rb index 4806354b60..afc90dc1ed 100644 --- a/spec/unit/knife/node_show_spec.rb +++ b/spec/unit/knife/node_show_spec.rb @@ -16,14 +16,14 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::NodeShow do let(:node) do node = Chef::Node.new() node.name("adam") - node.run_list = ['role[base]'] + node.run_list = ["role[base]"] node end @@ -54,10 +54,10 @@ describe Chef::Knife::NodeShow do end it "should pretty print json" do - knife.config[:format] = 'json' + knife.config[:format] = "json" stdout = StringIO.new allow(knife.ui).to receive(:stdout).and_return(stdout) - expect(Chef::Node).to receive(:load).with('adam').and_return(node) + expect(Chef::Node).to receive(:load).with("adam").and_return(node) knife.run expect(stdout.string).to eql("{\n \"name\": \"adam\",\n \"chef_environment\": \"_default\",\n \"run_list\": [\n\n]\n,\n \"normal\": {\n\n }\n}\n") end diff --git a/spec/unit/knife/osc_user_create_spec.rb b/spec/unit/knife/osc_user_create_spec.rb index e4ed78fe2b..006d50484d 100644 --- a/spec/unit/knife/osc_user_create_spec.rb +++ b/spec/unit/knife/osc_user_create_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" Chef::Knife::OscUserCreate.load_deps @@ -34,13 +34,13 @@ describe Chef::Knife::OscUserCreate do allow(@knife.ui).to receive(:stdout).and_return(@stdout) allow(@knife.ui).to receive(:stderr).and_return(@stderr) - @knife.name_args = [ 'a_user' ] + @knife.name_args = [ "a_user" ] @knife.config[:user_password] = "foobar" @user = Chef::User.new @user.name "a_user" @user_with_private_key = Chef::User.new @user_with_private_key.name "a_user" - @user_with_private_key.private_key 'private_key' + @user_with_private_key.private_key "private_key" allow(@user).to receive(:create).and_return(@user_with_private_key) allow(Chef::User).to receive(:new).and_return(@user) allow(Chef::User).to receive(:from_hash).and_return(@user) @@ -61,7 +61,7 @@ describe Chef::Knife::OscUserCreate do end it "exits with an error if password is blank" do - @knife.config[:user_password] = '' + @knife.config[:user_password] = "" expect { @knife.run }.to raise_error SystemExit expect(@stderr.string).to match /You must specify a non-blank password/ end @@ -86,7 +86,7 @@ describe Chef::Knife::OscUserCreate do it "writes the private key to a file when --file is specified" do @knife.config[:file] = "/tmp/a_file" filehandle = double("filehandle") - expect(filehandle).to receive(:print).with('private_key') + expect(filehandle).to receive(:print).with("private_key") expect(File).to receive(:open).with("/tmp/a_file", "w").and_yield(filehandle) @knife.run end diff --git a/spec/unit/knife/osc_user_delete_spec.rb b/spec/unit/knife/osc_user_delete_spec.rb index 4a3ec4228f..c0e3b0fbf9 100644 --- a/spec/unit/knife/osc_user_delete_spec.rb +++ b/spec/unit/knife/osc_user_delete_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" # DEPRECATION NOTE # This code only remains to support users still operating with @@ -27,15 +27,15 @@ describe Chef::Knife::OscUserDelete do before(:each) do Chef::Knife::OscUserDelete.load_deps @knife = Chef::Knife::OscUserDelete.new - @knife.name_args = [ 'my_user' ] + @knife.name_args = [ "my_user" ] end - it 'deletes the user' do - expect(@knife).to receive(:delete_object).with(Chef::User, 'my_user') + it "deletes the user" do + expect(@knife).to receive(:delete_object).with(Chef::User, "my_user") @knife.run end - it 'prints usage and exits when a user name is not provided' do + it "prints usage and exits when a user name is not provided" do @knife.name_args = [] expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal) diff --git a/spec/unit/knife/osc_user_edit_spec.rb b/spec/unit/knife/osc_user_edit_spec.rb index 279f2e30ef..55574bdc38 100644 --- a/spec/unit/knife/osc_user_edit_spec.rb +++ b/spec/unit/knife/osc_user_edit_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" # DEPRECATION NOTE # This code only remains to support users still operating with @@ -32,18 +32,18 @@ describe Chef::Knife::OscUserEdit do @knife = Chef::Knife::OscUserEdit.new allow(@knife.ui).to receive(:stderr).and_return(@stderr) allow(@knife.ui).to receive(:stdout).and_return(@stdout) - @knife.name_args = [ 'my_user' ] + @knife.name_args = [ "my_user" ] @knife.config[:disable_editing] = true end - it 'loads and edits the user' do + it "loads and edits the user" do data = { :name => "my_user" } allow(Chef::User).to receive(:load).with("my_user").and_return(data) expect(@knife).to receive(:edit_data).with(data).and_return(data) @knife.run end - it 'prints usage and exits when a user name is not provided' do + it "prints usage and exits when a user name is not provided" do @knife.name_args = [] expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal) diff --git a/spec/unit/knife/osc_user_list_spec.rb b/spec/unit/knife/osc_user_list_spec.rb index f496a414b8..bc86e4ce97 100644 --- a/spec/unit/knife/osc_user_list_spec.rb +++ b/spec/unit/knife/osc_user_list_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" # DEPRECATION NOTE # This code only remains to support users still operating with @@ -29,7 +29,7 @@ describe Chef::Knife::OscUserList do @knife = Chef::Knife::OscUserList.new end - it 'lists the users' do + it "lists the users" do expect(Chef::User).to receive(:list) expect(@knife).to receive(:format_list_for_display) @knife.run diff --git a/spec/unit/knife/osc_user_reregister_spec.rb b/spec/unit/knife/osc_user_reregister_spec.rb index 989eb180f1..95fa2c2dc8 100644 --- a/spec/unit/knife/osc_user_reregister_spec.rb +++ b/spec/unit/knife/osc_user_reregister_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" # DEPRECATION NOTE # This code only remains to support users still operating with @@ -27,31 +27,31 @@ describe Chef::Knife::OscUserReregister do before(:each) do Chef::Knife::OscUserReregister.load_deps @knife = Chef::Knife::OscUserReregister.new - @knife.name_args = [ 'a_user' ] - @user_mock = double('user_mock', :private_key => "private_key") + @knife.name_args = [ "a_user" ] + @user_mock = double("user_mock", :private_key => "private_key") allow(Chef::User).to receive(:load).and_return(@user_mock) @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) end - it 'prints usage and exits when a user name is not provided' do + it "prints usage and exits when a user name is not provided" do @knife.name_args = [] expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal) expect { @knife.run }.to raise_error(SystemExit) end - it 'reregisters the user and prints the key' do + it "reregisters the user and prints the key" do expect(@user_mock).to receive(:reregister).and_return(@user_mock) @knife.run expect(@stdout.string).to match( /private_key/ ) end - it 'writes the private key to a file when --file is specified' do + it "writes the private key to a file when --file is specified" do expect(@user_mock).to receive(:reregister).and_return(@user_mock) - @knife.config[:file] = '/tmp/a_file' + @knife.config[:file] = "/tmp/a_file" filehandle = StringIO.new - expect(File).to receive(:open).with('/tmp/a_file', 'w').and_yield(filehandle) + expect(File).to receive(:open).with("/tmp/a_file", "w").and_yield(filehandle) @knife.run expect(filehandle.string).to eq("private_key") end diff --git a/spec/unit/knife/osc_user_show_spec.rb b/spec/unit/knife/osc_user_show_spec.rb index 18d2086099..12f3bb069e 100644 --- a/spec/unit/knife/osc_user_show_spec.rb +++ b/spec/unit/knife/osc_user_show_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" # DEPRECATION NOTE # This code only remains to support users still operating with @@ -27,17 +27,17 @@ describe Chef::Knife::OscUserShow do before(:each) do Chef::Knife::OscUserShow.load_deps @knife = Chef::Knife::OscUserShow.new - @knife.name_args = [ 'my_user' ] - @user_mock = double('user_mock') + @knife.name_args = [ "my_user" ] + @user_mock = double("user_mock") end - it 'loads and displays the user' do - expect(Chef::User).to receive(:load).with('my_user').and_return(@user_mock) + it "loads and displays the user" do + expect(Chef::User).to receive(:load).with("my_user").and_return(@user_mock) expect(@knife).to receive(:format_for_display).with(@user_mock) @knife.run end - it 'prints usage and exits when a user name is not provided' do + it "prints usage and exits when a user name is not provided" do @knife.name_args = [] expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal) diff --git a/spec/unit/knife/raw_spec.rb b/spec/unit/knife/raw_spec.rb index ab929abd39..14cdfbd614 100644 --- a/spec/unit/knife/raw_spec.rb +++ b/spec/unit/knife/raw_spec.rb @@ -15,11 +15,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'spec_helper' +require "spec_helper" describe Chef::Knife::Raw do let(:rest) do - r = double('Chef::Knife::Raw::RawInputServerAPI') + r = double("Chef::Knife::Raw::RawInputServerAPI") allow(Chef::Knife::Raw::RawInputServerAPI).to receive(:new).and_return(r) r end @@ -35,8 +35,8 @@ describe Chef::Knife::Raw do it "should set the x-ops-request-source header when --proxy-auth is set" do knife.config[:proxy_auth] = true expect(rest).to receive(:request).with(:GET, "/nodes", - { 'Content-Type' => 'application/json', - 'x-ops-request-source' => 'web'}, false) + { "Content-Type" => "application/json", + "x-ops-request-source" => "web"}, false) knife.run end end diff --git a/spec/unit/knife/role_bulk_delete_spec.rb b/spec/unit/knife/role_bulk_delete_spec.rb index 5b79e52a04..55bf05e806 100644 --- a/spec/unit/knife/role_bulk_delete_spec.rb +++ b/spec/unit/knife/role_bulk_delete_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleBulkDelete do before(:each) do diff --git a/spec/unit/knife/role_create_spec.rb b/spec/unit/knife/role_create_spec.rb index fb748c51f6..23c747efc9 100644 --- a/spec/unit/knife/role_create_spec.rb +++ b/spec/unit/knife/role_create_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleCreate do before(:each) do diff --git a/spec/unit/knife/role_delete_spec.rb b/spec/unit/knife/role_delete_spec.rb index b1a0d90410..6d7d0d964e 100644 --- a/spec/unit/knife/role_delete_spec.rb +++ b/spec/unit/knife/role_delete_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleDelete do before(:each) do diff --git a/spec/unit/knife/role_edit_spec.rb b/spec/unit/knife/role_edit_spec.rb index 0975c6458d..8026d8a21d 100644 --- a/spec/unit/knife/role_edit_spec.rb +++ b/spec/unit/knife/role_edit_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleEdit do before(:each) do diff --git a/spec/unit/knife/role_env_run_list_add_spec.rb b/spec/unit/knife/role_env_run_list_add_spec.rb index f286d5fd0d..743aa55d9d 100644 --- a/spec/unit/knife/role_env_run_list_add_spec.rb +++ b/spec/unit/knife/role_env_run_list_add_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleEnvRunListAdd do before(:each) do @@ -48,7 +48,7 @@ describe Chef::Knife::RoleEnvRunListAdd do it "should have a QA environment" do @knife.run - expect(@role.active_run_list_for('QA')).to eq('QA') + expect(@role.active_run_list_for("QA")).to eq("QA") end it "should load the role named will" do @@ -58,7 +58,7 @@ describe Chef::Knife::RoleEnvRunListAdd do it "should be able to add an environment specific run list" do @knife.run - expect(@role.run_list_for('QA')[0]).to eq('role[monkey]') + expect(@role.run_list_for("QA")[0]).to eq("role[monkey]") end it "should save the role" do diff --git a/spec/unit/knife/role_env_run_list_clear_spec.rb b/spec/unit/knife/role_env_run_list_clear_spec.rb index 525376c358..6a5157d5d4 100644 --- a/spec/unit/knife/role_env_run_list_clear_spec.rb +++ b/spec/unit/knife/role_env_run_list_clear_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleEnvRunListClear do before(:each) do @@ -60,7 +60,7 @@ describe Chef::Knife::RoleEnvRunListClear do it "should remove the item from the run list" do @setup.run @knife.run - expect(@role.run_list_for('QA')[0]).to be_nil + expect(@role.run_list_for("QA")[0]).to be_nil expect(@role.run_list[0]).to be_nil end @@ -82,15 +82,15 @@ describe Chef::Knife::RoleEnvRunListClear do @setup.run @setup.name_args = [ "will", "PRD", "recipe[orange::chicken]", "role[monkey]", "recipe[duck::type]", "role[person]", "role[bird]", "role[town]" ] @setup.run - @knife.name_args = [ 'will', 'QA' ] + @knife.name_args = [ "will", "QA" ] @knife.run - expect(@role.run_list_for('QA')[0]).to be_nil - expect(@role.run_list_for('PRD')[0]).to eq('recipe[orange::chicken]') - expect(@role.run_list_for('PRD')[1]).to eq('role[monkey]') - expect(@role.run_list_for('PRD')[2]).to eq('recipe[duck::type]') - expect(@role.run_list_for('PRD')[3]).to eq('role[person]') - expect(@role.run_list_for('PRD')[4]).to eq('role[bird]') - expect(@role.run_list_for('PRD')[5]).to eq('role[town]') + expect(@role.run_list_for("QA")[0]).to be_nil + expect(@role.run_list_for("PRD")[0]).to eq("recipe[orange::chicken]") + expect(@role.run_list_for("PRD")[1]).to eq("role[monkey]") + expect(@role.run_list_for("PRD")[2]).to eq("recipe[duck::type]") + expect(@role.run_list_for("PRD")[3]).to eq("role[person]") + expect(@role.run_list_for("PRD")[4]).to eq("role[bird]") + expect(@role.run_list_for("PRD")[5]).to eq("role[town]") end end end diff --git a/spec/unit/knife/role_env_run_list_remove_spec.rb b/spec/unit/knife/role_env_run_list_remove_spec.rb index a15d0af691..329ac2aff0 100644 --- a/spec/unit/knife/role_env_run_list_remove_spec.rb +++ b/spec/unit/knife/role_env_run_list_remove_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleEnvRunListRemove do before(:each) do @@ -60,8 +60,8 @@ describe Chef::Knife::RoleEnvRunListRemove do it "should remove the item from the run list" do @setup.run @knife.run - expect(@role.run_list_for('QA')[0]).not_to eq('role[monkey]') - expect(@role.run_list_for('QA')[0]).to eq('role[person]') + expect(@role.run_list_for("QA")[0]).not_to eq("role[monkey]") + expect(@role.run_list_for("QA")[0]).to eq("role[person]") expect(@role.run_list[0]).to be_nil end @@ -83,22 +83,22 @@ describe Chef::Knife::RoleEnvRunListRemove do @setup.run @setup.name_args = [ "will", "PRD", "recipe[orange::chicken]", "role[monkey]", "recipe[duck::type]", "role[person]", "role[bird]", "role[town]" ] @setup.run - @knife.name_args = [ 'will', 'QA', 'role[monkey]' ] + @knife.name_args = [ "will", "QA", "role[monkey]" ] @knife.run - @knife.name_args = [ 'will', 'QA', 'recipe[duck::type]' ] + @knife.name_args = [ "will", "QA", "recipe[duck::type]" ] @knife.run - expect(@role.run_list_for('QA')).not_to include('role[monkey]') - expect(@role.run_list_for('QA')).not_to include('recipe[duck::type]') - expect(@role.run_list_for('QA')[0]).to eq('recipe[orange::chicken]') - expect(@role.run_list_for('QA')[1]).to eq('role[person]') - expect(@role.run_list_for('QA')[2]).to eq('role[bird]') - expect(@role.run_list_for('QA')[3]).to eq('role[town]') - expect(@role.run_list_for('PRD')[0]).to eq('recipe[orange::chicken]') - expect(@role.run_list_for('PRD')[1]).to eq('role[monkey]') - expect(@role.run_list_for('PRD')[2]).to eq('recipe[duck::type]') - expect(@role.run_list_for('PRD')[3]).to eq('role[person]') - expect(@role.run_list_for('PRD')[4]).to eq('role[bird]') - expect(@role.run_list_for('PRD')[5]).to eq('role[town]') + expect(@role.run_list_for("QA")).not_to include("role[monkey]") + expect(@role.run_list_for("QA")).not_to include("recipe[duck::type]") + expect(@role.run_list_for("QA")[0]).to eq("recipe[orange::chicken]") + expect(@role.run_list_for("QA")[1]).to eq("role[person]") + expect(@role.run_list_for("QA")[2]).to eq("role[bird]") + expect(@role.run_list_for("QA")[3]).to eq("role[town]") + expect(@role.run_list_for("PRD")[0]).to eq("recipe[orange::chicken]") + expect(@role.run_list_for("PRD")[1]).to eq("role[monkey]") + expect(@role.run_list_for("PRD")[2]).to eq("recipe[duck::type]") + expect(@role.run_list_for("PRD")[3]).to eq("role[person]") + expect(@role.run_list_for("PRD")[4]).to eq("role[bird]") + expect(@role.run_list_for("PRD")[5]).to eq("role[town]") end end end diff --git a/spec/unit/knife/role_env_run_list_replace_spec.rb b/spec/unit/knife/role_env_run_list_replace_spec.rb index ea48601b8d..bb7b79e3f0 100644 --- a/spec/unit/knife/role_env_run_list_replace_spec.rb +++ b/spec/unit/knife/role_env_run_list_replace_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleEnvRunListReplace do before(:each) do @@ -60,8 +60,8 @@ describe Chef::Knife::RoleEnvRunListReplace do it "should remove the item from the run list" do @setup.run @knife.run - expect(@role.run_list_for('QA')[1]).not_to eq('role[dude]') - expect(@role.run_list_for('QA')[1]).to eq('role[person]') + expect(@role.run_list_for("QA")[1]).not_to eq("role[dude]") + expect(@role.run_list_for("QA")[1]).to eq("role[person]") expect(@role.run_list[0]).to be_nil end @@ -83,24 +83,24 @@ describe Chef::Knife::RoleEnvRunListReplace do @setup.run @setup.name_args = [ "will", "PRD", "recipe[orange::chicken]", "role[monkey]", "recipe[duck::type]", "role[person]", "role[bird]", "role[town]" ] @setup.run - @knife.name_args = [ 'will', 'QA', 'role[monkey]', 'role[gibbon]' ] + @knife.name_args = [ "will", "QA", "role[monkey]", "role[gibbon]" ] @knife.run - @knife.name_args = [ 'will', 'QA', 'recipe[duck::type]', 'recipe[duck::mallard]' ] + @knife.name_args = [ "will", "QA", "recipe[duck::type]", "recipe[duck::mallard]" ] @knife.run - expect(@role.run_list_for('QA')).not_to include('role[monkey]') - expect(@role.run_list_for('QA')).not_to include('recipe[duck::type]') - expect(@role.run_list_for('QA')[0]).to eq('recipe[orange::chicken]') - expect(@role.run_list_for('QA')[1]).to eq('role[gibbon]') - expect(@role.run_list_for('QA')[2]).to eq('recipe[duck::mallard]') - expect(@role.run_list_for('QA')[3]).to eq('role[person]') - expect(@role.run_list_for('QA')[4]).to eq('role[bird]') - expect(@role.run_list_for('QA')[5]).to eq('role[town]') - expect(@role.run_list_for('PRD')[0]).to eq('recipe[orange::chicken]') - expect(@role.run_list_for('PRD')[1]).to eq('role[monkey]') - expect(@role.run_list_for('PRD')[2]).to eq('recipe[duck::type]') - expect(@role.run_list_for('PRD')[3]).to eq('role[person]') - expect(@role.run_list_for('PRD')[4]).to eq('role[bird]') - expect(@role.run_list_for('PRD')[5]).to eq('role[town]') + expect(@role.run_list_for("QA")).not_to include("role[monkey]") + expect(@role.run_list_for("QA")).not_to include("recipe[duck::type]") + expect(@role.run_list_for("QA")[0]).to eq("recipe[orange::chicken]") + expect(@role.run_list_for("QA")[1]).to eq("role[gibbon]") + expect(@role.run_list_for("QA")[2]).to eq("recipe[duck::mallard]") + expect(@role.run_list_for("QA")[3]).to eq("role[person]") + expect(@role.run_list_for("QA")[4]).to eq("role[bird]") + expect(@role.run_list_for("QA")[5]).to eq("role[town]") + expect(@role.run_list_for("PRD")[0]).to eq("recipe[orange::chicken]") + expect(@role.run_list_for("PRD")[1]).to eq("role[monkey]") + expect(@role.run_list_for("PRD")[2]).to eq("recipe[duck::type]") + expect(@role.run_list_for("PRD")[3]).to eq("role[person]") + expect(@role.run_list_for("PRD")[4]).to eq("role[bird]") + expect(@role.run_list_for("PRD")[5]).to eq("role[town]") expect(@role.run_list[0]).to be_nil end end diff --git a/spec/unit/knife/role_env_run_list_set_spec.rb b/spec/unit/knife/role_env_run_list_set_spec.rb index f3abb86fcf..0932b07ffd 100644 --- a/spec/unit/knife/role_env_run_list_set_spec.rb +++ b/spec/unit/knife/role_env_run_list_set_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleEnvRunListSet do before(:each) do @@ -60,9 +60,9 @@ describe Chef::Knife::RoleEnvRunListSet do it "should replace all the items in the runlist with what is specified" do @setup.run @knife.run - expect(@role.run_list_for('QA')[0]).to eq("role[owen]") - expect(@role.run_list_for('QA')[1]).to eq("role[mauntel]") - expect(@role.run_list_for('QA')[2]).to be_nil + expect(@role.run_list_for("QA")[0]).to eq("role[owen]") + expect(@role.run_list_for("QA")[1]).to eq("role[mauntel]") + expect(@role.run_list_for("QA")[2]).to be_nil expect(@role.run_list[0]).to be_nil end @@ -86,15 +86,15 @@ describe Chef::Knife::RoleEnvRunListSet do @setup.run @knife.name_args = [ "will", "QA", "role[coke]", "role[pepsi]" ] @knife.run - expect(@role.run_list_for('QA')[0]).to eq("role[coke]") - expect(@role.run_list_for('QA')[1]).to eq("role[pepsi]") - expect(@role.run_list_for('QA')[2]).to be_nil - expect(@role.run_list_for('PRD')[0]).to eq('recipe[orange::chicken]') - expect(@role.run_list_for('PRD')[1]).to eq('role[monkey]') - expect(@role.run_list_for('PRD')[2]).to eq('recipe[duck::type]') - expect(@role.run_list_for('PRD')[3]).to eq('role[person]') - expect(@role.run_list_for('PRD')[4]).to eq('role[bird]') - expect(@role.run_list_for('PRD')[5]).to eq('role[town]') + expect(@role.run_list_for("QA")[0]).to eq("role[coke]") + expect(@role.run_list_for("QA")[1]).to eq("role[pepsi]") + expect(@role.run_list_for("QA")[2]).to be_nil + expect(@role.run_list_for("PRD")[0]).to eq("recipe[orange::chicken]") + expect(@role.run_list_for("PRD")[1]).to eq("role[monkey]") + expect(@role.run_list_for("PRD")[2]).to eq("recipe[duck::type]") + expect(@role.run_list_for("PRD")[3]).to eq("role[person]") + expect(@role.run_list_for("PRD")[4]).to eq("role[bird]") + expect(@role.run_list_for("PRD")[5]).to eq("role[town]") expect(@role.run_list[0]).to be_nil end end diff --git a/spec/unit/knife/role_from_file_spec.rb b/spec/unit/knife/role_from_file_spec.rb index 9379f08de3..b08d4bfc59 100644 --- a/spec/unit/knife/role_from_file_spec.rb +++ b/spec/unit/knife/role_from_file_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" Chef::Knife::RoleFromFile.load_deps @@ -39,7 +39,7 @@ describe Chef::Knife::RoleFromFile do describe "run" do it "should load from a file" do - expect(@knife.loader).to receive(:load_from).with('roles', 'adam.rb').and_return(@role) + expect(@knife.loader).to receive(:load_from).with("roles", "adam.rb").and_return(@role) @knife.run end @@ -60,8 +60,8 @@ describe Chef::Knife::RoleFromFile do describe "run with multiple arguments" do it "should load each file" do @knife.name_args = [ "adam.rb", "caleb.rb" ] - expect(@knife.loader).to receive(:load_from).with('roles', 'adam.rb').and_return(@role) - expect(@knife.loader).to receive(:load_from).with('roles', 'caleb.rb').and_return(@role) + expect(@knife.loader).to receive(:load_from).with("roles", "adam.rb").and_return(@role) + expect(@knife.loader).to receive(:load_from).with("roles", "caleb.rb").and_return(@role) @knife.run end end diff --git a/spec/unit/knife/role_list_spec.rb b/spec/unit/knife/role_list_spec.rb index 65c4f94ff2..0cb4e08337 100644 --- a/spec/unit/knife/role_list_spec.rb +++ b/spec/unit/knife/role_list_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleList do before(:each) do diff --git a/spec/unit/knife/role_run_list_add_spec.rb b/spec/unit/knife/role_run_list_add_spec.rb index d61c114912..425dd0a9a1 100644 --- a/spec/unit/knife/role_run_list_add_spec.rb +++ b/spec/unit/knife/role_run_list_add_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleRunListAdd do before(:each) do diff --git a/spec/unit/knife/role_run_list_clear_spec.rb b/spec/unit/knife/role_run_list_clear_spec.rb index e5a6e18673..42980467e2 100644 --- a/spec/unit/knife/role_run_list_clear_spec.rb +++ b/spec/unit/knife/role_run_list_clear_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleRunListClear do before(:each) do @@ -78,7 +78,7 @@ describe Chef::Knife::RoleRunListClear do it "should remove the items from the run list" do @setup.name_args = [ "will", "recipe[orange::chicken]", "role[monkey]", "recipe[duck::type]", "role[person]", "role[bird]", "role[town]" ] @setup.run - @knife.name_args = [ 'will' ] + @knife.name_args = [ "will" ] @knife.run expect(@role.run_list[0]).to be_nil end diff --git a/spec/unit/knife/role_run_list_remove_spec.rb b/spec/unit/knife/role_run_list_remove_spec.rb index 0f4adf253b..5c3da5c3f7 100644 --- a/spec/unit/knife/role_run_list_remove_spec.rb +++ b/spec/unit/knife/role_run_list_remove_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleRunListRemove do before(:each) do @@ -59,7 +59,7 @@ describe Chef::Knife::RoleRunListRemove do it "should remove the item from the run list" do @setup.run @knife.run - expect(@role.run_list[0]).to eq('role[person]') + expect(@role.run_list[0]).to eq("role[person]") expect(@role.run_list[1]).to be_nil end @@ -79,16 +79,16 @@ describe Chef::Knife::RoleRunListRemove do it "should remove the items from the run list" do @setup.name_args = [ "will", "recipe[orange::chicken]", "role[monkey]", "recipe[duck::type]", "role[person]", "role[bird]", "role[town]" ] @setup.run - @knife.name_args = [ 'will', 'role[monkey]' ] + @knife.name_args = [ "will", "role[monkey]" ] @knife.run - @knife.name_args = [ 'will', 'recipe[duck::type]' ] + @knife.name_args = [ "will", "recipe[duck::type]" ] @knife.run - expect(@role.run_list).not_to include('role[monkey]') - expect(@role.run_list).not_to include('recipe[duck::type]') - expect(@role.run_list[0]).to eq('recipe[orange::chicken]') - expect(@role.run_list[1]).to eq('role[person]') - expect(@role.run_list[2]).to eq('role[bird]') - expect(@role.run_list[3]).to eq('role[town]') + expect(@role.run_list).not_to include("role[monkey]") + expect(@role.run_list).not_to include("recipe[duck::type]") + expect(@role.run_list[0]).to eq("recipe[orange::chicken]") + expect(@role.run_list[1]).to eq("role[person]") + expect(@role.run_list[2]).to eq("role[bird]") + expect(@role.run_list[3]).to eq("role[town]") end end end diff --git a/spec/unit/knife/role_run_list_replace_spec.rb b/spec/unit/knife/role_run_list_replace_spec.rb index 2ff38f573c..44fb3caabc 100644 --- a/spec/unit/knife/role_run_list_replace_spec.rb +++ b/spec/unit/knife/role_run_list_replace_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleRunListReplace do before(:each) do @@ -59,10 +59,10 @@ describe Chef::Knife::RoleRunListReplace do it "should remove the item from the run list" do @setup.run @knife.run - expect(@role.run_list[0]).to eq('role[monkey]') - expect(@role.run_list[1]).not_to eq('role[dude]') - expect(@role.run_list[1]).to eq('role[person]') - expect(@role.run_list[2]).to eq('role[fixer]') + expect(@role.run_list[0]).to eq("role[monkey]") + expect(@role.run_list[1]).not_to eq("role[dude]") + expect(@role.run_list[1]).to eq("role[person]") + expect(@role.run_list[2]).to eq("role[fixer]") expect(@role.run_list[3]).to be_nil end @@ -82,18 +82,18 @@ describe Chef::Knife::RoleRunListReplace do it "should replace the items from the run list" do @setup.name_args = [ "will", "recipe[orange::chicken]", "role[monkey]", "recipe[duck::type]", "role[person]", "role[bird]", "role[town]" ] @setup.run - @knife.name_args = [ 'will', 'role[monkey]', 'role[gibbon]' ] + @knife.name_args = [ "will", "role[monkey]", "role[gibbon]" ] @knife.run - @knife.name_args = [ 'will', 'recipe[duck::type]', 'recipe[duck::mallard]' ] + @knife.name_args = [ "will", "recipe[duck::type]", "recipe[duck::mallard]" ] @knife.run - expect(@role.run_list).not_to include('role[monkey]') - expect(@role.run_list).not_to include('recipe[duck::type]') - expect(@role.run_list[0]).to eq('recipe[orange::chicken]') - expect(@role.run_list[1]).to eq('role[gibbon]') - expect(@role.run_list[2]).to eq('recipe[duck::mallard]') - expect(@role.run_list[3]).to eq('role[person]') - expect(@role.run_list[4]).to eq('role[bird]') - expect(@role.run_list[5]).to eq('role[town]') + expect(@role.run_list).not_to include("role[monkey]") + expect(@role.run_list).not_to include("recipe[duck::type]") + expect(@role.run_list[0]).to eq("recipe[orange::chicken]") + expect(@role.run_list[1]).to eq("role[gibbon]") + expect(@role.run_list[2]).to eq("recipe[duck::mallard]") + expect(@role.run_list[3]).to eq("role[person]") + expect(@role.run_list[4]).to eq("role[bird]") + expect(@role.run_list[5]).to eq("role[town]") expect(@role.run_list[6]).to be_nil end end diff --git a/spec/unit/knife/role_run_list_set_spec.rb b/spec/unit/knife/role_run_list_set_spec.rb index 1350741f10..73d42cf2a2 100644 --- a/spec/unit/knife/role_run_list_set_spec.rb +++ b/spec/unit/knife/role_run_list_set_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleRunListSet do before(:each) do diff --git a/spec/unit/knife/role_show_spec.rb b/spec/unit/knife/role_show_spec.rb index b086136186..2b5b0eec18 100644 --- a/spec/unit/knife/role_show_spec.rb +++ b/spec/unit/knife/role_show_spec.rb @@ -16,10 +16,10 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::RoleShow do - let(:role) { 'base' } + let(:role) { "base" } let(:knife) do knife = Chef::Knife::RoleShow.new @@ -27,21 +27,21 @@ describe Chef::Knife::RoleShow do knife end - let(:role_mock) { double('role_mock') } + let(:role_mock) { double("role_mock") } - describe 'run' do - it 'should list the role' do - expect(Chef::Role).to receive(:load).with('base').and_return(role_mock) + describe "run" do + it "should list the role" do + expect(Chef::Role).to receive(:load).with("base").and_return(role_mock) expect(knife).to receive(:format_for_display).with(role_mock) knife.run end - it 'should pretty print json' do - knife.config[:format] = 'json' + it "should pretty print json" do + knife.config[:format] = "json" stdout = StringIO.new allow(knife.ui).to receive(:stdout).and_return(stdout) fake_role_contents = {"foo"=>"bar", "baz"=>"qux"} - expect(Chef::Role).to receive(:load).with('base').and_return(fake_role_contents) + expect(Chef::Role).to receive(:load).with("base").and_return(fake_role_contents) knife.run expect(stdout.string).to eql("{\n \"foo\": \"bar\",\n \"baz\": \"qux\"\n}\n") end @@ -49,7 +49,7 @@ describe Chef::Knife::RoleShow do context "without a role name" do let(:role) { } - it 'should print usage and exit when a role name is not provided' do + it "should print usage and exit when a role name is not provided" do expect(knife).to receive(:show_usage) expect(knife.ui).to receive(:fatal) expect { knife.run }.to raise_error(SystemExit) diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb index 197dc4ca77..adaa8829a5 100644 --- a/spec/unit/knife/ssh_spec.rb +++ b/spec/unit/knife/ssh_spec.rb @@ -16,9 +16,9 @@ # limitations under the License. # -require 'spec_helper' -require 'net/ssh' -require 'net/ssh/multi' +require "spec_helper" +require "net/ssh" +require "net/ssh/multi" describe Chef::Knife::Ssh do before(:each) do @@ -54,7 +54,7 @@ describe Chef::Knife::Ssh do @knife.config[:attribute] = "ipaddress" Chef::Config[:knife][:ssh_attribute] = "ipaddress" # this value will be in the config file configure_query([@node_foo, @node_bar]) - expect(@knife).to receive(:session_from_list).with([['10.0.0.1', nil], ['10.0.0.2', nil]]) + expect(@knife).to receive(:session_from_list).with([["10.0.0.1", nil], ["10.0.0.2", nil]]) @knife.configure_session end @@ -62,7 +62,7 @@ describe Chef::Knife::Ssh do Chef::Config[:knife][:ssh_attribute] = "config_file" # this value will be in the config file @knife.config[:attribute] = "ipaddress" # this is the value of the command line via #configure_attribute configure_query([@node_foo, @node_bar]) - expect(@knife).to receive(:session_from_list).with([['10.0.0.1', nil], ['10.0.0.2', nil]]) + expect(@knife).to receive(:session_from_list).with([["10.0.0.1", nil], ["10.0.0.2", nil]]) @knife.configure_session end end @@ -70,8 +70,8 @@ describe Chef::Knife::Ssh do it "searchs for and returns an array of fqdns" do configure_query([@node_foo, @node_bar]) expect(@knife).to receive(:session_from_list).with([ - ['foo.example.org', nil], - ['bar.example.org', nil], + ["foo.example.org", nil], + ["bar.example.org", nil], ]) @knife.configure_session end @@ -86,8 +86,8 @@ describe Chef::Knife::Ssh do it "returns an array of cloud public hostnames" do configure_query([@node_foo, @node_bar]) expect(@knife).to receive(:session_from_list).with([ - ['ec2-10-0-0-1.compute-1.amazonaws.com', nil], - ['ec2-10-0-0-2.compute-1.amazonaws.com', nil], + ["ec2-10-0-0-1.compute-1.amazonaws.com", nil], + ["ec2-10-0-0-2.compute-1.amazonaws.com", nil], ]) @knife.configure_session end @@ -97,15 +97,15 @@ describe Chef::Knife::Ssh do context "when cloud hostnames are available but empty" do before do - @node_foo.automatic_attrs[:cloud][:public_hostname] = '' - @node_bar.automatic_attrs[:cloud][:public_hostname] = '' + @node_foo.automatic_attrs[:cloud][:public_hostname] = "" + @node_bar.automatic_attrs[:cloud][:public_hostname] = "" end it "returns an array of fqdns" do configure_query([@node_foo, @node_bar]) expect(@knife).to receive(:session_from_list).with([ - ['foo.example.org', nil], - ['bar.example.org', nil], + ["foo.example.org", nil], + ["bar.example.org", nil], ]) @knife.configure_session end @@ -143,7 +143,7 @@ describe Chef::Knife::Ssh do it "returns an array of provided values" do @knife.instance_variable_set(:@name_args, ["foo.example.org bar.example.org"]) - expect(@knife).to receive(:session_from_list).with(['foo.example.org', 'bar.example.org']) + expect(@knife).to receive(:session_from_list).with(["foo.example.org", "bar.example.org"]) @knife.configure_session end end @@ -159,7 +159,7 @@ describe Chef::Knife::Ssh do Chef::Config[:knife][:ssh_attribute] = nil @knife.config[:attribute] = nil @node_foo.automatic_attrs[:cloud][:public_hostname] = "ec2-10-0-0-1.compute-1.amazonaws.com" - @node_bar.automatic_attrs[:cloud][:public_hostname] = '' + @node_bar.automatic_attrs[:cloud][:public_hostname] = "" end it "should return fqdn by default" do @@ -190,21 +190,21 @@ describe Chef::Knife::Ssh do before :each do @knife.instance_variable_set(:@longest, 0) ssh_config = {:timeout => 50, :user => "locutus", :port => 23 } - allow(Net::SSH).to receive(:configuration_for).with('the.b.org').and_return(ssh_config) + allow(Net::SSH).to receive(:configuration_for).with("the.b.org").and_return(ssh_config) end it "uses the port from an ssh config file" do - @knife.session_from_list([['the.b.org', nil]]) + @knife.session_from_list([["the.b.org", nil]]) expect(@knife.session.servers[0].port).to eq(23) end it "uses the port from a cloud attr" do - @knife.session_from_list([['the.b.org', 123]]) + @knife.session_from_list([["the.b.org", 123]]) expect(@knife.session.servers[0].port).to eq(123) end it "uses the user from an ssh config file" do - @knife.session_from_list([['the.b.org', 123]]) + @knife.session_from_list([["the.b.org", 123]]) expect(@knife.session.servers[0].user).to eq("locutus") end end @@ -279,7 +279,7 @@ describe Chef::Knife::Ssh do expect(@query).to receive(:search).and_return([[@node_foo]]) allow(Chef::Search::Query).to receive(:new).and_return(@query) allow(@knife).to receive(:ssh_command).and_return(exit_code) - @knife.name_args = ['*:*', 'false'] + @knife.name_args = ["*:*", "false"] end context "with an error" do diff --git a/spec/unit/knife/ssl_check_spec.rb b/spec/unit/knife/ssl_check_spec.rb index feeb85c8af..5fe1b18cb7 100644 --- a/spec/unit/knife/ssl_check_spec.rb +++ b/spec/unit/knife/ssl_check_spec.rb @@ -17,7 +17,7 @@ # require "spec_helper" -require 'stringio' +require "stringio" describe Chef::Knife::SslCheck do diff --git a/spec/unit/knife/ssl_fetch_spec.rb b/spec/unit/knife/ssl_fetch_spec.rb index 5982ed9470..be098e4834 100644 --- a/spec/unit/knife/ssl_fetch_spec.rb +++ b/spec/unit/knife/ssl_fetch_spec.rb @@ -16,8 +16,8 @@ # limitations under the License. # -require 'spec_helper' -require 'chef/knife/ssl_fetch' +require "spec_helper" +require "chef/knife/ssl_fetch" describe Chef::Knife::SslFetch do diff --git a/spec/unit/knife/status_spec.rb b/spec/unit/knife/status_spec.rb index 11728a6f9b..c2866dc0f6 100644 --- a/spec/unit/knife/status_spec.rb +++ b/spec/unit/knife/status_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::Status do before(:each) do diff --git a/spec/unit/knife/tag_create_spec.rb b/spec/unit/knife/tag_create_spec.rb index 586ec118bd..6a3ced3f5b 100644 --- a/spec/unit/knife/tag_create_spec.rb +++ b/spec/unit/knife/tag_create_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Chef::Knife::TagCreate do before(:each) do diff --git a/spec/unit/knife/tag_delete_spec.rb b/spec/unit/knife/tag_delete_spec.rb index e7fa108947..3095eda191 100644 --- a/spec/unit/knife/tag_delete_spec.rb +++ b/spec/unit/knife/tag_delete_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Chef::Knife::TagDelete do before(:each) do diff --git a/spec/unit/knife/tag_list_spec.rb b/spec/unit/knife/tag_list_spec.rb index 9c71d22f06..97cd8e7efa 100644 --- a/spec/unit/knife/tag_list_spec.rb +++ b/spec/unit/knife/tag_list_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require "spec_helper" describe Chef::Knife::TagList do before(:each) do diff --git a/spec/unit/knife/user_create_spec.rb b/spec/unit/knife/user_create_spec.rb index fa5c8324b4..e05d518c1a 100644 --- a/spec/unit/knife/user_create_spec.rb +++ b/spec/unit/knife/user_create_spec.rb @@ -17,7 +17,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" Chef::Knife::UserCreate.load_deps @@ -41,7 +41,7 @@ describe Chef::Knife::UserCreate do # delete this once OSC11 support is gone context "when only one name_arg is passed" do before do - knife.name_args = ['some_user'] + knife.name_args = ["some_user"] allow(knife).to receive(:run_osc_11_user_create).and_raise(SystemExit) end @@ -61,7 +61,7 @@ describe Chef::Knife::UserCreate do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do let(:name_args) { [] } - let(:fieldname) { 'username' } + let(:fieldname) { "username" } end end @@ -79,38 +79,38 @@ describe Chef::Knife::UserCreate do context "when FIRST_NAME isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ['some_user', 'some_display_name'] } - let(:fieldname) { 'first name' } + let(:name_args) { ["some_user", "some_display_name"] } + let(:fieldname) { "first name" } end end context "when LAST_NAME isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ['some_user', 'some_display_name', 'some_first_name'] } - let(:fieldname) { 'last name' } + let(:name_args) { ["some_user", "some_display_name", "some_first_name"] } + let(:fieldname) { "last name" } end end context "when EMAIL isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ['some_user', 'some_display_name', 'some_first_name', 'some_last_name'] } - let(:fieldname) { 'email' } + let(:name_args) { ["some_user", "some_display_name", "some_first_name", "some_last_name"] } + let(:fieldname) { "email" } end end context "when PASSWORD isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ['some_user', 'some_display_name', 'some_first_name', 'some_last_name', 'some_email'] } - let(:fieldname) { 'password' } + let(:name_args) { ["some_user", "some_display_name", "some_first_name", "some_last_name", "some_email"] } + let(:fieldname) { "password" } end end context "when all mandatory fields are validly specified" do before do - knife.name_args = ['some_user', 'some_display_name', 'some_first_name', 'some_last_name', 'some_email', 'some_password'] + knife.name_args = ["some_user", "some_display_name", "some_first_name", "some_last_name", "some_email", "some_password"] allow(knife).to receive(:edit_data).and_return(knife.user.to_hash) allow(knife).to receive(:create_user_from_hash).and_return(knife.user) end @@ -122,12 +122,12 @@ describe Chef::Knife::UserCreate do it "sets all the mandatory fields" do knife.run - expect(knife.user.username).to eq('some_user') - expect(knife.user.display_name).to eq('some_display_name') - expect(knife.user.first_name).to eq('some_first_name') - expect(knife.user.last_name).to eq('some_last_name') - expect(knife.user.email).to eq('some_email') - expect(knife.user.password).to eq('some_password') + expect(knife.user.username).to eq("some_user") + expect(knife.user.display_name).to eq("some_display_name") + expect(knife.user.first_name).to eq("some_first_name") + expect(knife.user.last_name).to eq("some_last_name") + expect(knife.user.email).to eq("some_email") + expect(knife.user.password).to eq("some_password") end context "when user_key and prevent_keygen are passed" do @@ -166,14 +166,14 @@ describe Chef::Knife::UserCreate do context "when --user-key is passed" do before do - knife.config[:user_key] = 'some_key' - allow(File).to receive(:read).and_return('some_key') + knife.config[:user_key] = "some_key" + allow(File).to receive(:read).and_return("some_key") allow(File).to receive(:expand_path) end it "sets user.public_key" do knife.run - expect(knife.user.public_key).to eq('some_key') + expect(knife.user.public_key).to eq("some_key") end end @@ -191,20 +191,20 @@ describe Chef::Knife::UserCreate do context "when --file is passed" do before do - knife.config[:file] = '/some/path' + knife.config[:file] = "/some/path" end it "creates a new file of the path passed" do - filehandle = double('filehandle') - expect(filehandle).to receive(:print).with('some_private_key') - expect(File).to receive(:open).with('/some/path', 'w').and_yield(filehandle) + filehandle = double("filehandle") + expect(filehandle).to receive(:print).with("some_private_key") + expect(File).to receive(:open).with("/some/path", "w").and_yield(filehandle) knife.run end end context "when --file is not passed" do it "prints the private key to stdout" do - expect(knife.ui).to receive(:msg).with('some_private_key') + expect(knife.ui).to receive(:msg).with("some_private_key") knife.run end end diff --git a/spec/unit/knife/user_delete_spec.rb b/spec/unit/knife/user_delete_spec.rb index a24160624a..f2f8b1537d 100644 --- a/spec/unit/knife/user_delete_spec.rb +++ b/spec/unit/knife/user_delete_spec.rb @@ -16,18 +16,18 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::UserDelete do let(:knife) { Chef::Knife::UserDelete.new } - let(:user) { double('user_object') } + let(:user) { double("user_object") } let(:stdout) { StringIO.new } before(:each) do Chef::Knife::UserDelete.load_deps - knife.name_args = [ 'my_user' ] + knife.name_args = [ "my_user" ] allow(Chef::UserV1).to receive(:load).and_return(user) - allow(user).to receive(:username).and_return('my_user') + allow(user).to receive(:username).and_return("my_user") allow(knife.ui).to receive(:stderr).and_return(stdout) allow(knife.ui).to receive(:stdout).and_return(stdout) end @@ -50,13 +50,13 @@ describe Chef::Knife::UserDelete do end end - it 'deletes the user' do + it "deletes the user" do #expect(knife).to receive(:delete_object).with(Chef::UserV1, 'my_user') - expect(knife).to receive(:delete_object).with('my_user') + expect(knife).to receive(:delete_object).with("my_user") knife.run end - it 'prints usage and exits when a user name is not provided' do + it "prints usage and exits when a user name is not provided" do knife.name_args = [] expect(knife).to receive(:show_usage) expect(knife.ui).to receive(:fatal) diff --git a/spec/unit/knife/user_edit_spec.rb b/spec/unit/knife/user_edit_spec.rb index a21d982d29..072a27be01 100644 --- a/spec/unit/knife/user_edit_spec.rb +++ b/spec/unit/knife/user_edit_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::UserEdit do let(:knife) { Chef::Knife::UserEdit.new } @@ -28,7 +28,7 @@ describe Chef::Knife::UserEdit do Chef::Knife::UserEdit.load_deps allow(knife.ui).to receive(:stderr).and_return(@stderr) allow(knife.ui).to receive(:stdout).and_return(@stdout) - knife.name_args = [ 'my_user' ] + knife.name_args = [ "my_user" ] knife.config[:disable_editing] = true end @@ -50,14 +50,14 @@ describe Chef::Knife::UserEdit do end end - it 'loads and edits the user' do + it "loads and edits the user" do data = { "username" => "my_user" } allow(Chef::UserV1).to receive(:load).with("my_user").and_return(data) expect(knife).to receive(:edit_data).with(data).and_return(data) knife.run end - it 'prints usage and exits when a user name is not provided' do + it "prints usage and exits when a user name is not provided" do knife.name_args = [] expect(knife).to receive(:show_usage) expect(knife.ui).to receive(:fatal) diff --git a/spec/unit/knife/user_list_spec.rb b/spec/unit/knife/user_list_spec.rb index fa2bac426e..753929e250 100644 --- a/spec/unit/knife/user_list_spec.rb +++ b/spec/unit/knife/user_list_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::UserList do let(:knife) { Chef::Knife::UserList.new } @@ -28,7 +28,7 @@ describe Chef::Knife::UserList do allow(knife.ui).to receive(:stdout).and_return(stdout) end - it 'lists the users' do + it "lists the users" do expect(Chef::UserV1).to receive(:list) expect(knife).to receive(:format_list_for_display) knife.run diff --git a/spec/unit/knife/user_reregister_spec.rb b/spec/unit/knife/user_reregister_spec.rb index 89aa6726cd..1907b5fa50 100644 --- a/spec/unit/knife/user_reregister_spec.rb +++ b/spec/unit/knife/user_reregister_spec.rb @@ -16,20 +16,20 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::UserReregister do let(:knife) { Chef::Knife::UserReregister.new } - let(:user_mock) { double('user_mock', :private_key => "private_key") } + let(:user_mock) { double("user_mock", :private_key => "private_key") } let(:stdout) { StringIO.new } before do Chef::Knife::UserReregister.load_deps - knife.name_args = [ 'a_user' ] + knife.name_args = [ "a_user" ] allow(Chef::UserV1).to receive(:load).and_return(user_mock) allow(knife.ui).to receive(:stdout).and_return(stdout) allow(knife.ui).to receive(:stderr).and_return(stdout) - allow(user_mock).to receive(:username).and_return('a_user') + allow(user_mock).to receive(:username).and_return("a_user") end # delete this once OSC11 support is gone @@ -50,24 +50,24 @@ describe Chef::Knife::UserReregister do end end - it 'prints usage and exits when a user name is not provided' do + it "prints usage and exits when a user name is not provided" do knife.name_args = [] expect(knife).to receive(:show_usage) expect(knife.ui).to receive(:fatal) expect { knife.run }.to raise_error(SystemExit) end - it 'reregisters the user and prints the key' do + it "reregisters the user and prints the key" do expect(user_mock).to receive(:reregister).and_return(user_mock) knife.run expect(stdout.string).to match( /private_key/ ) end - it 'writes the private key to a file when --file is specified' do + it "writes the private key to a file when --file is specified" do expect(user_mock).to receive(:reregister).and_return(user_mock) - knife.config[:file] = '/tmp/a_file' + knife.config[:file] = "/tmp/a_file" filehandle = StringIO.new - expect(File).to receive(:open).with('/tmp/a_file', 'w').and_yield(filehandle) + expect(File).to receive(:open).with("/tmp/a_file", "w").and_yield(filehandle) knife.run expect(filehandle.string).to eq("private_key") end diff --git a/spec/unit/knife/user_show_spec.rb b/spec/unit/knife/user_show_spec.rb index 7c39e428c0..12e8424af2 100644 --- a/spec/unit/knife/user_show_spec.rb +++ b/spec/unit/knife/user_show_spec.rb @@ -16,17 +16,17 @@ # limitations under the License. # -require 'spec_helper' +require "spec_helper" describe Chef::Knife::UserShow do let(:knife) { Chef::Knife::UserShow.new } - let(:user_mock) { double('user_mock') } + let(:user_mock) { double("user_mock") } let(:stdout) { StringIO.new } before do Chef::Knife::UserShow.load_deps - knife.name_args = [ 'my_user' ] - allow(user_mock).to receive(:username).and_return('my_user') + knife.name_args = [ "my_user" ] + allow(user_mock).to receive(:username).and_return("my_user") allow(knife.ui).to receive(:stderr).and_return(stdout) allow(knife.ui).to receive(:stdout).and_return(stdout) end @@ -35,7 +35,7 @@ describe Chef::Knife::UserShow do context "when the username field is not supported by the server" do before do allow(knife).to receive(:run_osc_11_user_show).and_raise(SystemExit) - allow(Chef::UserV1).to receive(:load).with('my_user').and_return(user_mock) + allow(Chef::UserV1).to receive(:load).with("my_user").and_return(user_mock) allow(user_mock).to receive(:username).and_return(nil) end @@ -50,13 +50,13 @@ describe Chef::Knife::UserShow do end end - it 'loads and displays the user' do - expect(Chef::UserV1).to receive(:load).with('my_user').and_return(user_mock) + it "loads and displays the user" do + expect(Chef::UserV1).to receive(:load).with("my_user").and_return(user_mock) expect(knife).to receive(:format_for_display).with(user_mock) knife.run end - it 'prints usage and exits when a user name is not provided' do + it "prints usage and exits when a user name is not provided" do knife.name_args = [] expect(knife).to receive(:show_usage) expect(knife.ui).to receive(:fatal) |