Sha256: c2ecdaee153a8c6a7e428569b74fb9e8393e0709417793cdac239aad9cb4644d

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'

describe Evrone::CI::Router::Middleware::UpdateBuildStatus do
  let(:exit_code)   { 0 }
  let(:app)         { ->(_) { exit_code } }
  let(:build)       { create :build }
  let(:env)         { OpenStruct.new build: build }
  let(:mid)         { described_class.new app }
  let(:messages)    { Evrone::CI::Router::BuildStatusConsumer.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 "UpdateBuildStatus message" do
            its(:status) { should eq 2 }
          end
        end

        context "last" do
          subject { messages.last }
          it_should_behave_like "UpdateBuildStatus 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 "UpdateBuildStatus message" do
          its(:status) { should eq 2 }
        end
      end

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

    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evrone-ci-router-0.2.0.pre0 spec/lib/middleware/update_build_status_spec.rb