require 'spec_helper' require 'fileutils' require 'pathname' describe Vx::Router do let(:build) { create :build } let(:router) { described_class.new build } subject { router } context "just created" do its(:build) { should eq build } end context "#perform" do subject { router.perform } it { should be_true } end context "#update_build_status" do let(:messages) { Vx::Router::BuildStatusConsumer.messages } let(:first_message) { messages.first } let(:last_message) { messages.last } it "should delivery STARTED and FINISHED when success" do router.update_build_status { true } expect(messages).to have(2).items expect(first_message.status).to eq Vx::Router::Build::STARTED expect(last_message.status).to eq Vx::Router::Build::FINISHED end it "should delivery STARTED and FAILED when failed" do router.update_build_status { false } expect(messages).to have(2).items expect(first_message.status).to eq Vx::Router::Build::STARTED expect(last_message.status).to eq Vx::Router::Build::FAILED end it "should delivery STARTED and FAILED when exception raised" do router.update_build_status { raise "Ignore Me" } expect(messages).to have(2).items expect(first_message.status).to eq Vx::Router::Build::STARTED expect(last_message.status).to eq Vx::Router::Build::FAILED end end context "#load_configuration" do subject { router.load_configuration } it "should build new BuildConfiguration instance from message" do expect(subject).to be_true expect(router.configuration).to be end end context "#create_and_delivery_build_matrix" do let(:messages) { Vx::Router::JobsConsumer.messages } let(:message) { messages.first } subject { router.create_and_delivery_build_matrix } before do stub(router).configuration { create :configuration } end it "should create build matrix from source configuration and delivery its to jobs" do expect(subject).to be_true expect(messages).to have(1).item expect(message.job_id).to eq 1 end it "should publish job_status message with status = INITIALIZED" do expect { subject }.to change(Vx::Router::JobStatusConsumer.messages, :count).by(1) message = Vx::Router::JobStatusConsumer.messages.last expect(message.build_id).to eq build.message.id expect(message.job_id).to eq 1 expect(message.status).to eq 0 end end end