New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute proc in the context of the instance #2

Merged
merged 1 commit into from Jan 20, 2015
Jump to file or symbol
Failed to load files and symbols.
+9 −1
Diff settings

Always

Just for now

@@ -7,7 +7,7 @@ def self.stub_any_instance name, val_or_callable, &block
define_method(name) do |*args|
if val_or_callable.respond_to? :call then
val_or_callable.call(*args)
instance_exec(*args, &val_or_callable)
else
val_or_callable
end
@@ -33,4 +33,12 @@ def test_does_not_raise_warnings
assert_empty $stderr.string
assert got_here
end
def test_proc_has_access_to_self
twice_size = -> { self.size * 2 }
String.stub_any_instance(:length, twice_size) do
assert_equal 6, 'abc'.length
end
end
end
ProTip! Use n and p to navigate between commits in a pull request.