require 'spec_helper' describe Evrone::CI::Router::Build do let(:msg) { create :message, 'PerformBuild' } let(:build) { described_class.new msg } subject { build } context "just created" do its(:message) { should eq msg } its(:output) { should be_an_instance_of(Evrone::CI::Common::OutputBuffer)} its(:output_counter) { should eq 0 } end context "publish_build_log_message" do let(:data) { 'log' } subject { build.publish_build_log_message data } it { should be_an_instance_of(Evrone::CI::Message::BuildLog) } its(:build_id) { should eq build.message.id } its(:tm) { should eq 1 } its(:log) { should eq data } it "should increment counter" do expect { subject }.to change(build, :output_counter).by(1) end it "should delivery message" do expect { subject }.to change(Evrone::CI::Router::BuildLogsConsumer.messages, :count).by(1) expect(last_build_log_message.log).to eq data end end context "to_build_status_message" do subject { build.to_build_status_message Evrone::CI::Router::Build::STARTED } before do build.jobs_count = 1 end it { should be_an_instance_of(Evrone::CI::Message::BuildStatus) } its(:build_id) { should eq build.message.id } its(:status) { should eq 2 } its(:tm) { should be } its(:jobs_count) { should eq 1 } end context "add_to_output" do let(:data) { 'data' } let(:messages) { Evrone::CI::Router::BuildLogsConsumer.messages } subject do build.add_to_output(data) build.output.flush build end it "should delivery message" do expect { subject }.to change(messages, :size).by(1) expect(last_build_log_message.log).to eq data end it "should increment output_counter" do expect { subject }.to change(build, :output_counter).by(1) expect(last_build_log_message.tm).to eq 1 end end context "add_command_to_output" do let(:data) { 'data' } let(:messages) { Evrone::CI::Router::BuildLogsConsumer.messages } subject do build.add_command_to_output(data) build.output.flush build end it "should delivery message" do expect { subject }.to change(messages, :size).by(1) expect(last_build_log_message.log).to eq "$ #{data}\n" end it "should increment output_counter" do expect { subject }.to change(build, :output_counter).by(1) expect(last_build_log_message.tm).to eq 1 end end context ".to_perform_job_message" do let(:config) { create :configuration } let(:job_id) { 2 } subject { build.to_perform_job_message config, job_id } it { should be_an_instance_of Evrone::CI::Message::PerformJob } context "created message" do its(:id) { should eq build.message.id } its(:name) { should eq build.message.name } its(:job_id) { should eq job_id } its(:before_script) { should be } its(:script) { should be } its(:after_script) { should be } its(:matrix_keys) { should eq ['rvm:2.0.0'] } end end context "scm_class" do subject { build.scm_class } it { should eq ::Evrone::CI::SCM::Git } end end