Module: Typhoeus::Hydra::Stubbing::SharedMethods

Included in:
Typhoeus::Hydra::Stubbing
Defined in:
lib/typhoeus/hydra/stubbing.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



34
35
36
37
38
39
# File 'lib/typhoeus/hydra/stubbing.rb', line 34

def self.extended(base)
  class << base
    attr_accessor :stubs
  end
  base.stubs = []
end

Instance Method Details

#clear_stubsObject



10
11
12
# File 'lib/typhoeus/hydra/stubbing.rb', line 10

def clear_stubs
  self.stubs = []
end

#find_stub_from_request(request) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/typhoeus/hydra/stubbing.rb', line 18

def find_stub_from_request(request)
  stub_finders.each do |finder|
    if response = finder.call(request)
      mock = HydraMock.new(/.*/, :any)
      mock.and_return(response)
      return mock
    end
  end

  stubs.detect { |stub| stub.matches?(request) }
end

#register_stub_finder(&block) ⇒ Object



14
15
16
# File 'lib/typhoeus/hydra/stubbing.rb', line 14

def register_stub_finder(&block)
  stub_finders << block
end

#stub(method, url, options = {}) ⇒ Object



5
6
7
8
# File 'lib/typhoeus/hydra/stubbing.rb', line 5

def stub(method, url, options = {})
  stubs << HydraMock.new(url, method, options)
  stubs.last
end

#stub_findersObject



30
31
32
# File 'lib/typhoeus/hydra/stubbing.rb', line 30

def stub_finders
  @stub_finders ||= []
end