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 '' } end context "create_build_log_message" do let(:tm) { Time.new(2012, 12, 10, 15, 45) } let(:data) { 'log' } subject { build.create_build_log_message data } before do mock(Time).now { tm } end it { should be_an_instance_of(Evrone::CI::Message::BuildLog) } its(:build_id) { should eq build.message.id } its(:tm) { should eq tm.to_i } its(:log) { should eq data } 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 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 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 end end