require 'spec_helper' require 'yaml' describe Evrone::CI::Router::BuildMatrix do let(:attributes) { { env: %w{ FOO=1 BAR=2 }, rvm: %w{ 1.8.7 1.9.3 2.0.0 }, scala: %w{ 2.9.2 2.10.1 } } } let(:travis) { create :travis, attributes: attributes } let(:matrix) { described_class.new travis } subject { matrix } context "just created" do its(:travis) { should eq travis } end context "keys" do subject { matrix.keys } it { should eq %w{ env rvm scala } } context "without matrix" do let(:attributes) { {} } it { should eq [] } end end context 'travises' do context "values" do subject { matrix.travises } it { should have(12).items } context "attributes" do subject { matrix.travises.map(&:to_matrix_s) } it do should eq [ "env:BAR=2, rvm:1.8.7, scala:2.10.1", "env:FOO=1, rvm:1.8.7, scala:2.10.1", "env:BAR=2, rvm:1.8.7, scala:2.9.2", "env:FOO=1, rvm:1.8.7, scala:2.9.2", "env:BAR=2, rvm:1.9.3, scala:2.10.1", "env:FOO=1, rvm:1.9.3, scala:2.10.1", "env:BAR=2, rvm:1.9.3, scala:2.9.2", "env:FOO=1, rvm:1.9.3, scala:2.9.2", "env:BAR=2, rvm:2.0.0, scala:2.10.1", "env:FOO=1, rvm:2.0.0, scala:2.10.1", "env:BAR=2, rvm:2.0.0, scala:2.9.2", "env:FOO=1, rvm:2.0.0, scala:2.9.2" ] end context "without matrix" do let(:attributes) { { rvm: %w{ 2.0.0 }, } } it { should eq ['rvm:2.0.0'] } end end end end context 'attributes_for_new_travises' do subject { matrix.attributes_for_new_travises } it { should have(12).items } its(:first) { should eq("rvm" => "1.8.7", "scala" => "2.10.1", "env" => "BAR=2") } its(:last) { should eq("rvm" => "2.0.0", "scala" => "2.9.2", "env" => "FOO=1") } end context 'extract_pair_of_key_and_values' do subject { matrix.extract_pair_of_key_and_values } it { should eq [ ["rvm", %w{ 1.8.7 1.9.3 2.0.0 }], ["scala", %w{ 2.9.2 2.10.1 }], ["env", %w{ FOO=1 BAR=2 }] ] } end context "permutate_and_build_values" do subject { format_values matrix.permutate_and_build_values } let(:expected) { [ %w{env:BAR=2 rvm:1.8.7 scala:2.10.1}, %w{env:BAR=2 rvm:1.8.7 scala:2.9.2}, %w{env:BAR=2 rvm:1.9.3 scala:2.10.1}, %w{env:BAR=2 rvm:1.9.3 scala:2.9.2}, %w{env:BAR=2 rvm:2.0.0 scala:2.10.1}, %w{env:BAR=2 rvm:2.0.0 scala:2.9.2}, %w{env:FOO=1 rvm:1.8.7 scala:2.10.1}, %w{env:FOO=1 rvm:1.8.7 scala:2.9.2}, %w{env:FOO=1 rvm:1.9.3 scala:2.10.1}, %w{env:FOO=1 rvm:1.9.3 scala:2.9.2}, %w{env:FOO=1 rvm:2.0.0 scala:2.10.1}, %w{env:FOO=1 rvm:2.0.0 scala:2.9.2}, ] } it { should eq expected } context "with empty keys" do let(:attributes) { { env: %w{ FOO=1 BAR=2 }, rvm: %w{ 1.8.7 1.9.3 2.0.0 }, scala: %w{ 2.9.2 2.10.1 }, java: [], go: nil } } it { should eq expected } end context "with one key" do let(:attributes) { { rvm: %w{ 1.9.3 2.0.0 }, } } let(:expected) {[ %w{ rvm:1.9.3 }, %w{ rvm:2.0.0 } ]} it { should eq expected } end context "without matrix" do let(:attributes) { { rvm: %w{ 2.0.0 }, } } let(:expected) {[ %w{ rvm:2.0.0 } ]} it { should eq expected } end def format_values(values) values.map{|i| i.map(&:to_s).sort }.sort end end end