diff options
author | Ranjib Dey <ranjib@pagerduty.com> | 2015-06-12 23:51:14 -0700 |
---|---|---|
committer | Ranjib Dey <ranjib@pagerduty.com> | 2015-06-12 23:51:14 -0700 |
commit | 414b3b2bea634c48f6c1996b0e7a5884cc3ad2c7 (patch) | |
tree | a9a9f750021114e0b6f8d46145ae8dee2b9f8ac4 /spec/unit/knife/user_reregister_spec.rb | |
parent | fdde9a0a476c407d34882631b50406cf585c6602 (diff) | |
parent | b08c9010c387c762a6fa82fa9ae8c2a5e5c8594d (diff) | |
download | chef-414b3b2bea634c48f6c1996b0e7a5884cc3ad2c7.tar.gz |
Merge remote-tracking branch 'origin/master' into HEAD
Conflicts:
lib/chef/chef_class.rb
Diffstat (limited to 'spec/unit/knife/user_reregister_spec.rb')
-rw-r--r-- | spec/unit/knife/user_reregister_spec.rb | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/spec/unit/knife/user_reregister_spec.rb b/spec/unit/knife/user_reregister_spec.rb index 1268716f40..412a6ec374 100644 --- a/spec/unit/knife/user_reregister_spec.rb +++ b/spec/unit/knife/user_reregister_spec.rb @@ -19,35 +19,56 @@ require 'spec_helper' describe Chef::Knife::UserReregister do - before(:each) do + let(:knife) { Chef::Knife::UserReregister.new } + let(:user_mock) { double('user_mock', :private_key => "private_key") } + let(:stdout) { StringIO.new } + + before do Chef::Knife::UserReregister.load_deps - @knife = Chef::Knife::UserReregister.new - @knife.name_args = [ 'a_user' ] - @user_mock = double('user_mock', :private_key => "private_key") - allow(Chef::User).to receive(:load).and_return(@user_mock) - @stdout = StringIO.new - allow(@knife.ui).to receive(:stdout).and_return(@stdout) + knife.name_args = [ 'a_user' ] + allow(Chef::User).to receive(:load).and_return(user_mock) + allow(knife.ui).to receive(:stdout).and_return(stdout) + allow(knife.ui).to receive(:stderr).and_return(stdout) + allow(user_mock).to receive(:username).and_return('a_user') + end + + # delete this once OSC11 support is gone + context "when the username field is not supported by the server" do + before do + allow(knife).to receive(:run_osc_11_user_reregister).and_raise(SystemExit) + allow(user_mock).to receive(:username).and_return(nil) + end + + it "displays the osc warning" do + expect(knife.ui).to receive(:warn).with(knife.osc_11_warning) + expect{ knife.run }.to raise_error(SystemExit) + end + + it "forwards the command to knife osc_user edit" do + expect(knife).to receive(:run_osc_11_user_reregister) + expect{ knife.run }.to raise_error(SystemExit) + end end it 'prints usage and exits when a user name is not provided' do - @knife.name_args = [] - expect(@knife).to receive(:show_usage) - expect(@knife.ui).to receive(:fatal) - expect { @knife.run }.to raise_error(SystemExit) + knife.name_args = [] + expect(knife).to receive(:show_usage) + expect(knife.ui).to receive(:fatal) + expect { knife.run }.to raise_error(SystemExit) end it 'reregisters the user and prints the key' do - expect(@user_mock).to receive(:reregister).and_return(@user_mock) - @knife.run - expect(@stdout.string).to match( /private_key/ ) + expect(user_mock).to receive(:reregister).and_return(user_mock) + knife.run + expect(stdout.string).to match( /private_key/ ) end it 'writes the private key to a file when --file is specified' do - expect(@user_mock).to receive(:reregister).and_return(@user_mock) - @knife.config[:file] = '/tmp/a_file' + expect(user_mock).to receive(:reregister).and_return(user_mock) + knife.config[:file] = '/tmp/a_file' filehandle = StringIO.new expect(File).to receive(:open).with('/tmp/a_file', 'w').and_yield(filehandle) - @knife.run + knife.run expect(filehandle.string).to eq("private_key") end end |