From baf1d3bb7e1f059afa6a15afe67703246c6d9bee Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin Date: Thu, 18 Feb 2016 16:06:11 +0300 Subject: [PATCH] Update rspec and fix tests Change-Id: I4e3f1de45899c99ffb3d7c950385bd873b7ffede --- astute.gemspec | 2 +- spec/unit/cobbler_spec.rb | 4 ++-- spec/unit/deployment_engine_spec.rb | 2 +- spec/unit/nailgun_hooks_spec.rb | 4 +++- .../upload_cirros_image_hook_spec.rb | 16 +++++++++------- .../generate_keys_hook_spec.rb | 17 +++++++++-------- .../generate_ssh_keys_hook_spec.rb | 16 +++++++++------- .../sync_puppet_stuff_hook_spec.rb | 2 +- spec/unit/task_deployment_spec.rb | 4 ++-- 9 files changed, 37 insertions(+), 30 deletions(-) diff --git a/astute.gemspec b/astute.gemspec index a3c5e7eb..6979b8dc 100644 --- a/astute.gemspec +++ b/astute.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'facter' s.add_development_dependency 'rake', '10.0.4' - s.add_development_dependency 'rspec', '2.13.0' + s.add_development_dependency 'rspec', '>= 3.4.0' s.add_development_dependency 'mocha', '0.13.3' s.add_development_dependency 'simplecov', '~> 0.7.1' s.add_development_dependency 'simplecov-rcov', '~> 0.2.3' diff --git a/spec/unit/cobbler_spec.rb b/spec/unit/cobbler_spec.rb index 78687d02..ac395a06 100644 --- a/spec/unit/cobbler_spec.rb +++ b/spec/unit/cobbler_spec.rb @@ -211,7 +211,7 @@ describe Cobbler do cobbler = Astute::Provision::Cobbler.new cobbler.stubs(:sleep).with(10).times(1) - expect { cobbler.sync }.to_not raise_exception(Net::ReadTimeout) + expect { cobbler.sync }.not_to raise_exception(Net::ReadTimeout) end it 'should try sync several time before raise a exception (XMLRPC)' do @@ -227,7 +227,7 @@ describe Cobbler do cobbler = Astute::Provision::Cobbler.new cobbler.stubs(:sleep).with(10).times(1) - expect { cobbler.sync }.to_not raise_exception(XMLRPC::FaultException) + expect { cobbler.sync }.not_to raise_exception(XMLRPC::FaultException) end it 'should raise a exception if sync do not succeed after several(3) tries' do diff --git a/spec/unit/deployment_engine_spec.rb b/spec/unit/deployment_engine_spec.rb index fa0a909f..3e71cef5 100644 --- a/spec/unit/deployment_engine_spec.rb +++ b/spec/unit/deployment_engine_spec.rb @@ -48,7 +48,7 @@ describe Astute::DeploymentEngine do end it 'should be avaliable as superclass' do - expect { Engine.new(ctx) }.to be_true + expect(Engine.new(ctx)).to be_truthy end end diff --git a/spec/unit/nailgun_hooks_spec.rb b/spec/unit/nailgun_hooks_spec.rb index a3fe47c6..da075fd8 100644 --- a/spec/unit/nailgun_hooks_spec.rb +++ b/spec/unit/nailgun_hooks_spec.rb @@ -682,7 +682,9 @@ describe Astute::NailgunHooks do .then.raises(Astute::MClientError) .then.returns([mc_result('3', true)]) - expect {hooks.process}.to_not raise_error(Astute::DeploymentEngineError) + expect { + hooks.process + }.not_to raise_error(Astute::DeploymentEngineError) end it 'should fail if it still raise error after retries' do diff --git a/spec/unit/post_deployment_actions/upload_cirros_image_hook_spec.rb b/spec/unit/post_deployment_actions/upload_cirros_image_hook_spec.rb index 4b1cf4c1..8611956f 100644 --- a/spec/unit/post_deployment_actions/upload_cirros_image_hook_spec.rb +++ b/spec/unit/post_deployment_actions/upload_cirros_image_hook_spec.rb @@ -108,8 +108,9 @@ describe Astute::UploadCirrosImage do .returns(:data => {:exit_code => 1}).times(5) upload_cirros_image.stubs(:sleep).with(10).times(4) - expect {upload_cirros_image.process(deploy_data, ctx)} - .to_not raise_error(Astute::CirrosError) + expect { + upload_cirros_image.process(deploy_data, ctx) + }.not_to raise_error(Astute::CirrosError) end it 'should not send node error status for last node and raise if deploy \ @@ -121,8 +122,9 @@ describe Astute::UploadCirrosImage do .returns(:data => {:exit_code => 1}).times(5) upload_cirros_image.stubs(:sleep).with(10).times(4) - expect {upload_cirros_image.process([deploy_data.last], ctx)} - .to_not raise_error(Astute::CirrosError) + expect { + upload_cirros_image.process([deploy_data.last], ctx) + }.not_to raise_error(Astute::CirrosError) end it 'should try to add image again if we only add new nodes \ @@ -137,7 +139,7 @@ describe Astute::UploadCirrosImage do upload_cirros_image.stubs(:run_shell_command) .returns(:data => {:exit_code => 0}) .then.returns(:data => {:exit_code => 0}) - expect(upload_cirros_image.process(deploy_data, ctx)).to be_true + expect(upload_cirros_image.process(deploy_data, ctx)).to eq true end it 'should add new image if cluster deploy success and \ @@ -145,7 +147,7 @@ describe Astute::UploadCirrosImage do upload_cirros_image.stubs(:run_shell_command) .returns(:data => {:exit_code => 0}) .then.returns(:data => {:exit_code => 0}) - expect(upload_cirros_image.process(deploy_data, ctx)).to be_true + expect(upload_cirros_image.process(deploy_data, ctx)).to eq true end it 'should send node error status for controller and raise if deploy \ @@ -209,4 +211,4 @@ describe Astute::UploadCirrosImage do upload_cirros_image.process(deploy_data, ctx) end -end #'upload_cirros_image' \ No newline at end of file +end #'upload_cirros_image' diff --git a/spec/unit/pre_deployment_actions/generate_keys_hook_spec.rb b/spec/unit/pre_deployment_actions/generate_keys_hook_spec.rb index 7b0bfe09..c19b4680 100644 --- a/spec/unit/pre_deployment_actions/generate_keys_hook_spec.rb +++ b/spec/unit/pre_deployment_actions/generate_keys_hook_spec.rb @@ -44,14 +44,14 @@ describe Astute::GenerateKeys do end - it 'should save files in correct place: KEY_DIR//' do + it 'should save files in correct place: KEY_DIR///' do generate_keys.stubs(:run_system_command).returns([0, "", ""]) Dir.mktmpdir do |temp_dir| Astute.config.keys_src_dir = temp_dir generate_keys.process(deploy_data, ctx) - - expect { File.directory? File.join(temp_dir, 'mongodb.key') }.to be_true + key_dir = File.join(temp_dir, deploy_data.first['uid'].to_s, 'mongodb') + expect(File.directory? key_dir).to eq true end end @@ -100,13 +100,14 @@ describe Astute::GenerateKeys do it 'should not overwrite files' do Dir.mktmpdir do |temp_dir| Astute.config.keys_src_dir = temp_dir - key_path = File.join(temp_dir,'mongodb', 'mongodb.key') - FileUtils.mkdir_p File.join(temp_dir, 'mongodb') + key_dir = File.join(temp_dir, deploy_data.first['uid'].to_s, 'mongodb') + key_path = File.join(key_dir, 'mongodb.key') + FileUtils.mkdir_p key_dir File.open(key_path, 'w') { |file| file.write("say no overwrite") } generate_keys.process(deploy_data, ctx) - expect { File.exist? File.join(key_path, 'mongodb', 'mongodb.key') }.to be_true - expect { File.read File.join(key_path, 'mongodb', 'mongodb.key') == "say no overwrite" }.to be_true + expect(File.exist? key_path).to eq true + expect(File.read key_path).to eq 'say no overwrite' end end @@ -136,4 +137,4 @@ describe Astute::GenerateKeys do generate_keys.process(deploy_data, ctx) end -end \ No newline at end of file +end diff --git a/spec/unit/pre_deployment_actions/generate_ssh_keys_hook_spec.rb b/spec/unit/pre_deployment_actions/generate_ssh_keys_hook_spec.rb index e43d3195..226bad1b 100644 --- a/spec/unit/pre_deployment_actions/generate_ssh_keys_hook_spec.rb +++ b/spec/unit/pre_deployment_actions/generate_ssh_keys_hook_spec.rb @@ -44,14 +44,15 @@ describe Astute::GenerateSshKeys do end - it 'should save files in correct place: KEY_DIR//' do + it 'should save files in correct place: KEY_DIR///' do generate_ssh_keys.stubs(:run_system_command).returns([0, "", ""]) Dir.mktmpdir do |temp_dir| Astute.config.keys_src_dir = temp_dir generate_ssh_keys.process(deploy_data, ctx) + key_dir = File.join(temp_dir, deploy_data.first['uid'].to_s, 'nova') - expect { File.directory? File.join(temp_dir, 'nova') }.to be_true + expect(File.directory? key_dir).to eq true end end @@ -95,13 +96,14 @@ describe Astute::GenerateSshKeys do it 'should not overwrite files' do Dir.mktmpdir do |temp_dir| Astute.config.keys_src_dir = temp_dir - key_path = File.join(temp_dir,'nova', 'nova') - FileUtils.mkdir_p File.join(temp_dir,'nova') + key_dir = File.join(temp_dir, deploy_data.first['uid'].to_s, 'nova') + key_path = File.join(key_dir, 'nova') + FileUtils.mkdir_p key_dir File.open(key_path, 'w') { |file| file.write("say no overwrite") } generate_ssh_keys.process(deploy_data, ctx) - expect { File.exist? File.join(key_path, 'nova', 'nova') }.to be_true - expect { File.read File.join(key_path, 'nova', 'nova') == "say no overwrite" }.to be_true + expect(File.exist? key_path).to eq true + expect(File.read key_path).to eq 'say no overwrite' end end @@ -121,4 +123,4 @@ describe Astute::GenerateSshKeys do generate_ssh_keys.process(deploy_data, ctx) end -end \ No newline at end of file +end diff --git a/spec/unit/pre_deployment_actions/sync_puppet_stuff_hook_spec.rb b/spec/unit/pre_deployment_actions/sync_puppet_stuff_hook_spec.rb index a1b18bc4..8da65fb8 100644 --- a/spec/unit/pre_deployment_actions/sync_puppet_stuff_hook_spec.rb +++ b/spec/unit/pre_deployment_actions/sync_puppet_stuff_hook_spec.rb @@ -81,7 +81,7 @@ describe Astute::SyncPuppetStuff do Astute::MClient.any_instance.stubs(:check_results_with_retries) .raises(Astute::MClientError) .then.returns("") - expect { sync_puppet_stuff.process(nodes, ctx) }.to_not raise_error(Astute::MClientError) + expect { sync_puppet_stuff.process(nodes, ctx) }.not_to raise_error(Astute::MClientError) end end diff --git a/spec/unit/task_deployment_spec.rb b/spec/unit/task_deployment_spec.rb index de908688..ea50f9e3 100644 --- a/spec/unit/task_deployment_spec.rb +++ b/spec/unit/task_deployment_spec.rb @@ -89,8 +89,8 @@ describe Astute::TaskDeployment do it 'should support virtual node' do d_t = task_deployment.send(:support_virtual_node, deployment_tasks) - expect(d_t.keys.include?('virtual_sync_node')).to be_true - expect(d_t.keys.include?('null')).to be_false + expect(d_t.keys).to include 'virtual_sync_node' + expect(d_t.keys).not_to include 'null' end it 'should remove failed nodes' do