Skip to content

Commit

Permalink
Remove dependency on a working rake to run the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Jun 1, 2011
1 parent 107e801 commit 7382dc8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
18 changes: 6 additions & 12 deletions lib/rubygems/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -777,12 +777,13 @@ def process_based_port
##
# Allows the proper version of +rake+ to be used for the test.

def build_rake_in
def build_rake_in(good=true)
gem_ruby = Gem.ruby
Gem.ruby = @@ruby
env_rake = ENV["rake"]
ENV["rake"] = @@rake
yield @@rake
rake = (good ? @@good_rake : @@bad_rake)
ENV["rake"] = rake
yield rake
ensure
Gem.ruby = gem_ruby
if env_rake
Expand Down Expand Up @@ -822,15 +823,8 @@ def self.rubybin
end

@@ruby = rubybin
env_rake = ENV['rake']
ruby19_rake = File.expand_path("bin/rake", @@project_dir)
@@rake = if env_rake then
ENV["rake"]
elsif File.exist? ruby19_rake then
@@ruby + " " + ruby19_rake
else
'rake'
end
@@good_rake = "#{rubybin} #{File.expand_path('../../../test/rubygems/good_rake.rb', __FILE__)}"
@@bad_rake = "#{rubybin} #{File.expand_path('../../../test/rubygems/bad_rake.rb', __FILE__)}"

##
# Construct a new Gem::Dependency.
Expand Down
1 change: 1 addition & 0 deletions test/rubygems/bad_rake.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit 1
1 change: 1 addition & 0 deletions test/rubygems/good_rake.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit 0
26 changes: 13 additions & 13 deletions test/rubygems/test_gem_ext_rake_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ def test_class_build
output = []
realdir = nil # HACK /tmp vs. /private/tmp

build_rake_in do
build_rake_in do |rake|
Dir.chdir @ext do
realdir = Dir.pwd
Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', nil, @dest_path, output
end
end

output = output.join "\n"
output = output.join "\n"

refute_match %r%^rake failed:%, output
assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, output
assert_match %r%^#{Regexp.escape @@rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, output
refute_match %r%^rake failed:%, output
assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, output
assert_match %r%^#{Regexp.escape rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, output
end
end

def test_class_build_fail
Expand All @@ -44,22 +44,22 @@ def test_class_build_fail
File.open("Rakefile","w") do |f|
f.puts "task :default do abort 'fail' end"
end
EO_MKRF
EO_MKRF
end

output = []

error = assert_raises Gem::InstallError do
build_rake_in do
build_rake_in(false) do |rake|
error = assert_raises Gem::InstallError do
Dir.chdir @ext do
Gem::Ext::RakeBuilder.build "mkrf_conf.rb", nil, @dest_path, output
end
end
end

assert_match %r%^rake failed:%, error.message
assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, error.message
assert_match %r%^#{Regexp.escape @@rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, error.message
assert_match %r%^rake failed:%, error.message
assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, error.message
assert_match %r%^#{Regexp.escape rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, error.message
end
end

end
Expand Down

0 comments on commit 7382dc8

Please sign in to comment.