Class: Object

Inherits:
BasicObject
Includes:
InstanceExecHelper, Spec::Expectations::ObjectExpectations, Spec::Mocks::Methods
Defined in:
lib/spec/matchers/extensions/instance_exec.rb,
lib/spec/mocks/extensions/object.rb,
lib/spec/expectations/extensions/object.rb

Overview

based on Bounded Spec InstanceExec (Mauricio Fernandez) eigenclass.org/hiki/bounded+space+instance_exec

Defined Under Namespace

Modules: InstanceExecHelper

Instance Method Summary collapse

Methods included from Spec::Expectations::ObjectExpectations

#should, #should_not

Methods included from Spec::Mocks::Methods

#as_null_object, #null_object?, #received_message?, #rspec_reset, #rspec_verify, #should_not_receive, #should_receive, #stub!

Instance Method Details

#instance_exec(*args, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/spec/matchers/extensions/instance_exec.rb', line 9

def instance_exec(*args, &block)
  begin
    orig_critical, Thread.critical = Thread.critical, true
    n = 0
    n += 1 while respond_to?(method_name="__instance_exec#{n}")
    InstanceExecHelper.module_eval{ define_method(method_name, &block) }
  ensure
    Thread.critical = orig_critical
  end
  begin
    return send(method_name, *args)
  ensure
    InstanceExecHelper.module_eval{ remove_method(method_name) } rescue nil
  end
end