Class: Alice::Adapter::Test::Stubs

Inherits:
Object
  • Object
show all
Defined in:
lib/alice/adapter/test.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Stubs

Returns a new instance of Stubs.

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
# File 'lib/alice/adapter/test.rb', line 18

def initialize
  # {:get => [Stub, Stub]}
  @stack = {}
  yield self if block_given?
end

Instance Method Details

#delete(path, &block) ⇒ Object



49
50
51
# File 'lib/alice/adapter/test.rb', line 49

def delete(path, &block)
  new_stub(:delete, path, block)
end

#empty?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/alice/adapter/test.rb', line 24

def empty?
  @stack.empty?
end

#get(path, &block) ⇒ Object



33
34
35
# File 'lib/alice/adapter/test.rb', line 33

def get(path, &block)
  new_stub(:get, path, block)
end

#head(path, &block) ⇒ Object



37
38
39
# File 'lib/alice/adapter/test.rb', line 37

def head(path, &block)
  new_stub(:head, path, block)
end

#match(request_method, path) ⇒ Object



28
29
30
31
# File 'lib/alice/adapter/test.rb', line 28

def match(request_method, path)
  return false if !@stack.key?(request_method)
  @stack[request_method].detect { |stub| stub.matches?(path) }
end

#new_stub(request_method, path, block) ⇒ Object



53
54
55
# File 'lib/alice/adapter/test.rb', line 53

def new_stub(request_method, path, block)
  (@stack[request_method] ||= []) << Stub.new(path, block)
end

#post(path, &block) ⇒ Object



41
42
43
# File 'lib/alice/adapter/test.rb', line 41

def post(path, &block)
  new_stub(:post, path, block)
end

#put(path, &block) ⇒ Object



45
46
47
# File 'lib/alice/adapter/test.rb', line 45

def put(path, &block)
  new_stub(:put, path, block)
end