change subject with named let)

This commit is contained in:
Anton Chuchkalov 2016-01-20 10:32:57 +03:00
parent f4d13ce19f
commit a96ea68922

View File

@ -78,12 +78,8 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
describe '#create_server' do describe '#create_server' do
let!(:without_bootstrap) { @without_bootstrap = true } let(:image) { double('Image instance', remote_user: 'remote_user') }
let!(:run_list) { @run_list = %w(role[asd]) } let(:create_server) {
let!(:key) { @key = 'key' }
let!(:image) { double('Image instance', remote_user: 'remote_user') }
subject {
executor.create_server( executor.create_server(
'created_by' => 'user', 'created_by' => 'user',
'run_list' => @run_list, 'run_list' => @run_list,
@ -97,10 +93,13 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
allow(provider).to receive(:create_server) { true } allow(provider).to receive(:create_server) { true }
allow(stubbed_connector).to receive(:image) { image } allow(stubbed_connector).to receive(:image) { image }
allow(stubbed_connector).to receive(:server_insert) allow(stubbed_connector).to receive(:server_insert)
@without_bootstrap = true
@run_list = %w(role[asd])
@key = 'key'
end end
it 'builds server model from given options' do it 'builds server model from given options' do
subject create_server
expect(executor.server.created_by).to eq 'user' expect(executor.server.created_by).to eq 'user'
expect(executor.server.chef_node_name).to eq 'node_name' expect(executor.server.chef_node_name).to eq 'node_name'
expect(executor.server.key).to eq @key expect(executor.server.key).to eq @key
@ -109,46 +108,46 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it 'sets run list to an empty array by default' do it 'sets run list to an empty array by default' do
@run_list = nil @run_list = nil
subject create_server
expect(executor.server.run_list).to eq [] expect(executor.server.run_list).to eq []
end end
it 'sets key to default provider ssh key by default' do it 'sets key to default provider ssh key by default' do
@key = nil @key = nil
allow(provider).to receive(:ssh_key) { 'default_key' } allow(provider).to receive(:ssh_key) { 'default_key' }
subject create_server
expect(executor.server.key).to eq 'default_key' expect(executor.server.key).to eq 'default_key'
end end
it 'runs hooks' do it 'runs hooks' do
expect(executor).to receive(:run_hook).with(:before_create).ordered expect(executor).to receive(:run_hook).with(:before_create).ordered
expect(executor).to receive(:run_hook).with(:after_create).ordered expect(executor).to receive(:run_hook).with(:after_create).ordered
subject create_server
end end
it 'creates server in cloud' do it 'creates server in cloud' do
expect(provider).to receive(:create_server).with( expect(provider).to receive(:create_server).with(
an_instance_of(Devops::Model::Server), deploy_env.image, deploy_env.flavor, deploy_env.subnets, deploy_env.groups, output an_instance_of(Devops::Model::Server), deploy_env.image, deploy_env.flavor, deploy_env.subnets, deploy_env.groups, output
) )
subject create_server
end end
it 'inserts built server into mongo' do it 'inserts built server into mongo' do
expect(stubbed_connector).to receive(:server_insert) expect(stubbed_connector).to receive(:server_insert)
subject create_server
end end
it 'schedules expiration for server' do it 'schedules expiration for server' do
deploy_env.expires = '2m' deploy_env.expires = '2m'
allow(DeleteServerWorker).to receive(:perform_in) allow(DeleteServerWorker).to receive(:perform_in)
expect(DeleteServerWorker).to receive(:perform_in).with(120, {server_chef_node_name: 'node_name'}) expect(DeleteServerWorker).to receive(:perform_in).with(120, {server_chef_node_name: 'node_name'})
subject create_server
end end
it "doesn't schedule expiration if deploy_env.expires is nil" do it "doesn't schedule expiration if deploy_env.expires is nil" do
deploy_env.expires = nil deploy_env.expires = nil
expect(DeleteServerWorker).not_to receive(:perform_in) expect(DeleteServerWorker).not_to receive(:perform_in)
subject create_server
end end
context 'without_bootstrap option is false' do context 'without_bootstrap option is false' do
@ -157,7 +156,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
allow(image).to receive(:bootstrap_template) { 'template' } allow(image).to receive(:bootstrap_template) { 'template' }
allow(executor).to receive(:two_phase_bootstrap) allow(executor).to receive(:two_phase_bootstrap)
expect(executor).to receive(:two_phase_bootstrap) expect(executor).to receive(:two_phase_bootstrap)
subject create_server
end end
end end
@ -167,7 +166,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
allow(image).to receive(:bootstrap_template) { 'template' } allow(image).to receive(:bootstrap_template) { 'template' }
allow(executor).to receive(:two_phase_bootstrap) allow(executor).to receive(:two_phase_bootstrap)
expect(executor).to receive(:two_phase_bootstrap) expect(executor).to receive(:two_phase_bootstrap)
subject create_server
end end
end end
@ -175,7 +174,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it "doesn't launch bootstrap" do it "doesn't launch bootstrap" do
@without_bootstrap = true @without_bootstrap = true
expect(executor).not_to receive(:two_phase_bootstrap) expect(executor).not_to receive(:two_phase_bootstrap)
subject create_server
end end
end end
@ -187,19 +186,19 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it 'rollbacks server creating' do it 'rollbacks server creating' do
expect(executor).to receive(:roll_back) expect(executor).to receive(:roll_back)
subject create_server
end end
it 'deletes server from mongo' do it 'deletes server from mongo' do
expect(stubbed_connector).to receive(:server_delete) expect(stubbed_connector).to receive(:server_delete)
subject create_server
end end
end end
context "if creating server in cloud wasn't successful" do context "if creating server in cloud wasn't successful" do
it 'returns creating_server_in_cloud_failed error code' do it 'returns creating_server_in_cloud_failed error code' do
allow(provider).to receive(:create_server) { false } allow(provider).to receive(:create_server) { false }
expect(subject).to eq 10 expect(create_server).to eq 10
end end
end end
end end
@ -207,8 +206,8 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
describe '#bootstrap', stubbed_knife: true do describe '#bootstrap', stubbed_knife: true do
subject { executor.bootstrap({}) }
let(:image) { double('Key instance', path: 'path') } let(:image) { double('Key instance', path: 'path') }
let(:bootstrap) { executor.bootstrap({}) }
before do before do
allow(executor).to receive(:sleep) allow(executor).to receive(:sleep)
@ -223,19 +222,19 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it 'run before hook' do it 'run before hook' do
expect(executor).to receive(:run_hook).with(:before_bootstrap, output).ordered expect(executor).to receive(:run_hook).with(:before_bootstrap, output).ordered
expect(executor).to receive(:run_hook).with(:after_bootstrap, output).ordered expect(executor).to receive(:run_hook).with(:after_bootstrap, output).ordered
subject bootstrap
end end
context "when server's private ip is unset" do context "when server's private ip is unset" do
it 'returns server_bootstrap_private_ip_unset error code' do it 'returns server_bootstrap_private_ip_unset error code' do
server.private_ip = nil server.private_ip = nil
expect(subject).to eq 4 expect(bootstrap).to eq 4
end end
end end
it 'tries to ssh to server' do it 'tries to ssh to server' do
expect(executor).to receive(:execute_system_command).with(/ssh/) expect(executor).to receive(:execute_system_command).with(/ssh/)
subject bootstrap
end end
context "couldn't ssh to server" do context "couldn't ssh to server" do
@ -244,11 +243,11 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it 'tries to ssh to server maximum MAX_SSH_RETRIES_AMOUNT times' do it 'tries to ssh to server maximum MAX_SSH_RETRIES_AMOUNT times' do
max_retries = Devops::Executor::ServerExecutor::MAX_SSH_RETRIES_AMOUNT max_retries = Devops::Executor::ServerExecutor::MAX_SSH_RETRIES_AMOUNT
expect(executor).to receive(:execute_system_command).exactly(max_retries).times expect(executor).to receive(:execute_system_command).exactly(max_retries).times
subject bootstrap
end end
it 'returns server_bootstrap_fail error code' do it 'returns server_bootstrap_fail error code' do
expect(subject).to eq 2 expect(bootstrap).to eq 2
end end
end end
@ -258,24 +257,24 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it "sets default chef node name if it's nil" do it "sets default chef node name if it's nil" do
executor.server.chef_node_name = nil executor.server.chef_node_name = nil
expect {subject}.to change {executor.server.chef_node_name}.to 'chef_node' expect {bootstrap}.to change {executor.server.chef_node_name}.to 'chef_node'
end end
it 'executes knife bootstrap' do it 'executes knife bootstrap' do
expect(stubbed_knife).to receive(:knife_bootstrap).with(output, server.private_ip, instance_of(Array)) expect(stubbed_knife).to receive(:knife_bootstrap).with(output, server.private_ip, instance_of(Array))
subject bootstrap
end end
it "bootstraps to public ip if it's set" do it "bootstraps to public ip if it's set" do
server.public_ip = '8.8.8.8' server.public_ip = '8.8.8.8'
expect(stubbed_knife).to receive(:knife_bootstrap).with(output, '8.8.8.8', instance_of(Array)) expect(stubbed_knife).to receive(:knife_bootstrap).with(output, '8.8.8.8', instance_of(Array))
subject bootstrap
end end
context 'after successful bootstrap' do context 'after successful bootstrap' do
it "updates server's chef node name in db" do it "updates server's chef node name in db" do
expect(stubbed_connector).to receive(:server_set_chef_node_name).with(instance_of(Devops::Model::Server)) expect(stubbed_connector).to receive(:server_set_chef_node_name).with(instance_of(Devops::Model::Server))
subject bootstrap
end end
end end
@ -283,12 +282,12 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
before { allow(stubbed_knife).to receive(:knife_bootstrap).and_return(123) } before { allow(stubbed_knife).to receive(:knife_bootstrap).and_return(123) }
it 'returns :server_bootstrap_fail code' do it 'returns :server_bootstrap_fail code' do
expect(subject).to eq 2 expect(bootstrap).to eq 2
end end
it "doesn't run after hook" do it "doesn't run after hook" do
expect(executor).to receive(:run_hook).with(:before_bootstrap, output) expect(executor).to receive(:run_hook).with(:before_bootstrap, output)
subject bootstrap
end end
end end
end end
@ -297,7 +296,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
describe '#two_phase_bootstrap', stubbed_knife: true do describe '#two_phase_bootstrap', stubbed_knife: true do
subject { executor.two_phase_bootstrap({}) } let(:two_phase_bootstrap) { executor.two_phase_bootstrap({}) }
before do before do
allow(provider).to receive(:run_list) {[]} allow(provider).to receive(:run_list) {[]}
@ -319,37 +318,37 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it 'builds run list' do it 'builds run list' do
expect(executor).to receive(:compute_run_list) expect(executor).to receive(:compute_run_list)
subject two_phase_bootstrap
end end
it 'sets run list to chef node' do it 'sets run list to chef node' do
expect(stubbed_knife).to receive(:set_run_list) expect(stubbed_knife).to receive(:set_run_list)
subject two_phase_bootstrap
end end
it 'deploys server' do it 'deploys server' do
expect(executor).to receive(:deploy_server) expect(executor).to receive(:deploy_server)
subject two_phase_bootstrap
end end
context 'if deploy was successful' do context 'if deploy was successful' do
it 'returns 0' do it 'returns 0' do
allow(executor).to receive(:deploy_server) { 0 } allow(executor).to receive(:deploy_server) { 0 }
expect(subject).to eq 0 expect(two_phase_bootstrap).to eq 0
end end
end end
context "if deploy wasn't successful" do context "if deploy wasn't successful" do
it 'returns :deploy_failed code' do it 'returns :deploy_failed code' do
allow(executor).to receive(:deploy_server) { 1 } allow(executor).to receive(:deploy_server) { 1 }
expect(subject).to eq 8 expect(two_phase_bootstrap).to eq 8
end end
end end
context 'when an error occured during deploy' do context 'when an error occured during deploy' do
it 'returns :deploy_unknown_error code' do it 'returns :deploy_unknown_error code' do
allow(executor).to receive(:deploy_server) { raise } allow(executor).to receive(:deploy_server) { raise }
expect(subject).to eq 6 expect(two_phase_bootstrap).to eq 6
end end
end end
end end
@ -361,7 +360,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
allow(stubbed_connector).to receive(:server_delete) allow(stubbed_connector).to receive(:server_delete)
expect(executor).to receive(:roll_back).ordered expect(executor).to receive(:roll_back).ordered
expect(stubbed_connector).to receive(:server_delete).ordered expect(stubbed_connector).to receive(:server_delete).ordered
subject two_phase_bootstrap
end end
end end
end end
@ -369,21 +368,19 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
context "when bootstrap wasn't successful" do context "when bootstrap wasn't successful" do
it 'returns :server_bootstrap_fail error code' do it 'returns :server_bootstrap_fail error code' do
allow(executor).to receive(:bootstrap) { 1 } allow(executor).to receive(:bootstrap) { 1 }
expect(subject).to eq 2 expect(two_phase_bootstrap).to eq 2
end end
end end
context 'when an error occured during bootstrap' do context 'when an error occured during bootstrap' do
it 'returns :server_bootstrap_unknown_error error code' do it 'returns :server_bootstrap_unknown_error error code' do
allow(executor).to receive(:bootstrap) { raise } allow(executor).to receive(:bootstrap) { raise }
expect(subject).to eq 7 expect(two_phase_bootstrap).to eq 7
end end
end end
end end
describe '#check_server_on_chef_server', stubbed_knife: true do describe '#check_server_on_chef_server', stubbed_knife: true do
subject { executor.check_server_on_chef_server }
before do before do
server.chef_node_name = 'a' server.chef_node_name = 'a'
allow(stubbed_knife).to receive(:chef_node_list) { @node_list } allow(stubbed_knife).to receive(:chef_node_list) { @node_list }
@ -392,17 +389,17 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it 'returns true when node_name in node list and in client list' do it 'returns true when node_name in node list and in client list' do
@node_list = %w(a); @client_list = %w(a) @node_list = %w(a); @client_list = %w(a)
expect(subject).to be true expect(executor.check_server_on_chef_server).to be true
end end
it "returns false if node name isn't in node list" do it "returns false if node name isn't in node list" do
@node_list = []; @client_list = %w(a) @node_list = []; @client_list = %w(a)
expect(subject).to be false expect(executor.check_server_on_chef_server).to be false
end end
it "returns false if node name isn't in node list" do it "returns false if node name isn't in node list" do
@node_list = %w(a); @client_list = [] @node_list = %w(a); @client_list = []
expect(subject).to be false expect(executor.check_server_on_chef_server).to be false
end end
end end
@ -464,7 +461,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
let(:joined_initial_tags) { initial_tags.join(' ') } let(:joined_initial_tags) { initial_tags.join(' ') }
let(:given_tags) { %w(c d) } let(:given_tags) { %w(c d) }
let(:joined_given_tags) { given_tags.join(' ') } let(:joined_given_tags) { given_tags.join(' ') }
subject { executor.deploy_server_with_tags(given_tags, {}) } let(:deploy_server_with_tags) { executor.deploy_server_with_tags(given_tags, {}) }
before do before do
@current_tags = initial_tags.dup @current_tags = initial_tags.dup
@ -490,7 +487,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
expect(stubbed_knife).to receive(:swap_tags).with(instance_of(String), joined_initial_tags, joined_given_tags).ordered expect(stubbed_knife).to receive(:swap_tags).with(instance_of(String), joined_initial_tags, joined_given_tags).ordered
expect(executor).to receive(:deploy_server).ordered expect(executor).to receive(:deploy_server).ordered
expect(stubbed_knife).to receive(:swap_tags).with(instance_of(String), joined_given_tags, joined_initial_tags).ordered expect(stubbed_knife).to receive(:swap_tags).with(instance_of(String), joined_given_tags, joined_initial_tags).ordered
subject deploy_server_with_tags
end end
end end
@ -498,7 +495,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it 'restores tags anyway' do it 'restores tags anyway' do
allow(executor).to receive(:deploy_server) { raise } allow(executor).to receive(:deploy_server) { raise }
expect { expect {
subject deploy_server_with_tags
}.to raise_error StandardError }.to raise_error StandardError
expect(current_tags).to eq initial_tags expect(current_tags).to eq initial_tags
end end
@ -507,7 +504,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
context 'if cannot add tags to server' do context 'if cannot add tags to server' do
it 'returns :server_cannot_update_tags code' do it 'returns :server_cannot_update_tags code' do
allow(stubbed_knife).to receive(:swap_tags) { false } allow(stubbed_knife).to receive(:swap_tags) { false }
expect(subject).to eq 3 expect(deploy_server_with_tags).to eq 3
end end
end end
end end
@ -519,7 +516,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
let(:json_file_name) { 'json.json' } let(:json_file_name) { 'json.json' }
let(:json_file_path) { File.join(SpecSupport.tmp_dir, json_file_name) } let(:json_file_path) { File.join(SpecSupport.tmp_dir, json_file_name) }
subject { executor.deploy_server(deploy_info) } let(:deploy_server) { executor.deploy_server(deploy_info) }
before do before do
allow(executor).to receive(:run_hook).with(:before_deploy, any_args) allow(executor).to receive(:run_hook).with(:before_deploy, any_args)
@ -534,7 +531,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it 'runs before_deploy and after_deploy hooks' do it 'runs before_deploy and after_deploy hooks' do
expect(executor).to receive(:run_hook).with(:before_deploy, any_args).ordered expect(executor).to receive(:run_hook).with(:before_deploy, any_args).ordered
expect(executor).to receive(:run_hook).with(:after_deploy, any_args).ordered expect(executor).to receive(:run_hook).with(:after_deploy, any_args).ordered
subject deploy_server
end end
context 'when uses json file' do context 'when uses json file' do
@ -560,13 +557,13 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it 'writes deploy_info to json file if it not exists' do it 'writes deploy_info to json file if it not exists' do
expect { subject }.to change { Dir.entries(SpecSupport.tmp_dir)} expect { deploy_server }.to change { Dir.entries(SpecSupport.tmp_dir)}
end end
it "writes deploy_info to given json file name if it doesn't exist" do it "writes deploy_info to given json file name if it doesn't exist" do
FileUtils.rm(json_file_path) if File.exists?(json_file_path) FileUtils.rm(json_file_path) if File.exists?(json_file_path)
deploy_info['json_file'] = json_file_name deploy_info['json_file'] = json_file_name
expect { subject }.to change { expect { deploy_server }.to change {
Dir.entries(SpecSupport.tmp_dir) Dir.entries(SpecSupport.tmp_dir)
} }
FileUtils.rm(json_file_path) FileUtils.rm(json_file_path)
@ -575,7 +572,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it 'reads json from file if it exists' do it 'reads json from file if it exists' do
deploy_info['json_file'] = json_file_name deploy_info['json_file'] = json_file_name
File.open(json_file_path, 'w') { |file| file.puts '{"foo": "bar"'} File.open(json_file_path, 'w') { |file| file.puts '{"foo": "bar"'}
expect { subject }.not_to change { expect { deploy_server }.not_to change {
Dir.entries(SpecSupport.tmp_dir) Dir.entries(SpecSupport.tmp_dir)
} }
FileUtils.rm(json_file_path) FileUtils.rm(json_file_path)
@ -585,7 +582,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
deploy_info['json_file'] = json_file_name deploy_info['json_file'] = json_file_name
regexp = %r(-j http://host.com:8080/api/v2.0/deploy/data/#{json_file_name}) regexp = %r(-j http://host.com:8080/api/v2.0/deploy/data/#{json_file_name})
expect(stubbed_knife).to receive(:ssh_stream).with(anything, regexp, any_args) expect(stubbed_knife).to receive(:ssh_stream).with(anything, regexp, any_args)
subject deploy_server
end end
end end
@ -598,41 +595,41 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it "adds run list to command if server's stack is set" do it "adds run list to command if server's stack is set" do
server.stack = 'stack' server.stack = 'stack'
expect(stubbed_knife).to receive(:ssh_stream).with(anything, %r(-r foo,bar), any_args) expect(stubbed_knife).to receive(:ssh_stream).with(anything, %r(-r foo,bar), any_args)
subject deploy_server
end end
it "doesn't add run list to command if server's stack is unset" do it "doesn't add run list to command if server's stack is unset" do
expect(stubbed_knife).to receive(:ssh_stream).with(anything, 'chef-client --no-color', any_args) expect(stubbed_knife).to receive(:ssh_stream).with(anything, 'chef-client --no-color', any_args)
subject deploy_server
end end
end end
it "uses server's key" do it "uses server's key" do
expect(stubbed_connector).to receive(:key).with('key_id') expect(stubbed_connector).to receive(:key).with('key_id')
expect(stubbed_knife).to receive(:ssh_stream).with(any_args, 'path_to_key') expect(stubbed_knife).to receive(:ssh_stream).with(any_args, 'path_to_key')
subject deploy_server
end end
it "uses public ip if it's set" do it "uses public ip if it's set" do
server.public_ip = '127.0.0.1' server.public_ip = '127.0.0.1'
expect(stubbed_knife).to receive(:ssh_stream).with(anything, anything, '127.0.0.1', any_args) expect(stubbed_knife).to receive(:ssh_stream).with(anything, anything, '127.0.0.1', any_args)
subject deploy_server
end end
it "uses private_ip if public_ip isn't set" do it "uses private_ip if public_ip isn't set" do
expect(stubbed_knife).to receive(:ssh_stream).with(anything, anything, server.private_ip, any_args) expect(stubbed_knife).to receive(:ssh_stream).with(anything, anything, server.private_ip, any_args)
subject deploy_server
end end
context 'if deploy was successful' do context 'if deploy was successful' do
it "updates server's last operation" do it "updates server's last operation" do
expect(server).to receive(:set_last_operation).with('deploy', anything) expect(server).to receive(:set_last_operation).with('deploy', anything)
expect(stubbed_connector).to receive(:server_update).with(server) expect(stubbed_connector).to receive(:server_update).with(server)
subject deploy_server
end end
it 'returns 0' do it 'returns 0' do
expect(subject).to eq 0 expect(deploy_server).to eq 0
end end
end end
@ -641,26 +638,26 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
it "doesn't run after_deploy hook" do it "doesn't run after_deploy hook" do
expect(executor).to receive(:run_hook).with(:before_deploy, any_args) expect(executor).to receive(:run_hook).with(:before_deploy, any_args)
expect(executor).not_to receive(:run_hook).with(:after_deploy, any_args) expect(executor).not_to receive(:run_hook).with(:after_deploy, any_args)
subject deploy_server
end end
it 'returns 1' do it 'returns 1' do
expect(subject).to eq 1 expect(deploy_server).to eq 1
end end
end end
end end
describe '#delete_from_chef_server', stubbed_knife: true do describe '#delete_from_chef_server', stubbed_knife: true do
subject { executor.delete_from_chef_server('foo') } let(:delete_from_chef_server) { executor.delete_from_chef_server('foo') }
before do before do
allow(stubbed_knife).to receive(:chef_client_delete) allow(stubbed_knife).to receive(:chef_client_delete)
allow(stubbed_knife).to receive(:chef_node_delete) allow(stubbed_knife).to receive(:chef_node_delete)
subject delete_from_chef_server
end end
it 'returns hash with :chef_node and :chef_client keys' do it 'returns hash with :chef_node and :chef_client keys' do
expect(subject).to be_a(Hash).and include(:chef_node, :chef_client) expect(delete_from_chef_server).to be_a(Hash).and include(:chef_node, :chef_client)
end end
it 'calls to :chef_node_delete and :chef_client_delete' do it 'calls to :chef_node_delete and :chef_client_delete' do