require 'spec_helper' describe Evrone::CI::Worker::Job do let(:message) { create :message, 'PerformJob' } let(:job) { described_class.new message } subject { job } context "just created" do its(:message) { should eq message } end context "create_job_log_message" do let(:tm) { Time.new(2012, 12, 10, 15, 45) } let(:data) { 'log' } subject { job.create_job_log_message data } before do mock(Time).now { tm } end it { should be_an_instance_of(Evrone::CI::Message::JobLog) } its(:job_id) { should eq job.message.job_id } its(:build_id) { should eq job.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::Worker::JobLogsConsumer.messages } subject { job.add_to_output(data) ; job } 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::Worker::JobLogsConsumer.messages } subject { job.add_command_to_output(data) ; job } its(:output) { should eq "$ #{data}\n" } it "should delivery message" do expect { subject }.to change(messages, :size).by(1) end end end