Class: Grasshopper::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/grasshopper/stub.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStub

Returns a new instance of Stub.



3
4
5
# File 'lib/grasshopper/stub.rb', line 3

def initialize
  @stubs = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



15
16
17
18
19
# File 'lib/grasshopper/stub.rb', line 15

def method_missing(sym, *args)
  @@stub = self
  @@message = [sym, args]
  @stubs[[sym, args]]
end

Class Method Details

.like(stubs) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/grasshopper/stub.rb', line 21

def self.like(stubs)
  stub = Stub.new
  stubs.each do |method, retval|
    Stub.when(stub.send(method)).then_return(retval)
  end
  stub
end

.when(whatever) ⇒ Object



11
12
13
# File 'lib/grasshopper/stub.rb', line 11

def self.when(whatever)
  StubHelper.new(@@stub, @@message)
end

Instance Method Details

#add_a_stub(message, retval) ⇒ Object



7
8
9
# File 'lib/grasshopper/stub.rb', line 7

def add_a_stub(message, retval)
  @stubs[message] = retval
end