Module: RBS::Test::Spy

Defined in:
lib/rbs/test/spy.rb

Defined Under Namespace

Classes: InstanceSpy, SingletonSpy, WrapSpy

Class Method Summary collapse

Class Method Details

.instance_method(mod, method_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rbs/test/spy.rb', line 19

def self.instance_method(mod, method_name)
  spy = InstanceSpy.new(mod: mod, method_name: method_name)

  if block_given?
    begin
      spy.setup
      yield spy
    ensure
      spy.reset
    end
  else
    spy
  end
end

.singleton_method(object, method_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rbs/test/spy.rb', line 4

def self.singleton_method(object, method_name)
  spy = SingletonSpy.new(object: object, method_name: method_name)

  if block_given?
    begin
      spy.setup
      yield spy
    ensure
      spy.reset
    end
  else
    spy
  end
end

.wrap(object, method_name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rbs/test/spy.rb', line 34

def self.wrap(object, method_name)
  spy = WrapSpy.new(object: object, method_name: method_name)

  if block_given?
    begin
      yield spy, spy.wrapped_object
    end
  else
    spy
  end
end