Sha256: 3357a4caec8db363f282e1c2a0e786e4bd6b5a211b4fde8abd3b3ff812b8ab4a

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require 'spec_helper'
require 'pathname'

describe Evrone::CI::Router::Middleware::CreateBuildMatrix do
  let(:app)      { ->(_) { 0 } }
  let(:build)    { create :build }
  let(:env)      { OpenStruct.new build: build, repo_dir: repo_dir }
  let(:repo_dir) { Pathname.new fixture_path("repo") }
  let(:matrix)   { described_class.new app }

  it { should be }

  context "call" do
    let(:travis) { create :travis, attributes: { rvm: %w{ 1.9.3 2.0.0 } } }
    subject { matrix.call env }

    context "successfuly" do
      before do
        mock(matrix).load_travis(repo_dir) { travis }
      end

      it { should eq 0 }

      it "should create and delivery jobs " do
        expect{ subject }.to change{
          Evrone::CI::Router::JobsConsumer.messages.count
        }.by(2)
      end

      context "first delivered job" do
        let(:m) { Evrone::CI::Router::JobsConsumer.messages.first }
        subject { m }
        before { matrix.call env }

        its("job_id") { should eq 1 }
      end

      context "last delivered job" do
        let(:m) { Evrone::CI::Router::JobsConsumer.messages.last }
        subject { m }
        before { matrix.call env }

        its("job_id") { should eq 2 }
      end

      context "update build" do
        it "should assign jobs_count" do
          expect{ subject }.to change(build, :jobs_count).from(nil).to(2)
        end

        it "should assign matrix" do
          expect{ subject }.to change(build, :matrix).from(nil).to(%w{rvm})
        end
      end
    end

    context "when travis.yml not found" do

      before do
        mock(Evrone::CI::Router::Travis).from_file(anything){ nil }
      end

      it "should return -1" do
        expect(subject).to eq(-1)
      end

      it "cannot delivery any job" do
        expect{ subject }.to_not change(Evrone::CI::Router::JobsConsumer.messages, :size)
      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/create_build_matrix_spec.rb