Sha256: 31e06f81a145938353c2e44f264d27a1f5d0a5ab669320d0c8c49703107577ca

Contents?: true

Size: 1.62 KB

Versions: 19

Compression:

Stored size: 1.62 KB

Contents

require 'spec_helper'

describe Evrone::CI::Worker::UpdateJobStatus do
  let(:exit_code)   { 0 }
  let(:app)         { ->(_) { exit_code } }
  let(:job)         { create :job }
  let(:env)         { OpenStruct.new job: job }
  let(:mid)         { described_class.new app }
  let(:messages)    { Evrone::CI::Worker::JobStatusConsumer.messages }

  subject { mid.call env }

  it "should delivery 2 messages" do
    expect {
      subject
    }.to change(messages, :size).by(2)
  end

  { 0 => 3, 1 => 4, -1 => 5 }.each do |code, status|
    context "when exit code is #{code}" do
      let(:exit_code) { code }
      it { should eq code }

      context "messages" do
        before { mid.call env }

        context "first" do
          subject { messages.first }
          it_should_behave_like "UpdateJobStatus message" do
            its(:status) { should eq 2 }
          end
        end

        context "last" do
          subject { messages.last }
          it_should_behave_like "UpdateJobStatus message" do
            its(:status) { should eq status }
          end
        end

      end
    end
  end

  context "when raise exception" do
    let(:app) { ->(_) { raise "Ignore Me" } }
    it { should eq(-1) }

    context "messages" do
      before { mid.call env }

      context "first" do
        subject { messages.first }
        it_should_behave_like "UpdateJobStatus message" do
          its(:status) { should eq 2 }
        end
      end

      context "last" do
        subject { messages.last }
        it_should_behave_like "UpdateJobStatus message" do
          its(:status) { should eq 5 }
        end
      end

    end
  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
evrone-ci-worker-0.2.0.pre20 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre19 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre18 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre17 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre15 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre14 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre13 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre12 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre11 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre10 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre9 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre8 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre7 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre6 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre5 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre4 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre3 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre1 spec/lib/worker/middlewares/update_job_status_spec.rb
evrone-ci-worker-0.2.0.pre0 spec/lib/worker/middlewares/update_job_status_spec.rb