diff --git a/lib/knapsack_pro.rb b/lib/knapsack_pro.rb index 987697bc..5c0b0aa4 100644 --- a/lib/knapsack_pro.rb +++ b/lib/knapsack_pro.rb @@ -12,6 +12,7 @@ require_relative 'knapsack_pro/config/ci/circle' require_relative 'knapsack_pro/config/ci/semaphore' require_relative 'knapsack_pro/config/ci/buildkite' +require_relative 'knapsack_pro/config/ci/travis' require_relative 'knapsack_pro/config/env' require_relative 'knapsack_pro/client/api/action' require_relative 'knapsack_pro/client/api/v1/base' diff --git a/lib/knapsack_pro/config/ci/travis.rb b/lib/knapsack_pro/config/ci/travis.rb new file mode 100644 index 00000000..cc1950be --- /dev/null +++ b/lib/knapsack_pro/config/ci/travis.rb @@ -0,0 +1,28 @@ +module KnapsackPro + module Config + module CI + class Travis < Base + def node_total + ENV['KNAPSACK_PRO_CI_NODE_TOTAL'] + end + + def node_index + ENV['KNAPSACK_PRO_CI_NODE_INDEX'] + end + + def commit_hash + ENV['TRAVIS_COMMIT'] + end + + def branch + ENV['TRAVIS_BRANCH'] + end + + def project_dir + ENV['TRAVIS_BUILD_DIR'] + end + end + end + end +end + diff --git a/spec/knapsack_pro/config/ci/travis_spec.rb b/spec/knapsack_pro/config/ci/travis_spec.rb new file mode 100644 index 00000000..b9234b62 --- /dev/null +++ b/spec/knapsack_pro/config/ci/travis_spec.rb @@ -0,0 +1,74 @@ +describe KnapsackPro::Config::CI::Travis do + let(:env) { {} } + + before do + stub_const('ENV', env) + end + + it { should be_kind_of KnapsackPro::Config::CI::Base } + + describe '#node_total' do + subject { described_class.new.node_total } + + context 'when environment exists' do + let(:env) { { 'KNAPSACK_PRO_CI_NODE_TOTAL' => 4 } } + it { should eql 4 } + end + + context "when environment doesn't exist" do + it { should be nil } + end + end + + describe '#node_index' do + subject { described_class.new.node_index } + + context 'when environment exists' do + let(:env) { { 'KNAPSACK_PRO_CI_NODE_INDEX' => 3 } } + it { should eql 3 } + end + + context "when environment doesn't exist" do + it { should be nil } + end + end + + describe '#commit_hash' do + subject { described_class.new.commit_hash } + + context 'when environment exists' do + let(:env) { { 'TRAVIS_COMMIT' => '3fa64859337f6e56409d49f865d13fd7' } } + it { should eql '3fa64859337f6e56409d49f865d13fd7' } + end + + context "when environment doesn't exist" do + it { should be nil } + end + end + + describe '#branch' do + subject { described_class.new.branch } + + context 'when environment exists' do + let(:env) { { 'TRAVIS_BRANCH' => 'master' } } + it { should eql 'master' } + end + + context "when environment doesn't exist" do + it { should be nil } + end + end + + describe '#project_dir' do + subject { described_class.new.project_dir } + + context 'when environment exists' do + let(:env) { { 'TRAVIS_BUILD_DIR' => 'knapsack_pro-ruby' } } + it { should eql 'knapsack_pro-ruby' } + end + + context "when environment doesn't exist" do + it { should be nil } + end + end +end