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
watch(%r{db/.+\.rb}) { rspec.spec_dir }
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" }
end

View File

@ -79,15 +79,14 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
describe '#create_server' do
let(:image) { double('Image instance', remote_user: 'remote_user') }
let(:create_server) {
executor.create_server(
'created_by' => 'user',
'run_list' => @run_list,
'name' => 'node_name',
'key' => @key,
'without_bootstrap' => @without_bootstrap
)
}
let(:create_server_options) { {
'created_by' => 'user',
'run_list' => @run_list,
'name' => 'node_name',
'key' => @key,
'without_bootstrap' => @without_bootstrap
} }
let(:create_server) { executor.create_server(create_server_options) }
before do
allow(provider).to receive(:create_server) { true }
@ -150,7 +149,7 @@ RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connec
create_server
end
context 'without_bootstrap option is false' do
context 'without_bootstrap option is false or nil' do
it 'launches bootstrap' do
@without_bootstrap = false
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)
create_server
end
end
context 'without_bootstrap option is nil' do
it 'launches bootstrap' do
@without_bootstrap = nil
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)
create_server
end
# it 'passes additional deployers to bootstrap' do
# executor = described_class.new(server, output)
# end
end
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
require 'spec/connectors/shared_connectors_specs'
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'
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(:perform_with_bootstrap) { worker.perform('stack_attributes' => stack_attrs) }
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
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_servers_bootstrapper) { stack_servers_bootstrapper }
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) }
end
it 'requires "stack_attributes" in options' do
expect{
worker.perform({})
}.to raise_error KeyError
expect{ worker.perform({}) }.to raise_error KeyError
end
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
end
it 'updates report about operation, creates stack and persists stack servers' do
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(stack_servers_persister).to receive(:persist).ordered
perform_without_bootstrap