Skip to content

Commit

Permalink
Merge branch 'gemfile-discovery' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Bugno committed Apr 13, 2011
2 parents bb54fd9 + ac4324d commit 7d0f987
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/big_tuna/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Runner
def self.execute(dir, command)
end_command = "cd #{dir} && #{command}"
BigTuna.logger.debug("Executing: #{end_command}")
with_clean_env do
with_clean_env(dir) do
output = Output.new(dir, command)
buffer = []
status = Open4.popen4(end_command) do |_, _, stdout, stderr|
Expand All @@ -18,13 +18,20 @@ def self.execute(dir, command)
end
end

def self.with_clean_env
def self.with_clean_env(dir)
Bundler.with_clean_env do
begin
rails_env = ENV.delete("RAILS_ENV")
old_bundle_gemfile = nil
bundle_gemfile = File.join(dir, "Gemfile")
if File.file?(bundle_gemfile)
old_bundle_gemfile = ENV.delete("BUNDLE_GEMFILE")
ENV["BUNDLE_GEMFILE"] = bundle_gemfile
end
yield
ensure
ENV["RAILS_ENV"] = rails_env if rails_env # if nil, then don't set any key
ENV["BUNDLE_GEMFILE"] = old_bundle_gemfile if old_bundle_gemfile
end
end
end
Expand Down
43 changes: 43 additions & 0 deletions test/unit/bundler_project_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'test_helper'

class BundlerProjectTest < ActiveSupport::TestCase
def setup
super
create_bundler_test_repo
end

def teardown
destroy_test_repo
super
end

test "bundler projects are auto-discovered" do
project = project_with_steps({:name => "bundlerproject", :vcs_source => "test/files/bundler_repo", :vcs_type => "git"}, "env")
project.build!
run_delayed_jobs()
build = project.recent_build
envs = build.parts[0].output[0].stdout
bundle_gemfile_env = envs.map! { |e| e.split("=") }.assoc("BUNDLE_GEMFILE")
assert_equal File.join(build.build_dir, "Gemfile"), bundle_gemfile_env[1]
end

private
def create_bundler_test_repo
command = <<-CMD.gsub("\n", "; ")
mkdir -p test/files/bundler_repo
cd test/files/bundler_repo
git init
git config user.name git
git config user.email git@example.com
echo "my file" > file
touch Gemfile
git add file Gemfile
git commit -m "bundler project added"
CMD
`#{command}`
end

def destroy_test_repo
FileUtils.rm_rf 'test/files/bundler_repo'
end
end

0 comments on commit 7d0f987

Please sign in to comment.