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 eq '' } its(:output_counter) { should eq 0 } end context "create_build_log_message" do let(:data) { 'log' } subject { build.create_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 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 } context "when commit_info exists" do before do build.commit_info = OpenStruct.new( author: "author", email: "email", sha: 'sha', message: "message" ) end its(:commit_author) { should eq 'author' } its(:commit_author_email) { should eq 'email' } its(:commit_sha) { should eq 'sha' } its(:commit_message) { should eq 'message' } end end context "add_to_output" do let(:data) { 'data' } let(:messages) { Evrone::CI::Router::BuildLogsConsumer.messages } subject { build.add_to_output(data) ; build } its(:output) { should eq data } it "should delivery message" do expect { subject }.to change(messages, :size).by(1) end it "should increment output_counter" do expect { subject }.to change(build, :output_counter).by(1) expect(messages.first.tm).to eq 1 end end context "add_command_to_output" do let(:data) { 'data' } let(:messages) { Evrone::CI::Router::BuildLogsConsumer.messages } subject { build.add_command_to_output(data) ; build } its(:output) { should eq "$ #{data}\n" } it "should delivery message" do expect { subject }.to change(messages, :size).by(1) end it "should increment output_counter" do expect { subject }.to change(build, :output_counter).by(1) expect(messages.first.tm).to eq 1 end end context ".to_perform_job_message" do let(:travis) { create :travis } let(:job_id) { 2 } subject { build.to_perform_job_message travis, 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(:src) { should eq build.message.src } its(:sha) { should eq build.message.sha } its(:deploy_key) { should eq build.message.deploy_key } its(:job_id) { should eq job_id } its(:before_script) { should be } its(:script) { should be } its(:matrix_keys) { should eq ['rvm:2.0.0'] } end context "when commit_info.sha exists" do before do build.commit_info = OpenStruct.new sha: "commit info sha" end its(:sha) { should eq 'commit info sha' } end end end