Class: Capyspy::Spy

Inherits:
Object
  • Object
show all
Defined in:
lib/capyspy/spy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, method) ⇒ Spy

Returns a new instance of Spy.



5
6
7
8
9
10
# File 'lib/capyspy/spy.rb', line 5

def initialize(page, method)
  @page = page
  @method = method.to_s
  
  init
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



3
4
5
# File 'lib/capyspy/spy.rb', line 3

def method
  @method
end

#pageObject (readonly)

Returns the value of attribute page.



3
4
5
# File 'lib/capyspy/spy.rb', line 3

def page
  @page
end

Instance Method Details

#and_call_fake(function) ⇒ Object



22
23
24
25
# File 'lib/capyspy/spy.rb', line 22

def and_call_fake(function)
  with_spy 'callThrough = false', "fake = #{function}"
  self
end

#and_call_throughObject



12
13
14
15
# File 'lib/capyspy/spy.rb', line 12

def and_call_through
  with_spy 'callThrough = true'
  self
end

#and_return(value) ⇒ Object



17
18
19
20
# File 'lib/capyspy/spy.rb', line 17

def and_return(value)
  with_spy 'callThrough = false', "fake = function() { return #{value.to_json}; }"
  self
end

#callsObject



27
28
29
# File 'lib/capyspy/spy.rb', line 27

def calls
  with_spy 'calls'
end

#to_sObject



31
32
33
# File 'lib/capyspy/spy.rb', line 31

def to_s
  method
end