Permalink
Browse files

Remove InEnvironment from TestRakeApplication

  • Loading branch information...
1 parent feb1afd commit 98e8772db9f0a1db21f12101d033c811d03a0a78 @drbrain drbrain committed Jun 22, 2011
Showing with 228 additions and 114 deletions.
  1. +8 −3 lib/rake/application.rb
  2. +74 −0 test/helper.rb
  3. +146 −111 test/test_rake_application.rb
View
@@ -22,6 +22,9 @@ class Application
# Name of the actual rakefile used.
attr_reader :rakefile
+ # Number of columns on the terminal
+ attr_accessor :terminal_columns
+
# List of the top level task names (task names from the command line).
attr_reader :top_level_tasks
@@ -43,6 +46,7 @@ def initialize
add_loader('rf', DefaultLoader.new)
add_loader('rake', DefaultLoader.new)
@tty_output = STDOUT.tty?
+ @terminal_columns = ENV['RAKE_COLUMNS'].to_i
end
# Run the Rake application. The run method performs the following
@@ -198,7 +202,7 @@ def tty_output=( tty_output_state )
# We will truncate output if we are outputting to a TTY or if we've been
# given an explicit column width to honor
def truncate_output?
- tty_output? || ENV['RAKE_COLUMNS']
+ tty_output? || @terminal_columns.nonzero?
end
# Display the tasks and comments.
@@ -210,6 +214,7 @@ def display_tasks_and_comments
when :tasks
width = displayable_tasks.collect { |t| t.name_with_args.length }.max || 10
max_column = truncate_output? ? terminal_width - name.size - width - 7 : nil
+
displayable_tasks.each do |t|
printf "#{name} %-#{width}s # %s\n",
t.name_with_args, max_column ? truncate(t.comment, max_column) : t.comment
@@ -234,8 +239,8 @@ def display_tasks_and_comments
end
def terminal_width
- if ENV['RAKE_COLUMNS']
- result = ENV['RAKE_COLUMNS'].to_i
+ if @terminal_columns.nonzero?
+ result = @terminal_columns
else
result = unix? ? dynamic_width : 80
end
View
@@ -3,6 +3,7 @@
require 'flexmock/test_unit_integration'
require 'minitest/autorun'
require 'rake'
+require 'tmpdir'
require File.expand_path('../file_creation', __FILE__)
require File.expand_path('../in_environment', __FILE__)
@@ -20,13 +21,28 @@ class TaskManager
end
def setup
+ ARGV.clear
+
@orig_PWD = Dir.pwd
+ @orig_RAKE_SYSTEM = ENV['RAKE_SYSTEM']
+
+ tmpdir = Dir.chdir Dir.tmpdir do Dir.pwd end
+ @tempdir = File.join tmpdir, "test_rake_#{$$}"
+
+ FileUtils.mkdir_p @tempdir
end
def teardown
flexmock_teardown
Dir.chdir @orig_PWD
+ FileUtils.rm_rf @tempdir
+
+ if @orig_RAKE_SYSTEM then
+ ENV['RAKE_SYSTEM'] = @orig_RAKE_SYSTEM
+ else
+ ENV.delete 'RAKE_SYSTEM'
+ end
end
def ignore_deprecations
@@ -36,6 +52,64 @@ def ignore_deprecations
Rake.application.options.ignore_deprecate = false
end
+ def rake_system
+ @system_dir = File.join @tempdir, 'system'
+
+ FileUtils.mkdir_p @system_dir
+
+ open File.join(@system_dir, 'sys1.rake'), 'w' do |io|
+ io << <<-SYS
+task "sys1" do
+ puts "SYS1"
+end
+ SYS
+ end
+
+ ENV['RAKE_SYSTEM'] = @system_dir
+
+ Dir.chdir @tempdir
+ end
+
+ def rakefile contents
+ open File.join(@tempdir, 'Rakefile'), 'w' do |io|
+ io << contents
+ end
+
+ Dir.chdir @tempdir
+ end
+
+ def rakefile_default
+ rakefile <<-DEFAULT
+if ENV['TESTTOPSCOPE']
+ puts "TOPSCOPE"
+end
+
+task :default do
+ puts "DEFAULT"
+end
+
+task :other => [:default] do
+ puts "OTHER"
+end
+
+task :task_scope do
+ if ENV['TESTTASKSCOPE']
+ puts "TASKSCOPE"
+ end
+end
+ DEFAULT
+ end
+
+ def rakefile_unittest
+ rakefile '# Empty Rakefile for Unit Test'
+
+ subdir = File.join @tempdir, 'subdir'
+ FileUtils.mkdir_p subdir
+
+ readme = File.join subdir, 'README'
+ FileUtils.touch readme
+ end
+
end
# workarounds for 1.8
Oops, something went wrong.

0 comments on commit 98e8772

Please sign in to comment.