spec/kontena/cli/common_spec.rb in kontena-cli-0.13.4 vs spec/kontena/cli/common_spec.rb in kontena-cli-0.14.0

- old
+ new

@@ -87,11 +87,10 @@ ] }) expect(subject.current_master['url']).to eq('someurl') expect(subject.current_master['name']).to eq('alias') - end end describe '#settings' do it 'migrates old settings' do @@ -119,7 +118,46 @@ expect(File).to receive(:write).with(subject.settings_filename, JSON.pretty_generate(expected_settings)) subject.settings end + end + + describe '#error' do + it 'prints error message to stderr if given and raise error' do + expect($stderr).to receive(:puts).with('error message!') + expect{subject.error('error message!')}.to raise_error(SystemExit) + end + end + + describe '#confirm_command' do + it 'returns true if input matches' do + allow(subject).to receive(:prompt).and_return('name-to-confirm') + + expect(subject.confirm_command('name-to-confirm')).to be_truthy + expect{subject.confirm_command('name-to-confirm')}.to_not raise_error + end + + it 'raises error unless input matches' do + expect(subject).to receive(:prompt).and_return('wrong-name') + expect(subject).to receive(:error).with(/did not match/) + + subject.confirm_command('name-to-confirm') + end + end + + describe '#confirm' do + it 'returns true if confirmed' do + allow(subject).to receive(:prompt).and_return('y') + + expect(subject.confirm).to be_truthy + expect{subject.confirm}.to_not raise_error + end + + it 'raises error unless confirmed' do + expect(subject).to receive(:prompt).and_return('ei') + expect(subject).to receive(:error).with(/Aborted/) + + subject.confirm + end end end