Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/knapsack_pro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
28 changes: 28 additions & 0 deletions lib/knapsack_pro/config/ci/travis.rb
Original file line number Diff line number Diff line change
@@ -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

74 changes: 74 additions & 0 deletions spec/knapsack_pro/config/ci/travis_spec.rb
Original file line number Diff line number Diff line change
@@ -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