Skip to content

Commit

Permalink
Merge pull request #48 from origin/gem-spec-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksieger committed Aug 3, 2017
2 parents 97e4a35 + fcd1d21 commit 2361f8f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/brew/gem/formula.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class RubyGemsDownloadStrategy < AbstractDownloadStrategy
def fetch
ohai "Fetching <%= name %> from gem source"
HOMEBREW_CACHE.cd do
ENV['GEM_SPEC_CACHE'] = "#{HOMEBREW_CACHE}/gem_spec_cache"
system "gem", "fetch", "<%= name %>", "--version", resource.version
end
end
Expand Down
18 changes: 12 additions & 6 deletions spec/brew/gem_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'fileutils'

RSpec.describe Brew::Gem, type: :aruba do
def brew_gem(command); run_complete "#{brew_gem_exe} #{command}"; end
Expand Down Expand Up @@ -44,23 +45,28 @@ def brew(command); run_complete "brew #{command}"; end
it { is_expected.to_not be_successfully_executed }
end

install_metadata = { integration: true }
install_metadata = { integration: true, exit_timeout: 30 }
install_metadata.update announce_stderr: true, announce_stdout: true if ENV['DEBUG']

context "install/uninstall", install_metadata do
def bundler_linked?; File.exists?("#{`brew --prefix`.chomp}/bin/bundle"); end
def bundler_linked?; File.exists?("#{brew('--prefix').output.chomp}/bin/bundle"); end

before :all do
fixture = :all
fixture = :each if ENV['DEBUG'] # So that Aruba announces all the before/after commands as well

before fixture do
# Ensure we download bundler fresh
FileUtils.rm_f Dir["#{brew('--cache').output.chomp}/bundler*.gem"]
if bundler_linked?
@bundler_pre_linked = true
raise "bundler already linked in homebrew; either unlink or re-run rspec with '--tag ~integration'"
end
expect(brew_gem("install bundler")).to be_successfully_executed
expect(brew("gem install bundler")).to be_successfully_executed
end

after :all do |example|
after fixture do |example|
unless @bundler_pre_linked
expect(brew_gem("uninstall bundler")).to be_successfully_executed
expect(brew("gem uninstall bundler")).to be_successfully_executed
expect(brew("list gem-bundler")).to_not be_successfully_executed
end
end
Expand Down
10 changes: 8 additions & 2 deletions spec/support/aruba.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ def brew_gem_exe
end

module CleanEnv
OUR_BREW_GEM_HOME = File.expand_path('../../..', __FILE__)
OUR_BREW_GEM_BIN = "#{OUR_BREW_GEM_HOME}/bin"

def run(*args)
clean_env = Bundler.clean_env
(ENV.keys - clean_env.keys).each {|k| delete_environment_variable k }
Expand All @@ -16,8 +19,11 @@ def run(*args)
delete_environment_variable "GEM_PATH"
delete_environment_variable "GEM_HOME"
path = ENV['PATH'].split(/:/)
# Remove .rvm/.rbenv stuff from PATH
set_environment_variable "PATH", path.reject {|x| x =~ %r{/.(rvm|rbenv)/} }.join(":")
# Remove .rvm/.rbenv/.bundle stuff from PATH
path = path.reject {|x| x =~ %r{/.(rvm|rbenv)/} || x =~ %r{#{OUR_BREW_GEM_HOME}/.bundle} }
# Ensure that `brew` finds our local `brew-gem` command by putting it first in the path
path.unshift OUR_BREW_GEM_BIN unless path.first == OUR_BREW_GEM_BIN
set_environment_variable "PATH", path.join(":")
super
end
end
Expand Down

0 comments on commit 2361f8f

Please sign in to comment.