simplify specs

This commit is contained in:
Anton Chuchkalov 2016-03-17 12:49:19 +02:00
parent 7fb5862f85
commit 5b139b5235
10 changed files with 29 additions and 30 deletions

View File

@ -43,5 +43,6 @@ guard :rspec, cmd: "rspec" do
# Devops files # Devops files
watch(%r{db/.+\.rb}) { rspec.spec_dir } watch(%r{db/.+\.rb}) { rspec.spec_dir }
watch(%r{lib/executors/.+\.rb}) { "#{rspec.spec_dir}/executors" } watch(%r{lib/executors/.+\.rb}) { "#{rspec.spec_dir}/executors" }
watch(%r{workers/.+\.rb}) { "#{rspec.spec_dir}/workers" }
watch(%r{workers/stack_bootstrap/.+\.rb}) { "#{rspec.spec_dir}/workers" } watch(%r{workers/stack_bootstrap/.+\.rb}) { "#{rspec.spec_dir}/workers" }
end end

View File

@ -79,15 +79,14 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
describe '#create_server' do describe '#create_server' do
let(:image) { double('Image instance', remote_user: 'remote_user') } let(:image) { double('Image instance', remote_user: 'remote_user') }
let(:create_server) { let(:create_server_options) { {
executor.create_server( 'created_by' => 'user',
'created_by' => 'user', 'run_list' => @run_list,
'run_list' => @run_list, 'name' => 'node_name',
'name' => 'node_name', 'key' => @key,
'key' => @key, 'without_bootstrap' => @without_bootstrap
'without_bootstrap' => @without_bootstrap } }
) let(:create_server) { executor.create_server(create_server_options) }
}
before do before do
allow(provider).to receive(:create_server) { true } allow(provider).to receive(:create_server) { true }
@ -150,7 +149,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
create_server create_server
end end
context 'without_bootstrap option is false' do context 'without_bootstrap option is false or nil' do
it 'launches bootstrap' do it 'launches bootstrap' do
@without_bootstrap = false @without_bootstrap = false
allow(image).to receive(:bootstrap_template) { 'template' } allow(image).to receive(:bootstrap_template) { 'template' }
@ -158,9 +157,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
expect(executor).to receive(:two_phase_bootstrap) expect(executor).to receive(:two_phase_bootstrap)
create_server create_server
end end
end
context 'without_bootstrap option is nil' do
it 'launches bootstrap' do it 'launches bootstrap' do
@without_bootstrap = nil @without_bootstrap = nil
allow(image).to receive(:bootstrap_template) { 'template' } allow(image).to receive(:bootstrap_template) { 'template' }
@ -168,6 +165,10 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
expect(executor).to receive(:two_phase_bootstrap) expect(executor).to receive(:two_phase_bootstrap)
create_server create_server
end end
# it 'passes additional deployers to bootstrap' do
# executor = described_class.new(server, output)
# end
end end
context 'without_bootstrap option is true' do context 'without_bootstrap option is true' do

View File

@ -1,7 +1,3 @@
RSpec.shared_context 'auto_model', type: :model do
require 'spec/models/shared_validation_specs'
end
RSpec.shared_context 'auto_connector', type: :connector do RSpec.shared_context 'auto_connector', type: :connector do
require 'spec/connectors/shared_connectors_specs' require 'spec/connectors/shared_connectors_specs'
end end

View File

@ -0,0 +1,3 @@
RSpec.shared_context 'type_model', type: :model do
require 'spec/models/shared_validation_specs'
end

View File

@ -0,0 +1,6 @@
RSpec.shared_context 'type_worker', type: :worker do
before do
allow(worker).to receive(:call).and_yield
worker.out = double(:out, puts: nil, flush: nil)
end
end

View File

@ -1,9 +1,6 @@
require 'workers/stack_bootstrap_worker' require 'workers/stack_bootstrap_worker'
RSpec.describe StackBootstrapWorker, type: :worker, stubbed_connector: true do RSpec.describe StackBootstrapWorker, type: :worker, stubbed_connector: true do
let(:out) { double(:out, puts: nil, flush: nil) }
let(:file) { 'temp.txt' }
let(:stack_attrs) { attributes_for(:stack_ec2).stringify_keys } let(:stack_attrs) { attributes_for(:stack_ec2).stringify_keys }
let(:perform_with_bootstrap) { worker.perform('stack_attributes' => stack_attrs) } let(:perform_with_bootstrap) { worker.perform('stack_attributes' => stack_attrs) }
let(:perform_without_bootstrap) { worker.perform('stack_attributes' => stack_attrs.merge('without_bootstrap' => true)) } let(:perform_without_bootstrap) { worker.perform('stack_attributes' => stack_attrs.merge('without_bootstrap' => true)) }
@ -14,34 +11,29 @@ RSpec.describe StackBootstrapWorker, type: :worker, stubbed_connector: true do
before do before do
allow(Provider::ProviderFactory).to receive(:providers).and_return(%w(ec2)) allow(Provider::ProviderFactory).to receive(:providers).and_return(%w(ec2))
allow(stubbed_connector).to receive(:save_report)
allow(stubbed_connector).to receive(:report) { build(:report) }
allow(stubbed_connector).to receive(:report_update)
allow(stubbed_connector).to receive(:stack_insert)
allow(worker).to receive(:update_report)
allow(worker).to receive(:stack_synchronizer) { stack_synchronizer } allow(worker).to receive(:stack_synchronizer) { stack_synchronizer }
allow(worker).to receive(:stack_servers_bootstrapper) { stack_servers_bootstrapper } allow(worker).to receive(:stack_servers_bootstrapper) { stack_servers_bootstrapper }
allow(worker).to receive(:stack_servers_persister) { stack_servers_persister } allow(worker).to receive(:stack_servers_persister) { stack_servers_persister }
allow(worker).to receive(:call).and_yield
worker.out = out allow(stubbed_connector).to receive(:stack_insert)
allow(Devops::Model::StackEc2).to receive(:create) { Devops::Model::StackEc2.new(stack_attrs) } allow(Devops::Model::StackEc2).to receive(:create) { Devops::Model::StackEc2.new(stack_attrs) }
end end
it 'requires "stack_attributes" in options' do it 'requires "stack_attributes" in options' do
expect{ expect{ worker.perform({}) }.to raise_error KeyError
worker.perform({})
}.to raise_error KeyError
end end
it 'updates report about operation' do it 'updates report about operation' do
expect(stubbed_connector).to receive(:report_update).with(instance_of(Devops::Model::Report)) expect(worker).to receive(:update_report)
perform_without_bootstrap perform_without_bootstrap
end end
it 'updates report about operation, creates stack and persists stack servers' do it 'updates report about operation, creates stack and persists stack servers' do
allow(worker).to receive(:create_stack).and_call_original allow(worker).to receive(:create_stack).and_call_original
expect(stubbed_connector).to receive(:report_update).with(instance_of(Devops::Model::Report)).ordered expect(worker).to receive(:update_report).ordered
expect(worker).to receive(:create_stack).ordered expect(worker).to receive(:create_stack).ordered
expect(stack_servers_persister).to receive(:persist).ordered expect(stack_servers_persister).to receive(:persist).ordered
perform_without_bootstrap perform_without_bootstrap