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:


20
21
22
23
24
# File 'lib/alice/adapter/test.rb', line 20

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

Instance Method Details

#delete(path, &block) ⇒ Object


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

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

#empty?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/alice/adapter/test.rb', line 26

def empty?
  @stack.empty?
end

#get(path, &block) ⇒ Object


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

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

#head(path, &block) ⇒ Object


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

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

#match(request_method, path, body) ⇒ Object


30
31
32
33
34
# File 'lib/alice/adapter/test.rb', line 30

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

#new_stub(request_method, path, body = nil, &block) ⇒ Object


56
57
58
# File 'lib/alice/adapter/test.rb', line 56

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

#post(path, body, &block) ⇒ Object


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

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

#put(path, body, &block) ⇒ Object


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

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