summaryrefslogtreecommitdiff
path: root/spec/unit/knife
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/knife')
-rw-r--r--spec/unit/knife/bootstrap_spec.rb164
-rw-r--r--spec/unit/knife/client_bulk_delete_spec.rb48
-rw-r--r--spec/unit/knife/client_create_spec.rb34
-rw-r--r--spec/unit/knife/client_delete_spec.rb30
-rw-r--r--spec/unit/knife/client_edit_spec.rb8
-rw-r--r--spec/unit/knife/client_list_spec.rb4
-rw-r--r--spec/unit/knife/client_reregister_spec.rb18
-rw-r--r--spec/unit/knife/configure_client_spec.rb40
-rw-r--r--spec/unit/knife/configure_spec.rb170
-rw-r--r--spec/unit/knife/cookbook_bulk_delete_spec.rb30
-rw-r--r--spec/unit/knife/cookbook_create_spec.rb118
-rw-r--r--spec/unit/knife/cookbook_delete_spec.rb98
-rw-r--r--spec/unit/knife/cookbook_download_spec.rb112
-rw-r--r--spec/unit/knife/cookbook_list_spec.rb18
-rw-r--r--spec/unit/knife/cookbook_metadata_from_file_spec.rb16
-rw-r--r--spec/unit/knife/cookbook_metadata_spec.rb88
-rw-r--r--spec/unit/knife/cookbook_show_spec.rb58
-rw-r--r--spec/unit/knife/cookbook_site_download_spec.rb50
-rw-r--r--spec/unit/knife/cookbook_site_install_spec.rb76
-rw-r--r--spec/unit/knife/cookbook_site_share_spec.rb110
-rw-r--r--spec/unit/knife/cookbook_site_unshare_spec.rb30
-rw-r--r--spec/unit/knife/cookbook_test_spec.rb32
-rw-r--r--spec/unit/knife/cookbook_upload_spec.rb122
-rw-r--r--spec/unit/knife/core/bootstrap_context_spec.rb44
-rw-r--r--spec/unit/knife/core/cookbook_scm_repo_spec.rb72
-rw-r--r--spec/unit/knife/core/object_loader_spec.rb6
-rw-r--r--spec/unit/knife/core/subcommand_loader_spec.rb64
-rw-r--r--spec/unit/knife/core/ui_spec.rb144
-rw-r--r--spec/unit/knife/data_bag_from_file_spec.rb2
-rw-r--r--spec/unit/knife/environment_compare_spec.rb24
-rw-r--r--spec/unit/knife/environment_create_spec.rb32
-rw-r--r--spec/unit/knife/environment_delete_spec.rb28
-rw-r--r--spec/unit/knife/environment_edit_spec.rb30
-rw-r--r--spec/unit/knife/environment_from_file_spec.rb34
-rw-r--r--spec/unit/knife/environment_list_spec.rb14
-rw-r--r--spec/unit/knife/environment_show_spec.rb20
-rw-r--r--spec/unit/knife/index_rebuild_spec.rb34
-rw-r--r--spec/unit/knife/knife_help.rb48
-rw-r--r--spec/unit/knife/node_bulk_delete_spec.rb28
-rw-r--r--spec/unit/knife/node_delete_spec.rb22
-rw-r--r--spec/unit/knife/node_edit_spec.rb34
-rw-r--r--spec/unit/knife/node_environment_set_spec.rb24
-rw-r--r--spec/unit/knife/node_from_file_spec.rb16
-rw-r--r--spec/unit/knife/node_list_spec.rb18
-rw-r--r--spec/unit/knife/node_run_list_add_spec.rb58
-rw-r--r--spec/unit/knife/node_run_list_remove_spec.rb20
-rw-r--r--spec/unit/knife/node_run_list_set_spec.rb54
-rw-r--r--spec/unit/knife/role_bulk_delete_spec.rb24
-rw-r--r--spec/unit/knife/role_create_spec.rb24
-rw-r--r--spec/unit/knife/role_delete_spec.rb20
-rw-r--r--spec/unit/knife/role_edit_spec.rb26
-rw-r--r--spec/unit/knife/role_from_file_spec.rb20
-rw-r--r--spec/unit/knife/role_list_spec.rb14
-rw-r--r--spec/unit/knife/ssh_spec.rb132
-rw-r--r--spec/unit/knife/ssl_check_spec.rb54
-rw-r--r--spec/unit/knife/ssl_fetch_spec.rb12
-rw-r--r--spec/unit/knife/status_spec.rb10
-rw-r--r--spec/unit/knife/tag_create_spec.rb10
-rw-r--r--spec/unit/knife/tag_delete_spec.rb12
-rw-r--r--spec/unit/knife/tag_list_spec.rb8
-rw-r--r--spec/unit/knife/user_create_spec.rb36
-rw-r--r--spec/unit/knife/user_delete_spec.rb8
-rw-r--r--spec/unit/knife/user_edit_spec.rb14
-rw-r--r--spec/unit/knife/user_list_spec.rb4
-rw-r--r--spec/unit/knife/user_reregister_spec.rb20
-rw-r--r--spec/unit/knife/user_show_spec.rb10
66 files changed, 1401 insertions, 1401 deletions
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index 2599e44a56..4de2b4531d 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -23,7 +23,7 @@ require 'net/ssh'
describe Chef::Knife::Bootstrap do
before do
- Chef::Platform.stub(:windows?) { false }
+ allow(Chef::Platform).to receive(:windows?) { false }
end
let(:knife) do
Chef::Log.logger = Logger.new(StringIO.new)
@@ -32,7 +32,7 @@ describe Chef::Knife::Bootstrap do
k = Chef::Knife::Bootstrap.new
k.merge_configs
- k.ui.stub(:stderr).and_return(stderr)
+ allow(k.ui).to receive(:stderr).and_return(stderr)
allow(k).to receive(:encryption_secret_provided_ignore_encrypt_flag?).and_return(false)
k
end
@@ -42,8 +42,8 @@ describe Chef::Knife::Bootstrap do
let(:bootstrap_template) { nil }
it "should use chef-full as default template" do
- knife.bootstrap_template.should be_a_kind_of(String)
- File.basename(knife.bootstrap_template).should eq("chef-full")
+ expect(knife.bootstrap_template).to be_a_kind_of(String)
+ expect(File.basename(knife.bootstrap_template)).to eq("chef-full")
end
context "when finding templates" do
@@ -52,7 +52,7 @@ describe Chef::Knife::Bootstrap do
let(:bootstrap_template) { "/opt/blah/not/exists/template.erb" }
it "raises an error" do
- lambda { knife.find_template }.should raise_error
+ expect { knife.find_template }.to raise_error
end
end
@@ -60,8 +60,8 @@ describe Chef::Knife::Bootstrap do
let(:bootstrap_template) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")) }
it "loads the given file as the template" do
- Chef::Log.should_receive(:debug)
- knife.find_template.should eq(File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")))
+ expect(Chef::Log).to receive(:debug)
+ expect(knife.find_template).to eq(File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")))
end
end
end
@@ -78,7 +78,7 @@ describe Chef::Knife::Bootstrap do
let(:gem_files_template_path) { "/Users/schisamo/.rvm/gems/ruby-1.9.2-p180@chef-0.10/gems/knife-windows-0.5.4/lib/chef/knife/bootstrap/fake-bootstrap-template.erb" }
def configure_chef_config_dir
- Chef::Knife.stub(:chef_config_dir).and_return("/knife/chef/config")
+ allow(Chef::Knife).to receive(:chef_config_dir).and_return("/knife/chef/config")
end
def configure_env_home
@@ -86,13 +86,13 @@ describe Chef::Knife::Bootstrap do
end
def configure_gem_files
- Gem.stub(:find_files).and_return([ gem_files_template_path ])
+ allow(Gem).to receive(:find_files).and_return([ gem_files_template_path ])
end
before(:each) do
@original_home = ENV['HOME']
ENV['HOME'] = nil
- File.should_receive(:exists?).with(bootstrap_template).and_return(false)
+ expect(File).to receive(:exists?).with(bootstrap_template).and_return(false)
end
after(:each) do
@@ -105,11 +105,11 @@ describe Chef::Knife::Bootstrap do
configure_env_home
configure_gem_files
- File.should_receive(:exists?).with(builtin_template_path).and_return(true)
+ expect(File).to receive(:exists?).with(builtin_template_path).and_return(true)
end
it "should load the template from built-in templates" do
- knife.find_template.should eq(builtin_template_path)
+ expect(knife.find_template).to eq(builtin_template_path)
end
end
@@ -119,8 +119,8 @@ describe Chef::Knife::Bootstrap do
configure_env_home
configure_gem_files
- File.should_receive(:exists?).with(builtin_template_path).and_return(false)
- File.should_receive(:exists?).with(chef_config_dir_template_path).and_return(true)
+ expect(File).to receive(:exists?).with(builtin_template_path).and_return(false)
+ expect(File).to receive(:exists?).with(chef_config_dir_template_path).and_return(true)
it "should load the template from chef_config_dir" do
knife.find_template.should eq(chef_config_dir_template_path)
@@ -134,13 +134,13 @@ describe Chef::Knife::Bootstrap do
configure_env_home
configure_gem_files
- File.should_receive(:exists?).with(builtin_template_path).and_return(false)
- File.should_receive(:exists?).with(chef_config_dir_template_path).and_return(false)
- File.should_receive(:exists?).with(env_home_template_path).and_return(true)
+ expect(File).to receive(:exists?).with(builtin_template_path).and_return(false)
+ expect(File).to receive(:exists?).with(chef_config_dir_template_path).and_return(false)
+ expect(File).to receive(:exists?).with(env_home_template_path).and_return(true)
end
it "should load the template from chef_config_dir" do
- knife.find_template.should eq(env_home_template_path)
+ expect(knife.find_template).to eq(env_home_template_path)
end
end
@@ -149,13 +149,13 @@ describe Chef::Knife::Bootstrap do
configure_chef_config_dir
configure_gem_files
- File.should_receive(:exists?).with(builtin_template_path).and_return(false)
- File.should_receive(:exists?).with(chef_config_dir_template_path).and_return(false)
- File.should_receive(:exists?).with(gem_files_template_path).and_return(true)
+ expect(File).to receive(:exists?).with(builtin_template_path).and_return(false)
+ expect(File).to receive(:exists?).with(chef_config_dir_template_path).and_return(false)
+ expect(File).to receive(:exists?).with(gem_files_template_path).and_return(true)
end
it "should load the template from Gem files" do
- knife.find_template.should eq(gem_files_template_path)
+ expect(knife.find_template).to eq(gem_files_template_path)
end
end
end
@@ -166,7 +166,7 @@ describe Chef::Knife::Bootstrap do
it "sets the knife :bootstrap_template config" do
knife.parse_options([t,"blahblah"])
knife.merge_configs
- knife.bootstrap_template.should eq("blahblah")
+ expect(knife.bootstrap_template).to eq("blahblah")
end
end
end
@@ -175,19 +175,19 @@ describe Chef::Knife::Bootstrap do
let(:bootstrap_template) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")) }
it "should return an empty run_list" do
- knife.render_template.should == '{"run_list":[]}'
+ expect(knife.render_template).to eq('{"run_list":[]}')
end
it "should have role[base] in the run_list" do
knife.parse_options(["-r","role[base]"])
knife.merge_configs
- knife.render_template.should == '{"run_list":["role[base]"]}'
+ expect(knife.render_template).to eq('{"run_list":["role[base]"]}')
end
it "should have role[base] and recipe[cupcakes] in the run_list" do
knife.parse_options(["-r", "role[base],recipe[cupcakes]"])
knife.merge_configs
- knife.render_template.should == '{"run_list":["role[base]","recipe[cupcakes]"]}'
+ expect(knife.render_template).to eq('{"run_list":["role[base]","recipe[cupcakes]"]}')
end
it "should have foo => {bar => baz} in the first_boot" do
@@ -195,7 +195,7 @@ describe Chef::Knife::Bootstrap do
knife.merge_configs
expected_hash = FFI_Yajl::Parser.new.parse('{"foo":{"bar":"baz"},"run_list":[]}')
actual_hash = FFI_Yajl::Parser.new.parse(knife.render_template)
- actual_hash.should == expected_hash
+ expect(actual_hash).to eq(expected_hash)
end
end
@@ -205,14 +205,14 @@ describe Chef::Knife::Bootstrap do
it "should create a hint file when told to" do
knife.parse_options(["--hint", "openstack"])
knife.merge_configs
- knife.render_template.should match /\/etc\/chef\/ohai\/hints\/openstack.json/
+ expect(knife.render_template).to match /\/etc\/chef\/ohai\/hints\/openstack.json/
end
it "should populate a hint file with JSON when given a file to read" do
- ::File.stub(:read).and_return('{ "foo" : "bar" }')
+ allow(::File).to receive(:read).and_return('{ "foo" : "bar" }')
knife.parse_options(["--hint", "openstack=hints/openstack.json"])
knife.merge_configs
- knife.render_template.should match /\{\"foo\":\"bar\"\}/
+ expect(knife.render_template).to match /\{\"foo\":\"bar\"\}/
end
end
@@ -235,7 +235,7 @@ describe Chef::Knife::Bootstrap do
let(:setting) { "api.opscode.com" }
it "renders the client.rb with a single FQDN no_proxy entry" do
- rendered_template.should match(%r{.*no_proxy\s*"api.opscode.com".*})
+ expect(rendered_template).to match(%r{.*no_proxy\s*"api.opscode.com".*})
end
end
@@ -243,7 +243,7 @@ describe Chef::Knife::Bootstrap do
let(:setting) { "api.opscode.com,172.16.10.*" }
it "renders the client.rb with comma-separated FQDN and wildcard IP address no_proxy entries" do
- rendered_template.should match(%r{.*no_proxy\s*"api.opscode.com,172.16.10.\*".*})
+ expect(rendered_template).to match(%r{.*no_proxy\s*"api.opscode.com,172.16.10.\*".*})
end
end
@@ -251,7 +251,7 @@ describe Chef::Knife::Bootstrap do
let(:options) { ["--node-ssl-verify-mode", "none"] }
it "renders the client.rb with ssl_verify_mode set to :verify_none" do
- rendered_template.should match(/ssl_verify_mode :verify_none/)
+ expect(rendered_template).to match(/ssl_verify_mode :verify_none/)
end
end
@@ -259,7 +259,7 @@ describe Chef::Knife::Bootstrap do
let(:options) { ["--node-ssl-verify-mode", "peer"] }
it "renders the client.rb with ssl_verify_mode set to :verify_peer" do
- rendered_template.should match(/ssl_verify_mode :verify_peer/)
+ expect(rendered_template).to match(/ssl_verify_mode :verify_peer/)
end
end
@@ -267,7 +267,7 @@ describe Chef::Knife::Bootstrap do
let(:options) { ["--node-ssl-verify-mode", "all"] }
it "raises error" do
- lambda{ rendered_template }.should raise_error
+ expect{ rendered_template }.to raise_error
end
end
@@ -275,7 +275,7 @@ describe Chef::Knife::Bootstrap do
let(:options) { ["--node-verify-api-cert"] }
it "renders the client.rb with verify_api_cert set to true" do
- rendered_template.should match(/verify_api_cert true/)
+ expect(rendered_template).to match(/verify_api_cert true/)
end
end
@@ -283,7 +283,7 @@ describe Chef::Knife::Bootstrap do
let(:options) { ["--no-node-verify-api-cert"] }
it "renders the client.rb with verify_api_cert set to false" do
- rendered_template.should match(/verify_api_cert false/)
+ expect(rendered_template).to match(/verify_api_cert false/)
end
end
end
@@ -301,13 +301,13 @@ describe Chef::Knife::Bootstrap do
it "creates a secret file" do
expect(knife).to receive(:encryption_secret_provided_ignore_encrypt_flag?).and_return(true)
expect(knife).to receive(:read_secret).and_return(secret)
- rendered_template.should match(%r{#{secret}})
+ expect(rendered_template).to match(%r{#{secret}})
end
it "renders the client.rb with an encrypted_data_bag_secret entry" do
expect(knife).to receive(:encryption_secret_provided_ignore_encrypt_flag?).and_return(true)
expect(knife).to receive(:read_secret).and_return(secret)
- rendered_template.should match(%r{encrypted_data_bag_secret\s*"/etc/chef/encrypted_data_bag_secret"})
+ expect(rendered_template).to match(%r{encrypted_data_bag_secret\s*"/etc/chef/encrypted_data_bag_secret"})
end
end
@@ -322,8 +322,8 @@ describe Chef::Knife::Bootstrap do
before do
Chef::Config[:trusted_certs_dir] = trusted_certs_dir
- IO.stub(:read).and_call_original
- IO.stub(:read).with(File.expand_path(Chef::Config[:validation_key])).and_return("")
+ allow(IO).to receive(:read).and_call_original
+ allow(IO).to receive(:read).with(File.expand_path(Chef::Config[:validation_key])).and_return("")
end
def certificates
@@ -331,22 +331,22 @@ describe Chef::Knife::Bootstrap do
end
it "creates /etc/chef/trusted_certs" do
- rendered_template.should match(%r{mkdir -p /etc/chef/trusted_certs})
+ expect(rendered_template).to match(%r{mkdir -p /etc/chef/trusted_certs})
end
it "copies the certificates in the directory" do
certificates.each do |cert|
- IO.should_receive(:read).with(File.expand_path(cert))
+ expect(IO).to receive(:read).with(File.expand_path(cert))
end
certificates.each do |cert|
- rendered_template.should match(%r{cat > /etc/chef/trusted_certs/#{File.basename(cert)} <<'EOP'})
+ expect(rendered_template).to match(%r{cat > /etc/chef/trusted_certs/#{File.basename(cert)} <<'EOP'})
end
end
it "doesn't create /etc/chef/trusted_certs if :trusted_certs_dir is empty" do
- Dir.should_receive(:glob).with(File.join(trusted_certs_dir, "*.{crt,pem}")).and_return([])
- rendered_template.should_not match(%r{mkdir -p /etc/chef/trusted_certs})
+ expect(Dir).to receive(:glob).with(File.join(trusted_certs_dir, "*.{crt,pem}")).and_return([])
+ expect(rendered_template).not_to match(%r{mkdir -p /etc/chef/trusted_certs})
end
end
@@ -361,57 +361,57 @@ describe Chef::Knife::Bootstrap do
Chef::Config[:knife][:ssh_port] = nil
knife.config[:forward_agent] = true
knife.config[:identity_file] = "~/.ssh/me.rsa"
- knife.stub(:render_template).and_return("")
+ allow(knife).to receive(:render_template).and_return("")
knife.knife_ssh
end
it "configures the hostname" do
- knife_ssh.name_args.first.should == "foo.example.com"
+ expect(knife_ssh.name_args.first).to eq("foo.example.com")
end
it "configures the ssh user" do
- knife_ssh.config[:ssh_user].should == 'rooty'
+ expect(knife_ssh.config[:ssh_user]).to eq('rooty')
end
it "configures the ssh password" do
- knife_ssh.config[:ssh_password].should == 'open_sesame'
+ expect(knife_ssh.config[:ssh_password]).to eq('open_sesame')
end
it "configures the ssh port" do
- knife_ssh.config[:ssh_port].should == '4001'
+ expect(knife_ssh.config[:ssh_port]).to eq('4001')
end
it "configures the ssh agent forwarding" do
- knife_ssh.config[:forward_agent].should == true
+ expect(knife_ssh.config[:forward_agent]).to eq(true)
end
it "configures the ssh identity file" do
- knife_ssh.config[:identity_file].should == '~/.ssh/me.rsa'
+ expect(knife_ssh.config[:identity_file]).to eq('~/.ssh/me.rsa')
end
end
context "validating use_sudo_password" do
before do
knife.config[:ssh_password] = "password"
- knife.stub(:render_template).and_return("")
+ allow(knife).to receive(:render_template).and_return("")
end
it "use_sudo_password contains description and long params for help" do
- knife.options.should have_key(:use_sudo_password) \
- and knife.options[:use_sudo_password][:description].to_s.should_not == ''\
- and knife.options[:use_sudo_password][:long].to_s.should_not == ''
+ 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('')
end
it "uses the password from --ssh-password for sudo when --use-sudo-password is set" do
knife.config[:use_sudo] = true
knife.config[:use_sudo_password] = true
- knife.ssh_command.should include("echo \'#{knife.config[:ssh_password]}\' | sudo -S")
+ expect(knife.ssh_command).to include("echo \'#{knife.config[:ssh_password]}\' | sudo -S")
end
it "should not honor --use-sudo-password when --use-sudo is not set" do
knife.config[:use_sudo] = false
knife.config[:use_sudo_password] = true
- knife.ssh_command.should_not include("echo #{knife.config[:ssh_password]} | sudo -S")
+ expect(knife.ssh_command).not_to include("echo #{knife.config[:ssh_password]} | sudo -S")
end
end
@@ -424,34 +424,34 @@ describe Chef::Knife::Bootstrap do
Chef::Config[:knife][:identity_file] = "~/.ssh/you.rsa"
Chef::Config[:knife][:ssh_gateway] = "towel.blinkenlights.nl"
Chef::Config[:knife][:host_key_verify] = true
- knife.stub(:render_template).and_return("")
+ allow(knife).to receive(:render_template).and_return("")
knife.config = {}
knife.merge_configs
knife.knife_ssh
end
it "configures the ssh user" do
- knife_ssh.config[:ssh_user].should == 'curiosity'
+ expect(knife_ssh.config[:ssh_user]).to eq('curiosity')
end
it "configures the ssh port" do
- knife_ssh.config[:ssh_port].should == '2430'
+ expect(knife_ssh.config[:ssh_port]).to eq('2430')
end
it "configures the ssh agent forwarding" do
- knife_ssh.config[:forward_agent].should == true
+ expect(knife_ssh.config[:forward_agent]).to eq(true)
end
it "configures the ssh identity file" do
- knife_ssh.config[:identity_file].should == '~/.ssh/you.rsa'
+ expect(knife_ssh.config[:identity_file]).to eq('~/.ssh/you.rsa')
end
it "configures the ssh gateway" do
- knife_ssh.config[:ssh_gateway].should == 'towel.blinkenlights.nl'
+ expect(knife_ssh.config[:ssh_gateway]).to eq('towel.blinkenlights.nl')
end
it "configures the host key verify mode" do
- knife_ssh.config[:host_key_verify].should == true
+ expect(knife_ssh.config[:host_key_verify]).to eq(true)
end
end
@@ -460,27 +460,27 @@ describe Chef::Knife::Bootstrap do
knife.name_args = ["foo.example.com"]
knife.config[:ssh_user] = "rooty"
knife.config[:identity_file] = "~/.ssh/me.rsa"
- knife.stub(:render_template).and_return("")
+ allow(knife).to receive(:render_template).and_return("")
k = knife.knife_ssh
- k.stub(:get_password).and_return('typed_in_password')
- knife.stub(:knife_ssh).and_return(k)
+ 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
- knife_ssh_with_password_auth.config[:ssh_password].should == '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
- knife_ssh_with_password_auth.config[:identity_file].should be_nil
+ expect(knife_ssh_with_password_auth.config[:identity_file]).to be_nil
end
end
end
it "verifies that a server to bootstrap was given as a command line arg" do
knife.name_args = nil
- lambda { knife.run }.should raise_error(SystemExit)
- stderr.string.should match /ERROR:.+FQDN or ip/
+ expect { knife.run }.to raise_error(SystemExit)
+ expect(stderr.string).to match /ERROR:.+FQDN or ip/
end
describe "when running the bootstrap" do
@@ -488,31 +488,31 @@ describe Chef::Knife::Bootstrap do
knife.name_args = ["foo.example.com"]
knife.config[:ssh_user] = "rooty"
knife.config[:identity_file] = "~/.ssh/me.rsa"
- knife.stub(:render_template).and_return("")
+ allow(knife).to receive(:render_template).and_return("")
knife_ssh = knife.knife_ssh
- knife.stub(:knife_ssh).and_return(knife_ssh)
+ allow(knife).to receive(:knife_ssh).and_return(knife_ssh)
knife_ssh
end
it "configures the underlying ssh command and then runs it" do
- knife_ssh.should_receive(:run)
+ expect(knife_ssh).to receive(:run)
knife.run
end
it "falls back to password based auth when auth fails the first time" do
- knife.stub(:puts)
+ allow(knife).to receive(:puts)
fallback_knife_ssh = knife_ssh.dup
- knife_ssh.should_receive(:run).and_raise(Net::SSH::AuthenticationFailed.new("no ssh for you"))
- knife.stub(:knife_ssh_with_password_auth).and_return(fallback_knife_ssh)
- fallback_knife_ssh.should_receive(:run)
+ expect(knife_ssh).to receive(:run).and_raise(Net::SSH::AuthenticationFailed.new("no ssh for you"))
+ allow(knife).to receive(:knife_ssh_with_password_auth).and_return(fallback_knife_ssh)
+ expect(fallback_knife_ssh).to receive(:run)
knife.run
end
it "raises the exception if config[:ssh_password] is set and an authentication exception is raised" do
knife.config[:ssh_password] = "password"
- knife_ssh.should_receive(:run).and_raise(Net::SSH::AuthenticationFailed)
- lambda { knife.run }.should raise_error(Net::SSH::AuthenticationFailed)
+ expect(knife_ssh).to receive(:run).and_raise(Net::SSH::AuthenticationFailed)
+ expect { knife.run }.to raise_error(Net::SSH::AuthenticationFailed)
end
end
diff --git a/spec/unit/knife/client_bulk_delete_spec.rb b/spec/unit/knife/client_bulk_delete_spec.rb
index d5cfda9885..45bb4dd16c 100644
--- a/spec/unit/knife/client_bulk_delete_spec.rb
+++ b/spec/unit/knife/client_bulk_delete_spec.rb
@@ -28,10 +28,10 @@ describe Chef::Knife::ClientBulkDelete do
k = Chef::Knife::ClientBulkDelete.new
k.name_args = name_args
k.config = option_args
- k.ui.stub(:stdout).and_return(stdout_io)
- k.ui.stub(:stderr).and_return(stderr_io)
- k.ui.stub(:confirm).and_return(knife_confirm)
- k.ui.stub(:confirm_without_exit).and_return(knife_confirm)
+ allow(k.ui).to receive(:stdout).and_return(stdout_io)
+ allow(k.ui).to receive(:stderr).and_return(stderr_io)
+ allow(k.ui).to receive(:confirm).and_return(knife_confirm)
+ allow(k.ui).to receive(:confirm_without_exit).and_return(knife_confirm)
k
}
@@ -47,7 +47,7 @@ describe Chef::Knife::ClientBulkDelete do
nonvalidator_client_names.each do |client_name|
client = Chef::ApiClient.new()
client.name(client_name)
- client.stub(:destroy).and_return(true)
+ allow(client).to receive(:destroy).and_return(true)
clients[client_name] = client
end
@@ -61,8 +61,8 @@ describe Chef::Knife::ClientBulkDelete do
validator_client_names.each do |validator_client_name|
validator_client = Chef::ApiClient.new()
validator_client.name(validator_client_name)
- validator_client.stub(:validator).and_return(true)
- validator_client.stub(:destroy).and_return(true)
+ allow(validator_client).to receive(:validator).and_return(true)
+ allow(validator_client).to receive(:destroy).and_return(true)
clients[validator_client_name] = validator_client
end
@@ -75,7 +75,7 @@ describe Chef::Knife::ClientBulkDelete do
}
before(:each) do
- Chef::ApiClient.stub(:list).and_return(clients)
+ allow(Chef::ApiClient).to receive(:list).and_return(clients)
end
describe "run" do
@@ -83,44 +83,44 @@ describe Chef::Knife::ClientBulkDelete do
let(:name_args) { [ ] }
it "should exit if the regex is not provided" do
- lambda { knife.run }.should raise_error(SystemExit)
+ expect { knife.run }.to raise_error(SystemExit)
end
end
describe "with any clients" do
it "should get the list of the clients" do
- Chef::ApiClient.should_receive(:list)
+ expect(Chef::ApiClient).to receive(:list)
knife.run
end
it "should print the name of the clients" do
knife.run
client_names.each do |client_name|
- stdout.should include(client_name)
+ expect(stdout).to include(client_name)
end
end
it "should confirm you really want to delete them" do
- knife.ui.should_receive(:confirm)
+ expect(knife.ui).to receive(:confirm)
knife.run
end
describe "without --delete-validators" do
it "should mention that validator clients wont be deleted" do
knife.run
- stdout.should include("Following clients are validators and will not be deleted.")
+ expect(stdout).to include("Following clients are validators and will not be deleted.")
info = stdout.index "Following clients are validators and will not be deleted."
val = stdout.index "myorg-validator"
- (val > info).should be_true
+ expect(val > info).to be_truthy
end
it "should only delete nonvalidator clients" do
nonvalidator_clients.each_value do |c|
- c.should_receive(:destroy)
+ expect(c).to receive(:destroy)
end
validator_clients.each_value do |c|
- c.should_not_receive(:destroy)
+ expect(c).not_to receive(:destroy)
end
knife.run
@@ -132,18 +132,18 @@ describe Chef::Knife::ClientBulkDelete do
it "should mention that validator clients will be deleted" do
knife.run
- stdout.should include("The following validators will be deleted")
+ expect(stdout).to include("The following validators will be deleted")
end
it "should confirm twice" do
- knife.ui.should_receive(:confirm).once
- knife.ui.should_receive(:confirm_without_exit).once
+ expect(knife.ui).to receive(:confirm).once
+ expect(knife.ui).to receive(:confirm_without_exit).once
knife.run
end
it "should delete all clients" do
clients.each_value do |c|
- c.should_receive(:destroy)
+ expect(c).to receive(:destroy)
end
knife.run
@@ -155,10 +155,10 @@ describe Chef::Knife::ClientBulkDelete do
let(:name_args) { [ "^ti" ] }
it "should only delete clients that match the regex" do
- clients["tim"].should_receive(:destroy)
- clients["stephen"].should_not_receive(:destroy)
- clients["dan"].should_not_receive(:destroy)
- clients["myorg-validator"].should_not_receive(:destroy)
+ expect(clients["tim"]).to receive(:destroy)
+ expect(clients["stephen"]).not_to receive(:destroy)
+ expect(clients["dan"]).not_to receive(:destroy)
+ expect(clients["myorg-validator"]).not_to receive(:destroy)
knife.run
end
end
diff --git a/spec/unit/knife/client_create_spec.rb b/spec/unit/knife/client_create_spec.rb
index 59238d69ec..8e7cc4a5e3 100644
--- a/spec/unit/knife/client_create_spec.rb
+++ b/spec/unit/knife/client_create_spec.rb
@@ -31,53 +31,53 @@ describe Chef::Knife::ClientCreate do
}
@knife.name_args = [ "adam" ]
@client = Chef::ApiClient.new
- @client.stub(:save).and_return({ 'private_key' => '' })
- @knife.stub(:edit_data).and_return(@client)
- @knife.stub(:puts)
- Chef::ApiClient.stub(:new).and_return(@client)
+ allow(@client).to receive(:save).and_return({ 'private_key' => '' })
+ allow(@knife).to receive(:edit_data).and_return(@client)
+ allow(@knife).to receive(:puts)
+ allow(Chef::ApiClient).to receive(:new).and_return(@client)
@stderr = StringIO.new
- @knife.ui.stub(:stderr).and_return(@stderr)
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
end
describe "run" do
it "should create a new Client" do
- Chef::ApiClient.should_receive(:new).and_return(@client)
+ expect(Chef::ApiClient).to receive(:new).and_return(@client)
@knife.run
- @stderr.string.should match /created client.+adam/i
+ expect(@stderr.string).to match /created client.+adam/i
end
it "should set the Client name" do
- @client.should_receive(:name).with("adam")
+ expect(@client).to receive(:name).with("adam")
@knife.run
end
it "by default it is not an admin" do
- @client.should_receive(:admin).with(false)
+ expect(@client).to receive(:admin).with(false)
@knife.run
end
it "by default it is not a validator" do
- @client.should_receive(:validator).with(false)
+ expect(@client).to receive(:validator).with(false)
@knife.run
end
it "should allow you to edit the data" do
- @knife.should_receive(:edit_data).with(@client)
+ expect(@knife).to receive(:edit_data).with(@client)
@knife.run
end
it "should save the Client" do
- @client.should_receive(:save)
+ expect(@client).to receive(:save)
@knife.run
end
describe "with -f or --file" do
it "should write the private key to a file" do
@knife.config[:file] = "/tmp/monkeypants"
- @client.stub(:save).and_return({ 'private_key' => "woot" })
+ allow(@client).to receive(:save).and_return({ 'private_key' => "woot" })
filehandle = double("Filehandle")
- filehandle.should_receive(:print).with('woot')
- File.should_receive(:open).with("/tmp/monkeypants", "w").and_yield(filehandle)
+ expect(filehandle).to receive(:print).with('woot')
+ expect(File).to receive(:open).with("/tmp/monkeypants", "w").and_yield(filehandle)
@knife.run
end
end
@@ -85,7 +85,7 @@ describe Chef::Knife::ClientCreate do
describe "with -a or --admin" do
it "should create an admin client" do
@knife.config[:admin] = true
- @client.should_receive(:admin).with(true)
+ expect(@client).to receive(:admin).with(true)
@knife.run
end
end
@@ -93,7 +93,7 @@ describe Chef::Knife::ClientCreate do
describe "with --validator" do
it "should create an validator client" do
@knife.config[:validator] = true
- @client.should_receive(:validator).with(true)
+ expect(@client).to receive(:validator).with(true)
@knife.run
end
end
diff --git a/spec/unit/knife/client_delete_spec.rb b/spec/unit/knife/client_delete_spec.rb
index c7908a0934..0fb5e0bab7 100644
--- a/spec/unit/knife/client_delete_spec.rb
+++ b/spec/unit/knife/client_delete_spec.rb
@@ -30,52 +30,52 @@ describe Chef::Knife::ClientDelete do
describe 'run' do
it 'should delete the client' do
- @knife.should_receive(:delete_object).with(Chef::ApiClient, 'adam', 'client')
+ expect(@knife).to receive(:delete_object).with(Chef::ApiClient, 'adam', 'client')
@knife.run
end
it 'should print usage and exit when a client name is not provided' do
@knife.name_args = []
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife).to receive(:show_usage)
+ expect(@knife.ui).to receive(:fatal)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
describe 'with a validator' do
before(:each) do
- Chef::Knife::UI.stub(:confirm).and_return(true)
- @knife.stub(:confirm).and_return(true)
+ allow(Chef::Knife::UI).to receive(:confirm).and_return(true)
+ allow(@knife).to receive(:confirm).and_return(true)
@client = Chef::ApiClient.new
- Chef::ApiClient.should_receive(:load).and_return(@client)
+ expect(Chef::ApiClient).to receive(:load).and_return(@client)
end
it 'should delete non-validator client if --delete-validators is not set' do
@knife.config[:delete_validators] = false
- @client.should_receive(:destroy).and_return(@client)
- @knife.should_receive(:msg)
+ expect(@client).to receive(:destroy).and_return(@client)
+ expect(@knife).to receive(:msg)
@knife.run
end
it 'should delete non-validator client if --delete-validators is set' do
@knife.config[:delete_validators] = true
- @client.should_receive(:destroy).and_return(@client)
- @knife.should_receive(:msg)
+ expect(@client).to receive(:destroy).and_return(@client)
+ expect(@knife).to receive(:msg)
@knife.run
end
it 'should not delete validator client if --delete-validators is not set' do
@client.validator(true)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run}.should raise_error(SystemExit)
+ 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
@knife.config[:delete_validators] = true
- @client.should_receive(:destroy).and_return(@client)
- @knife.should_receive(:msg)
+ expect(@client).to receive(:destroy).and_return(@client)
+ expect(@knife).to receive(:msg)
@knife.run
end
diff --git a/spec/unit/knife/client_edit_spec.rb b/spec/unit/knife/client_edit_spec.rb
index 1d7049be30..c040c5e2f2 100644
--- a/spec/unit/knife/client_edit_spec.rb
+++ b/spec/unit/knife/client_edit_spec.rb
@@ -26,15 +26,15 @@ describe Chef::Knife::ClientEdit do
describe 'run' do
it 'should edit the client' do
- @knife.should_receive(:edit_object).with(Chef::ApiClient, 'adam')
+ expect(@knife).to receive(:edit_object).with(Chef::ApiClient, 'adam')
@knife.run
end
it 'should print usage and exit when a client name is not provided' do
@knife.name_args = []
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife).to receive(:show_usage)
+ expect(@knife.ui).to receive(:fatal)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
end
diff --git a/spec/unit/knife/client_list_spec.rb b/spec/unit/knife/client_list_spec.rb
index c4834ad8d1..eff01da4e9 100644
--- a/spec/unit/knife/client_list_spec.rb
+++ b/spec/unit/knife/client_list_spec.rb
@@ -26,8 +26,8 @@ describe Chef::Knife::ClientList do
describe 'run' do
it 'should list the clients' do
- Chef::ApiClient.should_receive(:list)
- @knife.should_receive(:format_list_for_display)
+ expect(Chef::ApiClient).to receive(:list)
+ expect(@knife).to receive(:format_list_for_display)
@knife.run
end
end
diff --git a/spec/unit/knife/client_reregister_spec.rb b/spec/unit/knife/client_reregister_spec.rb
index daf18d5d25..f1be4ed570 100644
--- a/spec/unit/knife/client_reregister_spec.rb
+++ b/spec/unit/knife/client_reregister_spec.rb
@@ -24,7 +24,7 @@ describe Chef::Knife::ClientReregister do
@knife.name_args = [ 'adam' ]
@client_mock = double('client_mock', :private_key => "foo_key")
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
context "when no client name is given on the command line" do
@@ -33,29 +33,29 @@ describe Chef::Knife::ClientReregister do
end
it 'should print usage and exit when a client name is not provided' do
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ 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
- Chef::ApiClient.should_receive(:reregister).with('adam').and_return(@client_mock)
+ expect(Chef::ApiClient).to receive(:reregister).with('adam').and_return(@client_mock)
@knife.run
- @stdout.string.should match( /foo_key/ )
+ 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
- Chef::ApiClient.should_receive(:reregister).with('adam').and_return(@client_mock)
+ expect(Chef::ApiClient).to receive(:reregister).with('adam').and_return(@client_mock)
@knife.config[:file] = '/tmp/monkeypants'
filehandle = StringIO.new
- File.should_receive(:open).with('/tmp/monkeypants', 'w').and_yield(filehandle)
+ expect(File).to receive(:open).with('/tmp/monkeypants', 'w').and_yield(filehandle)
@knife.run
- filehandle.string.should == "foo_key"
+ expect(filehandle.string).to eq("foo_key")
end
end
diff --git a/spec/unit/knife/configure_client_spec.rb b/spec/unit/knife/configure_client_spec.rb
index de2a5a41e5..363743f8cc 100644
--- a/spec/unit/knife/configure_client_spec.rb
+++ b/spec/unit/knife/configure_client_spec.rb
@@ -26,16 +26,16 @@ describe Chef::Knife::ConfigureClient do
Chef::Config[:validation_key] = '/etc/chef/validation.pem'
@stderr = StringIO.new
- @knife.ui.stub(:stderr).and_return(@stderr)
+ 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
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal).with(/must provide the directory/)
- lambda {
+ expect(@knife).to receive(:show_usage)
+ expect(@knife.ui).to receive(:fatal).with(/must provide the directory/)
+ expect {
@knife.run
- }.should raise_error SystemExit
+ }.to raise_error SystemExit
end
describe 'when specifing a directory' do
@@ -43,39 +43,39 @@ describe Chef::Knife::ConfigureClient do
@knife.name_args = ['/home/bob/.chef']
@client_file = StringIO.new
@validation_file = StringIO.new
- File.should_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)
- File.should_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)
- IO.should_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
- FileUtils.should_receive(:mkdir_p).with('/home/bob/.chef')
+ expect(FileUtils).to receive(:mkdir_p).with('/home/bob/.chef')
@knife.run
end
it 'should write out the config file' do
- FileUtils.stub(:mkdir_p)
+ allow(FileUtils).to receive(:mkdir_p)
@knife.run
- @client_file.string.should match /log_level\s+\:info/
- @client_file.string.should match /log_location\s+STDOUT/
- @client_file.string.should match /chef_server_url\s+'https\:\/\/chef\.example\.com'/
- @client_file.string.should match /validation_client_name\s+'chef-validator'/
+ expect(@client_file.string).to match /log_level\s+\:info/
+ expect(@client_file.string).to match /log_location\s+STDOUT/
+ expect(@client_file.string).to match /chef_server_url\s+'https\:\/\/chef\.example\.com'/
+ expect(@client_file.string).to match /validation_client_name\s+'chef-validator'/
end
it 'should write out the validation.pem file' do
- FileUtils.stub(:mkdir_p)
+ allow(FileUtils).to receive(:mkdir_p)
@knife.run
- @validation_file.string.should match /foo_bar_baz/
+ expect(@validation_file.string).to match /foo_bar_baz/
end
it 'should print information on what is being configured' do
- FileUtils.stub(:mkdir_p)
+ allow(FileUtils).to receive(:mkdir_p)
@knife.run
- @stderr.string.should match /creating client configuration/i
- @stderr.string.should match /writing client\.rb/i
- @stderr.string.should match /writing validation\.pem/i
+ expect(@stderr.string).to match /creating client configuration/i
+ expect(@stderr.string).to match /writing client\.rb/i
+ expect(@stderr.string).to match /writing validation\.pem/i
end
end
end
diff --git a/spec/unit/knife/configure_spec.rb b/spec/unit/knife/configure_spec.rb
index c16019dcf7..e3ea1f052c 100644
--- a/spec/unit/knife/configure_spec.rb
+++ b/spec/unit/knife/configure_spec.rb
@@ -7,19 +7,19 @@ describe Chef::Knife::Configure do
Chef::Config[:node_name] = "webmonkey.example.com"
@knife = Chef::Knife::Configure.new
@rest_client = double("null rest client", :post_rest => { :result => :true })
- @knife.stub(:rest).and_return(@rest_client)
+ allow(@knife).to receive(:rest).and_return(@rest_client)
@out = StringIO.new
- @knife.ui.stub(:stdout).and_return(@out)
+ allow(@knife.ui).to receive(:stdout).and_return(@out)
@knife.config[:config_file] = '/home/you/.chef/knife.rb'
@in = StringIO.new("\n" * 7)
- @knife.ui.stub(:stdin).and_return(@in)
+ allow(@knife.ui).to receive(:stdin).and_return(@in)
@err = StringIO.new
- @knife.ui.stub(:stderr).and_return(@err)
+ allow(@knife.ui).to receive(:stderr).and_return(@err)
- Ohai::System.stub(:new).and_return(ohai)
+ allow(Ohai::System).to receive(:new).and_return(ohai)
end
@@ -27,8 +27,8 @@ describe Chef::Knife::Configure do
let(:ohai) do
o = {}
- o.stub(:require_plugin)
- o.stub(:load_plugins)
+ allow(o).to receive(:require_plugin)
+ allow(o).to receive(:load_plugins)
o[:fqdn] = fqdn
o
end
@@ -44,63 +44,63 @@ describe Chef::Knife::Configure do
it "asks the user for the URL of the chef server" do
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Please enter the chef server URL: [#{default_server_url}]"))
- @knife.chef_server.should == default_server_url
+ expect(@out.string).to match(Regexp.escape("Please enter the chef server URL: [#{default_server_url}]"))
+ expect(@knife.chef_server).to eq(default_server_url)
end
it "asks the user for the clientname they want for the new client if -i is specified" do
@knife.config[:initial] = true
- Etc.stub(:getlogin).and_return("a-new-user")
+ allow(Etc).to receive(:getlogin).and_return("a-new-user")
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Please enter a name for the new user: [a-new-user]"))
- @knife.new_client_name.should == Etc.getlogin
+ expect(@out.string).to match(Regexp.escape("Please enter a name for the new user: [a-new-user]"))
+ expect(@knife.new_client_name).to eq(Etc.getlogin)
end
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'
- Etc.stub(:getlogin).and_return("a-new-user")
+ allow(Etc).to receive(:getlogin).and_return("a-new-user")
@knife.ask_user_for_config
- @out.string.should_not match(Regexp.escape("Please enter a name for the new user"))
- @knife.new_client_name.should == 'testnode'
+ expect(@out.string).not_to match(Regexp.escape("Please enter a name for the new user"))
+ 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
- Etc.stub(:getlogin).and_return("a-new-user")
+ allow(Etc).to receive(:getlogin).and_return("a-new-user")
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Please enter an existing username or clientname for the API: [a-new-user]"))
- @knife.new_client_name.should == Etc.getlogin
+ expect(@out.string).to match(Regexp.escape("Please enter an existing username or clientname for the API: [a-new-user]"))
+ expect(@knife.new_client_name).to eq(Etc.getlogin)
end
it "asks the user for the existing admin client's name if -i is specified" do
@knife.config[:initial] = true
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Please enter the existing admin name: [admin]"))
- @knife.admin_client_name.should == 'admin'
+ expect(@out.string).to match(Regexp.escape("Please enter the existing admin name: [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.ask_user_for_config
- @out.string.should_not match(Regexp.escape("Please enter the existing admin:"))
- @knife.admin_client_name.should == 'my-webui'
+ expect(@out.string).not_to match(Regexp.escape("Please enter the existing admin:"))
+ 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
- @out.string.should_not match(Regexp.escape("Please enter the existing admin: [admin]"))
- @knife.admin_client_name.should_not == 'admin'
+ expect(@out.string).not_to match(Regexp.escape("Please enter the existing admin: [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
@knife.config[:initial] = true
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Please enter the location of the existing admin's private key: [#{default_admin_key}]"))
+ expect(@out.string).to match(Regexp.escape("Please enter the location of the existing admin's private key: [#{default_admin_key}]"))
if windows?
- @knife.admin_client_key.capitalize.should == default_admin_key_win32.capitalize
+ expect(@knife.admin_client_key.capitalize).to eq(default_admin_key_win32.capitalize)
else
- @knife.admin_client_key.should == default_admin_key
+ expect(@knife.admin_client_key).to eq(default_admin_key)
end
end
@@ -108,61 +108,61 @@ describe Chef::Knife::Configure do
@knife.config[:initial] = true
@knife.config[:admin_client_key] = '/home/you/.chef/my-webui.pem'
@knife.ask_user_for_config
- @out.string.should_not match(Regexp.escape("Please enter the location of the existing admin client's private key:"))
+ expect(@out.string).not_to match(Regexp.escape("Please enter the location of the existing admin client's private key:"))
if windows?
- @knife.admin_client_key.should match %r{^[A-Za-z]:/home/you/\.chef/my-webui\.pem$}
+ expect(@knife.admin_client_key).to match %r{^[A-Za-z]:/home/you/\.chef/my-webui\.pem$}
else
- @knife.admin_client_key.should == '/home/you/.chef/my-webui.pem'
+ expect(@knife.admin_client_key).to eq('/home/you/.chef/my-webui.pem')
end
end
it "should not ask the user for the location of the existing admin key if -i is not specified" do
@knife.ask_user_for_config
- @out.string.should_not match(Regexp.escape("Please enter the location of the existing admin client's private key: [#{default_admin_key}]"))
+ expect(@out.string).not_to match(Regexp.escape("Please enter the location of the existing admin client's private key: [#{default_admin_key}]"))
if windows?
- @knife.admin_client_key.should_not == default_admin_key_win32
+ expect(@knife.admin_client_key).not_to eq(default_admin_key_win32)
else
- @knife.admin_client_key.should_not == default_admin_key
+ expect(@knife.admin_client_key).not_to eq(default_admin_key)
end
end
it "asks the user for the location of a chef repo" do
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Please enter the path to a chef repository (or leave blank):"))
- @knife.chef_repo.should == ''
+ expect(@out.string).to match(Regexp.escape("Please enter the path to a chef repository (or leave blank):"))
+ expect(@knife.chef_repo).to eq('')
end
it "asks the users for the name of the validation client" do
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Please enter the validation clientname: [chef-validator]"))
- @knife.validation_client_name.should == 'chef-validator'
+ expect(@out.string).to match(Regexp.escape("Please enter the validation clientname: [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.ask_user_for_config
- @out.string.should_not match(Regexp.escape("Please enter the validation clientname:"))
- @knife.validation_client_name.should == 'my-validator'
+ expect(@out.string).not_to match(Regexp.escape("Please enter the validation clientname:"))
+ expect(@knife.validation_client_name).to eq('my-validator')
end
it "asks the users for the location of the validation key" do
@knife.ask_user_for_config
- @out.string.should match(Regexp.escape("Please enter the location of the validation key: [#{default_validator_key}]"))
+ expect(@out.string).to match(Regexp.escape("Please enter the location of the validation key: [#{default_validator_key}]"))
if windows?
- @knife.validation_key.capitalize.should == default_validator_key_win32.capitalize
+ expect(@knife.validation_key.capitalize).to eq(default_validator_key_win32.capitalize)
else
- @knife.validation_key.should == default_validator_key
+ expect(@knife.validation_key).to eq(default_validator_key)
end
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.ask_user_for_config
- @out.string.should_not match(Regexp.escape("Please enter the location of the validation key:"))
+ expect(@out.string).not_to match(Regexp.escape("Please enter the location of the validation key:"))
if windows?
- @knife.validation_key.should match %r{^[A-Za-z]:/home/you/\.chef/my-validation\.pem$}
+ expect(@knife.validation_key).to match %r{^[A-Za-z]:/home/you/\.chef/my-validation\.pem$}
else
- @knife.validation_key.should == '/home/you/.chef/my-validation.pem'
+ expect(@knife.validation_key).to eq('/home/you/.chef/my-validation.pem')
end
end
@@ -176,68 +176,68 @@ describe Chef::Knife::Configure do
@knife.config[:validation_key] = '/home/you/.chef/my-validation.pem'
@knife.config[:repository] = ''
@knife.config[:client_key] = '/home/you/a-new-user.pem'
- Etc.stub(:getlogin).and_return('a-new-user')
+ allow(Etc).to receive(:getlogin).and_return('a-new-user')
@knife.ask_user_for_config
- @out.string.should match(/\s*/)
+ expect(@out.string).to match(/\s*/)
- @knife.new_client_name.should == 'testnode'
- @knife.chef_server.should == 'http://localhost:5000'
- @knife.admin_client_name.should == '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?
- @knife.admin_client_key.should match %r{^[A-Za-z]:/home/you/\.chef/my-webui\.pem$}
- @knife.validation_key.should match %r{^[A-Za-z]:/home/you/\.chef/my-validation\.pem$}
- @knife.new_client_key.should match %r{^[A-Za-z]:/home/you/a-new-user\.pem$}
+ 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
- @knife.admin_client_key.should == '/home/you/.chef/my-webui.pem'
- @knife.validation_key.should == '/home/you/.chef/my-validation.pem'
- @knife.new_client_key.should == '/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
- @knife.validation_client_name.should == 'my-validator'
- @knife.chef_repo.should == ''
+ 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
- File.stub(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
- File.stub(:expand_path).with("/home/you/.chef/#{Etc.getlogin}.pem").and_return("/home/you/.chef/#{Etc.getlogin}.pem")
- File.stub(:expand_path).with(default_validator_key).and_return(default_validator_key)
- File.stub(:expand_path).with(default_admin_key).and_return(default_admin_key)
- FileUtils.should_receive(:mkdir_p).with("/home/you/.chef")
+ allow(File).to receive(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
+ allow(File).to receive(:expand_path).with("/home/you/.chef/#{Etc.getlogin}.pem").and_return("/home/you/.chef/#{Etc.getlogin}.pem")
+ allow(File).to receive(:expand_path).with(default_validator_key).and_return(default_validator_key)
+ allow(File).to receive(:expand_path).with(default_admin_key).and_return(default_admin_key)
+ expect(FileUtils).to receive(:mkdir_p).with("/home/you/.chef")
config_file = StringIO.new
- ::File.should_receive(:open).with("/home/you/.chef/knife.rb", "w").and_yield config_file
+ expect(::File).to receive(:open).with("/home/you/.chef/knife.rb", "w").and_yield config_file
@knife.config[:repository] = '/home/you/chef-repo'
@knife.run
- config_file.string.should match(/^node_name[\s]+'#{Etc.getlogin}'$/)
- config_file.string.should match(%r{^client_key[\s]+'/home/you/.chef/#{Etc.getlogin}.pem'$})
- config_file.string.should match(/^validation_client_name\s+'chef-validator'$/)
- config_file.string.should match(%r{^validation_key\s+'#{default_validator_key}'$})
- config_file.string.should match(%r{^chef_server_url\s+'#{default_server_url}'$})
- config_file.string.should match(%r{cookbook_path\s+\[ '/home/you/chef-repo/cookbooks' \]})
+ 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'$})
+ expect(config_file.string).to match(/^validation_client_name\s+'chef-validator'$/)
+ expect(config_file.string).to match(%r{^validation_key\s+'#{default_validator_key}'$})
+ expect(config_file.string).to match(%r{^chef_server_url\s+'#{default_server_url}'$})
+ expect(config_file.string).to match(%r{cookbook_path\s+\[ '/home/you/chef-repo/cookbooks' \]})
end
it "creates a new client when given the --initial option" do
- File.should_receive(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
- File.should_receive(:expand_path).with("/home/you/.chef/a-new-user.pem").and_return("/home/you/.chef/a-new-user.pem")
- File.should_receive(:expand_path).with(default_validator_key).and_return(default_validator_key)
- File.should_receive(:expand_path).with(default_admin_key).and_return(default_admin_key)
+ expect(File).to receive(:expand_path).with("/home/you/.chef/knife.rb").and_return("/home/you/.chef/knife.rb")
+ expect(File).to receive(:expand_path).with("/home/you/.chef/a-new-user.pem").and_return("/home/you/.chef/a-new-user.pem")
+ expect(File).to receive(:expand_path).with(default_validator_key).and_return(default_validator_key)
+ expect(File).to receive(:expand_path).with(default_admin_key).and_return(default_admin_key)
Chef::Config[:node_name] = "webmonkey.example.com"
user_command = Chef::Knife::UserCreate.new
- user_command.should_receive(:run)
+ expect(user_command).to receive(:run)
- Etc.stub(:getlogin).and_return("a-new-user")
+ allow(Etc).to receive(:getlogin).and_return("a-new-user")
- Chef::Knife::UserCreate.stub(:new).and_return(user_command)
- FileUtils.should_receive(:mkdir_p).with("/home/you/.chef")
- ::File.should_receive(:open).with("/home/you/.chef/knife.rb", "w")
+ allow(Chef::Knife::UserCreate).to receive(:new).and_return(user_command)
+ expect(FileUtils).to receive(:mkdir_p).with("/home/you/.chef")
+ expect(::File).to receive(:open).with("/home/you/.chef/knife.rb", "w")
@knife.config[:initial] = true
@knife.config[:user_password] = "blah"
@knife.run
- user_command.name_args.should == Array("a-new-user")
- user_command.config[:user_password].should == "blah"
- user_command.config[:admin].should be_true
- user_command.config[:file].should == "/home/you/.chef/a-new-user.pem"
- user_command.config[:yes].should be_true
- user_command.config[:disable_editing].should be_true
+ expect(user_command.name_args).to eq(Array("a-new-user"))
+ expect(user_command.config[:user_password]).to eq("blah")
+ expect(user_command.config[:admin]).to be_truthy
+ expect(user_command.config[:file]).to eq("/home/you/.chef/a-new-user.pem")
+ expect(user_command.config[:yes]).to be_truthy
+ expect(user_command.config[:disable_editing]).to be_truthy
end
end
diff --git a/spec/unit/knife/cookbook_bulk_delete_spec.rb b/spec/unit/knife/cookbook_bulk_delete_spec.rb
index fb4b1d1484..98cd06bbbc 100644
--- a/spec/unit/knife/cookbook_bulk_delete_spec.rb
+++ b/spec/unit/knife/cookbook_bulk_delete_spec.rb
@@ -28,19 +28,19 @@ describe Chef::Knife::CookbookBulkDelete do
@knife.name_args = ["."]
@stdout = StringIO.new
@stderr = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
- @knife.ui.stub(:stderr).and_return(@stderr)
- @knife.ui.stub(:confirm).and_return(true)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
+ allow(@knife.ui).to receive(:confirm).and_return(true)
@cookbooks = Hash.new
%w{cheezburger pizza lasagna}.each do |cookbook_name|
cookbook = Chef::CookbookVersion.new(cookbook_name)
@cookbooks[cookbook_name] = cookbook
end
@rest = double("Chef::REST")
- @rest.stub(:get_rest).and_return(@cookbooks)
- @rest.stub(:delete_rest).and_return(true)
- @knife.stub(:rest).and_return(@rest)
- Chef::CookbookVersion.stub(:list).and_return(@cookbooks)
+ allow(@rest).to receive(:get_rest).and_return(@cookbooks)
+ allow(@rest).to receive(:delete_rest).and_return(true)
+ allow(@knife).to receive(:rest).and_return(@rest)
+ allow(Chef::CookbookVersion).to receive(:list).and_return(@cookbooks)
end
@@ -49,41 +49,41 @@ 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"}]}}
- @rest.stub(:get_rest).with('cookbooks/cheezburger').and_return(@cheezburger)
+ allow(@rest).to receive(:get_rest).with('cookbooks/cheezburger').and_return(@cheezburger)
@pizza = {'pizza' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-pizza", "version" => "2.0.0"}]}}
- @rest.stub(:get_rest).with('cookbooks/pizza').and_return(@pizza)
+ allow(@rest).to receive(:get_rest).with('cookbooks/pizza').and_return(@pizza)
@lasagna = {'lasagna' => {"url" => "file:///dev/null", "versions" => [{"url" => "file:///dev/null-lasagna", "version" => "3.0.0"}]}}
- @rest.stub(:get_rest).with('cookbooks/lasagna').and_return(@lasagna)
+ allow(@rest).to receive(:get_rest).with('cookbooks/lasagna').and_return(@lasagna)
end
it "should print the cookbooks you are about to delete" do
expected = @knife.ui.list(@cookbooks.keys.sort, :columns_down)
@knife.run
- @stdout.string.should match(/#{expected}/)
+ expect(@stdout.string).to match(/#{expected}/)
end
it "should confirm you really want to delete them" do
- @knife.ui.should_receive(:confirm)
+ expect(@knife.ui).to receive(:confirm)
@knife.run
end
it "should delete each cookbook" do
{"cheezburger" => "1.0.0", "pizza" => "2.0.0", "lasagna" => '3.0.0'}.each do |cookbook_name, version|
- @rest.should_receive(:delete_rest).with("cookbooks/#{cookbook_name}/#{version}")
+ expect(@rest).to receive(:delete_rest).with("cookbooks/#{cookbook_name}/#{version}")
end
@knife.run
end
it "should only delete cookbooks that match the regex" do
@knife.name_args = ["cheezburger"]
- @rest.should_receive(:delete_rest).with('cookbooks/cheezburger/1.0.0')
+ expect(@rest).to receive(:delete_rest).with('cookbooks/cheezburger/1.0.0')
@knife.run
end
end
it "should exit if the regex is not provided" do
@knife.name_args = []
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
diff --git a/spec/unit/knife/cookbook_create_spec.rb b/spec/unit/knife/cookbook_create_spec.rb
index 06475d3ac9..3354432d39 100644
--- a/spec/unit/knife/cookbook_create_spec.rb
+++ b/spec/unit/knife/cookbook_create_spec.rb
@@ -26,29 +26,29 @@ describe Chef::Knife::CookbookCreate do
@knife.config = {}
@knife.name_args = ["foobar"]
@stdout = StringIO.new
- @knife.stub(:stdout).and_return(@stdout)
+ allow(@knife).to receive(:stdout).and_return(@stdout)
end
describe "run" do
# Fixes CHEF-2579
it "should expand the path of the cookbook directory" do
- File.should_receive(:expand_path).with("~/tmp/monkeypants")
+ expect(File).to receive(:expand_path).with("~/tmp/monkeypants")
@knife.config = {:cookbook_path => "~/tmp/monkeypants"}
- @knife.stub(:create_cookbook)
- @knife.stub(:create_readme)
- @knife.stub(:create_changelog)
- @knife.stub(:create_metadata)
+ allow(@knife).to receive(:create_cookbook)
+ allow(@knife).to receive(:create_readme)
+ allow(@knife).to receive(:create_changelog)
+ allow(@knife).to receive(:create_metadata)
@knife.run
end
it "should create a new cookbook with default values to copyright name, email, readme format and license if those are not supplied" do
@dir = Dir.tmpdir
@knife.config = {:cookbook_path => @dir}
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "YOUR_COMPANY_NAME", "none")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "md")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "YOUR_COMPANY_NAME", "YOUR_EMAIL", "none", "md")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "YOUR_COMPANY_NAME", "none")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "md")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "YOUR_COMPANY_NAME", "YOUR_EMAIL", "none", "md")
@knife.run
end
@@ -59,10 +59,10 @@ describe Chef::Knife::CookbookCreate do
:cookbook_copyright => "Opscode, Inc"
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "none")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "md")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "YOUR_EMAIL", "none", "md")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "none")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "md")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "YOUR_EMAIL", "none", "md")
@knife.run
end
@@ -74,10 +74,10 @@ describe Chef::Knife::CookbookCreate do
:cookbook_email => "nuo@opscode.com"
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "none")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "md")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "none", "md")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "none")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "md")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "none", "md")
@knife.run
end
@@ -90,10 +90,10 @@ describe Chef::Knife::CookbookCreate do
:cookbook_license => "apachev2"
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "apachev2")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "md")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "apachev2", "md")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "apachev2")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "md")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "apachev2", "md")
@knife.run
end
@@ -106,10 +106,10 @@ describe Chef::Knife::CookbookCreate do
:cookbook_license => false
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "none")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "md")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "none", "md")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "none")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "md")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "none", "md")
@knife.run
end
@@ -122,10 +122,10 @@ describe Chef::Knife::CookbookCreate do
:cookbook_license => "false"
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "none")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "md")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "none", "md")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "none")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "md")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "none", "md")
@knife.run
end
@@ -138,10 +138,10 @@ describe Chef::Knife::CookbookCreate do
:cookbook_license => "gplv2"
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "gplv2")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "md")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "gplv2", "md")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "gplv2")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "md")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "gplv2", "md")
@knife.run
end
@@ -154,10 +154,10 @@ describe Chef::Knife::CookbookCreate do
:cookbook_license => "gplv3"
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "gplv3")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "md")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "gplv3", "md")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "gplv3")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "md")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "gplv3", "md")
@knife.run
end
@@ -170,10 +170,10 @@ describe Chef::Knife::CookbookCreate do
:cookbook_license => "mit"
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "mit")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "md")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "mit", "md")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "mit")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "md")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "mit", "md")
@knife.run
end
@@ -187,10 +187,10 @@ describe Chef::Knife::CookbookCreate do
:readme_format => "rdoc"
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "mit")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "rdoc")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "mit", "rdoc")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "mit")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "rdoc")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "mit", "rdoc")
@knife.run
end
@@ -204,10 +204,10 @@ describe Chef::Knife::CookbookCreate do
:readme_format => "mkd"
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "mit")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "mkd")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "mit", "mkd")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "mit")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "mkd")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "mit", "mkd")
@knife.run
end
@@ -221,10 +221,10 @@ describe Chef::Knife::CookbookCreate do
:readme_format => "txt"
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "mit")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "txt")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "mit", "txt")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "mit")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "txt")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "mit", "txt")
@knife.run
end
@@ -238,10 +238,10 @@ describe Chef::Knife::CookbookCreate do
:readme_format => "foo"
}
@knife.name_args=["foobar"]
- @knife.should_receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "mit")
- @knife.should_receive(:create_readme).with(@dir, @knife.name_args.first, "foo")
- @knife.should_receive(:create_changelog).with(@dir, @knife.name_args.first)
- @knife.should_receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "mit", "foo")
+ expect(@knife).to receive(:create_cookbook).with(@dir, @knife.name_args.first, "Opscode, Inc", "mit")
+ expect(@knife).to receive(:create_readme).with(@dir, @knife.name_args.first, "foo")
+ expect(@knife).to receive(:create_changelog).with(@dir, @knife.name_args.first)
+ expect(@knife).to receive(:create_metadata).with(@dir, @knife.name_args.first, "Opscode, Inc", "nuo@opscode.com", "mit", "foo")
@knife.run
end
@@ -252,7 +252,7 @@ describe Chef::Knife::CookbookCreate do
it "should throw an argument error" do
@dir = Dir.tmpdir
- lambda{@knife.run}.should raise_error(ArgumentError)
+ expect{@knife.run}.to raise_error(ArgumentError)
end
end
diff --git a/spec/unit/knife/cookbook_delete_spec.rb b/spec/unit/knife/cookbook_delete_spec.rb
index 53b120be71..4e75a689e3 100644
--- a/spec/unit/knife/cookbook_delete_spec.rb
+++ b/spec/unit/knife/cookbook_delete_spec.rb
@@ -24,29 +24,29 @@ describe Chef::Knife::CookbookDelete do
@knife.name_args = ['foobar']
@knife.cookbook_name = 'foobar'
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
@stderr = StringIO.new
- @knife.ui.stub(:stderr).and_return(@stderr)
+ 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
@knife.name_args = []
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ 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
- @knife.should_receive(:delete_without_explicit_version)
+ 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'
- @knife.should_receive(:delete_explicit_version)
+ expect(@knife).to receive(:delete_explicit_version)
@knife.run
end
end
@@ -54,7 +54,7 @@ describe Chef::Knife::CookbookDelete do
describe 'with -a or --all' do
it 'should delete all versions of the cookbook' do
@knife.config[:all] = true
- @knife.should_receive(:delete_all_versions)
+ expect(@knife).to receive(:delete_all_versions)
@knife.run
end
end
@@ -62,9 +62,9 @@ describe Chef::Knife::CookbookDelete do
describe 'with -p or --purge' do
it 'should prompt to purge the files' do
@knife.config[:purge] = true
- @knife.should_receive(:confirm).
+ expect(@knife).to receive(:confirm).
with(/.+Are you sure you want to purge files.+/)
- @knife.should_receive(:delete_without_explicit_version)
+ expect(@knife).to receive(:delete_without_explicit_version)
@knife.run
end
end
@@ -75,10 +75,10 @@ describe Chef::Knife::CookbookDelete do
it 'should delete the specific cookbook version' do
@knife.cookbook_name = 'foobar'
@knife.version = '1.0.0'
- @knife.should_receive(:delete_object).with(Chef::CookbookVersion,
+ expect(@knife).to receive(:delete_object).with(Chef::CookbookVersion,
'foobar version 1.0.0',
'cookbook').and_yield()
- @knife.should_receive(:delete_request).with('cookbooks/foobar/1.0.0')
+ expect(@knife).to receive(:delete_request).with('cookbooks/foobar/1.0.0')
@knife.delete_explicit_version
end
end
@@ -86,8 +86,8 @@ describe Chef::Knife::CookbookDelete do
describe 'delete_all_versions' do
it 'should prompt to delete all versions of the cookbook' do
@knife.cookbook_name = 'foobar'
- @knife.should_receive(:confirm).with('Do you really want to delete all versions of foobar')
- @knife.should_receive(:delete_all_without_confirmation)
+ 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
@@ -95,9 +95,9 @@ describe Chef::Knife::CookbookDelete do
describe 'delete_all_without_confirmation' do
it 'should delete all versions without confirmation' do
versions = ['1.0.0', '1.1.0']
- @knife.should_receive(:available_versions).and_return(versions)
+ expect(@knife).to receive(:available_versions).and_return(versions)
versions.each do |v|
- @knife.should_receive(:delete_version_without_confirmation).with(v)
+ expect(@knife).to receive(:delete_version_without_confirmation).with(v)
end
@knife.delete_all_without_confirmation
end
@@ -105,20 +105,20 @@ describe Chef::Knife::CookbookDelete do
describe 'delete_without_explicit_version' do
it 'should exit if there are no available versions' do
- @knife.should_receive(:available_versions).and_return(nil)
- lambda { @knife.delete_without_explicit_version }.should raise_error(SystemExit)
+ 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
- @knife.should_receive(:available_versions).at_least(:once).and_return(['1.0.0'])
- @knife.should_receive(:delete_explicit_version)
+ 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
- @knife.should_receive(:available_versions).at_least(:once).and_return(['1.0.0', '1.1.0'])
- @knife.should_receive(:ask_which_versions_to_delete).and_return(['1.0.0', '1.1.0'])
- @knife.should_receive(:delete_versions_without_confirmation).with(['1.0.0', '1.1.0'])
+ 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
@@ -126,7 +126,7 @@ describe Chef::Knife::CookbookDelete do
describe 'available_versions' do
before(:each) do
@rest_mock = double('rest')
- @knife.should_receive(:rest).and_return(@rest_mock)
+ 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'} ]}
@@ -134,85 +134,85 @@ describe Chef::Knife::CookbookDelete do
end
it 'should return the list of versions of the cookbook' do
- @rest_mock.should_receive(:get_rest).with('cookbooks/foobar').and_return(@cookbook_data)
- @knife.available_versions.should == ['1.0.0', '1.1.0', '2.0.0']
+ expect(@rest_mock).to receive(:get_rest).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')
- @rest_mock.should_receive(:get_rest).and_raise(exception)
- lambda { @knife.available_versions }.should raise_error Net::HTTPServerException
+ expect(@rest_mock).to receive(:get_rest).and_raise(exception)
+ expect { @knife.available_versions }.to raise_error Net::HTTPServerException
end
describe "if the cookbook can't be found" do
before(:each) do
- @rest_mock.should_receive(:get_rest).
+ expect(@rest_mock).to receive(:get_rest).
and_raise(Net::HTTPServerException.new('404 Not Found', '404'))
end
it 'should print an error' do
@knife.available_versions
- @stderr.string.should match /error.+cannot find a cookbook named foobar/i
+ expect(@stderr.string).to match /error.+cannot find a cookbook named foobar/i
end
it 'should return nil' do
- @knife.available_versions.should == nil
+ expect(@knife.available_versions).to eq(nil)
end
end
end
describe 'ask_which_version_to_delete' do
before(:each) do
- @knife.stub(: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
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
- @knife.should_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
- @knife.should_receive(:ask_question).and_return('')
- @knife.ui.should_receive(:error).with(/no versions specified/i)
- lambda { @knife.ask_which_versions_to_delete }.should raise_error(SystemExit)
+ 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
- @knife.should_receive(:ask_question).and_return('100')
- @knife.ui.should_receive(:error).with(/100 is not a valid choice/i)
+ 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
- @knife.should_receive(:ask_question).and_return('1, 3')
- @knife.ask_which_versions_to_delete.should == ['1.0.0', '2.0.0']
+ 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
- @knife.should_receive(:ask_question).and_return('4')
- @knife.ask_which_versions_to_delete.should == [:all]
+ 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
- @knife.should_receive(:delete_request).with('cookbooks/foobar/1.0.0')
+ 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
- @knife.stub(:delete_request)
+ allow(@knife).to receive(:delete_request)
@knife.delete_version_without_confirmation('1.0.0')
- @stderr.string.should match /deleted cookbook\[foobar\]\[1.0.0\]/im
+ 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 = ''
@knife.config[:print_after] = true
- @knife.stub(:delete_request).and_return(object)
- @knife.should_receive(:format_for_display).with(object)
+ 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')
end
end
@@ -222,7 +222,7 @@ describe Chef::Knife::CookbookDelete do
it 'should delete each version without confirmation' do
versions = ['1.0.0', '1.1.0']
versions.each do |v|
- @knife.should_receive(:delete_version_without_confirmation).with(v)
+ expect(@knife).to receive(:delete_version_without_confirmation).with(v)
end
@knife.delete_versions_without_confirmation(versions)
end
@@ -230,7 +230,7 @@ describe Chef::Knife::CookbookDelete do
describe 'with -a or --all' do
it 'should delete all versions without confirmation' do
versions = [:all]
- @knife.should_receive(:delete_all_without_confirmation)
+ expect(@knife).to receive(:delete_all_without_confirmation)
@knife.delete_versions_without_confirmation(versions)
end
end
diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb
index 6f40a3396b..7ca1adfcb5 100644
--- a/spec/unit/knife/cookbook_download_spec.rb
+++ b/spec/unit/knife/cookbook_download_spec.rb
@@ -22,22 +22,22 @@ describe Chef::Knife::CookbookDownload do
before(:each) do
@knife = Chef::Knife::CookbookDownload.new
@stderr = StringIO.new
- @knife.ui.stub(:stderr).and_return(@stderr)
+ 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
@knife.name_args = []
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal).with(/must specify a cookbook name/)
- lambda { @knife.run }.should raise_error(SystemExit)
+ 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]
- @knife.should_receive(:determine_version).and_return(nil)
- @knife.ui.should_receive(:fatal).with('No such cookbook found')
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife).to receive(:determine_version).and_return(nil)
+ 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
@@ -45,7 +45,7 @@ describe Chef::Knife::CookbookDownload do
@knife.name_args = ['foobar']
@knife.config[:download_directory] = '/var/tmp/chef'
@rest_mock = double('rest')
- @knife.stub(:rest).and_return(@rest_mock)
+ allow(@knife).to receive(:rest).and_return(@rest_mock)
@manifest_data = {
:recipes => [
@@ -67,17 +67,17 @@ describe Chef::Knife::CookbookDownload do
}
@cookbook_mock = double('cookbook')
- @cookbook_mock.stub(:version).and_return('1.0.0')
- @cookbook_mock.stub(:manifest).and_return(@manifest_data)
- @rest_mock.should_receive(:get_rest).with('cookbooks/foobar/1.0.0').
+ allow(@cookbook_mock).to receive(:version).and_return('1.0.0')
+ allow(@cookbook_mock).to receive(:manifest).and_return(@manifest_data)
+ expect(@rest_mock).to receive(:get_rest).with('cookbooks/foobar/1.0.0').
and_return(@cookbook_mock)
end
it 'should determine which version if one was not explicitly specified'do
- @cookbook_mock.stub(:manifest).and_return({})
- @knife.should_receive(:determine_version).and_return('1.0.0')
- File.should_receive(:exists?).with('/var/tmp/chef/foobar-1.0.0').and_return(false)
- Chef::CookbookVersion.stub(:COOKBOOK_SEGEMENTS).and_return([])
+ 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)
+ allow(Chef::CookbookVersion).to receive(:COOKBOOK_SEGEMENTS).and_return([])
@knife.run
end
@@ -88,50 +88,50 @@ describe Chef::Knife::CookbookDownload do
@files_mocks = {}
@files.map { |f| File.basename(f) }.flatten.uniq.each do |f|
@files_mocks[f] = double("#{f}_mock")
- @files_mocks[f].stub(:path).and_return("/var/tmp/#{f}")
+ allow(@files_mocks[f]).to receive(:path).and_return("/var/tmp/#{f}")
end
end
it 'should print an error and exit if the cookbook download directory already exists' do
- File.should_receive(:exists?).with('/var/tmp/chef/foobar-1.0.0').and_return(true)
- @knife.ui.should_receive(:fatal).with(/\/var\/tmp\/chef\/foobar-1\.0\.0 exists/i)
- lambda { @knife.run }.should raise_error(SystemExit)
+ 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
before(:each) do
@files.map { |f| File.dirname(f) }.flatten.uniq.each do |dir|
- FileUtils.should_receive(:mkdir_p).with("/var/tmp/chef/foobar-1.0.0/#{dir}").
+ expect(FileUtils).to receive(:mkdir_p).with("/var/tmp/chef/foobar-1.0.0/#{dir}").
at_least(:once)
end
@files_mocks.each_pair do |file, mock|
- @rest_mock.should_receive(:get_rest).with("http://example.org/files/#{file}", true).
+ expect(@rest_mock).to receive(:get_rest).with("http://example.org/files/#{file}", true).
and_return(mock)
end
- @rest_mock.should_receive(:sign_on_redirect=).with(false).at_least(:once)
+ expect(@rest_mock).to receive(:sign_on_redirect=).with(false).at_least(:once)
@files.each do |f|
- FileUtils.should_receive(:mv).
+ expect(FileUtils).to receive(:mv).
with("/var/tmp/#{File.basename(f)}", "/var/tmp/chef/foobar-1.0.0/#{f}")
end
end
it "should download the cookbook when the cookbook download directory doesn't exist" do
- File.should_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|
- @stderr.string.should match /downloading #{segment}/im
+ expect(@stderr.string).to match /downloading #{segment}/im
end
- @stderr.string.should match /downloading foobar cookbook version 1\.0\.0/im
- @stderr.string.should match /cookbook downloaded to \/var\/tmp\/chef\/foobar-1\.0\.0/im
+ 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
@knife.config[:force] = true
- File.should_receive(:exists?).with('/var/tmp/chef/foobar-1.0.0').and_return(true)
- FileUtils.should_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
@@ -145,30 +145,30 @@ describe Chef::Knife::CookbookDownload do
describe 'determine_version' do
it 'should return nil if there are no versions' do
- @knife.should_receive(:available_versions).and_return(nil)
- @knife.determine_version.should == nil
- @knife.version.should == nil
+ 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
- @knife.should_receive(:available_versions).at_least(:once).and_return(['1.0.0'])
- @knife.determine_version.should == '1.0.0'
- @knife.version.should == '1.0.0'
+ 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
- @knife.should_receive(:available_versions).at_least(:once).and_return(['1.0.0', '2.0.0'])
- @knife.should_receive(:ask_which_version).and_return('1.0.0')
- @knife.determine_version.should == '1.0.0'
+ 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
@knife.config[:latest] = true
- @knife.should_receive(:available_versions).at_least(:once).
+ expect(@knife).to receive(:available_versions).at_least(:once).
and_return(['1.0.0', '1.1.0', '2.0.0'])
@knife.determine_version
- @knife.version.to_s.should == '2.0.0'
+ expect(@knife.version.to_s).to eq('2.0.0')
end
end
end
@@ -179,23 +179,23 @@ describe Chef::Knife::CookbookDownload do
end
it 'should return nil if there are no versions' do
- Chef::CookbookVersion.should_receive(:available_versions).
+ expect(Chef::CookbookVersion).to receive(:available_versions).
with('foobar').
and_return(nil)
- @knife.available_versions.should == nil
+ expect(@knife.available_versions).to eq(nil)
end
it 'should return the available versions' do
- Chef::CookbookVersion.should_receive(:available_versions).
+ expect(Chef::CookbookVersion).to receive(:available_versions).
with('foobar').
and_return(['1.1.0', '2.0.0', '1.0.0'])
- @knife.available_versions.should == [Chef::Version.new('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')]
+ Chef::Version.new('2.0.0')])
end
it 'should avoid multiple API calls to the server' do
- Chef::CookbookVersion.should_receive(:available_versions).
+ expect(Chef::CookbookVersion).to receive(:available_versions).
once.
with('foobar').
and_return(['1.1.0', '2.0.0', '1.0.0'])
@@ -207,31 +207,31 @@ describe Chef::Knife::CookbookDownload do
describe 'ask_which_version' do
before(:each) do
@knife.cookbook_name = 'foobar'
- @knife.stub(: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
prompt = /Which version do you want to download\?.+1\. foobar 1\.0\.0.+2\. foobar 1\.1\.0.+3\. foobar 2\.0\.0.+/m
- @knife.should_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
- @knife.should_receive(:ask_question).and_return('1')
+ expect(@knife).to receive(:ask_question).and_return('1')
@knife.ask_which_version
- @knife.version.should == '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
- @knife.should_receive(:ask_question).and_return('')
- @knife.ui.should_receive(:error).with(/is not a valid value/i)
- lambda { @knife.ask_which_version }.should raise_error(SystemExit)
+ 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
- @knife.should_receive(:ask_question).and_return('100')
- @knife.ui.should_receive(:error).with(/'100' is not a valid value/i)
- lambda { @knife.ask_which_version }.should raise_error(SystemExit)
+ 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
end
diff --git a/spec/unit/knife/cookbook_list_spec.rb b/spec/unit/knife/cookbook_list_spec.rb
index 9ff16edb37..559f700bb4 100644
--- a/spec/unit/knife/cookbook_list_spec.rb
+++ b/spec/unit/knife/cookbook_list_spec.rb
@@ -22,7 +22,7 @@ describe Chef::Knife::CookbookList do
before do
@knife = Chef::Knife::CookbookList.new
@rest_mock = double('rest')
- @knife.stub(:rest).and_return(@rest_mock)
+ allow(@knife).to receive(:rest).and_return(@rest_mock)
@cookbook_names = ['apache2', 'mysql']
@base_url = 'https://server.example.com/cookbooks'
@cookbook_data = {}
@@ -32,22 +32,22 @@ describe Chef::Knife::CookbookList do
'url' => "#{@base_url}/#{item}/1.0.1"}]}
end
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe 'run' do
it 'should display the latest version of the cookbooks' do
- @rest_mock.should_receive(:get_rest).with('/cookbooks?num_versions=1').
+ expect(@rest_mock).to receive(:get_rest).with('/cookbooks?num_versions=1').
and_return(@cookbook_data)
@knife.run
@cookbook_names.each do |item|
- @stdout.string.should match /#{item}\s+1\.0\.1/
+ expect(@stdout.string).to match /#{item}\s+1\.0\.1/
end
end
it 'should query cookbooks for the configured environment' do
@knife.config[:environment] = 'production'
- @rest_mock.should_receive(:get_rest).
+ expect(@rest_mock).to receive(:get_rest).
with('/environments/production/cookbooks?num_versions=1').
and_return(@cookbook_data)
@knife.run
@@ -56,11 +56,11 @@ describe Chef::Knife::CookbookList do
describe 'with -w or --with-uri' do
it 'should display the cookbook uris' do
@knife.config[:with_uri] = true
- @rest_mock.stub(:get_rest).and_return(@cookbook_data)
+ allow(@rest_mock).to receive(:get_rest).and_return(@cookbook_data)
@knife.run
@cookbook_names.each do |item|
pattern = /#{Regexp.escape(@cookbook_data[item]['versions'].first['url'])}/
- @stdout.string.should match pattern
+ expect(@stdout.string).to match pattern
end
end
end
@@ -75,11 +75,11 @@ describe Chef::Knife::CookbookList do
it 'should display all versions of the cookbooks' do
@knife.config[:all_versions] = true
- @rest_mock.should_receive(:get_rest).with('/cookbooks?num_versions=all').
+ expect(@rest_mock).to receive(:get_rest).with('/cookbooks?num_versions=all').
and_return(@cookbook_data)
@knife.run
@cookbook_names.each do |item|
- @stdout.string.should match /#{item}\s+1\.0\.1\s+1\.0\.0/
+ expect(@stdout.string).to match /#{item}\s+1\.0\.1\s+1\.0\.0/
end
end
end
diff --git a/spec/unit/knife/cookbook_metadata_from_file_spec.rb b/spec/unit/knife/cookbook_metadata_from_file_spec.rb
index 68ab6740ab..456e378ca2 100644
--- a/spec/unit/knife/cookbook_metadata_from_file_spec.rb
+++ b/spec/unit/knife/cookbook_metadata_from_file_spec.rb
@@ -27,10 +27,10 @@ describe Chef::Knife::CookbookMetadataFromFile do
@tgt = File.expand_path(File.join(CHEF_SPEC_DATA, "metadata", "quick_start", "metadata.json"))
@knife = Chef::Knife::CookbookMetadataFromFile.new
@knife.name_args = [ @src ]
- @knife.stub(:to_json_pretty).and_return(true)
+ allow(@knife).to receive(:to_json_pretty).and_return(true)
@md = Chef::Cookbook::Metadata.new
- Chef::Cookbook::Metadata.stub(:new).and_return(@md)
- $stdout.stub(:write)
+ allow(Chef::Cookbook::Metadata).to receive(:new).and_return(@md)
+ allow($stdout).to receive(:write)
end
after do
@@ -41,23 +41,23 @@ describe Chef::Knife::CookbookMetadataFromFile do
describe "run" do
it "should determine cookbook name from path" do
- @md.should_receive(:name).with()
- @md.should_receive(:name).with("quick_start")
+ expect(@md).to receive(:name).with(no_args)
+ expect(@md).to receive(:name).with("quick_start")
@knife.run
end
it "should load the metadata source" do
- @md.should_receive(:from_file).with(@src)
+ expect(@md).to receive(:from_file).with(@src)
@knife.run
end
it "should write out the metadata to the correct location" do
- File.should_receive(:open).with(@tgt, "w")
+ expect(File).to receive(:open).with(@tgt, "w")
@knife.run
end
it "should generate json from the metadata" do
- Chef::JSONCompat.should_receive(:to_json_pretty).with(@md)
+ expect(Chef::JSONCompat).to receive(:to_json_pretty).with(@md)
@knife.run
end
diff --git a/spec/unit/knife/cookbook_metadata_spec.rb b/spec/unit/knife/cookbook_metadata_spec.rb
index 1d6568739c..861d85f1f7 100644
--- a/spec/unit/knife/cookbook_metadata_spec.rb
+++ b/spec/unit/knife/cookbook_metadata_spec.rb
@@ -26,25 +26,25 @@ describe Chef::Knife::CookbookMetadata do
@json_data = '{ "version": "1.0.0" }'
@stdout = StringIO.new
@stderr = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
- @knife.ui.stub(:stderr).and_return(@stderr)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
+ 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
@knife.name_args = []
- @knife.ui.should_receive(:error).with(/you must specify the cookbook.+use the --all/i)
- lambda { @knife.run }.should raise_error(SystemExit)
+ 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 = ['']
- @knife.ui.should_receive(:error).with(/you must specify the cookbook.+use the --all/i)
- lambda { @knife.run }.should raise_error(SystemExit)
+ 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
- @knife.should_receive(:generate_metadata).with('foobar')
+ expect(@knife).to receive(:generate_metadata).with('foobar')
@knife.run
end
@@ -59,21 +59,21 @@ describe Chef::Knife::CookbookMetadata do
"foo" => @foo,
"bar" => @bar
}
- @cookbook_loader.should_receive(:load_cookbooks).and_return(@cookbook_loader)
- @knife.should_receive(:generate_metadata).with('foo')
- @knife.should_receive(:generate_metadata).with('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')
end
it 'should generate the metadata for each cookbook' do
Chef::Config[:cookbook_path] = @cookbook_dir
- Chef::CookbookLoader.should_receive(:new).with(@cookbook_dir).and_return(@cookbook_loader)
+ 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'
- Chef::CookbookLoader.should_receive(:new).with('/opt/chef/cookbooks').and_return(@cookbook_loader)
+ expect(Chef::CookbookLoader).to receive(:new).with('/opt/chef/cookbooks').and_return(@cookbook_loader)
@knife.run
end
end
@@ -84,21 +84,21 @@ describe Chef::Knife::CookbookMetadata do
describe 'generate_metadata' do
before(:each) do
@knife.config[:cookbook_path] = @cookbook_dir
- File.stub(:expand_path).with("#{@cookbook_dir}/foobar/metadata.rb").
+ 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
- File.should_receive(:exists?).with("#{@cookbook_dir}/foobar/metadata.rb").
+ expect(File).to receive(:exists?).with("#{@cookbook_dir}/foobar/metadata.rb").
and_return(true)
- @knife.should_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
- File.should_receive(:exists?).with("#{@cookbook_dir}/foobar/metadata.rb").
+ expect(File).to receive(:exists?).with("#{@cookbook_dir}/foobar/metadata.rb").
and_return(false)
- @knife.should_receive(:validate_metadata_json).with(@cookbook_dir, 'foobar')
+ expect(@knife).to receive(:validate_metadata_json).with(@cookbook_dir, 'foobar')
@knife.run
end
end
@@ -110,16 +110,16 @@ describe Chef::Knife::CookbookMetadata do
end
it 'should generate the metatdata json from metatdata.rb' do
- Chef::Cookbook::Metadata.stub(:new).and_return(@metadata_mock)
- @metadata_mock.should_receive(:name).with('foobar')
- @metadata_mock.should_receive(:from_file).with("#{@cookbook_dir}/foobar/metadata.rb")
- File.should_receive(:open).with("#{@cookbook_dir}/foobar/metadata.json", 'w').
+ allow(Chef::Cookbook::Metadata).to receive(:new).and_return(@metadata_mock)
+ 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').
and_yield(@json_file_mock)
- @json_file_mock.should_receive(:write).with(@json_data)
- Chef::JSONCompat.should_receive(:to_json_pretty).with(@metadata_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")
- @stderr.string.should match /generating metadata for foobar from #{@cookbook_dir}\/foobar\/metadata\.rb/im
+ expect(@stderr.string).to match /generating metadata for foobar from #{@cookbook_dir}\/foobar\/metadata\.rb/im
end
{ Chef::Exceptions::ObsoleteDependencySyntax => 'obsolote dependency',
@@ -127,32 +127,32 @@ describe Chef::Knife::CookbookMetadata do
}.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")
- Chef::Cookbook::Metadata.stub(:new).and_raise(exception)
- lambda {
+ allow(Chef::Cookbook::Metadata).to receive(:new).and_raise(exception)
+ expect {
@knife.generate_metadata_from_file('foobar', "#{@cookbook_dir}/foobar/metadata.rb")
- }.should raise_error(SystemExit)
- @stderr.string.should match /error: the cookbook 'foobar' contains invalid or obsolete metadata syntax/im
- @stderr.string.should match /in #{@cookbook_dir}\/foobar\/metadata\.rb/im
- @stderr.string.should match /#{description} blah/im
+ }.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
+ expect(@stderr.string).to match /#{description} blah/im
end
end
end
describe 'validate_metadata_json' do
it 'should validate the metadata json' do
- File.should_receive(:exist?).with("#{@cookbook_dir}/foobar/metadata.json").
+ expect(File).to receive(:exist?).with("#{@cookbook_dir}/foobar/metadata.json").
and_return(true)
- IO.should_receive(:read).with("#{@cookbook_dir}/foobar/metadata.json").
+ expect(IO).to receive(:read).with("#{@cookbook_dir}/foobar/metadata.json").
and_return(@json_data)
- Chef::Cookbook::Metadata.should_receive(:validate_json).with(@json_data)
+ expect(Chef::Cookbook::Metadata).to receive(:validate_json).with(@json_data)
@knife.validate_metadata_json(@cookbook_dir, 'foobar')
end
it 'should not try to validate the metadata json if the file does not exist' do
- File.should_receive(:exist?).with("#{@cookbook_dir}/foobar/metadata.json").
+ expect(File).to receive(:exist?).with("#{@cookbook_dir}/foobar/metadata.json").
and_return(false)
- IO.should_not_receive(:read)
- Chef::Cookbook::Metadata.should_not_receive(:validate_json)
+ expect(IO).not_to receive(:read)
+ expect(Chef::Cookbook::Metadata).not_to receive(:validate_json)
@knife.validate_metadata_json(@cookbook_dir, 'foobar')
end
@@ -160,18 +160,18 @@ describe Chef::Knife::CookbookMetadata do
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
- File.should_receive(:exist?).with("#{@cookbook_dir}/foobar/metadata.json").
+ expect(File).to receive(:exist?).with("#{@cookbook_dir}/foobar/metadata.json").
and_return(true)
- IO.should_receive(:read).with("#{@cookbook_dir}/foobar/metadata.json").
+ expect(IO).to receive(:read).with("#{@cookbook_dir}/foobar/metadata.json").
and_return(@json_data)
exception = klass.new("#{description} blah")
- Chef::Cookbook::Metadata.stub(:validate_json).and_raise(exception)
- lambda {
+ allow(Chef::Cookbook::Metadata).to receive(:validate_json).and_raise(exception)
+ expect {
@knife.validate_metadata_json(@cookbook_dir, 'foobar')
- }.should raise_error(SystemExit)
- @stderr.string.should match /error: the cookbook 'foobar' contains invalid or obsolete metadata syntax/im
- @stderr.string.should match /in #{@cookbook_dir}\/foobar\/metadata\.json/im
- @stderr.string.should match /#{description} blah/im
+ }.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
+ expect(@stderr.string).to match /#{description} blah/im
end
end
end
diff --git a/spec/unit/knife/cookbook_show_spec.rb b/spec/unit/knife/cookbook_show_spec.rb
index b862c3154c..bf480e3678 100644
--- a/spec/unit/knife/cookbook_show_spec.rb
+++ b/spec/unit/knife/cookbook_show_spec.rb
@@ -26,18 +26,18 @@ describe Chef::Knife::CookbookShow do
@knife.config = { }
@knife.name_args = [ "cookbook_name" ]
@rest = double(Chef::REST)
- @knife.stub(:rest).and_return(@rest)
- @knife.stub(:pretty_print).and_return(true)
- @knife.stub(:output).and_return(true)
+ allow(@knife).to receive(:rest).and_return(@rest)
+ allow(@knife).to receive(:pretty_print).and_return(true)
+ allow(@knife).to receive(:output).and_return(true)
end
describe "run" do
describe "with 0 arguments: help" do
it 'should should print usage and exit when given no arguments' do
@knife.name_args = []
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife).to receive(:show_usage)
+ expect(@knife.ui).to receive(:fatal)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
@@ -56,15 +56,15 @@ describe Chef::Knife::CookbookShow do
end
it "should show the raw cookbook data" do
- @rest.should_receive(:get_rest).with("cookbooks/cookbook_name").and_return(@response)
- @knife.should_receive(:format_cookbook_list_for_display).with(@response)
+ expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name").and_return(@response)
+ expect(@knife).to receive(:format_cookbook_list_for_display).with(@response)
@knife.run
end
it "should respect the user-supplied environment" do
@knife.config[:environment] = "foo"
- @rest.should_receive(:get_rest).with("environments/foo/cookbooks/cookbook_name").and_return(@response)
- @knife.should_receive(:format_cookbook_list_for_display).with(@response)
+ expect(@rest).to receive(:get_rest).with("environments/foo/cookbooks/cookbook_name").and_return(@response)
+ expect(@knife).to receive(:format_cookbook_list_for_display).with(@response)
@knife.run
end
end
@@ -76,8 +76,8 @@ describe Chef::Knife::CookbookShow do
end
it "should show the specific part of a cookbook" do
- @rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@response)
- @knife.should_receive(:output).with(@response)
+ expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@response)
+ expect(@knife).to receive(:output).with(@response)
@knife.run
end
end
@@ -101,8 +101,8 @@ describe Chef::Knife::CookbookShow do
end
it "should print the json of the part" do
- @rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- @knife.should_receive(:output).with(@cookbook_response.manifest["recipes"])
+ expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@knife).to receive(:output).with(@cookbook_response.manifest["recipes"])
@knife.run
end
end
@@ -125,9 +125,9 @@ describe Chef::Knife::CookbookShow do
end
it "should print the raw result of the request (likely a file!)" do
- @rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- @rest.should_receive(:get_rest).with("http://example.org/files/default.rb", true).and_return(StringIO.new(@response))
- @knife.should_receive(:pretty_print).with(@response)
+ expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get_rest).with("http://example.org/files/default.rb", true).and_return(StringIO.new(@response))
+ expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
end
@@ -177,9 +177,9 @@ describe Chef::Knife::CookbookShow do
@knife.config[:platform] = "example_platform"
@knife.config[:platform_version] = "1.0"
@knife.config[:fqdn] = "examplehost.example.org"
- @rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- @rest.should_receive(:get_rest).with("http://example.org/files/1111", true).and_return(StringIO.new(@response))
- @knife.should_receive(:pretty_print).with(@response)
+ expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get_rest).with("http://example.org/files/1111", true).and_return(StringIO.new(@response))
+ expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
end
@@ -189,9 +189,9 @@ describe Chef::Knife::CookbookShow do
@knife.config[:platform] = "ubuntu"
@knife.config[:platform_version] = "1.0"
@knife.config[:fqdn] = "differenthost.example.org"
- @rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- @rest.should_receive(:get_rest).with("http://example.org/files/3333", true).and_return(StringIO.new(@response))
- @knife.should_receive(:pretty_print).with(@response)
+ expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get_rest).with("http://example.org/files/3333", true).and_return(StringIO.new(@response))
+ expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
end
@@ -201,18 +201,18 @@ describe Chef::Knife::CookbookShow do
@knife.config[:platform] = "ubuntu"
@knife.config[:platform_version] = "9.10"
@knife.config[:fqdn] = "differenthost.example.org"
- @rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- @rest.should_receive(:get_rest).with("http://example.org/files/2222", true).and_return(StringIO.new(@response))
- @knife.should_receive(:pretty_print).with(@response)
+ expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get_rest).with("http://example.org/files/2222", true).and_return(StringIO.new(@response))
+ expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
end
describe "with none of the arguments, it should use the default" do
it "should pass them all" do
- @rest.should_receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
- @rest.should_receive(:get_rest).with("http://example.org/files/4444", true).and_return(StringIO.new(@response))
- @knife.should_receive(:pretty_print).with(@response)
+ expect(@rest).to receive(:get_rest).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response)
+ expect(@rest).to receive(:get_rest).with("http://example.org/files/4444", true).and_return(StringIO.new(@response))
+ expect(@knife).to receive(:pretty_print).with(@response)
@knife.run
end
end
diff --git a/spec/unit/knife/cookbook_site_download_spec.rb b/spec/unit/knife/cookbook_site_download_spec.rb
index 76ce6508d7..6676fb34a1 100644
--- a/spec/unit/knife/cookbook_site_download_spec.rb
+++ b/spec/unit/knife/cookbook_site_download_spec.rb
@@ -33,9 +33,9 @@ describe Chef::Knife::CookbookSiteDownload do
'latest_version' => "#{@cookbook_api_url}/apache2/versions/#{@version_us}",
'replacement' => 'other_apache2' }
- @knife.ui.stub(:stderr).and_return(@stderr)
- @knife.stub(:noauth_rest).and_return(@noauth_rest)
- @noauth_rest.should_receive(:get_rest).
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
+ allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest)
+ expect(@noauth_rest).to receive(:get_rest).
with("#{@cookbook_api_url}/apache2").
and_return(@current_data)
end
@@ -46,9 +46,9 @@ describe Chef::Knife::CookbookSiteDownload do
end
it 'should warn with info about the replacement' do
- @knife.ui.should_receive(:warn).
+ expect(@knife.ui).to receive(:warn).
with(/.+deprecated.+replaced by other_apache2.+/i)
- @knife.ui.should_receive(:warn).
+ expect(@knife.ui).to receive(:warn).
with(/use --force.+download.+/i)
@knife.run
end
@@ -61,15 +61,15 @@ describe Chef::Knife::CookbookSiteDownload do
@temp_file = double( :path => "/tmp/apache2_#{@version_us}.tgz" )
@file = File.join(Dir.pwd, "apache2-#{@version}.tar.gz")
- @noauth_rest.should_receive(:sign_on_redirect=).with(false)
+ expect(@noauth_rest).to receive(:sign_on_redirect=).with(false)
end
context 'downloading the latest version' do
before do
- @noauth_rest.should_receive(:get_rest).
+ expect(@noauth_rest).to receive(:get_rest).
with(@current_data['latest_version']).
and_return(@cookbook_data)
- @noauth_rest.should_receive(:get_rest).
+ expect(@noauth_rest).to receive(:get_rest).
with(@cookbook_data['file'], true).
and_return(@temp_file)
end
@@ -81,40 +81,40 @@ describe Chef::Knife::CookbookSiteDownload do
end
it 'should download the latest version' do
- @knife.ui.should_receive(:warn).
+ expect(@knife.ui).to receive(:warn).
with(/.+deprecated.+replaced by other_apache2.+/i)
- FileUtils.should_receive(:cp).with(@temp_file.path, @file)
+ expect(FileUtils).to receive(:cp).with(@temp_file.path, @file)
@knife.run
- @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
- @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
+ 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 download the latest version' do
- FileUtils.should_receive(:cp).with(@temp_file.path, @file)
+ expect(FileUtils).to receive(:cp).with(@temp_file.path, @file)
@knife.run
- @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
- @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
+ 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
before do
@file = '/opt/chef/cookbooks/apache2.tar.gz'
@knife.config[:file] = @file
- FileUtils.should_receive(:cp).with(@temp_file.path, @file)
+ expect(FileUtils).to receive(:cp).with(@temp_file.path, @file)
end
it 'should download the cookbook to the desired file' do
@knife.run
- @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
- @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
+ 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
- FileUtils.stub(:cp).and_return(true)
- @knife.version.should == @version
+ allow(FileUtils).to receive(:cp).and_return(true)
+ expect(@knife.version).to eq(@version)
@knife.run
end
end
@@ -131,16 +131,16 @@ describe Chef::Knife::CookbookSiteDownload do
end
it 'should download the desired version' do
- @noauth_rest.should_receive(:get_rest).
+ expect(@noauth_rest).to receive(:get_rest).
with("#{@cookbook_api_url}/apache2/versions/#{@version_us}").
and_return(@cookbook_data)
- @noauth_rest.should_receive(:get_rest).
+ expect(@noauth_rest).to receive(:get_rest).
with(@cookbook_data['file'], true).
and_return(@temp_file)
- FileUtils.should_receive(:cp).with(@temp_file.path, @file)
+ expect(FileUtils).to receive(:cp).with(@temp_file.path, @file)
@knife.run
- @stderr.string.should match /downloading apache2.+version.+#{Regexp.escape(@version)}/i
- @stderr.string.should match /cookbook save.+#{Regexp.escape(@file)}/i
+ 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
diff --git a/spec/unit/knife/cookbook_site_install_spec.rb b/spec/unit/knife/cookbook_site_install_spec.rb
index ff87a81b49..c4bd8f67d2 100644
--- a/spec/unit/knife/cookbook_site_install_spec.rb
+++ b/spec/unit/knife/cookbook_site_install_spec.rb
@@ -23,7 +23,7 @@ describe Chef::Knife::CookbookSiteInstall do
require 'chef/knife/core/cookbook_scm_repo'
@stdout = StringIO.new
@knife = Chef::Knife::CookbookSiteInstall.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
@knife.config = {}
if Chef::Platform.windows?
@install_path = 'C:/tmp/chef'
@@ -34,18 +34,18 @@ describe Chef::Knife::CookbookSiteInstall do
@stdout = StringIO.new
@stderr = StringIO.new
- @knife.stub(:stderr).and_return(@stdout)
- @knife.stub(:stdout).and_return(@stdout)
+ allow(@knife).to receive(:stderr).and_return(@stdout)
+ allow(@knife).to receive(:stdout).and_return(@stdout)
#Assume all external commands would have succeed. :(
- File.stub(:unlink)
- File.stub(:rmtree)
- @knife.stub(:shell_out!).and_return(true)
+ allow(File).to receive(:unlink)
+ allow(File).to receive(:rmtree)
+ allow(@knife).to receive(:shell_out!).and_return(true)
#CookbookSiteDownload Stup
@downloader = {}
- @knife.stub(:download_cookbook_to).and_return(@downloader)
- @downloader.stub(:version).and_return do
+ allow(@knife).to receive(:download_cookbook_to).and_return(@downloader)
+ allow(@downloader).to receive(:version) do
if @knife.name_args.size == 2
@knife.name_args[1]
else
@@ -57,49 +57,49 @@ describe Chef::Knife::CookbookSiteInstall do
@repo = double(:sanity_check => true, :reset_to_default_state => true,
:prepare_to_import => true, :finalize_updates_to => true,
:merge_updates_from => true)
- Chef::Knife::CookbookSCMRepo.stub(:new).and_return(@repo)
+ allow(Chef::Knife::CookbookSCMRepo).to receive(:new).and_return(@repo)
end
describe "run" do
it "should return an error if a cookbook name is not provided" do
@knife.name_args = []
- @knife.ui.should_receive(:error).with("Please specify a cookbook to download and install.")
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife.ui).to receive(:error).with("Please specify a cookbook to download and install.")
+ expect { @knife.run }.to raise_error(SystemExit)
end
it "should return an error if more than two arguments are given" do
@knife.name_args = ["foo", "bar", "baz"]
- @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.")
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.")
+ expect { @knife.run }.to raise_error(SystemExit)
end
it "should return an error if the second argument is not a version" do
@knife.name_args = ["getting-started", "1pass"]
- @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.")
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.")
+ expect { @knife.run }.to raise_error(SystemExit)
end
it "should return an error if the second argument is a four-digit version" do
@knife.name_args = ["getting-started", "0.0.0.1"]
- @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.")
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.")
+ expect { @knife.run }.to raise_error(SystemExit)
end
it "should return an error if the second argument is a one-digit version" do
@knife.name_args = ["getting-started", "1"]
- @knife.ui.should_receive(:error).with("Installing multiple cookbooks at once is not supported.")
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.")
+ expect { @knife.run }.to raise_error(SystemExit)
end
it "should install the specified version if second argument is a three-digit version" do
@knife.name_args = ["getting-started", "0.1.0"]
@knife.config[:no_deps] = true
upstream_file = File.join(@install_path, "getting-started.tar.gz")
- @knife.should_receive(:download_cookbook_to).with(upstream_file)
- @knife.should_receive(:extract_cookbook).with(upstream_file, "0.1.0")
- @knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
- @repo.should_receive(:merge_updates_from).with("getting-started", "0.1.0")
+ expect(@knife).to receive(:download_cookbook_to).with(upstream_file)
+ expect(@knife).to receive(:extract_cookbook).with(upstream_file, "0.1.0")
+ expect(@knife).to receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
+ expect(@repo).to receive(:merge_updates_from).with("getting-started", "0.1.0")
@knife.run
end
@@ -107,10 +107,10 @@ describe Chef::Knife::CookbookSiteInstall do
@knife.name_args = ["getting-started", "0.1"]
@knife.config[:no_deps] = true
upstream_file = File.join(@install_path, "getting-started.tar.gz")
- @knife.should_receive(:download_cookbook_to).with(upstream_file)
- @knife.should_receive(:extract_cookbook).with(upstream_file, "0.1")
- @knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
- @repo.should_receive(:merge_updates_from).with("getting-started", "0.1")
+ expect(@knife).to receive(:download_cookbook_to).with(upstream_file)
+ expect(@knife).to receive(:extract_cookbook).with(upstream_file, "0.1")
+ expect(@knife).to receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
+ expect(@repo).to receive(:merge_updates_from).with("getting-started", "0.1")
@knife.run
end
@@ -118,10 +118,10 @@ describe Chef::Knife::CookbookSiteInstall do
@knife.name_args = ["getting-started"]
@knife.config[:no_deps] = true
upstream_file = File.join(@install_path, "getting-started.tar.gz")
- @knife.should_receive(:download_cookbook_to).with(upstream_file)
- @knife.should_receive(:extract_cookbook).with(upstream_file, "0.3.0")
- @knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
- @repo.should_receive(:merge_updates_from).with("getting-started", "0.3.0")
+ expect(@knife).to receive(:download_cookbook_to).with(upstream_file)
+ expect(@knife).to receive(:extract_cookbook).with(upstream_file, "0.3.0")
+ expect(@knife).to receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
+ expect(@repo).to receive(:merge_updates_from).with("getting-started", "0.3.0")
@knife.run
end
@@ -130,8 +130,8 @@ describe Chef::Knife::CookbookSiteInstall do
@knife.config[:use_current_branch] = true
@knife.config[:no_deps] = true
upstream_file = File.join(@install_path, "getting-started.tar.gz")
- @repo.should_not_receive(:prepare_to_import)
- @repo.should_not_receive(:reset_to_default_state)
+ expect(@repo).not_to receive(:prepare_to_import)
+ expect(@repo).not_to receive(:reset_to_default_state)
@knife.run
end
@@ -140,11 +140,11 @@ describe Chef::Knife::CookbookSiteInstall do
@knife.config[:no_deps] = true
@knife.name_args = ["getting-started"]
upstream_file = File.join(@install_path, "getting-started.tar.gz")
- @knife.should_receive(:download_cookbook_to).with(upstream_file)
- @knife.should_receive(:extract_cookbook).with(upstream_file, "0.3.0")
- @knife.should_receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
- @repo.should_receive(:merge_updates_from).with("getting-started", "0.3.0")
- lambda { @knife.run }.should_not raise_error
+ expect(@knife).to receive(:download_cookbook_to).with(upstream_file)
+ expect(@knife).to receive(:extract_cookbook).with(upstream_file, "0.3.0")
+ expect(@knife).to receive(:clear_existing_files).with(File.join(@install_path, "getting-started"))
+ expect(@repo).to receive(:merge_updates_from).with("getting-started", "0.3.0")
+ expect { @knife.run }.not_to raise_error
end
end
end
diff --git a/spec/unit/knife/cookbook_site_share_spec.rb b/spec/unit/knife/cookbook_site_share_spec.rb
index b85db98d53..0f97261ad4 100644
--- a/spec/unit/knife/cookbook_site_share_spec.rb
+++ b/spec/unit/knife/cookbook_site_share_spec.rb
@@ -32,27 +32,27 @@ describe Chef::Knife::CookbookSiteShare do
@cookbook = Chef::CookbookVersion.new('cookbook_name')
@cookbook_loader = double('Chef::CookbookLoader')
- @cookbook_loader.stub(:cookbook_exists?).and_return(true)
- @cookbook_loader.stub(:[]).and_return(@cookbook)
- Chef::CookbookLoader.stub(:new).and_return(@cookbook_loader)
+ 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)
@noauth_rest = double(Chef::REST)
- @knife.stub(:noauth_rest).and_return(@noauth_rest)
+ allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest)
@cookbook_uploader = Chef::CookbookUploader.new('herpderp', :rest => "norest")
- Chef::CookbookUploader.stub(:new).and_return(@cookbook_uploader)
- @cookbook_uploader.stub(:validate_cookbooks).and_return(true)
- Chef::CookbookSiteStreamingUploader.stub(:create_build_dir).and_return(Dir.mktmpdir)
+ 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)
- @knife.stub(:shell_out!).and_return(true)
+ allow(@knife).to receive(:shell_out!).and_return(true)
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe 'run' do
before(:each) do
- @knife.stub(:do_upload).and_return(true)
+ allow(@knife).to receive(:do_upload).and_return(true)
@category_response = {
"name" => "cookbook_name",
"category" => "Testing Category"
@@ -66,72 +66,72 @@ describe Chef::Knife::CookbookSiteShare do
end
it 'should set true to config[:dry_run] as default' do
- @knife.config[:dry_run].should be_false
+ expect(@knife.config[:dry_run]).to be_falsey
end
it 'should should print usage and exit when given no arguments' do
@knife.name_args = []
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ 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']
- @noauth_rest.should_receive(:get_rest).with("http://cookbooks.opscode.com/api/v1/cookbooks/cookbook_name").and_return(@category_response)
- @knife.should_receive(:do_upload)
+ expect(@noauth_rest).to receive(:get_rest).with("http://cookbooks.opscode.com/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']
- @noauth_rest.should_receive(:get_rest).with("http://cookbooks.opscode.com/api/v1/cookbooks/cookbook_name").and_return(@bad_category_response)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@noauth_rest).to receive(:get_rest).with("http://cookbooks.opscode.com/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::REST throws an exception' do
@knife.name_args = ['cookbook_name']
- @noauth_rest.should_receive(:get_rest).with("http://cookbooks.opscode.com/api/v1/cookbooks/cookbook_name") { raise Errno::ECONNREFUSED, "Connection refused" }
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@noauth_rest).to receive(:get_rest).with("http://cookbooks.opscode.com/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
- @cookbook_loader.should_receive(:cookbook_exists?)
+ expect(@cookbook_loader).to receive(:cookbook_exists?)
@knife.run
end
it "should exit and log to error if the cookbook doesn't exist" do
- @cookbook_loader.stub(:cookbook_exists?).and_return(false)
- @knife.ui.should_receive(:error)
- lambda { @knife.run }.should raise_error(SystemExit)
+ allow(@cookbook_loader).to receive(:cookbook_exists?).and_return(false)
+ expect(@knife.ui).to receive(:error)
+ expect { @knife.run }.to raise_error(SystemExit)
end
it 'should make a tarball of the cookbook' do
- @knife.should_receive(:shell_out!) do |args|
- args.to_s.should match(/tar -czf/)
+ expect(@knife).to receive(:shell_out!) do |args|
+ expect(args.to_s).to match(/tar -czf/)
end
@knife.run
end
it 'should exit and log to error when the tarball creation fails' do
- @knife.stub(:shell_out!).and_raise(Chef::Exceptions::Exec)
- @knife.ui.should_receive(:error)
- lambda { @knife.run }.should raise_error(SystemExit)
+ 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
- @knife.should_receive(:do_upload)
- FileUtils.should_receive(:rm_rf)
+ expect(@knife).to receive(:do_upload)
+ expect(FileUtils).to receive(:rm_rf)
@knife.run
end
context "when the --dry-run flag is specified" do
before do
- Chef::CookbookSiteStreamingUploader.stub(:create_build_dir).and_return("/var/tmp/dummy")
+ allow(Chef::CookbookSiteStreamingUploader).to receive(:create_build_dir).and_return("/var/tmp/dummy")
@knife.config = { :dry_run => true }
- @knife.stub_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
@@ -152,46 +152,46 @@ describe Chef::Knife::CookbookSiteShare do
before(:each) do
@upload_response = double('Net::HTTPResponse')
- Chef::CookbookSiteStreamingUploader.stub(:post).and_return(@upload_response)
+ allow(Chef::CookbookSiteStreamingUploader).to receive(:post).and_return(@upload_response)
@stdout = StringIO.new
@stderr = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
- @knife.ui.stub(:stderr).and_return(@stderr)
- File.stub(:open).and_return(true)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
+ allow(File).to receive(:open).and_return(true)
end
it 'should post the cookbook to "https://supermarket.getchef.com"' do
response_text = Chef::JSONCompat.to_json({:uri => 'https://supermarket.getchef.com/cookbooks/cookbook_name'})
- @upload_response.stub(:body).and_return(response_text)
- @upload_response.stub(:code).and_return(201)
- Chef::CookbookSiteStreamingUploader.should_receive(:post).with(/supermarket\.getchef\.com/, anything(), anything(), anything())
+ 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\.getchef\.com/, 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']})
- @upload_response.stub(:body).and_return(response_text)
- @upload_response.stub(:code).and_return(409)
- lambda { @knife.run }.should raise_error(SystemExit)
- @stderr.string.should match(/ERROR(.+)cookbook 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
response_text = Chef::JSONCompat.to_json({:error_messages => ["You're holding it wrong"]})
- @upload_response.stub(:body).and_return(response_text)
- @upload_response.stub(:code).and_return(403)
- lambda { @knife.run }.should raise_error(SystemExit)
- @stderr.string.should match("ERROR(.*)You're holding it wrong")
+ allow(@upload_response).to receive(:body).and_return(response_text)
+ allow(@upload_response).to receive(:code).and_return(403)
+ expect { @knife.run }.to raise_error(SystemExit)
+ 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
response_text = Chef::JSONCompat.to_json({:system_error => "Your call was dropped", :reason => "There's a map for that"})
- @upload_response.stub(:body).and_return(response_text)
- @upload_response.stub(:code).and_return(500)
- @knife.ui.should_receive(:error).with(/#{Regexp.escape(response_text)}/)#.ordered
- @knife.ui.should_receive(:error).with(/Unknown error/)#.ordered
- lambda { @knife.run }.should raise_error(SystemExit)
+ allow(@upload_response).to receive(:body).and_return(response_text)
+ allow(@upload_response).to receive(:code).and_return(500)
+ expect(@knife.ui).to receive(:error).with(/#{Regexp.escape(response_text)}/)#.ordered
+ expect(@knife.ui).to receive(:error).with(/Unknown error/)#.ordered
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
diff --git a/spec/unit/knife/cookbook_site_unshare_spec.rb b/spec/unit/knife/cookbook_site_unshare_spec.rb
index 14cda65b43..ec46a8705c 100644
--- a/spec/unit/knife/cookbook_site_unshare_spec.rb
+++ b/spec/unit/knife/cookbook_site_unshare_spec.rb
@@ -24,13 +24,13 @@ describe Chef::Knife::CookbookSiteUnshare do
before(:each) do
@knife = Chef::Knife::CookbookSiteUnshare.new
@knife.name_args = ['cookbook_name']
- @knife.stub(:confirm).and_return(true)
+ allow(@knife).to receive(:confirm).and_return(true)
@rest = double('Chef::REST')
- @rest.stub(:delete_rest).and_return(true)
- @knife.stub(:rest).and_return(@rest)
+ allow(@rest).to receive(:delete_rest).and_return(true)
+ allow(@knife).to receive(:rest).and_return(@rest)
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe 'run' do
@@ -38,37 +38,37 @@ describe Chef::Knife::CookbookSiteUnshare do
describe 'with no cookbook argument' do
it 'should print the usage and exit' do
@knife.name_args = []
- @knife.ui.should_receive(:fatal)
- @knife.should_receive(:show_usage)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife.ui).to receive(:fatal)
+ expect(@knife).to receive(:show_usage)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
it 'should confirm you want to unshare the cookbook' do
- @knife.should_receive(:confirm)
+ expect(@knife).to receive(:confirm)
@knife.run
end
it 'should send a delete request to the cookbook site' do
- @rest.should_receive(:delete_rest)
+ expect(@rest).to receive(:delete_rest)
@knife.run
end
it 'should log an error and exit when forbidden' do
exception = double('403 "Forbidden"', :code => '403')
- @rest.stub(:delete_rest).and_raise(Net::HTTPServerException.new('403 "Forbidden"', exception))
- @knife.ui.should_receive(:error)
- lambda { @knife.run }.should raise_error(SystemExit)
+ allow(@rest).to receive(:delete_rest).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_rest' do
exception = double('500 "Application Error"', :code => '500')
- @rest.stub(:delete_rest).and_raise(Net::HTTPServerException.new('500 "Application Error"', exception))
- lambda { @knife.run }.should raise_error(Net::HTTPServerException)
+ allow(@rest).to receive(:delete_rest).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
- @knife.ui.should_receive(:info)
+ 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 0e261c02a4..ce74bcaa5d 100644
--- a/spec/unit/knife/cookbook_test_spec.rb
+++ b/spec/unit/knife/cookbook_test_spec.rb
@@ -26,55 +26,55 @@ describe Chef::Knife::CookbookTest do
Chef::Config[:node_name] = "webmonkey.example.com"
@knife = Chef::Knife::CookbookTest.new
@knife.config[:cookbook_path] = File.join(CHEF_SPEC_DATA,'cookbooks')
- @knife.cookbook_loader.stub(:cookbook_exists?).and_return(true)
+ allow(@knife.cookbook_loader).to receive(:cookbook_exists?).and_return(true)
@cookbooks = []
%w{tats central_market jimmy_johns pho}.each do |cookbook_name|
@cookbooks << Chef::CookbookVersion.new(cookbook_name)
end
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe "run" do
it "should test the cookbook" do
- @knife.stub(:test_cookbook).and_return(true)
+ allow(@knife).to receive(:test_cookbook).and_return(true)
@knife.name_args = ["italian"]
- @knife.should_receive(:test_cookbook).with("italian")
+ expect(@knife).to receive(:test_cookbook).with("italian")
@knife.run
end
it "should test multiple cookbooks when provided" do
- @knife.stub(:test_cookbook).and_return(true)
+ allow(@knife).to receive(:test_cookbook).and_return(true)
@knife.name_args = ["tats", "jimmy_johns"]
- @knife.should_receive(:test_cookbook).with("tats")
- @knife.should_receive(:test_cookbook).with("jimmy_johns")
- @knife.should_not_receive(:test_cookbook).with("central_market")
- @knife.should_not_receive(:test_cookbook).with("pho")
+ expect(@knife).to receive(:test_cookbook).with("tats")
+ expect(@knife).to receive(:test_cookbook).with("jimmy_johns")
+ expect(@knife).not_to receive(:test_cookbook).with("central_market")
+ expect(@knife).not_to receive(:test_cookbook).with("pho")
@knife.run
end
it "should test both ruby and templates" do
@knife.name_args = ["example"]
- @knife.config[:cookbook_path].should_not be_empty
+ expect(@knife.config[:cookbook_path]).not_to be_empty
Array(@knife.config[:cookbook_path]).reverse.each do |path|
- @knife.should_receive(:test_ruby).with(an_instance_of(Chef::Cookbook::SyntaxCheck))
- @knife.should_receive(:test_templates).with(an_instance_of(Chef::Cookbook::SyntaxCheck))
+ expect(@knife).to receive(:test_ruby).with(an_instance_of(Chef::Cookbook::SyntaxCheck))
+ expect(@knife).to receive(:test_templates).with(an_instance_of(Chef::Cookbook::SyntaxCheck))
end
@knife.run
end
describe "with -a or --all" do
it "should test all of the cookbooks" do
- @knife.stub(:test_cookbook).and_return(true)
+ allow(@knife).to receive(:test_cookbook).and_return(true)
@knife.config[:all] = true
@loader = {}
- @loader.stub(:load_cookbooks).and_return(@loader)
+ allow(@loader).to receive(:load_cookbooks).and_return(@loader)
@cookbooks.each do |cookbook|
@loader[cookbook.name] = cookbook
end
- @knife.stub(:cookbook_loader).and_return(@loader)
+ allow(@knife).to receive(:cookbook_loader).and_return(@loader)
@loader.each do |key, cookbook|
- @knife.should_receive(:test_cookbook).with(cookbook.name)
+ expect(@knife).to receive(:test_cookbook).with(cookbook.name)
end
@knife.run
end
diff --git a/spec/unit/knife/cookbook_upload_spec.rb b/spec/unit/knife/cookbook_upload_spec.rb
index e5c9a40cf1..5dbd456ad8 100644
--- a/spec/unit/knife/cookbook_upload_spec.rb
+++ b/spec/unit/knife/cookbook_upload_spec.rb
@@ -31,8 +31,8 @@ describe Chef::Knife::CookbookUpload do
let(:cookbook_loader) do
cookbook_loader = cookbooks_by_name.dup
- cookbook_loader.stub(:merged_cookbooks).and_return([])
- cookbook_loader.stub(:load_cookbooks).and_return(cookbook_loader)
+ allow(cookbook_loader).to receive(:merged_cookbooks).and_return([])
+ allow(cookbook_loader).to receive(:load_cookbooks).and_return(cookbook_loader)
cookbook_loader
end
@@ -45,23 +45,23 @@ describe Chef::Knife::CookbookUpload do
let(:knife) do
k = Chef::Knife::CookbookUpload.new
k.name_args = name_args
- k.ui.stub(:stdout).and_return(output)
- k.ui.stub(:stderr).and_return(output)
+ allow(k.ui).to receive(:stdout).and_return(output)
+ allow(k.ui).to receive(:stderr).and_return(output)
k
end
before(:each) do
- Chef::CookbookLoader.stub(:new).and_return(cookbook_loader)
+ allow(Chef::CookbookLoader).to receive(:new).and_return(cookbook_loader)
end
describe 'with --concurrency' do
it 'should upload cookbooks with predefined concurrency' do
- Chef::CookbookVersion.stub(:list_all_versions).and_return({})
+ allow(Chef::CookbookVersion).to receive(:list_all_versions).and_return({})
knife.config[:concurrency] = 3
test_cookbook = Chef::CookbookVersion.new('test_cookbook', '/tmp/blah')
- cookbook_loader.stub(:each).and_yield("test_cookbook", test_cookbook)
- cookbook_loader.stub(:cookbook_names).and_return(["test_cookbook"])
- Chef::CookbookUploader.should_receive(:new).
+ 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).
with( kind_of(Array), { :force => nil, :concurrency => 3}).
and_return(double("Chef::CookbookUploader", :upload_cookbooks=> true))
knife.run
@@ -70,26 +70,26 @@ describe Chef::Knife::CookbookUpload do
describe 'run' do
before(:each) do
- Chef::CookbookUploader.stub(:new => cookbook_uploader)
- Chef::CookbookVersion.stub(:list_all_versions).and_return({})
+ 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
knife.name_args = []
- knife.should_receive(:show_usage)
- knife.ui.should_receive(:fatal)
- lambda { knife.run }.should raise_error(SystemExit)
+ 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
- knife.should_receive(:upload).once
+ expect(knife).to receive(:upload).once
knife.run
end
it 'should report on success' do
- knife.should_receive(:upload).once
- knife.ui.should_receive(:info).with(/Uploaded 1 cookbook/)
+ expect(knife).to receive(:upload).once
+ expect(knife.ui).to receive(:info).with(/Uploaded 1 cookbook/)
knife.run
end
end
@@ -97,7 +97,7 @@ describe Chef::Knife::CookbookUpload do
describe 'when specifying the same cookbook name twice' do
it 'should upload the cookbook only once' do
knife.name_args = ['test_cookbook', 'test_cookbook']
- knife.should_receive(:upload).once
+ expect(knife).to receive(:upload).once
knife.run
end
end
@@ -105,8 +105,8 @@ describe Chef::Knife::CookbookUpload do
context "when uploading a cookbook that uses deprecated overlays" do
before do
- cookbook_loader.stub(:merged_cookbooks).and_return(['test_cookbook'])
- cookbook_loader.stub(:merged_cookbook_paths).
+ 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}})
end
@@ -123,7 +123,7 @@ test_cookbook:
/path/one/test_cookbook
/path/two/test_cookbook
E
- output.string.should include(expected_message)
+ expect(output.string).to include(expected_message)
end
end
@@ -139,17 +139,17 @@ E
end
it "should read only one cookbook" do
- cookbook_loader.should_receive(:[]).once.with('test_cookbook1').and_call_original
+ expect(cookbook_loader).to receive(:[]).once.with('test_cookbook1').and_call_original
knife.run
end
it "should not read all cookbooks" do
- cookbook_loader.should_not_receive(:load_cookbooks)
+ expect(cookbook_loader).not_to receive(:load_cookbooks)
knife.run
end
it "should upload only one cookbook" do
- knife.should_receive(:upload).exactly(1).times
+ expect(knife).to receive(:upload).exactly(1).times
knife.run
end
end
@@ -181,13 +181,13 @@ E
it "should upload all dependencies once" do
knife.config[:depends] = true
- knife.stub(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2", "test_cookbook3"])
- knife.should_receive(:upload).exactly(3).times
- lambda do
+ allow(knife).to receive(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2", "test_cookbook3"])
+ expect(knife).to receive(:upload).exactly(3).times
+ expect do
Timeout::timeout(5) do
knife.run
end
- end.should_not raise_error
+ end.not_to raise_error
end
end
@@ -196,50 +196,50 @@ E
before(:each) do
cookbook.metadata.depends("dependency")
- cookbook_loader.stub(:[]) do |ckbk|
+ allow(cookbook_loader).to receive(:[]) do |ckbk|
{ "test_cookbook" => cookbook,
"dependency" => cookbook_dependency}[ckbk]
end
- knife.stub(:cookbook_names).and_return(["cookbook_dependency", "test_cookbook"])
+ allow(knife).to receive(:cookbook_names).and_return(["cookbook_dependency", "test_cookbook"])
@stdout, @stderr, @stdin = StringIO.new, StringIO.new, StringIO.new
knife.ui = Chef::Knife::UI.new(@stdout, @stderr, @stdin, {})
end
it 'should exit and not upload the cookbook' do
- cookbook_loader.should_receive(:[]).once.with('test_cookbook')
- cookbook_loader.should_not_receive(:load_cookbooks)
- cookbook_uploader.should_not_receive(:upload_cookbooks)
+ 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
expect {knife.run}.to raise_error(SystemExit)
- @stderr.string.should include('Cookbook test_cookbook depends on cookbooks which are not currently')
- @stderr.string.should include('being uploaded and cannot be found on the server.')
- @stderr.string.should include("The missing cookbook(s) are: 'dependency' version '>= 0.0.0'")
+ 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')
cookbook.metadata.depends("dependency2")
- cookbook_loader.stub(:[]) do |ckbk|
+ allow(cookbook_loader).to receive(:[]) do |ckbk|
{ "test_cookbook" => cookbook,
"dependency" => cookbook_dependency,
"dependency2" => cookbook_dependency2}[ckbk]
end
- knife.stub(:cookbook_names).and_return(["dependency", "dependency2", "test_cookbook"])
+ allow(knife).to receive(:cookbook_names).and_return(["dependency", "dependency2", "test_cookbook"])
expect {knife.run}.to raise_error(SystemExit)
- @stderr.string.should include('Cookbook test_cookbook depends on cookbooks which are not currently')
- @stderr.string.should include('being uploaded and cannot be found on the server.')
- @stderr.string.should include("The missing cookbook(s) are:")
- @stderr.string.should include("'dependency' version '>= 0.0.0'")
- @stderr.string.should include("'dependency2' version '>= 0.0.0'")
+ 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'")
end
end
it "should freeze the version of the cookbooks if --freeze is specified" do
knife.config[:freeze] = true
- cookbook.should_receive(:freeze_version).once
+ expect(cookbook).to receive(:freeze_version).once
knife.run
end
@@ -248,25 +248,25 @@ E
knife.config[:all] = true
@test_cookbook1 = Chef::CookbookVersion.new('test_cookbook1', '/tmp/blah')
@test_cookbook2 = Chef::CookbookVersion.new('test_cookbook2', '/tmp/blah')
- cookbook_loader.stub(:each).and_yield("test_cookbook1", @test_cookbook1).and_yield("test_cookbook2", @test_cookbook2)
- cookbook_loader.stub(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2"])
+ 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
- knife.should_receive(:upload).once
+ expect(knife).to receive(:upload).once
knife.run
end
it 'should report on success' do
- knife.should_receive(:upload).once
- knife.ui.should_receive(:info).with(/Uploaded all cookbooks/)
+ 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
- knife.stub(:assert_environment_valid!).and_return(true)
+ allow(knife).to receive(:assert_environment_valid!).and_return(true)
knife.config[:environment] = "production"
- knife.should_receive(:update_version_constraints).once
+ expect(knife).to receive(:update_version_constraints).once
knife.run
end
end
@@ -274,21 +274,21 @@ E
describe 'when a frozen cookbook exists on the server' do
it 'should fail to replace it' do
exception = Chef::Exceptions::CookbookFrozen.new
- cookbook_uploader.should_receive(:upload_cookbooks).
+ expect(cookbook_uploader).to receive(:upload_cookbooks).
and_raise(exception)
- knife.ui.stub(:error)
- knife.ui.should_receive(:error).with(exception)
- lambda { knife.run }.should raise_error(SystemExit)
+ allow(knife.ui).to receive(:error)
+ expect(knife.ui).to receive(:error).with(exception)
+ expect { knife.run }.to raise_error(SystemExit)
end
it 'should not update the version constraints for an environment' do
- knife.stub(:assert_environment_valid!).and_return(true)
+ allow(knife).to receive(:assert_environment_valid!).and_return(true)
knife.config[:environment] = "production"
- knife.stub(:upload).and_raise(Chef::Exceptions::CookbookFrozen)
- knife.ui.should_receive(:error).with(/Failed to upload 1 cookbook/)
- knife.ui.should_receive(:warn).with(/Not updating version constraints/)
- knife.should_not_receive(:update_version_constraints)
- lambda { knife.run }.should raise_error(SystemExit)
+ allow(knife).to receive(:upload).and_raise(Chef::Exceptions::CookbookFrozen)
+ expect(knife.ui).to receive(:error).with(/Failed to upload 1 cookbook/)
+ expect(knife.ui).to receive(:warn).with(/Not updating version constraints/)
+ expect(knife).not_to receive(:update_version_constraints)
+ expect { knife.run }.to raise_error(SystemExit)
end
end
end # run
diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb
index cd53088419..1291571358 100644
--- a/spec/unit/knife/core/bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/bootstrap_context_spec.rb
@@ -35,18 +35,18 @@ describe Chef::Knife::Core::BootstrapContext do
subject(:bootstrap_context) { described_class.new(config, run_list, chef_config, secret) }
it "runs chef with the first-boot.json in the _default environment" do
- bootstrap_context.start_chef.should eq "chef-client -j /etc/chef/first-boot.json -E _default"
+ expect(bootstrap_context.start_chef).to eq "chef-client -j /etc/chef/first-boot.json -E _default"
end
describe "when in verbosity mode" do
let(:config) { {:verbosity => 2} }
it "adds '-l debug' when verbosity is >= 2" do
- bootstrap_context.start_chef.should eq "chef-client -j /etc/chef/first-boot.json -l debug -E _default"
+ expect(bootstrap_context.start_chef).to eq "chef-client -j /etc/chef/first-boot.json -l debug -E _default"
end
end
it "reads the validation key" do
- bootstrap_context.validation_key.should 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
@@ -56,7 +56,7 @@ chef_server_url "http://chef.example.com:4444"
validation_client_name "chef-validator-testing"
# Using default node name (fqdn)
EXPECTED
- bootstrap_context.config_content.should eq expected
+ expect(bootstrap_context.config_content).to eq expected
end
it "does not set a default log_level" do
@@ -66,14 +66,14 @@ EXPECTED
describe "alternate chef-client path" do
let(:chef_config){ {:chef_client_path => '/usr/local/bin/chef-client'} }
it "runs chef-client from another path when specified" do
- bootstrap_context.start_chef.should eq "/usr/local/bin/chef-client -j /etc/chef/first-boot.json -E _default"
+ expect(bootstrap_context.start_chef).to eq "/usr/local/bin/chef-client -j /etc/chef/first-boot.json -E _default"
end
end
describe "validation key path that contains a ~" do
let(:chef_config){ {:validation_key => '~/my.key'} }
it "reads the validation key when it contains a ~" do
- IO.should_receive(:read).with(File.expand_path("my.key", ENV['HOME']))
+ expect(IO).to receive(:read).with(File.expand_path("my.key", ENV['HOME']))
bootstrap_context.validation_key
end
end
@@ -81,44 +81,44 @@ EXPECTED
describe "when an explicit node name is given" do
let(:config){ {:chef_node_name => 'foobar.example.com' }}
it "sets the node name in the client.rb" do
- bootstrap_context.config_content.should match(/node_name "foobar\.example\.com"/)
+ expect(bootstrap_context.config_content).to match(/node_name "foobar\.example\.com"/)
end
end
describe "when bootstrapping into a specific environment" do
let(:chef_config){ {:environment => "prodtastic"} }
it "starts chef in the configured environment" do
- bootstrap_context.start_chef.should == '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
describe "when JSON attributes are given" do
let(:config) { {:first_boot_attributes => {:baz => :quux}} }
it "adds the attributes to first_boot" do
- Chef::JSONCompat.to_json(bootstrap_context.first_boot).should eq(Chef::JSONCompat.to_json({:baz => :quux, :run_list => run_list}))
+ expect(Chef::JSONCompat.to_json(bootstrap_context.first_boot)).to eq(Chef::JSONCompat.to_json({:baz => :quux, :run_list => run_list}))
end
end
describe "when JSON attributes are NOT given" do
it "sets first_boot equal to run_list" do
- Chef::JSONCompat.to_json(bootstrap_context.first_boot).should eq(Chef::JSONCompat.to_json({:run_list => run_list}))
+ expect(Chef::JSONCompat.to_json(bootstrap_context.first_boot)).to eq(Chef::JSONCompat.to_json({:run_list => run_list}))
end
end
describe "when an encrypted_data_bag_secret is provided" do
let(:secret) { "supersekret" }
it "reads the encrypted_data_bag_secret" do
- bootstrap_context.encrypted_data_bag_secret.should eq "supersekret"
+ expect(bootstrap_context.encrypted_data_bag_secret).to eq "supersekret"
end
end
describe "to support compatibility with existing templates" do
it "sets the @config instance variable" do
- bootstrap_context.instance_variable_get(:@config).should eq config
+ expect(bootstrap_context.instance_variable_get(:@config)).to eq config
end
it "sets the @run_list instance variable" do
- bootstrap_context.instance_variable_get(:@run_list).should eq run_list
+ expect(bootstrap_context.instance_variable_get(:@run_list)).to eq run_list
end
end
@@ -130,7 +130,7 @@ EXPECTED
end
it "should send the full version to the installer" do
- bootstrap_context.latest_current_chef_version_string.should eq("-v 11.12.4")
+ expect(bootstrap_context.latest_current_chef_version_string).to eq("-v 11.12.4")
end
end
@@ -142,20 +142,20 @@ EXPECTED
end
it "should send the full version to the installer and set the pre-release flag" do
- bootstrap_context.latest_current_chef_version_string.should eq("-v 11.12.4.rc.0 -p")
+ expect(bootstrap_context.latest_current_chef_version_string).to eq("-v 11.12.4.rc.0 -p")
end
end
describe "when a bootstrap_version is not specified" do
it "should send the latest current to the installer" do
# Intentionally hard coded in order not to replicate the logic.
- bootstrap_context.latest_current_chef_version_string.should eq("-v #{Chef::VERSION.to_i}")
+ expect(bootstrap_context.latest_current_chef_version_string).to eq("-v #{Chef::VERSION.to_i}")
end
end
describe "ssl_verify_mode" do
it "isn't set in the config_content by default" do
- bootstrap_context.config_content.should_not include("ssl_verify_mode")
+ expect(bootstrap_context.config_content).not_to include("ssl_verify_mode")
end
describe "when configured in config" do
@@ -166,14 +166,14 @@ EXPECTED
end
it "uses the config value" do
- bootstrap_context.config_content.should include("ssl_verify_mode :verify_peer")
+ expect(bootstrap_context.config_content).to include("ssl_verify_mode :verify_peer")
end
describe "when configured via CLI" do
let(:config) {{:node_ssl_verify_mode => "none"}}
it "uses CLI value" do
- bootstrap_context.config_content.should include("ssl_verify_mode :verify_none")
+ expect(bootstrap_context.config_content).to include("ssl_verify_mode :verify_none")
end
end
end
@@ -181,7 +181,7 @@ EXPECTED
describe "verify_api_cert" do
it "isn't set in the config_content by default" do
- bootstrap_context.config_content.should_not include("verify_api_cert")
+ expect(bootstrap_context.config_content).not_to include("verify_api_cert")
end
describe "when configured in config" do
@@ -192,14 +192,14 @@ EXPECTED
end
it "uses the config value" do
- bootstrap_context.config_content.should include("verify_api_cert false")
+ expect(bootstrap_context.config_content).to include("verify_api_cert false")
end
describe "when configured via CLI" do
let(:config) {{:node_verify_api_cert => true}}
it "uses CLI value" do
- bootstrap_context.config_content.should include("verify_api_cert true")
+ expect(bootstrap_context.config_content).to include("verify_api_cert true")
end
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 69da5400b0..2d66df31c1 100644
--- a/spec/unit/knife/core/cookbook_scm_repo_spec.rb
+++ b/spec/unit/knife/core/cookbook_scm_repo_spec.rb
@@ -39,45 +39,45 @@ BRANCHES
end
it "has a path to the cookbook repo" do
- @cookbook_repo.repo_path.should == @repo_path
+ expect(@cookbook_repo.repo_path).to eq(@repo_path)
end
it "has a default branch" do
- @cookbook_repo.default_branch.should == 'master'
+ expect(@cookbook_repo.default_branch).to eq('master')
end
describe "when sanity checking the repo" do
it "exits when the directory does not exist" do
- ::File.should_receive(:directory?).with(@repo_path).and_return(false)
- lambda {@cookbook_repo.sanity_check}.should raise_error(SystemExit)
+ expect(::File).to receive(:directory?).with(@repo_path).and_return(false)
+ expect {@cookbook_repo.sanity_check}.to raise_error(SystemExit)
end
describe "and the repo dir exists" do
before do
- ::File.stub(:directory?).with(@repo_path).and_return(true)
+ allow(::File).to receive(:directory?).with(@repo_path).and_return(true)
end
it "exits when there is no git repo" do
- ::File.stub(:directory?).with(/.*\.git/).and_return(false)
- lambda {@cookbook_repo.sanity_check}.should raise_error(SystemExit)
+ allow(::File).to receive(:directory?).with(/.*\.git/).and_return(false)
+ expect {@cookbook_repo.sanity_check}.to raise_error(SystemExit)
end
describe "and the repo is a git repo" do
before do
- ::File.stub(: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"}
- @cookbook_repo.should_receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@nobranches)
- lambda {@cookbook_repo.sanity_check}.should raise_error(SystemExit)
+ 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
describe "and the default branch exists" do
before do
@master_branch = Mixlib::ShellOut.new
@master_branch.stdout.replace "* master\n"
- @cookbook_repo.should_receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@master_branch)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git branch --no-color", :cwd => @repo_path).and_return(@master_branch)
end
it "exits when the git repo is dirty" do
@@ -85,14 +85,14 @@ BRANCHES
@dirty_status.stdout.replace(<<-DIRTY)
M chef/lib/chef/knife/cookbook_site_vendor.rb
DIRTY
- @cookbook_repo.should_receive(:shell_out!).with('git status --porcelain', :cwd => @repo_path).and_return(@dirty_status)
- lambda {@cookbook_repo.sanity_check}.should raise_error(SystemExit)
+ 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")}
- @cookbook_repo.stub(: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
- @cookbook_repo.should_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
- @cookbook_repo.should_receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list)
- @cookbook_repo.branch_exists?("chef-vendor-apache2").should be_true
- @cookbook_repo.should_receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list)
- @cookbook_repo.branch_exists?("chef-vendor-nginx").should be_false
+ 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.branch_exists?("chef-vendor-nginx")).to be_falsey
end
it "determines if a the branch not exists correctly without substring search" do
- @cookbook_repo.should_receive(:shell_out!).twice.with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list)
- @cookbook_repo.should_not be_branch_exists("chef-vendor-absent")
- @cookbook_repo.should be_branch_exists("chef-vendor-absent-new")
+ 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
- @cookbook_repo.should_receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list)
- @cookbook_repo.should_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
- @cookbook_repo.should_receive(:shell_out!).with('git branch --no-color', :cwd => @repo_path).and_return(@branch_list)
- @cookbook_repo.should_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")
- @cookbook_repo.stub(: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
- @cookbook_repo.updated?('apache2').should be_false
+ expect(@cookbook_repo.updated?('apache2')).to be_falsey
end
it "does nothing to finalize the updates" do
- @cookbook_repo.finalize_updates_to('apache2', '1.2.3').should be_false
+ expect(@cookbook_repo.finalize_updates_to('apache2', '1.2.3')).to be_falsey
end
end
@@ -159,18 +159,18 @@ DIRTY
before do
@updates = Mixlib::ShellOut.new
@updates.stdout.replace(" M cookbooks/apache2/recipes/default.rb\n")
- @cookbook_repo.stub(: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
- @cookbook_repo.updated?('apache2').should be_true
+ expect(@cookbook_repo.updated?('apache2')).to be_truthy
end
it "commits the changes to the repo and tags the commit" do
- @cookbook_repo.should_receive(:shell_out!).with("git add apache2", :cwd => @repo_path)
- @cookbook_repo.should_receive(:shell_out!).with("git commit -m \"Import apache2 version 1.2.3\" -- apache2", :cwd => @repo_path)
- @cookbook_repo.should_receive(:shell_out!).with("git tag -f cookbook-site-imported-apache2-1.2.3", :cwd => @repo_path)
- @cookbook_repo.finalize_updates_to("apache2", "1.2.3").should be_true
+ expect(@cookbook_repo).to receive(:shell_out!).with("git add apache2", :cwd => @repo_path)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git commit -m \"Import apache2 version 1.2.3\" -- apache2", :cwd => @repo_path)
+ expect(@cookbook_repo).to receive(:shell_out!).with("git tag -f cookbook-site-imported-apache2-1.2.3", :cwd => @repo_path)
+ expect(@cookbook_repo.finalize_updates_to("apache2", "1.2.3")).to be_truthy
end
end
@@ -180,7 +180,7 @@ DIRTY
end
it "resets to default state by checking out the default branch" do
- @cookbook_repo.should_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/object_loader_spec.rb b/spec/unit/knife/core/object_loader_spec.rb
index 53a538da91..67fa858029 100644
--- a/spec/unit/knife/core/object_loader_spec.rb
+++ b/spec/unit/knife/core/object_loader_spec.rb
@@ -24,17 +24,17 @@ describe Chef::Knife::Core::ObjectLoader do
before(:each) do
@knife = Chef::Knife.new
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
Dir.chdir(File.join(CHEF_SPEC_DATA, 'object_loader'))
end
shared_examples_for "Chef object" do |chef_class|
it "should create a #{chef_class} object" do
- @object.should be_a_kind_of(chef_class)
+ expect(@object).to be_a_kind_of(chef_class)
end
it "should has a attribute 'name'" do
- @object.name.should eql('test')
+ expect(@object.name).to eql('test')
end
end
diff --git a/spec/unit/knife/core/subcommand_loader_spec.rb b/spec/unit/knife/core/subcommand_loader_spec.rb
index 53664cb528..66c202f680 100644
--- a/spec/unit/knife/core/subcommand_loader_spec.rb
+++ b/spec/unit/knife/core/subcommand_loader_spec.rb
@@ -20,22 +20,22 @@ require 'spec_helper'
describe Chef::Knife::SubcommandLoader do
before do
- Chef::Platform.stub(:windows?) { false }
+ allow(Chef::Platform).to receive(:windows?) { false }
@home = File.join(CHEF_SPEC_DATA, 'knife-home')
@env = {'HOME' => @home}
@loader = Chef::Knife::SubcommandLoader.new(File.join(CHEF_SPEC_DATA, 'knife-site-subcommands'), @env)
end
it "builds a list of the core subcommand file require paths" do
- @loader.subcommand_files.should_not be_empty
+ expect(@loader.subcommand_files).not_to be_empty
@loader.subcommand_files.each do |require_path|
- require_path.should match(/chef\/knife\/.*|plugins\/knife\/.*/)
+ expect(require_path).to match(/chef\/knife\/.*|plugins\/knife\/.*/)
end
end
it "finds files installed via rubygems" do
- @loader.find_subcommands_via_rubygems.should include('chef/knife/node_create')
- @loader.find_subcommands_via_rubygems.each {|rel_path, abs_path| abs_path.should match(%r[chef/knife/.+])}
+ 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
@@ -44,33 +44,33 @@ describe Chef::Knife::SubcommandLoader do
'/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'
]
- $LOAD_PATH.should_receive(:map).and_return([])
+ expect($LOAD_PATH).to receive(:map).and_return([])
if Gem::Specification.respond_to? :latest_specs
- Gem::Specification.should_receive(:latest_specs).with(true).and_return(gems)
- gems[0].should_receive(:matches_for_glob).with(/chef\/knife\/\*\.rb\{(.*),\.rb,(.*)\}/).and_return(gem_files)
+ expect(Gem::Specification).to receive(:latest_specs).with(true).and_return(gems)
+ expect(gems[0]).to receive(:matches_for_glob).with(/chef\/knife\/\*\.rb\{(.*),\.rb,(.*)\}/).and_return(gem_files)
else
- Gem.source_index.should_receive(:latest_specs).with(true).and_return(gems)
- gems[0].should_receive(:require_paths).twice.and_return(['lib'])
- gems[0].should_receive(:full_gem_path).and_return('/usr/lib/ruby/gems/knife-ec2-0.5.12')
- Dir.should_receive(:[]).with('/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/*.rb').and_return(gem_files)
+ 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)
end
- @loader.should_receive(:find_subcommands_via_dirglob).and_return({})
- @loader.find_subcommands_via_rubygems.values.select { |file| file =~ /knife-ec2/ }.sort.should == gem_files
+ expect(@loader).to receive(:find_subcommands_via_dirglob).and_return({})
+ expect(@loader.find_subcommands_via_rubygems.values.select { |file| file =~ /knife-ec2/ }.sort).to eq(gem_files)
end
it "finds files using a dirglob when rubygems is not available" do
- @loader.find_subcommands_via_dirglob.should include('chef/knife/node_create')
- @loader.find_subcommands_via_dirglob.each {|rel_path, abs_path| abs_path.should match(%r[chef/knife/.+])}
+ 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')
- @loader.site_subcommands.should include(expected_command)
+ 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')
- @loader.site_subcommands.should include(expected_command)
+ expect(@loader.site_subcommands).to include(expected_command)
end
describe "finding 3rd party plugins" do
@@ -79,39 +79,39 @@ describe Chef::Knife::SubcommandLoader do
before do
env_dup = ENV.to_hash
- ENV.stub(:[]).and_return { |key| env_dup[key] }
- ENV.stub(:[]).with("HOME").and_return(env_home)
+ allow(ENV).to receive(:[]) { |key| env_dup[key] }
+ allow(ENV).to receive(:[]).with("HOME").and_return(env_home)
end
context "when there is not a ~/.chef/plugin_manifest.json file" do
before do
- File.stub(:exist?).with(manifest_path).and_return(false)
+ allow(File).to receive(:exist?).with(manifest_path).and_return(false)
end
it "searches rubygems for plugins" do
if Gem::Specification.respond_to?(:latest_specs)
- Gem::Specification.should_receive(:latest_specs).and_call_original
+ expect(Gem::Specification).to receive(:latest_specs).and_call_original
else
- Gem.source_index.should_receive(:latest_specs).and_call_original
+ expect(Gem.source_index).to receive(:latest_specs).and_call_original
end
@loader.subcommand_files.each do |require_path|
- require_path.should match(/chef\/knife\/.*|plugins\/knife\/.*/)
+ expect(require_path).to match(/chef\/knife\/.*|plugins\/knife\/.*/)
end
end
context "and HOME environment variable is not set" do
before do
- ENV.stub(:[]).with("HOME").and_return(nil)
+ allow(ENV).to receive(:[]).with("HOME").and_return(nil)
end
it "searches rubygems for plugins" do
if Gem::Specification.respond_to?(:latest_specs)
- Gem::Specification.should_receive(:latest_specs).and_call_original
+ expect(Gem::Specification).to receive(:latest_specs).and_call_original
else
- Gem.source_index.should_receive(:latest_specs).and_call_original
+ expect(Gem.source_index).to receive(:latest_specs).and_call_original
end
@loader.subcommand_files.each do |require_path|
- require_path.should match(/chef\/knife\/.*|plugins\/knife\/.*/)
+ expect(require_path).to match(/chef\/knife\/.*|plugins\/knife\/.*/)
end
end
end
@@ -135,13 +135,13 @@ describe Chef::Knife::SubcommandLoader do
let(:manifest_json) { Chef::JSONCompat.to_json(manifest_content) }
before do
- File.stub(:exist?).with(manifest_path).and_return(true)
- File.stub(:read).with(manifest_path).and_return(manifest_json)
+ allow(File).to receive(:exist?).with(manifest_path).and_return(true)
+ allow(File).to receive(:read).with(manifest_path).and_return(manifest_json)
end
it "uses paths from the manifest instead of searching gems" do
- Gem::Specification.should_not_receive(:latest_specs).and_call_original
- @loader.subcommand_files.should include(ec2_server_create_plugin)
+ expect(Gem::Specification).not_to receive(:latest_specs).and_call_original
+ expect(@loader.subcommand_files).to include(ec2_server_create_plugin)
end
end
diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb
index ed1037ebd5..83fff4c082 100644
--- a/spec/unit/knife/core/ui_spec.rb
+++ b/spec/unit/knife/core/ui_spec.rb
@@ -67,16 +67,16 @@ describe Chef::Knife::UI do
@ui.config[:disable_editing] = false
@ui.config[:editor] = my_editor
@mock = double('Tempfile')
- @mock.should_receive(:sync=).with(true)
- @mock.should_receive(:puts).with(json_from_ruby)
- @mock.should_receive(:close)
- @mock.should_receive(:path).at_least(:once).and_return(temp_path)
- Tempfile.should_receive(:open).with([ 'knife-edit-', '.json' ]).and_yield(@mock)
+ 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)
end
context "and the editor works" do
before do
- @ui.should_receive(:system).with("#{my_editor} #{temp_path}").and_return(true)
- IO.should_receive(:read).with(temp_path).and_return(json_from_editor)
+ expect(@ui).to receive(:system).with("#{my_editor} #{temp_path}").and_return(true)
+ expect(IO).to receive(:read).with(temp_path).and_return(json_from_editor)
end
context "when parse_output is false" do
@@ -93,8 +93,8 @@ describe Chef::Knife::UI do
end
context "when running the editor fails with nil" do
before do
- @ui.should_receive(:system).with("#{my_editor} #{temp_path}").and_return(nil)
- IO.should_not_receive(:read)
+ expect(@ui).to receive(:system).with("#{my_editor} #{temp_path}").and_return(nil)
+ expect(IO).not_to receive(:read)
end
it "throws an exception" do
expect{ subject }.to raise_error(RuntimeError)
@@ -102,8 +102,8 @@ describe Chef::Knife::UI do
end
context "when running the editor fails with false" do
before do
- @ui.should_receive(:system).with("#{my_editor} #{temp_path}").and_return(false)
- IO.should_not_receive(:read)
+ expect(@ui).to receive(:system).with("#{my_editor} #{temp_path}").and_return(false)
+ expect(IO).not_to receive(:read)
end
it "throws an exception" do
expect{ subject }.to raise_error(RuntimeError)
@@ -115,13 +115,13 @@ describe Chef::Knife::UI do
@ui.config[:disable_editing] = false
@ui.config[:editor] = my_editor
@tempfile = Tempfile.new([ 'knife-edit-', '.json' ])
- Tempfile.should_receive(:open).with([ 'knife-edit-', '.json' ]).and_yield(@tempfile)
+ expect(Tempfile).to receive(:open).with([ 'knife-edit-', '.json' ]).and_yield(@tempfile)
end
context "and the editor works" do
before do
- @ui.should_receive(:system).with("#{my_editor} #{@tempfile.path}").and_return(true)
- IO.should_receive(:read).with(@tempfile.path).and_return(json_from_editor)
+ expect(@ui).to receive(:system).with("#{my_editor} #{@tempfile.path}").and_return(true)
+ expect(IO).to receive(:read).with(@tempfile.path).and_return(json_from_editor)
end
context "when parse_output is false" do
@@ -153,33 +153,33 @@ describe Chef::Knife::UI do
describe "format_list_for_display" do
it "should print the full hash if --with-uri is true" do
@ui.config[:with_uri] = true
- @ui.format_list_for_display({ :marcy => :playground }).should == { :marcy => :playground }
+ expect(@ui.format_list_for_display({ :marcy => :playground })).to eq({ :marcy => :playground })
end
it "should print only the keys if --with-uri is false" do
@ui.config[:with_uri] = false
- @ui.format_list_for_display({ :marcy => :playground }).should == [ :marcy ]
+ expect(@ui.format_list_for_display({ :marcy => :playground })).to eq([ :marcy ])
end
end
shared_examples "an output mehthod handling IO exceptions" do |method|
it "should throw Errno::EIO exceptions" do
- @out.stub(:puts).and_raise(Errno::EIO)
- @err.stub(:puts).and_raise(Errno::EIO)
- lambda {@ui.send(method, "hi")}.should raise_error(Errno::EIO)
+ allow(@out).to receive(:puts).and_raise(Errno::EIO)
+ allow(@err).to receive(:puts).and_raise(Errno::EIO)
+ expect {@ui.send(method, "hi")}.to raise_error(Errno::EIO)
end
it "should ignore Errno::EPIPE exceptions (CHEF-3516)" do
- @out.stub(:puts).and_raise(Errno::EPIPE)
- @err.stub(:puts).and_raise(Errno::EPIPE)
- lambda {@ui.send(method, "hi")}.should raise_error(SystemExit)
+ allow(@out).to receive(:puts).and_raise(Errno::EPIPE)
+ allow(@err).to receive(:puts).and_raise(Errno::EPIPE)
+ expect {@ui.send(method, "hi")}.to raise_error(SystemExit)
end
it "should throw Errno::EPIPE exceptions with -VV (CHEF-3516)" do
@config[:verbosity] = 2
- @out.stub(:puts).and_raise(Errno::EPIPE)
- @err.stub(:puts).and_raise(Errno::EPIPE)
- lambda {@ui.send(method, "hi")}.should raise_error(Errno::EPIPE)
+ allow(@out).to receive(:puts).and_raise(Errno::EPIPE)
+ allow(@err).to receive(:puts).and_raise(Errno::EPIPE)
+ expect {@ui.send(method, "hi")}.to raise_error(Errno::EPIPE)
end
end
@@ -188,12 +188,12 @@ describe Chef::Knife::UI do
it "formats strings appropriately" do
@ui.output("hi")
- @out.string.should == "hi\n"
+ expect(@out.string).to eq("hi\n")
end
it "formats hashes appropriately" do
@ui.output({'hi' => 'a', 'lo' => 'b' })
- @out.string.should == <<EOM
+ expect(@out.string).to eq <<EOM
hi: a
lo: b
EOM
@@ -201,12 +201,12 @@ EOM
it "formats empty hashes appropriately" do
@ui.output({})
- @out.string.should == "\n"
+ expect(@out.string).to eq("\n")
end
it "formats arrays appropriately" do
@ui.output([ 'a', 'b' ])
- @out.string.should == <<EOM
+ expect(@out.string).to eq <<EOM
a
b
EOM
@@ -214,22 +214,22 @@ EOM
it "formats empty arrays appropriately" do
@ui.output([ ])
- @out.string.should == "\n"
+ expect(@out.string).to eq("\n")
end
it "formats single-member arrays appropriately" do
@ui.output([ 'a' ])
- @out.string.should == "a\n"
+ expect(@out.string).to eq("a\n")
end
it "formats nested single-member arrays appropriately" do
@ui.output([ [ 'a' ] ])
- @out.string.should == "a\n"
+ expect(@out.string).to eq("a\n")
end
it "formats nested arrays appropriately" do
@ui.output([ [ 'a', 'b' ], [ 'c', 'd' ]])
- @out.string.should == <<EOM
+ expect(@out.string).to eq <<EOM
a
b
@@ -240,7 +240,7 @@ EOM
it "formats nested arrays with single- and empty subarrays appropriately" do
@ui.output([ [ 'a', 'b' ], [ 'c' ], [], [ 'd', 'e' ]])
- @out.string.should == <<EOM
+ expect(@out.string).to eq <<EOM
a
b
@@ -254,7 +254,7 @@ EOM
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' }])
- @out.string.should == <<EOM
+ expect(@out.string).to eq <<EOM
a: b
c: d
@@ -267,7 +267,7 @@ EOM
it "formats hashes with empty array members appropriately" do
@ui.output({ 'a' => [], 'b' => 'c' })
- @out.string.should == <<EOM
+ expect(@out.string).to eq <<EOM
a:
b: c
EOM
@@ -275,7 +275,7 @@ EOM
it "formats hashes with single-member array values appropriately" do
@ui.output({ 'a' => [ 'foo' ], 'b' => 'c' })
- @out.string.should == <<EOM
+ expect(@out.string).to eq <<EOM
a: foo
b: c
EOM
@@ -283,7 +283,7 @@ EOM
it "formats hashes with array members appropriately" do
@ui.output({ 'a' => [ 'foo', 'bar' ], 'b' => 'c' })
- @out.string.should == <<EOM
+ expect(@out.string).to eq <<EOM
a:
foo
bar
@@ -293,7 +293,7 @@ EOM
it "formats hashes with single-member nested array values appropriately" do
@ui.output({ 'a' => [ [ 'foo' ] ], 'b' => 'c' })
- @out.string.should == <<EOM
+ expect(@out.string).to eq <<EOM
a:
foo
b: c
@@ -304,12 +304,12 @@ EOM
@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.
- @out.string.should == "a:\n foo\n bar\n \n baz\n bjork\nb: c\n"
+ 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' })
- @out.string.should == <<EOM
+ expect(@out.string).to eq <<EOM
a:
aa: bb
cc: dd
@@ -319,7 +319,7 @@ EOM
it "formats hashes with empty hash values appropriately" do
@ui.output({ 'a' => { }, 'b' => 'c' })
- @out.string.should == <<EOM
+ expect(@out.string).to eq <<EOM
a:
b: c
EOM
@@ -341,20 +341,20 @@ EOM
describe "format_for_display" do
it "should return the raw data" do
input = { :gi => :go }
- @ui.format_for_display(input).should == input
+ expect(@ui.format_for_display(input)).to eq(input)
end
describe "with --attribute passed" do
it "should return the deeply nested attribute" do
input = { "gi" => { "go" => "ge" }, "id" => "sample-data-bag-item" }
@ui.config[:attribute] = "gi.go"
- @ui.format_for_display(input).should == { "sample-data-bag-item" => { "gi.go" => "ge" } }
+ expect(@ui.format_for_display(input)).to eq({ "sample-data-bag-item" => { "gi.go" => "ge" } })
end
it "should return multiple attributes" do
input = { "gi" => "go", "hi" => "ho", "id" => "sample-data-bag-item" }
@ui.config[:attribute] = ["gi", "hi"]
- @ui.format_for_display(input).should == { "sample-data-bag-item" => { "gi" => "go", "hi"=> "ho" } }
+ expect(@ui.format_for_display(input)).to eq({ "sample-data-bag-item" => { "gi" => "go", "hi"=> "ho" } })
end
end
@@ -365,8 +365,8 @@ EOM
input.run_list("role[monkey]", "role[churchmouse]")
@ui.config[:run_list] = true
response = @ui.format_for_display(input)
- response["sample-node"]["run_list"][0].should == "role[monkey]"
- response["sample-node"]["run_list"][1].should == "role[churchmouse]"
+ expect(response["sample-node"]["run_list"][0]).to eq("role[monkey]")
+ expect(response["sample-node"]["run_list"][1]).to eq("role[churchmouse]")
end
end
end
@@ -388,7 +388,7 @@ EOM
it "should return an array of the cookbooks with versions" do
expected_response = [ "cookbook_name 3.0.0 2.0.0 1.0.0" ]
response = @ui.format_cookbook_list_for_display(@item)
- response.should == expected_response
+ expect(response).to eq(expected_response)
end
describe "with --with-uri" do
@@ -400,15 +400,15 @@ EOM
"3.0.0" => "http://url/cookbooks/3.0.0"}
}
@ui.config[:with_uri] = true
- @ui.format_cookbook_list_for_display(@item).should == response
+ expect(@ui.format_cookbook_list_for_display(@item)).to eq(response)
end
end
context "when running on Windows" do
before(:each) do
stdout = double('StringIO', :tty? => true)
- @ui.stub(:stdout).and_return(stdout)
- Chef::Platform.stub(:windows?) { true }
+ allow(@ui).to receive(:stdout).and_return(stdout)
+ allow(Chef::Platform).to receive(:windows?) { true }
Chef::Config.reset
end
@@ -444,36 +444,36 @@ EOM
let(:append_instructions) { true }
def run_confirm
- @ui.stub(:stdout).and_return(stdout)
- @ui.stdin.stub(:readline).and_return(answer)
+ allow(@ui).to receive(:stdout).and_return(stdout)
+ allow(@ui.stdin).to receive(:readline).and_return(answer)
@ui.confirm(question, append_instructions, default_choice)
end
def run_confirm_without_exit
- @ui.stub(:stdout).and_return(stdout)
- @ui.stdin.stub(:readline).and_return(answer)
+ allow(@ui).to receive(:stdout).and_return(stdout)
+ allow(@ui.stdin).to receive(:readline).and_return(answer)
@ui.confirm_without_exit(question, append_instructions, default_choice)
end
shared_examples_for "confirm with positive answer" do
it "confirm should return true" do
- run_confirm.should be_true
+ expect(run_confirm).to be_truthy
end
it "confirm_without_exit should return true" do
- run_confirm_without_exit.should be_true
+ expect(run_confirm_without_exit).to be_truthy
end
end
shared_examples_for "confirm with negative answer" do
it "confirm should exit 3" do
- lambda {
+ expect {
run_confirm
- }.should raise_error(SystemExit) { |e| e.status.should == 3 }
+ }.to raise_error(SystemExit) { |e| expect(e.status).to eq(3) }
end
it "confirm_without_exit should return false" do
- run_confirm_without_exit.should be_false
+ expect(run_confirm_without_exit).to be_falsey
end
end
@@ -482,7 +482,7 @@ EOM
it "should show 'Y/n' in the instructions" do
run_confirm
- output.should include("Y/n")
+ expect(output).to include("Y/n")
end
describe "with empty answer" do
@@ -503,7 +503,7 @@ EOM
it "should show 'y/N' in the instructions" do
run_confirm
- output.should include("y/N")
+ expect(output).to include("y/N")
end
describe "with empty answer" do
@@ -538,8 +538,8 @@ EOM
describe "with --y or --yes passed" do
it "should return true" do
@ui.config[:yes] = true
- run_confirm.should be_true
- output.should eq("")
+ expect(run_confirm).to be_truthy
+ expect(output).to eq("")
end
end
end
@@ -547,18 +547,18 @@ EOM
describe "when asking for free-form user input" do
it "asks a question and returns the answer provided by the user" do
out = StringIO.new
- @ui.stub(:stdout).and_return(out)
- @ui.stub(:stdin).and_return(StringIO.new("http://mychefserver.example.com\n"))
- @ui.ask_question("your chef server URL?").should == "http://mychefserver.example.com"
- out.string.should == "your chef server URL?"
+ allow(@ui).to receive(:stdout).and_return(out)
+ allow(@ui).to receive(:stdin).and_return(StringIO.new("http://mychefserver.example.com\n"))
+ expect(@ui.ask_question("your chef server URL?")).to eq("http://mychefserver.example.com")
+ expect(out.string).to eq("your chef server URL?")
end
it "suggests a default setting and returns the default when the user's response only contains whitespace" do
out = StringIO.new
- @ui.stub(:stdout).and_return(out)
- @ui.stub(:stdin).and_return(StringIO.new(" \n"))
- @ui.ask_question("your chef server URL? ", :default => 'http://localhost:4000').should == "http://localhost:4000"
- out.string.should == "your chef server URL? [http://localhost:4000] "
+ 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(out.string).to eq("your chef server URL? [http://localhost:4000] ")
end
end
diff --git a/spec/unit/knife/data_bag_from_file_spec.rb b/spec/unit/knife/data_bag_from_file_spec.rb
index 8de046e7a4..3882bff349 100644
--- a/spec/unit/knife/data_bag_from_file_spec.rb
+++ b/spec/unit/knife/data_bag_from_file_spec.rb
@@ -26,7 +26,7 @@ Chef::Knife::DataBagFromFile.load_deps
describe Chef::Knife::DataBagFromFile do
before :each do
- Chef::Platform.stub(:windows?) { false }
+ allow(Chef::Platform).to receive(:windows?) { false }
Chef::Config[:node_name] = "webmonkey.example.com"
FileUtils.mkdir_p([db_folder, db_folder2])
db_file.write(Chef::JSONCompat.to_json(plain_data))
diff --git a/spec/unit/knife/environment_compare_spec.rb b/spec/unit/knife/environment_compare_spec.rb
index 3606b617a9..6d4d3ead52 100644
--- a/spec/unit/knife/environment_compare_spec.rb
+++ b/spec/unit/knife/environment_compare_spec.rb
@@ -27,21 +27,21 @@ describe Chef::Knife::EnvironmentCompare do
"citm" => "http://localhost:4000/environments/citm"
}
- @knife.stub(:environment_list).and_return(@environments)
+ allow(@knife).to receive(:environment_list).and_return(@environments)
@constraints = {
"cita" => { "foo" => "= 1.0.1", "bar" => "= 0.0.4" },
"citm" => { "foo" => "= 1.0.1", "bar" => "= 0.0.2" }
}
- @knife.stub(:constraint_list).and_return(@constraints)
+ allow(@knife).to receive(:constraint_list).and_return(@constraints)
@cookbooks = { "foo"=>"= 1.0.1", "bar"=>"= 0.0.1" }
- @knife.stub(:cookbook_list).and_return(@cookbooks)
+ allow(@knife).to receive(:cookbook_list).and_return(@cookbooks)
@rest_double = double('rest')
- @knife.stub(:rest).and_return(@rest_double)
+ 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_data = {}
@@ -51,10 +51,10 @@ describe Chef::Knife::EnvironmentCompare do
'url' => "#{@base_url}/#{item}/1.0.1"}]}
end
- @rest_double.stub(:get_rest).with("/cookbooks?num_versions=1").and_return(@cookbook_data)
+ allow(@rest_double).to receive(:get_rest).with("/cookbooks?num_versions=1").and_return(@cookbook_data)
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe 'run' do
@@ -62,14 +62,14 @@ describe Chef::Knife::EnvironmentCompare do
@knife.config[:format] = 'summary'
@knife.run
@environments.each do |item, url|
- @stdout.string.should match /#{item}/ and @stdout.string.lines.count.should be 4
+ 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'
@knife.run
- @stdout.string.lines.count.should be 4
+ expect(@stdout.string.lines.count).to be 4
end
end
@@ -79,7 +79,7 @@ describe Chef::Knife::EnvironmentCompare do
@knife.config[:mismatch] = true
@knife.run
@constraints.each do |item, ver|
- @stdout.string.should match /#{ver[1]}/
+ expect(@stdout.string).to match /#{ver[1]}/
end
end
@@ -87,7 +87,7 @@ describe Chef::Knife::EnvironmentCompare do
@knife.config[:format] = 'summary'
@knife.config[:mismatch] = true
@knife.run
- @stdout.string.lines.count.should be 3
+ expect(@stdout.string.lines.count).to be 3
end
end
@@ -97,7 +97,7 @@ describe Chef::Knife::EnvironmentCompare do
@knife.config[:all] = true
@knife.run
@constraints.each do |item, ver|
- @stdout.string.should match /#{ver[1]}/
+ expect(@stdout.string).to match /#{ver[1]}/
end
end
@@ -105,7 +105,7 @@ describe Chef::Knife::EnvironmentCompare do
@knife.config[:format] = 'summary'
@knife.config[:all] = true
@knife.run
- @stdout.string.lines.count.should be 8
+ expect(@stdout.string.lines.count).to be 8
end
end
diff --git a/spec/unit/knife/environment_create_spec.rb b/spec/unit/knife/environment_create_spec.rb
index 81bf6731b7..04e45048ef 100644
--- a/spec/unit/knife/environment_create_spec.rb
+++ b/spec/unit/knife/environment_create_spec.rb
@@ -21,49 +21,49 @@ require 'spec_helper'
describe Chef::Knife::EnvironmentCreate do
before(:each) do
@knife = Chef::Knife::EnvironmentCreate.new
- @knife.stub(:msg).and_return true
- @knife.stub(:output).and_return true
- @knife.stub(:show_usage).and_return true
+ allow(@knife).to receive(:msg).and_return true
+ allow(@knife).to receive(:output).and_return true
+ allow(@knife).to receive(:show_usage).and_return true
@knife.name_args = [ "production" ]
@environment = Chef::Environment.new
- @environment.stub(:save)
+ allow(@environment).to receive(:save)
- Chef::Environment.stub(:new).and_return @environment
- @knife.stub(:edit_data).and_return @environment
+ allow(Chef::Environment).to receive(:new).and_return @environment
+ allow(@knife).to receive(:edit_data).and_return @environment
end
describe "run" do
it "should create a new environment" do
- Chef::Environment.should_receive(:new)
+ expect(Chef::Environment).to receive(:new)
@knife.run
end
it "should set the environment name" do
- @environment.should_receive(:name).with("production")
+ expect(@environment).to receive(:name).with("production")
@knife.run
end
it "should not print the environment" do
- @knife.should_not_receive(:output)
+ expect(@knife).not_to receive(:output)
@knife.run
end
it "should prompt you to edit the data" do
- @knife.should_receive(:edit_data).with(@environment)
+ expect(@knife).to receive(:edit_data).with(@environment)
@knife.run
end
it "should save the environment" do
- @environment.should_receive(:save)
+ expect(@environment).to receive(:save)
@knife.run
end
it "should show usage and exit when no environment name is provided" do
@knife.name_args = [ ]
- @knife.ui.should_receive(:fatal)
- @knife.should_receive(:show_usage)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife.ui).to receive(:fatal)
+ expect(@knife).to receive(:show_usage)
+ expect { @knife.run }.to raise_error(SystemExit)
end
describe "with --description" do
@@ -72,7 +72,7 @@ describe Chef::Knife::EnvironmentCreate do
end
it "should set the description" do
- @environment.should_receive(:description).with("This is production")
+ expect(@environment).to receive(:description).with("This is production")
@knife.run
end
end
@@ -83,7 +83,7 @@ describe Chef::Knife::EnvironmentCreate do
end
it "should pretty print the environment, formatted for display" do
- @knife.should_receive(:output).with(@environment)
+ expect(@knife).to receive(:output).with(@environment)
@knife.run
end
end
diff --git a/spec/unit/knife/environment_delete_spec.rb b/spec/unit/knife/environment_delete_spec.rb
index 0f6b5f3272..95df6e15fe 100644
--- a/spec/unit/knife/environment_delete_spec.rb
+++ b/spec/unit/knife/environment_delete_spec.rb
@@ -21,50 +21,50 @@ require 'spec_helper'
describe Chef::Knife::EnvironmentDelete do
before(:each) do
@knife = Chef::Knife::EnvironmentDelete.new
- @knife.stub(:msg).and_return true
- @knife.stub(:output).and_return true
- @knife.stub(:show_usage).and_return true
- @knife.stub(:confirm).and_return true
+ allow(@knife).to receive(:msg).and_return true
+ allow(@knife).to receive(:output).and_return true
+ allow(@knife).to receive(:show_usage).and_return true
+ allow(@knife).to receive(:confirm).and_return true
@knife.name_args = [ "production" ]
@environment = Chef::Environment.new
@environment.name("production")
@environment.description("Please delete me")
- @environment.stub(:destroy).and_return true
- Chef::Environment.stub(:load).and_return @environment
+ allow(@environment).to receive(:destroy).and_return true
+ allow(Chef::Environment).to receive(:load).and_return @environment
end
it "should confirm that you want to delete" do
- @knife.should_receive(:confirm)
+ expect(@knife).to receive(:confirm)
@knife.run
end
it "should load the environment" do
- Chef::Environment.should_receive(:load).with("production")
+ expect(Chef::Environment).to receive(:load).with("production")
@knife.run
end
it "should delete the environment" do
- @environment.should_receive(:destroy)
+ expect(@environment).to receive(:destroy)
@knife.run
end
it "should not print the environment" do
- @knife.should_not_receive(:output)
+ expect(@knife).not_to receive(:output)
@knife.run
end
it "should show usage and exit when no environment name is provided" do
@knife.name_args = []
- @knife.ui.should_receive(:fatal)
- @knife.should_receive(:show_usage)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife.ui).to receive(:fatal)
+ expect(@knife).to receive(:show_usage)
+ expect { @knife.run }.to raise_error(SystemExit)
end
describe "with --print-after" do
it "should pretty print the environment, formatted for display" do
@knife.config[:print_after] = true
- @knife.should_receive(:output).with(@environment)
+ expect(@knife).to receive(:output).with(@environment)
@knife.run
end
end
diff --git a/spec/unit/knife/environment_edit_spec.rb b/spec/unit/knife/environment_edit_spec.rb
index a82ead0b6b..61c2663a41 100644
--- a/spec/unit/knife/environment_edit_spec.rb
+++ b/spec/unit/knife/environment_edit_spec.rb
@@ -21,26 +21,26 @@ require 'spec_helper'
describe Chef::Knife::EnvironmentEdit do
before(:each) do
@knife = Chef::Knife::EnvironmentEdit.new
- @knife.ui.stub(:msg).and_return true
- @knife.ui.stub(:output).and_return true
- @knife.ui.stub(:show_usage).and_return true
+ allow(@knife.ui).to receive(:msg).and_return true
+ allow(@knife.ui).to receive(:output).and_return true
+ allow(@knife.ui).to receive(:show_usage).and_return true
@knife.name_args = [ "production" ]
@environment = Chef::Environment.new
@environment.name("production")
@environment.description("Please edit me")
- @environment.stub(:save).and_return true
- Chef::Environment.stub(:load).and_return @environment
- @knife.ui.stub(:edit_data).and_return @environment
+ allow(@environment).to receive(:save).and_return true
+ allow(Chef::Environment).to receive(:load).and_return @environment
+ allow(@knife.ui).to receive(:edit_data).and_return @environment
end
it "should load the environment" do
- Chef::Environment.should_receive(:load).with("production")
+ expect(Chef::Environment).to receive(:load).with("production")
@knife.run
end
it "should let you edit the environment" do
- @knife.ui.should_receive(:edit_data).with(@environment)
+ expect(@knife.ui).to receive(:edit_data).with(@environment)
@knife.run
end
@@ -48,31 +48,31 @@ describe Chef::Knife::EnvironmentEdit do
pansy = Chef::Environment.new
@environment.name("new_environment_name")
- @knife.ui.should_receive(:edit_data).with(@environment).and_return(pansy)
- pansy.should_receive(:save)
+ expect(@knife.ui).to receive(:edit_data).with(@environment).and_return(pansy)
+ expect(pansy).to receive(:save)
@knife.run
end
it "should not save the unedited environment data" do
- @environment.should_not_receive(:save)
+ expect(@environment).not_to receive(:save)
@knife.run
end
it "should not print the environment" do
- @knife.should_not_receive(:output)
+ expect(@knife).not_to receive(:output)
@knife.run
end
it "shoud show usage and exit when no environment name is provided" do
@knife.name_args = []
- @knife.should_receive(:show_usage)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife).to receive(:show_usage)
+ expect { @knife.run }.to raise_error(SystemExit)
end
describe "with --print-after" do
it "should pretty print the environment, formatted for display" do
@knife.config[:print_after] = true
- @knife.ui.should_receive(:output).with(@environment)
+ expect(@knife.ui).to receive(:output).with(@environment)
@knife.run
end
end
diff --git a/spec/unit/knife/environment_from_file_spec.rb b/spec/unit/knife/environment_from_file_spec.rb
index 562e7f8cf5..d150e5ee64 100644
--- a/spec/unit/knife/environment_from_file_spec.rb
+++ b/spec/unit/knife/environment_from_file_spec.rb
@@ -23,24 +23,24 @@ Chef::Knife::EnvironmentFromFile.load_deps
describe Chef::Knife::EnvironmentFromFile do
before(:each) do
- Chef::Platform.stub(:windows?) { false }
+ allow(Chef::Platform).to receive(:windows?) { false }
@knife = Chef::Knife::EnvironmentFromFile.new
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
@knife.name_args = [ "spec.rb" ]
@environment = Chef::Environment.new
@environment.name("spec")
@environment.description("runs the unit tests")
@environment.cookbook_versions({"apt" => "= 1.2.3"})
- @environment.stub(:save).and_return true
- @knife.loader.stub(:load_from).and_return @environment
+ allow(@environment).to receive(:save).and_return true
+ allow(@knife.loader).to receive(:load_from).and_return @environment
end
describe "run" do
it "loads the environment data from a file and saves it" do
- @knife.loader.should_receive(:load_from).with('environments', 'spec.rb').and_return(@environment)
- @environment.should_receive(:save)
+ expect(@knife.loader).to receive(:load_from).with('environments', 'spec.rb').and_return(@environment)
+ expect(@environment).to receive(:save)
@knife.run
end
@@ -48,41 +48,41 @@ describe Chef::Knife::EnvironmentFromFile do
before(:each) do
@env_apple = @environment.dup
@env_apple.name("apple")
- @knife.loader.stub(:load_from).with("apple.rb").and_return @env_apple
+ allow(@knife.loader).to receive(:load_from).with("apple.rb").and_return @env_apple
end
it "loads multiple environments if given" do
@knife.name_args = [ "spec.rb", "apple.rb" ]
- @environment.should_receive(:save).twice
+ expect(@environment).to receive(:save).twice
@knife.run
end
it "loads all environments with -a" do
- File.stub(:expand_path).with("./environments/").and_return("/tmp/environments")
- Dir.stub(:glob).with("/tmp/environments/*.{json,rb}").and_return(["spec.rb", "apple.rb"])
+ allow(File).to receive(:expand_path).with("./environments/").and_return("/tmp/environments")
+ allow(Dir).to receive(:glob).with("/tmp/environments/*.{json,rb}").and_return(["spec.rb", "apple.rb"])
@knife.name_args = []
- @knife.stub(:config).and_return({:all => true})
- @environment.should_receive(:save).twice
+ allow(@knife).to receive(:config).and_return({:all => true})
+ expect(@environment).to receive(:save).twice
@knife.run
end
end
it "should not print the environment" do
- @knife.should_not_receive(:output)
+ expect(@knife).not_to receive(:output)
@knife.run
end
it "should show usage and exit if not filename is provided" do
@knife.name_args = []
- @knife.ui.should_receive(:fatal)
- @knife.should_receive(:show_usage)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife.ui).to receive(:fatal)
+ expect(@knife).to receive(:show_usage)
+ expect { @knife.run }.to raise_error(SystemExit)
end
describe "with --print-after" do
it "should pretty print the environment, formatted for display" do
@knife.config[:print_after] = true
- @knife.should_receive(:output)
+ expect(@knife).to receive(:output)
@knife.run
end
end
diff --git a/spec/unit/knife/environment_list_spec.rb b/spec/unit/knife/environment_list_spec.rb
index 25d2714d23..6488a073b6 100644
--- a/spec/unit/knife/environment_list_spec.rb
+++ b/spec/unit/knife/environment_list_spec.rb
@@ -21,33 +21,33 @@ require 'spec_helper'
describe Chef::Knife::EnvironmentList do
before(:each) do
@knife = Chef::Knife::EnvironmentList.new
- @knife.stub(:msg).and_return true
- @knife.stub(:output).and_return true
- @knife.stub(:show_usage).and_return true
+ allow(@knife).to receive(:msg).and_return true
+ allow(@knife).to receive(:output).and_return true
+ allow(@knife).to receive(:show_usage).and_return true
@environments = {
"production" => "http://localhost:4000/environments/production",
"development" => "http://localhost:4000/environments/development",
"testing" => "http://localhost:4000/environments/testing"
}
- Chef::Environment.stub(:list).and_return @environments
+ allow(Chef::Environment).to receive(:list).and_return @environments
end
it "should make an api call to list the environments" do
- Chef::Environment.should_receive(:list)
+ expect(Chef::Environment).to receive(:list)
@knife.run
end
it "should print the environment names in a sorted list" do
names = @environments.keys.sort { |a,b| a <=> b }
- @knife.should_receive(:output).with(names)
+ expect(@knife).to receive(:output).with(names)
@knife.run
end
describe "with --with-uri" do
it "should print and unsorted list of the environments and their URIs" do
@knife.config[:with_uri] = true
- @knife.should_receive(:output).with(@environments)
+ expect(@knife).to receive(:output).with(@environments)
@knife.run
end
end
diff --git a/spec/unit/knife/environment_show_spec.rb b/spec/unit/knife/environment_show_spec.rb
index c7b0c21657..caac958f8e 100644
--- a/spec/unit/knife/environment_show_spec.rb
+++ b/spec/unit/knife/environment_show_spec.rb
@@ -21,32 +21,32 @@ require 'spec_helper'
describe Chef::Knife::EnvironmentShow do
before(:each) do
@knife = Chef::Knife::EnvironmentShow.new
- @knife.stub(:msg).and_return true
- @knife.stub(:output).and_return true
- @knife.stub(:show_usage).and_return true
+ allow(@knife).to receive(:msg).and_return true
+ allow(@knife).to receive(:output).and_return true
+ allow(@knife).to receive(:show_usage).and_return true
@knife.name_args = [ "production" ]
@environment = Chef::Environment.new
@environment.name("production")
@environment.description("Look at me!")
- Chef::Environment.stub(:load).and_return @environment
+ allow(Chef::Environment).to receive(:load).and_return @environment
end
it "should load the environment" do
- Chef::Environment.should_receive(:load).with("production")
+ expect(Chef::Environment).to receive(:load).with("production")
@knife.run
end
it "should pretty print the environment, formatted for display" do
- @knife.should_receive(:format_for_display).with(@environment)
- @knife.should_receive(:output)
+ expect(@knife).to receive(:format_for_display).with(@environment)
+ expect(@knife).to receive(:output)
@knife.run
end
it "should show usage and exit when no environment name is provided" do
@knife.name_args = []
- @knife.ui.should_receive(:fatal)
- @knife.should_receive(:show_usage)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife.ui).to receive(:fatal)
+ expect(@knife).to receive(:show_usage)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
diff --git a/spec/unit/knife/index_rebuild_spec.rb b/spec/unit/knife/index_rebuild_spec.rb
index 3a8ec00651..6c3b60bd88 100644
--- a/spec/unit/knife/index_rebuild_spec.rb
+++ b/spec/unit/knife/index_rebuild_spec.rb
@@ -24,18 +24,18 @@ describe Chef::Knife::IndexRebuild do
let(:rest_client){double(Chef::REST)}
let(:stub_rest!) do
- knife.should_receive(:rest).and_return(rest_client)
+ expect(knife).to receive(:rest).and_return(rest_client)
end
before :each do
# This keeps the test output clean
- knife.ui.stub(:stdout).and_return(StringIO.new)
+ allow(knife.ui).to receive(:stdout).and_return(StringIO.new)
end
context "#grab_api_info" do
let(:http_not_found_response) do
e = Net::HTTPNotFound.new("1.1", 404, "blah")
- e.stub(:[]).with("x-ops-api-info").and_return(api_header_value)
+ allow(e).to receive(:[]).with("x-ops-api-info").and_return(api_header_value)
e
end
@@ -45,20 +45,20 @@ describe Chef::Knife::IndexRebuild do
before(:each) do
stub_rest!
- rest_client.stub(:get_rest).and_raise(http_server_exception)
+ allow(rest_client).to receive(:get_rest).and_raise(http_server_exception)
end
context "against a Chef 11 server" do
let(:api_header_value){"flavor=osc;version=11.0.0;erchef=1.2.3"}
it "retrieves API information" do
- knife.grab_api_info.should == {"flavor" => "osc", "version" => "11.0.0", "erchef" => "1.2.3"}
+ expect(knife.grab_api_info).to eq({"flavor" => "osc", "version" => "11.0.0", "erchef" => "1.2.3"})
end
end # Chef 11
context "against a Chef 10 server" do
let(:api_header_value){nil}
it "finds no API information" do
- knife.grab_api_info.should == {}
+ expect(knife.grab_api_info).to eq({})
end
end # Chef 10
end # grab_api_info
@@ -66,18 +66,18 @@ describe Chef::Knife::IndexRebuild do
context "#unsupported_version?" do
context "with Chef 11 API metadata" do
it "is unsupported" do
- knife.unsupported_version?({"version" => "11.0.0", "flavor" => "osc", "erchef" => "1.2.3"}).should be_true
+ expect(knife.unsupported_version?({"version" => "11.0.0", "flavor" => "osc", "erchef" => "1.2.3"})).to be_truthy
end
it "only truly relies on the version being non-nil" do
- knife.unsupported_version?({"version" => "1", "flavor" => "osc", "erchef" => "1.2.3"}).should be_true
+ expect(knife.unsupported_version?({"version" => "1", "flavor" => "osc", "erchef" => "1.2.3"})).to be_truthy
end
end
context "with Chef 10 API metadata" do
it "is supported" do
# Chef 10 will have no metadata
- knife.unsupported_version?({}).should be_false
+ expect(knife.unsupported_version?({})).to be_falsey
end
end
end # unsupported_version?
@@ -85,7 +85,7 @@ describe Chef::Knife::IndexRebuild do
context "Simulating a 'knife index rebuild' run" do
before :each do
- knife.should_receive(:grab_api_info).and_return(api_info)
+ expect(knife).to receive(:grab_api_info).and_return(api_info)
server_specific_stubs!
end
@@ -97,8 +97,8 @@ describe Chef::Knife::IndexRebuild do
}
end
let(:server_specific_stubs!) do
- knife.should_receive(:unsupported_server_message).with(api_info)
- knife.should_receive(:exit).with(1)
+ expect(knife).to receive(:unsupported_server_message).with(api_info)
+ expect(knife).to receive(:exit).with(1)
end
it "should not be allowed" do
@@ -110,11 +110,11 @@ describe Chef::Knife::IndexRebuild do
let(:api_info){ {} }
let(:server_specific_stubs!) do
stub_rest!
- rest_client.should_receive(:post_rest).with("/search/reindex", {}).and_return("representative output")
- knife.should_not_receive(:unsupported_server_message)
- knife.should_receive(:deprecated_server_message)
- knife.should_receive(:nag)
- knife.should_receive(:output).with("representative output")
+ expect(rest_client).to receive(:post_rest).with("/search/reindex", {}).and_return("representative output")
+ expect(knife).not_to receive(:unsupported_server_message)
+ expect(knife).to receive(:deprecated_server_message)
+ expect(knife).to receive(:nag)
+ expect(knife).to receive(:output).with("representative output")
end
it "should be allowed" do
knife.run
diff --git a/spec/unit/knife/knife_help.rb b/spec/unit/knife/knife_help.rb
index e66a44801b..293bae17f4 100644
--- a/spec/unit/knife/knife_help.rb
+++ b/spec/unit/knife/knife_help.rb
@@ -26,66 +26,66 @@ describe Chef::Knife::Help do
end
it "should return a list of help topics" do
- @knife.help_topics.should include("knife-status")
+ expect(@knife.help_topics).to include("knife-status")
end
it "should run man for you" do
@knife.name_args = [ "shell" ]
- @knife.should_receive(:exec).with(/^man \/.*\/shell.1$/)
+ expect(@knife).to receive(:exec).with(/^man \/.*\/shell.1$/)
@knife.run
end
it "should suggest topics" do
@knife.name_args = [ "list" ]
- @knife.ui.stub(:msg)
- @knife.ui.should_receive(:info).with("Available help topics are: ")
- @knife.ui.should_receive(:msg).with(/knife/)
- @knife.stub(:exec)
- @knife.should_receive(:exit).with(1)
+ allow(@knife.ui).to receive(:msg)
+ expect(@knife.ui).to receive(:info).with("Available help topics are: ")
+ expect(@knife.ui).to receive(:msg).with(/knife/)
+ allow(@knife).to receive(:exec)
+ expect(@knife).to receive(:exit).with(1)
@knife.run
end
describe "find_manpage_path" do
it "should find the man page in the gem" do
- @knife.find_manpage_path("shell").should =~ /distro\/common\/man\/man1\/chef-shell.1$/
+ expect(@knife.find_manpage_path("shell")).to match(/distro\/common\/man\/man1\/chef-shell.1$/)
end
it "should provide the man page name if not in the gem" do
- @knife.find_manpage_path("foo").should == "foo"
+ expect(@knife.find_manpage_path("foo")).to eq("foo")
end
end
describe "find_manpages_for_query" do
it "should error if it does not find a match" do
- @knife.ui.stub(:error)
- @knife.ui.stub(:info)
- @knife.ui.stub(:msg)
- @knife.should_receive(:exit).with(1)
- @knife.ui.should_receive(:error).with("No help found for 'chickens'")
- @knife.ui.should_receive(:msg).with(/knife/)
+ allow(@knife.ui).to receive(:error)
+ allow(@knife.ui).to receive(:info)
+ allow(@knife.ui).to receive(:msg)
+ expect(@knife).to receive(:exit).with(1)
+ expect(@knife.ui).to receive(:error).with("No help found for 'chickens'")
+ expect(@knife.ui).to receive(:msg).with(/knife/)
@knife.find_manpages_for_query("chickens")
end
end
describe "print_help_topics" do
it "should print the known help topics" do
- @knife.ui.stub(:msg)
- @knife.ui.stub(:info)
- @knife.ui.should_receive(:msg).with(/knife/)
+ allow(@knife.ui).to receive(:msg)
+ allow(@knife.ui).to receive(:info)
+ expect(@knife.ui).to receive(:msg).with(/knife/)
@knife.print_help_topics
end
it "should shorten topics prefixed by knife-" do
- @knife.ui.stub(:msg)
- @knife.ui.stub(:info)
- @knife.ui.should_receive(:msg).with(/node/)
+ allow(@knife.ui).to receive(:msg)
+ allow(@knife.ui).to receive(:info)
+ expect(@knife.ui).to receive(:msg).with(/node/)
@knife.print_help_topics
end
it "should not leave topics prefixed by knife-" do
- @knife.ui.stub(:msg)
- @knife.ui.stub(:info)
- @knife.ui.should_not_receive(:msg).with(/knife-node/)
+ allow(@knife.ui).to receive(:msg)
+ allow(@knife.ui).to receive(:info)
+ expect(@knife.ui).not_to receive(:msg).with(/knife-node/)
@knife.print_help_topics
end
end
diff --git a/spec/unit/knife/node_bulk_delete_spec.rb b/spec/unit/knife/node_bulk_delete_spec.rb
index 3faece5469..57a8d0bf64 100644
--- a/spec/unit/knife/node_bulk_delete_spec.rb
+++ b/spec/unit/knife/node_bulk_delete_spec.rb
@@ -26,8 +26,8 @@ describe Chef::Knife::NodeBulkDelete do
@knife = Chef::Knife::NodeBulkDelete.new
@knife.name_args = ["."]
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
- @knife.ui.stub(:confirm).and_return(true)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:confirm).and_return(true)
@nodes = Hash.new
%w{adam brent jacob}.each do |node_name|
@nodes[node_name] = "http://localhost:4000/nodes/#{node_name}"
@@ -40,11 +40,11 @@ describe Chef::Knife::NodeBulkDelete do
inflatedish[name] = Chef::Node.new.tap {|n| n.name(name)}
inflatedish
end
- Chef::Node.should_receive(:list).and_return(@nodes)
+ expect(Chef::Node).to receive(:list).and_return(@nodes)
# I hate not having == defined for anything :(
actual = @knife.all_nodes
- actual.keys.should =~ expected.keys
- actual.values.map {|n| n.name }.should =~ %w[adam brent jacob]
+ expect(actual.keys).to match_array(expected.keys)
+ expect(actual.values.map {|n| n.name }).to match_array(%w[adam brent jacob])
end
end
@@ -53,41 +53,41 @@ describe Chef::Knife::NodeBulkDelete do
@inflatedish_list = @nodes.keys.inject({}) do |nodes_by_name, name|
node = Chef::Node.new()
node.name(name)
- node.stub(:destroy).and_return(true)
+ allow(node).to receive(:destroy).and_return(true)
nodes_by_name[name] = node
nodes_by_name
end
- @knife.stub(:all_nodes).and_return(@inflatedish_list)
+ allow(@knife).to receive(:all_nodes).and_return(@inflatedish_list)
end
it "should print the nodes you are about to delete" do
@knife.run
- @stdout.string.should match(/#{@knife.ui.list(@nodes.keys.sort, :columns_down)}/)
+ expect(@stdout.string).to match(/#{@knife.ui.list(@nodes.keys.sort, :columns_down)}/)
end
it "should confirm you really want to delete them" do
- @knife.ui.should_receive(:confirm)
+ expect(@knife.ui).to receive(:confirm)
@knife.run
end
it "should delete each node" do
@inflatedish_list.each_value do |n|
- n.should_receive(:destroy)
+ expect(n).to receive(:destroy)
end
@knife.run
end
it "should only delete nodes that match the regex" do
@knife.name_args = ['adam']
- @inflatedish_list['adam'].should_receive(:destroy)
- @inflatedish_list['brent'].should_not_receive(:destroy)
- @inflatedish_list['jacob'].should_not_receive(:destroy)
+ 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
it "should exit if the regex is not provided" do
@knife.name_args = []
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
diff --git a/spec/unit/knife/node_delete_spec.rb b/spec/unit/knife/node_delete_spec.rb
index 04eca389c6..0941d850e5 100644
--- a/spec/unit/knife/node_delete_spec.rb
+++ b/spec/unit/knife/node_delete_spec.rb
@@ -26,41 +26,41 @@ describe Chef::Knife::NodeDelete do
:print_after => nil
}
@knife.name_args = [ "adam" ]
- @knife.stub(:output).and_return(true)
- @knife.stub(:confirm).and_return(true)
+ allow(@knife).to receive(:output).and_return(true)
+ allow(@knife).to receive(:confirm).and_return(true)
@node = Chef::Node.new()
- @node.stub(:destroy).and_return(true)
- Chef::Node.stub(:load).and_return(@node)
+ allow(@node).to receive(:destroy).and_return(true)
+ allow(Chef::Node).to receive(:load).and_return(@node)
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe "run" do
it "should confirm that you want to delete" do
- @knife.should_receive(:confirm)
+ expect(@knife).to receive(:confirm)
@knife.run
end
it "should load the node" do
- Chef::Node.should_receive(:load).with("adam").and_return(@node)
+ expect(Chef::Node).to receive(:load).with("adam").and_return(@node)
@knife.run
end
it "should delete the node" do
- @node.should_receive(:destroy).and_return(@node)
+ expect(@node).to receive(:destroy).and_return(@node)
@knife.run
end
it "should not print the node" do
- @knife.should_not_receive(:output).with("poop")
+ expect(@knife).not_to receive(:output).with("poop")
@knife.run
end
describe "with -p or --print-after" do
it "should pretty print the node, formatted for display" do
@knife.config[:print_after] = true
- @knife.should_receive(:format_for_display).with(@node).and_return("poop")
- @knife.should_receive(:output).with("poop")
+ expect(@knife).to receive(:format_for_display).with(@node).and_return("poop")
+ expect(@knife).to receive(:output).with("poop")
@knife.run
end
end
diff --git a/spec/unit/knife/node_edit_spec.rb b/spec/unit/knife/node_edit_spec.rb
index 27db3416f4..58e2da2a1c 100644
--- a/spec/unit/knife/node_edit_spec.rb
+++ b/spec/unit/knife/node_edit_spec.rb
@@ -39,13 +39,13 @@ describe Chef::Knife::NodeEdit do
end
it "should load the node" do
- Chef::Node.should_receive(:load).with("adam").and_return(@node)
+ expect(Chef::Node).to receive(:load).with("adam").and_return(@node)
@knife.node
end
describe "after loading the node" do
before do
- @knife.stub(:node).and_return(@node)
+ allow(@knife).to receive(:node).and_return(@node)
@node.automatic_attrs = {:go => :away}
@node.default_attrs = {:hide => :me}
@node.override_attrs = {:dont => :show}
@@ -56,37 +56,37 @@ describe Chef::Knife::NodeEdit do
it "creates a view of the node without attributes from roles or ohai" do
actual = deserialized_json_view
- actual.should_not have_key("automatic")
- actual.should_not have_key("override")
- actual.should_not have_key("default")
- actual["normal"].should == {"do_show" => "these"}
- actual["run_list"].should == ["recipe[foo]"]
- actual["chef_environment"].should == "prod"
+ expect(actual).not_to have_key("automatic")
+ expect(actual).not_to have_key("override")
+ expect(actual).not_to have_key("default")
+ expect(actual["normal"]).to eq({"do_show" => "these"})
+ expect(actual["run_list"]).to eq(["recipe[foo]"])
+ expect(actual["chef_environment"]).to eq("prod")
end
it "shows the extra attributes when given the --all option" do
@knife.config[:all_attributes] = true
actual = deserialized_json_view
- actual["automatic"].should == {"go" => "away"}
- actual["override"].should == {"dont" => "show"}
- actual["default"].should == {"hide" => "me"}
- actual["normal"].should == {"do_show" => "these"}
- actual["run_list"].should == ["recipe[foo]"]
- actual["chef_environment"].should == "prod"
+ expect(actual["automatic"]).to eq({"go" => "away"})
+ expect(actual["override"]).to eq({"dont" => "show"})
+ expect(actual["default"]).to eq({"hide" => "me"})
+ expect(actual["normal"]).to eq({"do_show" => "these"})
+ expect(actual["run_list"]).to eq(["recipe[foo]"])
+ expect(actual["chef_environment"]).to eq("prod")
end
it "does not consider unedited data updated" do
view = deserialized_json_view
@knife.node_editor.send(:apply_updates, view)
- @knife.node_editor.should_not be_updated
+ expect(@knife.node_editor).not_to be_updated
end
it "considers edited data updated" do
view = deserialized_json_view
view["run_list"] << "role[fuuu]"
@knife.node_editor.send(:apply_updates, view)
- @knife.node_editor.should be_updated
+ expect(@knife.node_editor).to be_updated
end
end
@@ -94,7 +94,7 @@ describe Chef::Knife::NodeEdit do
describe "edit_node" do
before do
- @knife.stub(:node).and_return(@node)
+ allow(@knife).to receive(:node).and_return(@node)
end
let(:subject) { @knife.node_editor.edit_node }
diff --git a/spec/unit/knife/node_environment_set_spec.rb b/spec/unit/knife/node_environment_set_spec.rb
index 46ee1fea18..10267915d7 100644
--- a/spec/unit/knife/node_environment_set_spec.rb
+++ b/spec/unit/knife/node_environment_set_spec.rb
@@ -23,32 +23,32 @@ describe Chef::Knife::NodeEnvironmentSet do
Chef::Config[:node_name] = "webmonkey.example.com"
@knife = Chef::Knife::NodeEnvironmentSet.new
@knife.name_args = [ "adam", "bar" ]
- @knife.stub(:output).and_return(true)
+ allow(@knife).to receive(:output).and_return(true)
@node = Chef::Node.new()
@node.name("knifetest-node")
@node.chef_environment << "foo"
- @node.stub(:save).and_return(true)
- Chef::Node.stub(:load).and_return(@node)
+ allow(@node).to receive(:save).and_return(true)
+ allow(Chef::Node).to receive(:load).and_return(@node)
end
describe "run" do
it "should load the node" do
- Chef::Node.should_receive(:load).with("adam")
+ expect(Chef::Node).to receive(:load).with("adam")
@knife.run
end
it "should update the environment" do
@knife.run
- @node.chef_environment.should == 'bar'
+ expect(@node.chef_environment).to eq('bar')
end
it "should save the node" do
- @node.should_receive(:save)
+ expect(@node).to receive(:save)
@knife.run
end
it "should print the environment" do
- @knife.should_receive(:output).and_return(true)
+ expect(@knife).to receive(:output).and_return(true)
@knife.run
end
@@ -58,13 +58,13 @@ describe Chef::Knife::NodeEnvironmentSet do
@stdout = StringIO.new
@stderr = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
- @knife.ui.stub(:stderr).and_return(@stderr)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
end
it "should exit" do
@knife.name_args = [ "adam" ]
- lambda { @knife.run }.should raise_error SystemExit
+ expect { @knife.run }.to raise_error SystemExit
end
it "should show the user the usage and an error" do
@@ -72,8 +72,8 @@ describe Chef::Knife::NodeEnvironmentSet do
begin ; @knife.run ; rescue SystemExit ; end
- @stdout.string.should eq "USAGE: knife node environment set NODE ENVIRONMENT\n"
- @stderr.string.should eq "FATAL: You must specify a node name and an environment.\n"
+ expect(@stdout.string).to eq "USAGE: knife node environment set NODE ENVIRONMENT\n"
+ expect(@stderr.string).to eq "FATAL: You must specify a node name and an environment.\n"
end
end
end
diff --git a/spec/unit/knife/node_from_file_spec.rb b/spec/unit/knife/node_from_file_spec.rb
index 56a2a08b68..623904753e 100644
--- a/spec/unit/knife/node_from_file_spec.rb
+++ b/spec/unit/knife/node_from_file_spec.rb
@@ -28,30 +28,30 @@ describe Chef::Knife::NodeFromFile do
:print_after => nil
}
@knife.name_args = [ "adam.rb" ]
- @knife.stub(:output).and_return(true)
- @knife.stub(:confirm).and_return(true)
+ allow(@knife).to receive(:output).and_return(true)
+ allow(@knife).to receive(:confirm).and_return(true)
@node = Chef::Node.new()
- @node.stub(:save)
- @knife.loader.stub(:load_from).and_return(@node)
+ allow(@node).to receive(:save)
+ allow(@knife.loader).to receive(:load_from).and_return(@node)
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe "run" do
it "should load from a file" do
- @knife.loader.should_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
it "should not print the Node" do
- @knife.should_not_receive(:output)
+ expect(@knife).not_to receive(:output)
@knife.run
end
describe "with -p or --print-after" do
it "should print the Node" do
@knife.config[:print_after] = true
- @knife.should_receive(:output)
+ expect(@knife).to receive(:output)
@knife.run
end
end
diff --git a/spec/unit/knife/node_list_spec.rb b/spec/unit/knife/node_list_spec.rb
index cad2d6482d..71edea78f7 100644
--- a/spec/unit/knife/node_list_spec.rb
+++ b/spec/unit/knife/node_list_spec.rb
@@ -23,38 +23,38 @@ describe Chef::Knife::NodeList do
Chef::Config[:node_name] = "webmonkey.example.com"
Chef::Config[:environment] = nil # reset this value each time, as it is not reloaded
@knife = Chef::Knife::NodeList.new
- @knife.stub(:output).and_return(true)
+ allow(@knife).to receive(:output).and_return(true)
@list = {
"foo" => "http://example.com/foo",
"bar" => "http://example.com/foo"
}
- Chef::Node.stub(:list).and_return(@list)
- Chef::Node.stub(:list_by_environment).and_return(@list)
+ allow(Chef::Node).to receive(:list).and_return(@list)
+ allow(Chef::Node).to receive(:list_by_environment).and_return(@list)
end
describe "run" do
it "should list all of the nodes if -E is not specified" do
- Chef::Node.should_receive(:list).and_return(@list)
+ expect(Chef::Node).to receive(:list).and_return(@list)
@knife.run
end
it "should pretty print the list" do
- Chef::Node.should_receive(:list).and_return(@list)
- @knife.should_receive(:output).with([ "bar", "foo" ])
+ expect(Chef::Node).to receive(:list).and_return(@list)
+ expect(@knife).to receive(:output).with([ "bar", "foo" ])
@knife.run
end
it "should list nodes in the specific environment if -E ENVIRONMENT is specified" do
Chef::Config[:environment] = "prod"
- Chef::Node.should_receive(:list_by_environment).with("prod").and_return(@list)
+ expect(Chef::Node).to receive(:list_by_environment).with("prod").and_return(@list)
@knife.run
end
describe "with -w or --with-uri" do
it "should pretty print the hash" do
@knife.config[:with_uri] = true
- Chef::Node.should_receive(:list).and_return(@list)
- @knife.should_receive(:output).with(@list)
+ expect(Chef::Node).to receive(:list).and_return(@list)
+ expect(@knife).to receive(:output).with(@list)
@knife.run
end
end
diff --git a/spec/unit/knife/node_run_list_add_spec.rb b/spec/unit/knife/node_run_list_add_spec.rb
index bd33a359a2..92fbfd23fe 100644
--- a/spec/unit/knife/node_run_list_add_spec.rb
+++ b/spec/unit/knife/node_run_list_add_spec.rb
@@ -26,30 +26,30 @@ describe Chef::Knife::NodeRunListAdd do
:after => nil
}
@knife.name_args = [ "adam", "role[monkey]" ]
- @knife.stub(:output).and_return(true)
+ allow(@knife).to receive(:output).and_return(true)
@node = Chef::Node.new()
- @node.stub(:save).and_return(true)
- Chef::Node.stub(:load).and_return(@node)
+ allow(@node).to receive(:save).and_return(true)
+ allow(Chef::Node).to receive(:load).and_return(@node)
end
describe "run" do
it "should load the node" do
- Chef::Node.should_receive(:load).with("adam")
+ expect(Chef::Node).to receive(:load).with("adam")
@knife.run
end
it "should add to the run list" do
@knife.run
- @node.run_list[0].should == 'role[monkey]'
+ expect(@node.run_list[0]).to eq('role[monkey]')
end
it "should save the node" do
- @node.should_receive(:save)
+ expect(@node).to receive(:save)
@knife.run
end
it "should print the run list" do
- @knife.should_receive(:output).and_return(true)
+ expect(@knife).to receive(:output).and_return(true)
@knife.run
end
@@ -59,9 +59,9 @@ describe Chef::Knife::NodeRunListAdd do
@node.run_list << "role[barn]"
@knife.config[:after] = "role[acorns]"
@knife.run
- @node.run_list[0].should == "role[acorns]"
- @node.run_list[1].should == "role[monkey]"
- @node.run_list[2].should == "role[barn]"
+ expect(@node.run_list[0]).to eq("role[acorns]")
+ expect(@node.run_list[1]).to eq("role[monkey]")
+ expect(@node.run_list[2]).to eq("role[barn]")
end
end
@@ -71,9 +71,9 @@ describe Chef::Knife::NodeRunListAdd do
@node.run_list << "role[barn]"
@knife.config[:before] = "role[acorns]"
@knife.run
- @node.run_list[0].should == "role[monkey]"
- @node.run_list[1].should == "role[acorns]"
- @node.run_list[2].should == "role[barn]"
+ expect(@node.run_list[0]).to eq("role[monkey]")
+ expect(@node.run_list[1]).to eq("role[acorns]")
+ expect(@node.run_list[2]).to eq("role[barn]")
end
end
@@ -83,8 +83,8 @@ describe Chef::Knife::NodeRunListAdd do
@node.run_list << "role[barn]"
@knife.config[:before] = "role[acorns]"
@knife.config[:after] = "role[acorns]"
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife.ui).to receive(:fatal)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
@@ -93,9 +93,9 @@ describe Chef::Knife::NodeRunListAdd do
@knife.name_args = [ "adam", "role[monkey],role[duck]" ]
@node.run_list << "role[acorns]"
@knife.run
- @node.run_list[0].should == "role[acorns]"
- @node.run_list[1].should == "role[monkey]"
- @node.run_list[2].should == "role[duck]"
+ expect(@node.run_list[0]).to eq("role[acorns]")
+ expect(@node.run_list[1]).to eq("role[monkey]")
+ expect(@node.run_list[2]).to eq("role[duck]")
end
end
@@ -104,9 +104,9 @@ describe Chef::Knife::NodeRunListAdd do
@knife.name_args = [ "adam", "role[monkey], role[duck]" ]
@node.run_list << "role[acorns]"
@knife.run
- @node.run_list[0].should == "role[acorns]"
- @node.run_list[1].should == "role[monkey]"
- @node.run_list[2].should == "role[duck]"
+ expect(@node.run_list[0]).to eq("role[acorns]")
+ expect(@node.run_list[1]).to eq("role[monkey]")
+ expect(@node.run_list[2]).to eq("role[duck]")
end
end
@@ -115,9 +115,9 @@ describe Chef::Knife::NodeRunListAdd do
@knife.name_args = [ "adam", "role[monkey]", "role[duck]" ]
@node.run_list << "role[acorns]"
@knife.run
- @node.run_list[0].should == "role[acorns]"
- @node.run_list[1].should == "role[monkey]"
- @node.run_list[2].should == "role[duck]"
+ expect(@node.run_list[0]).to eq("role[acorns]")
+ expect(@node.run_list[1]).to eq("role[monkey]")
+ expect(@node.run_list[2]).to eq("role[duck]")
end
end
@@ -126,9 +126,9 @@ describe Chef::Knife::NodeRunListAdd do
@knife.name_args = [ "adam", "role[monkey]", "role[duck],recipe[bird::fly]" ]
@node.run_list << "role[acorns]"
@knife.run
- @node.run_list[0].should == "role[acorns]"
- @node.run_list[1].should == "role[monkey]"
- @node.run_list[2].should == "role[duck]"
+ expect(@node.run_list[0]).to eq("role[acorns]")
+ expect(@node.run_list[1]).to eq("role[monkey]")
+ expect(@node.run_list[2]).to eq("role[duck]")
end
end
@@ -137,8 +137,8 @@ describe Chef::Knife::NodeRunListAdd do
@knife.name_args = [ "adam", "role[monkey]," ]
@node.run_list << "role[acorns]"
@knife.run
- @node.run_list[0].should == "role[acorns]"
- @node.run_list[1].should == "role[monkey]"
+ expect(@node.run_list[0]).to eq("role[acorns]")
+ expect(@node.run_list[1]).to eq("role[monkey]")
end
end
end
diff --git a/spec/unit/knife/node_run_list_remove_spec.rb b/spec/unit/knife/node_run_list_remove_spec.rb
index 5a008a3e07..ea951e21dd 100644
--- a/spec/unit/knife/node_run_list_remove_spec.rb
+++ b/spec/unit/knife/node_run_list_remove_spec.rb
@@ -27,33 +27,33 @@ describe Chef::Knife::NodeRunListRemove do
@node = Chef::Node.new()
@node.name("knifetest-node")
@node.run_list << "role[monkey]"
- @node.stub(:save).and_return(true)
+ allow(@node).to receive(:save).and_return(true)
- @knife.ui.stub(:output).and_return(true)
- @knife.ui.stub(:confirm).and_return(true)
+ allow(@knife.ui).to receive(:output).and_return(true)
+ allow(@knife.ui).to receive(:confirm).and_return(true)
- Chef::Node.stub(:load).and_return(@node)
+ allow(Chef::Node).to receive(:load).and_return(@node)
end
describe "run" do
it "should load the node" do
- Chef::Node.should_receive(:load).with("adam").and_return(@node)
+ expect(Chef::Node).to receive(:load).with("adam").and_return(@node)
@knife.run
end
it "should remove the item from the run list" do
@knife.run
- @node.run_list[0].should_not == 'role[monkey]'
+ expect(@node.run_list[0]).not_to eq('role[monkey]')
end
it "should save the node" do
- @node.should_receive(:save).and_return(true)
+ expect(@node).to receive(:save).and_return(true)
@knife.run
end
it "should print the run list" do
@knife.config[:print_after] = true
- @knife.ui.should_receive(:output).with({ "knifetest-node" => { 'run_list' => [] } })
+ expect(@knife.ui).to receive(:output).with({ "knifetest-node" => { 'run_list' => [] } })
@knife.run
end
@@ -63,8 +63,8 @@ describe Chef::Knife::NodeRunListRemove do
@node.run_list << 'recipe[duck::type]'
@knife.name_args = [ 'adam', 'role[monkey],recipe[duck::type]' ]
@knife.run
- @node.run_list.should_not include('role[monkey]')
- @node.run_list.should_not include('recipe[duck::type]')
+ expect(@node.run_list).not_to include('role[monkey]')
+ expect(@node.run_list).not_to include('recipe[duck::type]')
end
end
end
diff --git a/spec/unit/knife/node_run_list_set_spec.rb b/spec/unit/knife/node_run_list_set_spec.rb
index 02281f8385..68daaafd70 100644
--- a/spec/unit/knife/node_run_list_set_spec.rb
+++ b/spec/unit/knife/node_run_list_set_spec.rb
@@ -24,30 +24,30 @@ describe Chef::Knife::NodeRunListSet do
@knife = Chef::Knife::NodeRunListSet.new
@knife.config = {}
@knife.name_args = [ "adam", "role[monkey]" ]
- @knife.stub(:output).and_return(true)
+ allow(@knife).to receive(:output).and_return(true)
@node = Chef::Node.new()
- @node.stub(:save).and_return(true)
- Chef::Node.stub(:load).and_return(@node)
+ allow(@node).to receive(:save).and_return(true)
+ allow(Chef::Node).to receive(:load).and_return(@node)
end
describe "run" do
it "should load the node" do
- Chef::Node.should_receive(:load).with("adam")
+ expect(Chef::Node).to receive(:load).with("adam")
@knife.run
end
it "should set the run list" do
@knife.run
- @node.run_list[0].should == 'role[monkey]'
+ expect(@node.run_list[0]).to eq('role[monkey]')
end
it "should save the node" do
- @node.should_receive(:save)
+ expect(@node).to receive(:save)
@knife.run
end
it "should print the run list" do
- @knife.should_receive(:output).and_return(true)
+ expect(@knife).to receive(:output).and_return(true)
@knife.run
end
@@ -55,8 +55,8 @@ describe Chef::Knife::NodeRunListSet do
it "should set the run list to all the entries" do
@knife.name_args = [ "adam", "role[monkey],role[duck]" ]
@knife.run
- @node.run_list[0].should == "role[monkey]"
- @node.run_list[1].should == "role[duck]"
+ expect(@node.run_list[0]).to eq("role[monkey]")
+ expect(@node.run_list[1]).to eq("role[duck]")
end
end
@@ -64,8 +64,8 @@ describe Chef::Knife::NodeRunListSet do
it "should set the run list to all the entries" do
@knife.name_args = [ "adam", "role[monkey], role[duck]" ]
@knife.run
- @node.run_list[0].should == "role[monkey]"
- @node.run_list[1].should == "role[duck]"
+ expect(@node.run_list[0]).to eq("role[monkey]")
+ expect(@node.run_list[1]).to eq("role[duck]")
end
end
@@ -73,8 +73,8 @@ describe Chef::Knife::NodeRunListSet do
it "should set the run list to all the entries" do
@knife.name_args = [ "adam", "role[monkey]", "role[duck]" ]
@knife.run
- @node.run_list[0].should == "role[monkey]"
- @node.run_list[1].should == "role[duck]"
+ expect(@node.run_list[0]).to eq("role[monkey]")
+ expect(@node.run_list[1]).to eq("role[duck]")
end
end
@@ -82,8 +82,8 @@ describe Chef::Knife::NodeRunListSet do
it "should add to the run list all the entries" do
@knife.name_args = [ "adam", "role[monkey]", "role[duck],recipe[bird::fly]" ]
@knife.run
- @node.run_list[0].should == "role[monkey]"
- @node.run_list[1].should == "role[duck]"
+ expect(@node.run_list[0]).to eq("role[monkey]")
+ expect(@node.run_list[1]).to eq("role[duck]")
end
end
@@ -91,7 +91,7 @@ describe Chef::Knife::NodeRunListSet do
it "should add to the run list one item" do
@knife.name_args = [ "adam", "role[monkey]," ]
@knife.run
- @node.run_list[0].should == "role[monkey]"
+ expect(@node.run_list[0]).to eq("role[monkey]")
end
end
@@ -99,15 +99,15 @@ describe Chef::Knife::NodeRunListSet do
it "should overwrite any existing run list items" do
@node.run_list << "role[acorns]"
@node.run_list << "role[zebras]"
- @node.run_list[0].should == "role[acorns]"
- @node.run_list[1].should == "role[zebras]"
- @node.run_list.run_list_items.size.should == 2
+ expect(@node.run_list[0]).to eq("role[acorns]")
+ expect(@node.run_list[1]).to eq("role[zebras]")
+ expect(@node.run_list.run_list_items.size).to eq(2)
@knife.name_args = [ "adam", "role[monkey]", "role[duck]" ]
@knife.run
- @node.run_list[0].should == "role[monkey]"
- @node.run_list[1].should == "role[duck]"
- @node.run_list.run_list_items.size.should == 2
+ expect(@node.run_list[0]).to eq("role[monkey]")
+ expect(@node.run_list[1]).to eq("role[duck]")
+ expect(@node.run_list.run_list_items.size).to eq(2)
end
end
@@ -117,13 +117,13 @@ describe Chef::Knife::NodeRunListSet do
@stdout = StringIO.new
@stderr = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
- @knife.ui.stub(:stderr).and_return(@stderr)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
end
it "should exit" do
@knife.name_args = [ "adam" ]
- lambda { @knife.run }.should raise_error SystemExit
+ expect { @knife.run }.to raise_error SystemExit
end
it "should show the user" do
@@ -131,8 +131,8 @@ describe Chef::Knife::NodeRunListSet do
begin ; @knife.run ; rescue SystemExit ; end
- @stdout.string.should eq "USAGE: knife node run_list set NODE ENTRIES (options)\n"
- @stderr.string.should eq "FATAL: You must supply both a node name and a run list.\n"
+ expect(@stdout.string).to eq "USAGE: knife node run_list set NODE ENTRIES (options)\n"
+ expect(@stderr.string).to eq "FATAL: You must supply both a node name and a run list.\n"
end
end
diff --git a/spec/unit/knife/role_bulk_delete_spec.rb b/spec/unit/knife/role_bulk_delete_spec.rb
index eb1d3b4cff..5b79e52a04 100644
--- a/spec/unit/knife/role_bulk_delete_spec.rb
+++ b/spec/unit/knife/role_bulk_delete_spec.rb
@@ -27,53 +27,53 @@ describe Chef::Knife::RoleBulkDelete do
}
@knife.name_args = ["."]
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
- @knife.ui.stub(:confirm).and_return(true)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:confirm).and_return(true)
@roles = Hash.new
%w{dev staging production}.each do |role_name|
role = Chef::Role.new()
role.name(role_name)
- role.stub(:destroy).and_return(true)
+ allow(role).to receive(:destroy).and_return(true)
@roles[role_name] = role
end
- Chef::Role.stub(:list).and_return(@roles)
+ allow(Chef::Role).to receive(:list).and_return(@roles)
end
describe "run" do
it "should get the list of the roles" do
- Chef::Role.should_receive(:list).and_return(@roles)
+ expect(Chef::Role).to receive(:list).and_return(@roles)
@knife.run
end
it "should print the roles you are about to delete" do
@knife.run
- @stdout.string.should match(/#{@knife.ui.list(@roles.keys.sort, :columns_down)}/)
+ expect(@stdout.string).to match(/#{@knife.ui.list(@roles.keys.sort, :columns_down)}/)
end
it "should confirm you really want to delete them" do
- @knife.ui.should_receive(:confirm)
+ expect(@knife.ui).to receive(:confirm)
@knife.run
end
it "should delete each role" do
@roles.each_value do |r|
- r.should_receive(:destroy)
+ expect(r).to receive(:destroy)
end
@knife.run
end
it "should only delete roles that match the regex" do
@knife.name_args = ["dev"]
- @roles["dev"].should_receive(:destroy)
- @roles["staging"].should_not_receive(:destroy)
- @roles["production"].should_not_receive(:destroy)
+ expect(@roles["dev"]).to receive(:destroy)
+ expect(@roles["staging"]).not_to receive(:destroy)
+ expect(@roles["production"]).not_to receive(:destroy)
@knife.run
end
it "should exit if the regex is not provided" do
@knife.name_args = []
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
diff --git a/spec/unit/knife/role_create_spec.rb b/spec/unit/knife/role_create_spec.rb
index a4d7392b68..fb748c51f6 100644
--- a/spec/unit/knife/role_create_spec.rb
+++ b/spec/unit/knife/role_create_spec.rb
@@ -26,45 +26,45 @@ describe Chef::Knife::RoleCreate do
:description => nil
}
@knife.name_args = [ "adam" ]
- @knife.stub(:output).and_return(true)
+ allow(@knife).to receive(:output).and_return(true)
@role = Chef::Role.new()
- @role.stub(:save)
- Chef::Role.stub(:new).and_return(@role)
- @knife.stub(:edit_data).and_return(@role)
+ allow(@role).to receive(:save)
+ allow(Chef::Role).to receive(:new).and_return(@role)
+ allow(@knife).to receive(:edit_data).and_return(@role)
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe "run" do
it "should create a new role" do
- Chef::Role.should_receive(:new).and_return(@role)
+ expect(Chef::Role).to receive(:new).and_return(@role)
@knife.run
end
it "should set the role name" do
- @role.should_receive(:name).with("adam")
+ expect(@role).to receive(:name).with("adam")
@knife.run
end
it "should not print the role" do
- @knife.should_not_receive(:output)
+ expect(@knife).not_to receive(:output)
@knife.run
end
it "should allow you to edit the data" do
- @knife.should_receive(:edit_data).with(@role)
+ expect(@knife).to receive(:edit_data).with(@role)
@knife.run
end
it "should save the role" do
- @role.should_receive(:save)
+ expect(@role).to receive(:save)
@knife.run
end
describe "with -d or --description" do
it "should set the description" do
@knife.config[:description] = "All is bob"
- @role.should_receive(:description).with("All is bob")
+ expect(@role).to receive(:description).with("All is bob")
@knife.run
end
end
@@ -72,7 +72,7 @@ describe Chef::Knife::RoleCreate do
describe "with -p or --print-after" do
it "should pretty print the node, formatted for display" do
@knife.config[:print_after] = true
- @knife.should_receive(:output).with(@role)
+ expect(@knife).to receive(:output).with(@role)
@knife.run
end
end
diff --git a/spec/unit/knife/role_delete_spec.rb b/spec/unit/knife/role_delete_spec.rb
index 0771446d49..b1a0d90410 100644
--- a/spec/unit/knife/role_delete_spec.rb
+++ b/spec/unit/knife/role_delete_spec.rb
@@ -26,40 +26,40 @@ describe Chef::Knife::RoleDelete do
:print_after => nil
}
@knife.name_args = [ "adam" ]
- @knife.stub(:output).and_return(true)
- @knife.stub(:confirm).and_return(true)
+ allow(@knife).to receive(:output).and_return(true)
+ allow(@knife).to receive(:confirm).and_return(true)
@role = Chef::Role.new()
- @role.stub(:destroy).and_return(true)
- Chef::Role.stub(:load).and_return(@role)
+ allow(@role).to receive(:destroy).and_return(true)
+ allow(Chef::Role).to receive(:load).and_return(@role)
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe "run" do
it "should confirm that you want to delete" do
- @knife.should_receive(:confirm)
+ expect(@knife).to receive(:confirm)
@knife.run
end
it "should load the Role" do
- Chef::Role.should_receive(:load).with("adam").and_return(@role)
+ expect(Chef::Role).to receive(:load).with("adam").and_return(@role)
@knife.run
end
it "should delete the Role" do
- @role.should_receive(:destroy).and_return(@role)
+ expect(@role).to receive(:destroy).and_return(@role)
@knife.run
end
it "should not print the Role" do
- @knife.should_not_receive(:output)
+ expect(@knife).not_to receive(:output)
@knife.run
end
describe "with -p or --print-after" do
it "should pretty print the Role, formatted for display" do
@knife.config[:print_after] = true
- @knife.should_receive(:output)
+ expect(@knife).to receive(:output)
@knife.run
end
end
diff --git a/spec/unit/knife/role_edit_spec.rb b/spec/unit/knife/role_edit_spec.rb
index f6d3b41d98..0975c6458d 100644
--- a/spec/unit/knife/role_edit_spec.rb
+++ b/spec/unit/knife/role_edit_spec.rb
@@ -24,22 +24,22 @@ describe Chef::Knife::RoleEdit do
@knife = Chef::Knife::RoleEdit.new
@knife.config[:print_after] = nil
@knife.name_args = [ "adam" ]
- @knife.ui.stub(:output).and_return(true)
+ allow(@knife.ui).to receive(:output).and_return(true)
@role = Chef::Role.new()
- @role.stub(:save)
- Chef::Role.stub(:load).and_return(@role)
- @knife.ui.stub(:edit_data).and_return(@role)
- @knife.ui.stub(:msg)
+ allow(@role).to receive(:save)
+ allow(Chef::Role).to receive(:load).and_return(@role)
+ allow(@knife.ui).to receive(:edit_data).and_return(@role)
+ allow(@knife.ui).to receive(:msg)
end
describe "run" do
it "should load the role" do
- Chef::Role.should_receive(:load).with("adam").and_return(@role)
+ expect(Chef::Role).to receive(:load).with("adam").and_return(@role)
@knife.run
end
it "should edit the role data" do
- @knife.ui.should_receive(:edit_data).with(@role)
+ expect(@knife.ui).to receive(:edit_data).with(@role)
@knife.run
end
@@ -47,29 +47,29 @@ describe Chef::Knife::RoleEdit do
pansy = Chef::Role.new
@role.name("new_role_name")
- @knife.ui.should_receive(:edit_data).with(@role).and_return(pansy)
- pansy.should_receive(:save)
+ expect(@knife.ui).to receive(:edit_data).with(@role).and_return(pansy)
+ expect(pansy).to receive(:save)
@knife.run
end
it "should not save the unedited role data" do
pansy = Chef::Role.new
- @knife.ui.should_receive(:edit_data).with(@role).and_return(pansy)
- pansy.should_not_receive(:save)
+ expect(@knife.ui).to receive(:edit_data).with(@role).and_return(pansy)
+ expect(pansy).not_to receive(:save)
@knife.run
end
it "should not print the role" do
- @knife.ui.should_not_receive(:output)
+ expect(@knife.ui).not_to receive(:output)
@knife.run
end
describe "with -p or --print-after" do
it "should pretty print the role, formatted for display" do
@knife.config[:print_after] = true
- @knife.ui.should_receive(:output).with(@role)
+ expect(@knife.ui).to receive(:output).with(@role)
@knife.run
end
end
diff --git a/spec/unit/knife/role_from_file_spec.rb b/spec/unit/knife/role_from_file_spec.rb
index 986414647c..9379f08de3 100644
--- a/spec/unit/knife/role_from_file_spec.rb
+++ b/spec/unit/knife/role_from_file_spec.rb
@@ -28,30 +28,30 @@ describe Chef::Knife::RoleFromFile do
:print_after => nil
}
@knife.name_args = [ "adam.rb" ]
- @knife.stub(:output).and_return(true)
- @knife.stub(:confirm).and_return(true)
+ allow(@knife).to receive(:output).and_return(true)
+ allow(@knife).to receive(:confirm).and_return(true)
@role = Chef::Role.new()
- @role.stub(:save)
- @knife.loader.stub(:load_from).and_return(@role)
+ allow(@role).to receive(:save)
+ allow(@knife.loader).to receive(:load_from).and_return(@role)
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe "run" do
it "should load from a file" do
- @knife.loader.should_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
it "should not print the role" do
- @knife.should_not_receive(:output)
+ expect(@knife).not_to receive(:output)
@knife.run
end
describe "with -p or --print-after" do
it "should print the role" do
@knife.config[:print_after] = true
- @knife.should_receive(:output)
+ expect(@knife).to receive(:output)
@knife.run
end
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" ]
- @knife.loader.should_receive(:load_from).with('roles', 'adam.rb').and_return(@role)
- @knife.loader.should_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 ef9642c04c..808a04d204 100644
--- a/spec/unit/knife/role_list_spec.rb
+++ b/spec/unit/knife/role_list_spec.rb
@@ -22,31 +22,31 @@ describe Chef::Knife::RoleList do
before(:each) do
Chef::Config[:node_name] = "webmonkey.example.com"
@knife = Chef::Knife::RoleList.new
- @knife.stub(:output).and_return(true)
+ allow(@knife).to receive(:output).and_return(true)
@list = {
"foo" => "http://example.com/foo",
"bar" => "http://example.com/foo"
}
- Chef::Role.stub(:list).and_return(@list)
+ allow(Chef::Role).to receive(:list).and_return(@list)
end
describe "run" do
it "should list the roles" do
- Chef::Role.should_receive(:list).and_return(@list)
+ expect(Chef::Role).to receive(:list).and_return(@list)
@knife.run
end
it "should pretty print the list" do
- Chef::Role.should_receive(:list).and_return(@list)
- @knife.should_receive(:output).with([ "bar", "foo" ])
+ expect(Chef::Role).to receive(:list).and_return(@list)
+ expect(@knife).to receive(:output).with([ "bar", "foo" ])
@knife.run
end
describe "with -w or --with-uri" do
it "should pretty print the hash" do
@knife.config[:with_uri] = true
- Chef::Role.should_receive(:list).and_return(@list)
- @knife.should_receive(:output).with(@list)
+ expect(Chef::Role).to receive(:list).and_return(@list)
+ expect(@knife).to receive(:output).with(@list)
@knife.run
end
end
diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb
index 10d63c9c74..501b02c933 100644
--- a/spec/unit/knife/ssh_spec.rb
+++ b/spec/unit/knife/ssh_spec.rb
@@ -45,8 +45,8 @@ describe Chef::Knife::Ssh do
end
def configure_query(node_array)
- @query.stub(:search).and_return([node_array])
- Chef::Search::Query.stub(:new).and_return(@query)
+ allow(@query).to receive(:search).and_return([node_array])
+ allow(Chef::Search::Query).to receive(:new).and_return(@query)
end
def self.should_return_specified_attributes
@@ -54,7 +54,7 @@ describe Chef::Knife::Ssh do
@knife.config[:attribute] = "ipaddress"
@knife.config[:attribute_from_cli] = "ipaddress"
configure_query([@node_foo, @node_bar])
- @knife.should_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,14 +62,14 @@ describe Chef::Knife::Ssh do
@knife.config[:attribute] = "config_file" # this value will be the config file
@knife.config[:attribute_from_cli] = "ipaddress" # this is the value of the command line via #configure_attribute
configure_query([@node_foo, @node_bar])
- @knife.should_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
it "searchs for and returns an array of fqdns" do
configure_query([@node_foo, @node_bar])
- @knife.should_receive(:session_from_list).with([
+ expect(@knife).to receive(:session_from_list).with([
['foo.example.org', nil],
['bar.example.org', nil]
])
@@ -86,7 +86,7 @@ describe Chef::Knife::Ssh do
it "returns an array of cloud public hostnames" do
configure_query([@node_foo, @node_bar])
- @knife.should_receive(:session_from_list).with([
+ 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]
])
@@ -98,22 +98,22 @@ describe Chef::Knife::Ssh do
it "should raise an error if no host are found" do
configure_query([ ])
- @knife.ui.should_receive(:fatal)
- @knife.should_receive(:exit).with(10)
+ expect(@knife.ui).to receive(:fatal)
+ expect(@knife).to receive(:exit).with(10)
@knife.configure_session
end
context "when there are some hosts found but they do not have an attribute to connect with" do
before do
- @query.stub(:search).and_return([[@node_foo, @node_bar]])
+ allow(@query).to receive(:search).and_return([[@node_foo, @node_bar]])
@node_foo.automatic_attrs[:fqdn] = nil
@node_bar.automatic_attrs[:fqdn] = nil
- Chef::Search::Query.stub(:new).and_return(@query)
+ allow(Chef::Search::Query).to receive(:new).and_return(@query)
end
it "should raise a specific error (CHEF-3402)" do
- @knife.ui.should_receive(:fatal).with(/^2 nodes found/)
- @knife.should_receive(:exit).with(10)
+ expect(@knife.ui).to receive(:fatal).with(/^2 nodes found/)
+ expect(@knife).to receive(:exit).with(10)
@knife.configure_session
end
end
@@ -126,7 +126,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"])
- @knife.should_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
@@ -140,34 +140,34 @@ describe Chef::Knife::Ssh do
it "should return fqdn by default" do
@knife.configure_attribute
- @knife.config[:attribute].should == "fqdn"
+ expect(@knife.config[:attribute]).to eq("fqdn")
end
it "should return the value set in the configuration file" do
Chef::Config[:knife][:ssh_attribute] = "config_file"
@knife.configure_attribute
- @knife.config[:attribute].should == "config_file"
+ expect(@knife.config[:attribute]).to eq("config_file")
end
it "should return the value set on the command line" do
@knife.config[:attribute] = "command_line"
@knife.configure_attribute
- @knife.config[:attribute].should == "command_line"
+ expect(@knife.config[:attribute]).to eq("command_line")
end
it "should set attribute_from_cli to the value of attribute from the command line" do
@knife.config[:attribute] = "command_line"
@knife.configure_attribute
- @knife.config[:attribute].should == "command_line"
- @knife.config[:attribute_from_cli].should == "command_line"
+ expect(@knife.config[:attribute]).to eq("command_line")
+ expect(@knife.config[:attribute_from_cli]).to eq("command_line")
end
it "should prefer the command line over the config file for the value of attribute_from_cli" do
Chef::Config[:knife][:ssh_attribute] = "config_file"
@knife.config[:attribute] = "command_line"
@knife.configure_attribute
- @knife.config[:attribute].should == "command_line"
- @knife.config[:attribute_from_cli].should == "command_line"
+ expect(@knife.config[:attribute]).to eq("command_line")
+ expect(@knife.config[:attribute_from_cli]).to eq("command_line")
end
end
@@ -175,22 +175,22 @@ describe Chef::Knife::Ssh do
before :each do
@knife.instance_variable_set(:@longest, 0)
ssh_config = {:timeout => 50, :user => "locutus", :port => 23 }
- Net::SSH.stub(: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.servers[0].port.should == 23
+ 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.servers[0].port.should == 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.servers[0].user.should == "locutus"
+ expect(@knife.session.servers[0].user).to eq("locutus")
end
end
@@ -206,26 +206,26 @@ describe Chef::Knife::Ssh do
let(:command) { "false" }
before do
- execution_channel.
- should_receive(:on_request).
+ expect(execution_channel).
+ to receive(:on_request).
and_yield(nil, double(:data_stream, :read_long => exit_status))
- session_channel.
- should_receive(:exec).
+ expect(session_channel).
+ to receive(:exec).
with(command).
and_yield(execution_channel, true)
- execution_channel2.
- should_receive(:on_request).
+ expect(execution_channel2).
+ to receive(:on_request).
and_yield(nil, double(:data_stream, :read_long => exit_status2))
- session_channel2.
- should_receive(:exec).
+ expect(session_channel2).
+ to receive(:exec).
with(command).
and_yield(execution_channel2, true)
- session.
- should_receive(:open_channel).
+ expect(session).
+ to receive(:open_channel).
and_yield(session_channel).
and_yield(session_channel2)
end
@@ -235,7 +235,7 @@ describe Chef::Knife::Ssh do
let(:exit_status2) { 0 }
it "returns a 0 exit code" do
- @knife.ssh_command(command, session).should == 0
+ expect(@knife.ssh_command(command, session)).to eq(0)
end
end
@@ -244,7 +244,7 @@ describe Chef::Knife::Ssh do
let(:exit_status2) { 0 }
it "returns a non-zero exit code" do
- @knife.ssh_command(command, session).should == 1
+ expect(@knife.ssh_command(command, session)).to eq(1)
end
end
@@ -253,7 +253,7 @@ describe Chef::Knife::Ssh do
let(:exit_status2) { 2 }
it "returns a non-zero exit code" do
- @knife.ssh_command(command, session).should == 2
+ expect(@knife.ssh_command(command, session)).to eq(2)
end
end
end
@@ -261,9 +261,9 @@ describe Chef::Knife::Ssh do
describe "#run" do
before do
@query = Chef::Search::Query.new
- @query.should_receive(:search).and_return([[@node_foo]])
- Chef::Search::Query.stub(:new).and_return(@query)
- @knife.stub(:ssh_command).and_return(exit_code)
+ 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']
end
@@ -271,7 +271,7 @@ describe Chef::Knife::Ssh do
let(:exit_code) { 1 }
it "should exit with a non-zero exit code" do
- @knife.should_receive(:exit).with(exit_code)
+ expect(@knife).to receive(:exit).with(exit_code)
@knife.run
end
end
@@ -280,7 +280,7 @@ describe Chef::Knife::Ssh do
let(:exit_code) { 0 }
it "should not exit" do
- @knife.should_not_receive(:exit)
+ expect(@knife).not_to receive(:exit)
@knife.run
end
end
@@ -296,23 +296,23 @@ describe Chef::Knife::Ssh do
# in this case ssh_password_ng exists, but ssh_password does not
it "should prompt for a password when ssh_passsword_ng is nil" do
@knife.config[:ssh_password_ng] = nil
- @knife.should_receive(:get_password).and_return("mysekretpassw0rd")
+ expect(@knife).to receive(:get_password).and_return("mysekretpassw0rd")
@knife.configure_password
- @knife.config[:ssh_password].should == "mysekretpassw0rd"
+ expect(@knife.config[:ssh_password]).to eq("mysekretpassw0rd")
end
it "should set ssh_password to false if ssh_password_ng is false" do
@knife.config[:ssh_password_ng] = false
- @knife.should_not_receive(:get_password)
+ expect(@knife).not_to receive(:get_password)
@knife.configure_password
- @knife.config[:ssh_password].should be_false
+ expect(@knife.config[:ssh_password]).to be_falsey
end
it "should set ssh_password to ssh_password_ng if we set a password" do
@knife.config[:ssh_password_ng] = "mysekretpassw0rd"
- @knife.should_not_receive(:get_password)
+ expect(@knife).not_to receive(:get_password)
@knife.configure_password
- @knife.config[:ssh_password].should == "mysekretpassw0rd"
+ expect(@knife.config[:ssh_password]).to eq("mysekretpassw0rd")
end
end
@@ -320,23 +320,23 @@ describe Chef::Knife::Ssh do
# in this case ssh_password exists, but ssh_password_ng does not
it "should set ssh_password to nil when ssh_password is nil" do
@knife.config[:ssh_password] = nil
- @knife.should_not_receive(:get_password)
+ expect(@knife).not_to receive(:get_password)
@knife.configure_password
- @knife.config[:ssh_password].should be_nil
+ expect(@knife.config[:ssh_password]).to be_nil
end
it "should set ssh_password to false when ssh_password is false" do
@knife.config[:ssh_password] = false
- @knife.should_not_receive(:get_password)
+ expect(@knife).not_to receive(:get_password)
@knife.configure_password
- @knife.config[:ssh_password].should be_false
+ expect(@knife.config[:ssh_password]).to be_falsey
end
it "should set ssh_password to ssh_password if we set a password" do
@knife.config[:ssh_password] = "mysekretpassw0rd"
- @knife.should_not_receive(:get_password)
+ expect(@knife).not_to receive(:get_password)
@knife.configure_password
- @knife.config[:ssh_password].should == "mysekretpassw0rd"
+ expect(@knife.config[:ssh_password]).to eq("mysekretpassw0rd")
end
end
context "when setting ssh_password in the config variable" do
@@ -347,23 +347,23 @@ describe Chef::Knife::Ssh do
# in this case ssh_password_ng exists, but ssh_password does not
it "should prompt for a password when ssh_passsword_ng is nil" do
@knife.config[:ssh_password_ng] = nil
- @knife.should_receive(:get_password).and_return("mysekretpassw0rd")
+ expect(@knife).to receive(:get_password).and_return("mysekretpassw0rd")
@knife.configure_password
- @knife.config[:ssh_password].should == "mysekretpassw0rd"
+ expect(@knife.config[:ssh_password]).to eq("mysekretpassw0rd")
end
it "should set ssh_password to the configured knife.rb value if ssh_password_ng is false" do
@knife.config[:ssh_password_ng] = false
- @knife.should_not_receive(:get_password)
+ expect(@knife).not_to receive(:get_password)
@knife.configure_password
- @knife.config[:ssh_password].should == "my_knife_passw0rd"
+ expect(@knife.config[:ssh_password]).to eq("my_knife_passw0rd")
end
it "should set ssh_password to ssh_password_ng if we set a password" do
@knife.config[:ssh_password_ng] = "mysekretpassw0rd"
- @knife.should_not_receive(:get_password)
+ expect(@knife).not_to receive(:get_password)
@knife.configure_password
- @knife.config[:ssh_password].should == "mysekretpassw0rd"
+ expect(@knife.config[:ssh_password]).to eq("mysekretpassw0rd")
end
end
@@ -371,23 +371,23 @@ describe Chef::Knife::Ssh do
# in this case ssh_password exists, but ssh_password_ng does not
it "should set ssh_password to the configured knife.rb value when ssh_password is nil" do
@knife.config[:ssh_password] = nil
- @knife.should_not_receive(:get_password)
+ expect(@knife).not_to receive(:get_password)
@knife.configure_password
- @knife.config[:ssh_password].should == "my_knife_passw0rd"
+ expect(@knife.config[:ssh_password]).to eq("my_knife_passw0rd")
end
it "should set ssh_password to the configured knife.rb value when ssh_password is false" do
@knife.config[:ssh_password] = false
- @knife.should_not_receive(:get_password)
+ expect(@knife).not_to receive(:get_password)
@knife.configure_password
- @knife.config[:ssh_password].should == "my_knife_passw0rd"
+ expect(@knife.config[:ssh_password]).to eq("my_knife_passw0rd")
end
it "should set ssh_password to ssh_password if we set a password" do
@knife.config[:ssh_password] = "mysekretpassw0rd"
- @knife.should_not_receive(:get_password)
+ expect(@knife).not_to receive(:get_password)
@knife.configure_password
- @knife.config[:ssh_password].should == "mysekretpassw0rd"
+ expect(@knife.config[:ssh_password]).to eq("mysekretpassw0rd")
end
end
end
diff --git a/spec/unit/knife/ssl_check_spec.rb b/spec/unit/knife/ssl_check_spec.rb
index bb803ce2ca..8eda555108 100644
--- a/spec/unit/knife/ssl_check_spec.rb
+++ b/spec/unit/knife/ssl_check_spec.rb
@@ -35,8 +35,8 @@ describe Chef::Knife::SslCheck do
subject(:ssl_check) do
s = Chef::Knife::SslCheck.new
- s.ui.stub(:stdout).and_return(stdout_io)
- s.ui.stub(:stderr).and_return(stderr_io)
+ allow(s.ui).to receive(:stdout).and_return(stdout_io)
+ allow(s.ui).to receive(:stderr).and_return(stderr_io)
s.name_args = name_args
s
end
@@ -106,17 +106,17 @@ E
before do
Chef::Config[:trusted_certs_dir] = trusted_certs_dir
- ssl_check.stub(:trusted_certificates).and_return([trusted_cert_file])
- store.stub(:add_cert).with(certificate)
- OpenSSL::X509::Store.stub(:new).and_return(store)
- OpenSSL::X509::Certificate.stub(:new).with(IO.read(trusted_cert_file)).and_return(certificate)
- ssl_check.stub(:verify_cert).and_return(true)
- ssl_check.stub(:verify_cert_host).and_return(true)
+ allow(ssl_check).to receive(:trusted_certificates).and_return([trusted_cert_file])
+ allow(store).to receive(:add_cert).with(certificate)
+ allow(OpenSSL::X509::Store).to receive(:new).and_return(store)
+ allow(OpenSSL::X509::Certificate).to receive(:new).with(IO.read(trusted_cert_file)).and_return(certificate)
+ allow(ssl_check).to receive(:verify_cert).and_return(true)
+ allow(ssl_check).to receive(:verify_cert_host).and_return(true)
end
context "when the trusted certificates have valid X509 properties" do
before do
- store.stub(:verify).with(certificate).and_return(true)
+ allow(store).to receive(:verify).with(certificate).and_return(true)
end
it "does not generate any X509 warnings" do
@@ -127,8 +127,8 @@ E
context "when the trusted certificates have invalid X509 properties" do
before do
- store.stub(:verify).with(certificate).and_return(false)
- store.stub(:error_string).and_return("unable to get local issuer certificate")
+ allow(store).to receive(:verify).with(certificate).and_return(false)
+ allow(store).to receive(:error_string).and_return("unable to get local issuer certificate")
end
it "generates a warning message with invalid certificate file names" do
@@ -145,8 +145,8 @@ E
let(:ssl_socket) { double(OpenSSL::SSL::SSLSocket) }
before do
- TCPSocket.should_receive(:new).with("foo.example.com", 8443).and_return(tcp_socket)
- OpenSSL::SSL::SSLSocket.should_receive(:new).with(tcp_socket, ssl_check.verify_peer_ssl_context).and_return(ssl_socket)
+ expect(TCPSocket).to receive(:new).with("foo.example.com", 8443).and_return(tcp_socket)
+ expect(OpenSSL::SSL::SSLSocket).to receive(:new).with(tcp_socket, ssl_check.verify_peer_ssl_context).and_return(ssl_socket)
end
def run
@@ -160,9 +160,9 @@ E
context "when the remote host's certificate is valid" do
before do
- ssl_check.should_receive(:verify_X509).and_return(true) # X509 valid certs (no warn)
- ssl_socket.should_receive(:connect) # no error
- ssl_socket.should_receive(:post_connection_check).with("foo.example.com") # no error
+ expect(ssl_check).to receive(:verify_X509).and_return(true) # X509 valid certs (no warn)
+ expect(ssl_socket).to receive(:connect) # no error
+ expect(ssl_socket).to receive(:post_connection_check).with("foo.example.com") # no error
end
it "prints a success message" do
@@ -182,23 +182,23 @@ E
before do
trap(:INT, "DEFAULT")
- TCPSocket.should_receive(:new).
+ expect(TCPSocket).to receive(:new).
with("foo.example.com", 8443).
and_return(tcp_socket_for_debug)
- OpenSSL::SSL::SSLSocket.should_receive(:new).
+ expect(OpenSSL::SSL::SSLSocket).to receive(:new).
with(tcp_socket_for_debug, ssl_check.noverify_peer_ssl_context).
and_return(ssl_socket_for_debug)
end
context "when the certificate's CN does not match the hostname" do
before do
- ssl_check.should_receive(:verify_X509).and_return(true) # X509 valid certs
- ssl_socket.should_receive(:connect) # no error
- ssl_socket.should_receive(:post_connection_check).
+ expect(ssl_check).to receive(:verify_X509).and_return(true) # X509 valid certs
+ expect(ssl_socket).to receive(:connect) # no error
+ expect(ssl_socket).to receive(:post_connection_check).
with("foo.example.com").
and_raise(OpenSSL::SSL::SSLError)
- ssl_socket_for_debug.should_receive(:connect)
- ssl_socket_for_debug.should_receive(:peer_cert).and_return(self_signed_crt)
+ expect(ssl_socket_for_debug).to receive(:connect)
+ expect(ssl_socket_for_debug).to receive(:peer_cert).and_return(self_signed_crt)
end
it "shows the CN used by the certificate and prints an error" do
@@ -212,11 +212,11 @@ E
context "when the cert is not signed by any trusted authority" do
before do
- ssl_check.should_receive(:verify_X509).and_return(true) # X509 valid certs
- ssl_socket.should_receive(:connect).
+ expect(ssl_check).to receive(:verify_X509).and_return(true) # X509 valid certs
+ expect(ssl_socket).to receive(:connect).
and_raise(OpenSSL::SSL::SSLError)
- ssl_socket_for_debug.should_receive(:connect)
- ssl_socket_for_debug.should_receive(:peer_cert).and_return(self_signed_crt)
+ expect(ssl_socket_for_debug).to receive(:connect)
+ expect(ssl_socket_for_debug).to receive(:peer_cert).and_return(self_signed_crt)
end
it "shows the CN used by the certificate and prints an error" do
diff --git a/spec/unit/knife/ssl_fetch_spec.rb b/spec/unit/knife/ssl_fetch_spec.rb
index 0d3c8913f7..24101dbe7a 100644
--- a/spec/unit/knife/ssl_fetch_spec.rb
+++ b/spec/unit/knife/ssl_fetch_spec.rb
@@ -36,8 +36,8 @@ describe Chef::Knife::SslFetch do
subject(:ssl_fetch) do
s = Chef::Knife::SslFetch.new
s.name_args = name_args
- s.ui.stub(:stdout).and_return(stdout_io)
- s.ui.stub(:stderr).and_return(stderr_io)
+ allow(s.ui).to receive(:stdout).and_return(stdout_io)
+ allow(s.ui).to receive(:stderr).and_return(stderr_io)
s
end
@@ -131,10 +131,10 @@ E
before do
Chef::Config.trusted_certs_dir = trusted_certs_dir
- TCPSocket.should_receive(:new).with("foo.example.com", 8443).and_return(tcp_socket)
- OpenSSL::SSL::SSLSocket.should_receive(:new).with(tcp_socket, ssl_fetch.noverify_peer_ssl_context).and_return(ssl_socket)
- ssl_socket.should_receive(:connect)
- ssl_socket.should_receive(:peer_cert_chain).and_return([self_signed_crt])
+ expect(TCPSocket).to receive(:new).with("foo.example.com", 8443).and_return(tcp_socket)
+ expect(OpenSSL::SSL::SSLSocket).to receive(:new).with(tcp_socket, ssl_fetch.noverify_peer_ssl_context).and_return(ssl_socket)
+ expect(ssl_socket).to receive(:connect)
+ expect(ssl_socket).to receive(:peer_cert_chain).and_return([self_signed_crt])
end
after do
diff --git a/spec/unit/knife/status_spec.rb b/spec/unit/knife/status_spec.rb
index bb43dd25e5..2522bc61b1 100644
--- a/spec/unit/knife/status_spec.rb
+++ b/spec/unit/knife/status_spec.rb
@@ -25,18 +25,18 @@ describe Chef::Knife::Status do
n.automatic_attrs["ohai_time"] = 1343845969
end
query = double("Chef::Search::Query")
- query.stub(:search).and_yield(node)
- Chef::Search::Query.stub(:new).and_return(query)
+ allow(query).to receive(:search).and_yield(node)
+ allow(Chef::Search::Query).to receive(:new).and_return(query)
@knife = Chef::Knife::Status.new
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
describe "run" do
it "should not colorize output unless it's writing to a tty" do
@knife.run
- @stdout.string.match(/foobar/).should_not be_nil
- @stdout.string.match(/\e.*ago/).should be_nil
+ expect(@stdout.string.match(/foobar/)).not_to be_nil
+ expect(@stdout.string.match(/\e.*ago/)).to be_nil
end
end
end
diff --git a/spec/unit/knife/tag_create_spec.rb b/spec/unit/knife/tag_create_spec.rb
index bafea8d268..586ec118bd 100644
--- a/spec/unit/knife/tag_create_spec.rb
+++ b/spec/unit/knife/tag_create_spec.rb
@@ -7,17 +7,17 @@ describe Chef::Knife::TagCreate do
@knife.name_args = [ Chef::Config[:node_name], "happytag" ]
@node = Chef::Node.new
- @node.stub :save
- Chef::Node.stub(:load).and_return @node
+ allow(@node).to receive :save
+ allow(Chef::Node).to receive(:load).and_return @node
@stderr = StringIO.new
- @knife.ui.stub(:stderr).and_return(@stderr)
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
end
describe "run" do
it "can create tags on a node" do
@knife.run
- @node.tags.should == ["happytag"]
- @stderr.string.should match /created tags happytag.+node webmonkey.example.com/i
+ expect(@node.tags).to eq(["happytag"])
+ expect(@stderr.string).to match /created tags happytag.+node webmonkey.example.com/i
end
end
end
diff --git a/spec/unit/knife/tag_delete_spec.rb b/spec/unit/knife/tag_delete_spec.rb
index 514228f0a2..e7fa108947 100644
--- a/spec/unit/knife/tag_delete_spec.rb
+++ b/spec/unit/knife/tag_delete_spec.rb
@@ -7,19 +7,19 @@ describe Chef::Knife::TagDelete do
@knife.name_args = [ Chef::Config[:node_name], "sadtag" ]
@node = Chef::Node.new
- @node.stub :save
+ allow(@node).to receive :save
@node.tags << "sadtag" << "happytag"
- Chef::Node.stub(:load).and_return @node
+ allow(Chef::Node).to receive(:load).and_return @node
@stderr = StringIO.new
- @knife.ui.stub(:stderr).and_return(@stderr)
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
end
describe "run" do
it "can delete tags on a node" do
- @node.tags.should == ["sadtag", "happytag"]
+ expect(@node.tags).to eq(["sadtag", "happytag"])
@knife.run
- @node.tags.should == ["happytag"]
- @stderr.string.should match /deleted.+sadtag/i
+ expect(@node.tags).to eq(["happytag"])
+ expect(@stderr.string).to match /deleted.+sadtag/i
end
end
end
diff --git a/spec/unit/knife/tag_list_spec.rb b/spec/unit/knife/tag_list_spec.rb
index 3724a5c0b7..9c71d22f06 100644
--- a/spec/unit/knife/tag_list_spec.rb
+++ b/spec/unit/knife/tag_list_spec.rb
@@ -7,16 +7,16 @@ describe Chef::Knife::TagList do
@knife.name_args = [ Chef::Config[:node_name], "sadtag" ]
@node = Chef::Node.new
- @node.stub :save
+ allow(@node).to receive :save
@node.tags << "sadtag" << "happytag"
- Chef::Node.stub(:load).and_return @node
+ allow(Chef::Node).to receive(:load).and_return @node
end
describe "run" do
it "can list tags on a node" do
expected = %w(sadtag happytag)
- @node.tags.should == expected
- @knife.should_receive(:output).with(expected)
+ expect(@node.tags).to eq(expected)
+ expect(@knife).to receive(:output).with(expected)
@knife.run
end
end
diff --git a/spec/unit/knife/user_create_spec.rb b/spec/unit/knife/user_create_spec.rb
index 58ef868053..ad8821cd0e 100644
--- a/spec/unit/knife/user_create_spec.rb
+++ b/spec/unit/knife/user_create_spec.rb
@@ -26,8 +26,8 @@ describe Chef::Knife::UserCreate do
@stdout = StringIO.new
@stderr = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
- @knife.ui.stub(:stderr).and_return(@stderr)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
@knife.name_args = [ 'a_user' ]
@knife.config[:user_password] = "foobar"
@@ -36,53 +36,53 @@ describe Chef::Knife::UserCreate do
@user_with_private_key = Chef::User.new
@user_with_private_key.name "a_user"
@user_with_private_key.private_key 'private_key'
- @user.stub(:create).and_return(@user_with_private_key)
- Chef::User.stub(:new).and_return(@user)
- Chef::User.stub(:from_hash).and_return(@user)
- @knife.stub(:edit_data).and_return(@user.to_hash)
+ 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)
+ allow(@knife).to receive(:edit_data).and_return(@user.to_hash)
end
it "creates a new user" do
- Chef::User.should_receive(:new).and_return(@user)
- @user.should_receive(:create)
+ expect(Chef::User).to receive(:new).and_return(@user)
+ expect(@user).to receive(:create)
@knife.run
- @stderr.string.should match /created user.+a_user/i
+ expect(@stderr.string).to match /created user.+a_user/i
end
it "sets the password" do
@knife.config[:user_password] = "a_password"
- @user.should_receive(:password).with("a_password")
+ expect(@user).to receive(:password).with("a_password")
@knife.run
end
it "exits with an error if password is blank" do
@knife.config[:user_password] = ''
- lambda { @knife.run }.should raise_error SystemExit
- @stderr.string.should match /You must specify a non-blank password/
+ expect { @knife.run }.to raise_error SystemExit
+ expect(@stderr.string).to match /You must specify a non-blank password/
end
it "sets the user name" do
- @user.should_receive(:name).with("a_user")
+ expect(@user).to receive(:name).with("a_user")
@knife.run
end
it "sets the public key if given" do
@knife.config[:user_key] = "/a/filename"
- File.stub(:read).with(File.expand_path("/a/filename")).and_return("a_key")
- @user.should_receive(:public_key).with("a_key")
+ allow(File).to receive(:read).with(File.expand_path("/a/filename")).and_return("a_key")
+ expect(@user).to receive(:public_key).with("a_key")
@knife.run
end
it "allows you to edit the data" do
- @knife.should_receive(:edit_data).with(@user)
+ expect(@knife).to receive(:edit_data).with(@user)
@knife.run
end
it "writes the private key to a file when --file is specified" do
@knife.config[:file] = "/tmp/a_file"
filehandle = double("filehandle")
- filehandle.should_receive(:print).with('private_key')
- File.should_receive(:open).with("/tmp/a_file", "w").and_yield(filehandle)
+ expect(filehandle).to receive(:print).with('private_key')
+ expect(File).to receive(:open).with("/tmp/a_file", "w").and_yield(filehandle)
@knife.run
end
end
diff --git a/spec/unit/knife/user_delete_spec.rb b/spec/unit/knife/user_delete_spec.rb
index be027e5128..94cfbf3db1 100644
--- a/spec/unit/knife/user_delete_spec.rb
+++ b/spec/unit/knife/user_delete_spec.rb
@@ -26,14 +26,14 @@ describe Chef::Knife::UserDelete do
end
it 'deletes the user' do
- @knife.should_receive(:delete_object).with(Chef::User, 'my_user')
+ 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
@knife.name_args = []
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife).to receive(:show_usage)
+ expect(@knife.ui).to receive(:fatal)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
diff --git a/spec/unit/knife/user_edit_spec.rb b/spec/unit/knife/user_edit_spec.rb
index 20a4c0d9e9..0eb75cfa9b 100644
--- a/spec/unit/knife/user_edit_spec.rb
+++ b/spec/unit/knife/user_edit_spec.rb
@@ -25,23 +25,23 @@ describe Chef::Knife::UserEdit do
Chef::Knife::UserEdit.load_deps
@knife = Chef::Knife::UserEdit.new
- @knife.ui.stub(:stderr).and_return(@stderr)
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stderr).and_return(@stderr)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
@knife.name_args = [ 'my_user' ]
@knife.config[:disable_editing] = true
end
it 'loads and edits the user' do
data = { :name => "my_user" }
- Chef::User.stub(:load).with("my_user").and_return(data)
- @knife.should_receive(:edit_data).with(data).and_return(data)
+ 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
@knife.name_args = []
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife).to receive(:show_usage)
+ expect(@knife.ui).to receive(:fatal)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end
diff --git a/spec/unit/knife/user_list_spec.rb b/spec/unit/knife/user_list_spec.rb
index 7a47f9ddba..db097a5c16 100644
--- a/spec/unit/knife/user_list_spec.rb
+++ b/spec/unit/knife/user_list_spec.rb
@@ -25,8 +25,8 @@ describe Chef::Knife::UserList do
end
it 'lists the users' do
- Chef::User.should_receive(:list)
- @knife.should_receive(:format_list_for_display)
+ expect(Chef::User).to receive(:list)
+ expect(@knife).to receive(:format_list_for_display)
@knife.run
end
end
diff --git a/spec/unit/knife/user_reregister_spec.rb b/spec/unit/knife/user_reregister_spec.rb
index 1cbbdb47d2..1268716f40 100644
--- a/spec/unit/knife/user_reregister_spec.rb
+++ b/spec/unit/knife/user_reregister_spec.rb
@@ -24,30 +24,30 @@ describe Chef::Knife::UserReregister do
@knife = Chef::Knife::UserReregister.new
@knife.name_args = [ 'a_user' ]
@user_mock = double('user_mock', :private_key => "private_key")
- Chef::User.stub(:load).and_return(@user_mock)
+ allow(Chef::User).to receive(:load).and_return(@user_mock)
@stdout = StringIO.new
- @knife.ui.stub(:stdout).and_return(@stdout)
+ allow(@knife.ui).to receive(:stdout).and_return(@stdout)
end
it 'prints usage and exits when a user name is not provided' do
@knife.name_args = []
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ 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
- @user_mock.should_receive(:reregister).and_return(@user_mock)
+ expect(@user_mock).to receive(:reregister).and_return(@user_mock)
@knife.run
- @stdout.string.should match( /private_key/ )
+ expect(@stdout.string).to match( /private_key/ )
end
it 'writes the private key to a file when --file is specified' do
- @user_mock.should_receive(:reregister).and_return(@user_mock)
+ expect(@user_mock).to receive(:reregister).and_return(@user_mock)
@knife.config[:file] = '/tmp/a_file'
filehandle = StringIO.new
- File.should_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
- filehandle.string.should == "private_key"
+ expect(filehandle.string).to eq("private_key")
end
end
diff --git a/spec/unit/knife/user_show_spec.rb b/spec/unit/knife/user_show_spec.rb
index af8485ad7d..f97cbc3f13 100644
--- a/spec/unit/knife/user_show_spec.rb
+++ b/spec/unit/knife/user_show_spec.rb
@@ -27,15 +27,15 @@ describe Chef::Knife::UserShow do
end
it 'loads and displays the user' do
- Chef::User.should_receive(:load).with('my_user').and_return(@user_mock)
- @knife.should_receive(:format_for_display).with(@user_mock)
+ 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
@knife.name_args = []
- @knife.should_receive(:show_usage)
- @knife.ui.should_receive(:fatal)
- lambda { @knife.run }.should raise_error(SystemExit)
+ expect(@knife).to receive(:show_usage)
+ expect(@knife.ui).to receive(:fatal)
+ expect { @knife.run }.to raise_error(SystemExit)
end
end