spec/sandbox.rb in assaf-buildr-1.3.3 vs spec/sandbox.rb in assaf-buildr-1.3.4
- old
+ new
@@ -19,16 +19,17 @@
# repository and cache these across test cases.
Buildr.application.instance_eval { @rakefile = File.expand_path('buildfile') }
repositories.remote << 'http://repo1.maven.org/maven2'
repositories.remote << 'http://scala-tools.org/repo-releases'
+# Add a 'require' here only for optional extensions, not for extensions that should be loaded by default.
require 'buildr/groovy'
-require 'buildr/scala'
Java.load # Anything added to the classpath.
-task('buildr:scala:download').invoke
-artifacts(TestFramework.frameworks.map(&:dependencies).flatten, JUnit.ant_taskdef).each { |a| file(a).invoke }
+artifacts(TestFramework.frameworks.map(&:dependencies).flatten, JUnit.ant_taskdef).each do |path|
+ file(path).invoke
+end
ENV['HOME'] = File.expand_path('tmp/home')
# We need to run all tests inside a _sandbox, tacking a snapshot of Buildr before the test,
# and restoring everything to its previous state after the test. Damn state changes.
@@ -40,17 +41,17 @@
def included(spec)
spec.before(:each) { sandbox }
spec.after(:each) { reset }
end
- # Require an addon without letting its callbacks pollute the Project class.
- def require_addon addon_require_path
- project_callbacks_without_addon = Project.class_eval { @callbacks }.dup
+ # Require an optional extension without letting its callbacks pollute the Project class.
+ def require_optional_extension(extension_require_path)
+ project_callbacks_without_extension = Project.class_eval { @callbacks }.dup
begin
- require addon_require_path
+ require extension_require_path
ensure
- Project.class_eval { @callbacks = project_callbacks_without_addon }
+ Project.class_eval { @callbacks = project_callbacks_without_extension }
end
end
end
@tasks = Buildr.application.tasks.collect do |original|
@@ -70,21 +71,22 @@
# Create a temporary directory where we can create files, e.g,
# for projects, compilation. We need a place that does not depend
# on the current directory.
@_sandbox[:original_dir] = Dir.pwd
- temp = File.join(File.dirname(__FILE__), '../tmp')
- FileUtils.mkpath temp
- Dir.chdir temp
+ @temp = File.join(File.dirname(__FILE__), '../tmp')
+ FileUtils.mkpath @temp
+ Dir.chdir @temp
+ ARGV.clear
Buildr.application = Buildr::Application.new
Sandbox.tasks.each { |block| block.call }
Buildr.application.instance_variable_set :@rules, Sandbox.rules.clone
Buildr.application.instance_eval { @rakefile = File.expand_path('buildfile') }
@_sandbox[:load_path] = $LOAD_PATH.clone
- @_sandbox[:loaded_features] = $LOADED_FEATURES.clone
+ #@_sandbox[:loaded_features] = $LOADED_FEATURES.clone
# Later on we'll want to lose all the on_define created during the test.
@_sandbox[:on_define] = Project.class_eval { (@on_define || []).dup }
@_sandbox[:callbacks] = Project.class_eval { (@callbacks || []).dup }
@_sandbox[:layout] = Layout.default.clone
@@ -93,10 +95,11 @@
# of some essential artifacts (e.g. JUnit artifacts required by build task), so we create
# these first (see above) and keep them across test cases.
@_sandbox[:artifacts] = Artifact.class_eval { @artifacts }.clone
Buildr.repositories.local = File.expand_path('repository')
ENV['HOME'] = File.expand_path('home')
+ ENV['BUILDR_ENV'] = 'development'
@_sandbox[:env_keys] = ENV.keys
['DEBUG', 'TEST', 'HTTP_PROXY', 'USER'].each { |k| ENV.delete(k) ; ENV.delete(k.downcase) }
# Remove testing local repository, and reset all repository settings.
@@ -119,11 +122,10 @@
callbacks = @_sandbox[:callbacks]
Project.class_eval { @callbacks = callbacks }
Layout.default = @_sandbox[:layout].clone
$LOAD_PATH.replace @_sandbox[:load_path]
- $LOADED_FEATURES.replace @_sandbox[:loaded_features]
- FileUtils.rm_rf Dir.pwd
+ FileUtils.rm_rf @temp
# Get rid of all artifacts.
@_sandbox[:artifacts].tap { |artifacts| Artifact.class_eval { @artifacts = artifacts } }
# Restore options.