aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authorJack Nagel2013-01-19 20:45:58 -0600
committerJack Nagel2013-01-21 17:24:11 -0600
commit2503cedf2c9ebb7e15029f126518f42ff0e5ee1c (patch)
treefb597e1412d419598001f9d5716def2fc681a37a /Library/Homebrew/test
parentc53af4211704c9f08366de5eb22251e5ffb4bdd5 (diff)
downloadbrew-2503cedf2c9ebb7e15029f126518f42ff0e5ee1c.tar.bz2
Object#instance_exec for Ruby 1.8.6
Not thread safe! But I don't think we care. We want to evaluate the env DSL block in the context of ENV for asthetic reasons, but we also want access to methods on the requirement instance. We can use #instance_exec to pass the requirement itself into the block: class Foo < Requirement env do |req| append 'PATH', req.some_path end def some_path which 'something' end end Also add a simplified version of Object#instance_exec for Ruby 1.8.6.
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/test_build_environment.rb14
-rw-r--r--Library/Homebrew/test/test_object.rb20
2 files changed, 34 insertions, 0 deletions
diff --git a/Library/Homebrew/test/test_build_environment.rb b/Library/Homebrew/test/test_build_environment.rb
index d8a227f51..6710662b5 100644
--- a/Library/Homebrew/test/test_build_environment.rb
+++ b/Library/Homebrew/test/test_build_environment.rb
@@ -31,6 +31,20 @@ class BuildEnvironmentTests < Test::Unit::TestCase
dump = Marshal.dump(@env)
assert Marshal.load(dump).userpaths?
end
+
+ def test_env_block
+ foo = mock("foo")
+ @env << Proc.new { foo.some_message }
+ foo.expects(:some_message)
+ @env.modify_build_environment
+ end
+
+ def test_env_block_with_argument
+ foo = mock("foo")
+ @env << Proc.new { |x| x.some_message }
+ foo.expects(:some_message)
+ @env.modify_build_environment(foo)
+ end
end
class BuildEnvironmentDSLTests < Test::Unit::TestCase
diff --git a/Library/Homebrew/test/test_object.rb b/Library/Homebrew/test/test_object.rb
new file mode 100644
index 000000000..debdd6c42
--- /dev/null
+++ b/Library/Homebrew/test/test_object.rb
@@ -0,0 +1,20 @@
+require 'testing_env'
+require 'extend/object'
+
+class InstanceExecTests < Test::Unit::TestCase
+ def test_evaluates_in_context_of_receiver
+ assert_equal 1, [1].instance_exec { first }
+ end
+
+ def test_passes_arguments_to_block
+ assert_equal 2, [1].instance_exec(1) { |x| first + x }
+ end
+
+ def test_does_not_persist_temporary_singleton_method
+ obj = Object.new
+ before = obj.methods
+ obj.instance_exec { methods }
+ after = obj.methods
+ assert_equal before, after
+ end
+end