Skip to content

Commit

Permalink
worker: fix config parsing when a config hash already was passed
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Fuchs committed Mar 23, 2011
1 parent c730646 commit 566ae69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/travis/buildable/config.rb
Expand Up @@ -14,8 +14,8 @@ def matrix?(config)
end

def initialize(config)
config = File.read(config) if config.is_a?(String)
replace(YAML.load(config).stringify_keys) rescue nil
config = YAML.load(File.read(config)) rescue {} if config.is_a?(String)
replace(config.stringify_keys)
rescue Errno::ENOENT => e
{}
end
Expand Down
12 changes: 4 additions & 8 deletions test/functional/travis/buildable_test.rb
Expand Up @@ -10,7 +10,6 @@ def setup
super
FileUtils.mkdir_p(Buildable.base_dir)
Buildable.any_instance.stubs(:execute)
Buildable.any_instance.stubs(:config).returns(config)
end

def teardown
Expand Down Expand Up @@ -46,27 +45,24 @@ def teardown
buildable.checkout
end

test "prepend_command: equals the build script if no env is given" do
test "prepend_command: equals the build script if no config is given" do
buildable = Buildable.new(:script => 'rake', :url => 'file://~/Development/projects/travis')
buildable.stubs(:config).returns(config)
assert_equal 'rake ci', buildable.prepend_env('rake ci')
end

test "prepend_command: prepends an rvm command if configured" do
buildable = Buildable.new(:script => 'rake', :url => 'file://~/Development/projects/travis', :env => [['rvm', '1.9.2']])
buildable.stubs(:config).returns(config('rvm' => '1.9.2'))
buildable = Buildable.new(:script => 'rake', :url => 'file://~/Development/projects/travis', :config => { 'rvm' => '1.9.2' })
assert_equal 'rvm use 1.9.2; rake ci', buildable.prepend_env('rake ci')
end

test "prepend_command: prepends an env var if configured" do
buildable = Buildable.new(:script => 'rake', :url => 'file://~/Development/projects/travis', :env => [['bundle_gemfile', 'ci/Gemfile.rails-2.3.x']])
buildable.stubs(:config).returns(config('gemfile' => 'gemfiles/rails-2.3.x'))
buildable = Buildable.new(:script => 'rake', :url => 'file://~/Development/projects/travis', :config => { 'gemfile' => 'gemfiles/rails-2.3.x' })
assert_equal 'BUNDLE_GEMFILE=gemfiles/rails-2.3.x rake ci', buildable.prepend_env('rake ci')
end

test "prepend_command: prepends both rvm command and env var if configured" do
buildable = Buildable.new(:script => 'rake', :url => 'file://~/Development/projects/travis', :env => [['rvm', '1.9.2'], ['bundle_gemfile', 'ci/Gemfile.rails-2.3.x']])
buildable.stubs(:config).returns(config('rvm' => '1.9.2', 'gemfile' => 'gemfiles/rails-2.3.x'))
buildable = Buildable.new(:script => 'rake', :url => 'file://~/Development/projects/travis', :config => { 'rvm' => '1.9.2', 'gemfile' => 'gemfiles/rails-2.3.x' })
assert_equal 'rvm use 1.9.2; BUNDLE_GEMFILE=gemfiles/rails-2.3.x rake ci', buildable.prepend_env('rake ci')
end

Expand Down

0 comments on commit 566ae69

Please sign in to comment.