From a9b7514a4e37a05b1bf570dfc0258566f9b890c9 Mon Sep 17 00:00:00 2001 From: ryanrlhh Date: Wed, 28 Oct 2015 15:08:44 +0800 Subject: [PATCH 1/2] Add Travis CI Configs --- lib/knapsack_pro/config/ci/travis.rb | 28 ++++++++ spec/knapsack_pro/config/ci/travis_spec.rb | 74 ++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 lib/knapsack_pro/config/ci/travis.rb create mode 100644 spec/knapsack_pro/config/ci/travis_spec.rb 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..6e938b3c --- /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 '/home/ubuntu/knapsack_pro-ruby' } + end + + context "when environment doesn't exist" do + it { should be nil } + end + end +end From 657dd698a5083226d8399966a9875cfcde56424a Mon Sep 17 00:00:00 2001 From: ryanrlhh Date: Wed, 28 Oct 2015 16:32:13 +0800 Subject: [PATCH 2/2] Fix failing build by adding ci/travis to lib/knapsack_pro.rb and fix incorrect spec --- lib/knapsack_pro.rb | 1 + spec/knapsack_pro/config/ci/travis_spec.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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/spec/knapsack_pro/config/ci/travis_spec.rb b/spec/knapsack_pro/config/ci/travis_spec.rb index 6e938b3c..b9234b62 100644 --- a/spec/knapsack_pro/config/ci/travis_spec.rb +++ b/spec/knapsack_pro/config/ci/travis_spec.rb @@ -64,7 +64,7 @@ context 'when environment exists' do let(:env) { { 'TRAVIS_BUILD_DIR' => 'knapsack_pro-ruby' } } - it { should eql '/home/ubuntu/knapsack_pro-ruby' } + it { should eql 'knapsack_pro-ruby' } end context "when environment doesn't exist" do