diff options
author | Claire McQuin <claire@getchef.com> | 2014-10-29 15:14:22 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2014-10-29 15:59:04 -0700 |
commit | 5fed7a65a2f024d964ecf2de1bcf2911cf8a600c (patch) | |
tree | 14cc6968e4fe4fd2485c0211088b25c645a80a4b /spec/unit/knife/ssh_spec.rb | |
parent | b92c309b0f1aa0837f76ab89d6c81c36076ceca9 (diff) | |
download | chef-5fed7a65a2f024d964ecf2de1bcf2911cf8a600c.tar.gz |
Update to RSpec 3.
Diffstat (limited to 'spec/unit/knife/ssh_spec.rb')
-rw-r--r-- | spec/unit/knife/ssh_spec.rb | 132 |
1 files changed, 66 insertions, 66 deletions
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 |