Sha256: 2a350a12cd1401bd2ab88b5adfd3327e46e242c29d050fae18a399fc02dc564e
Contents?: true
Size: 1.42 KB
Versions: 14
Compression:
Stored size: 1.42 KB
Contents
module Typhoeus class Hydra module Stubbing module SharedMethods def stub(method, url, options = {}) stubs << HydraMock.new(url, method, options) stubs.last end def clear_stubs self.stubs = [] end def register_stub_finder(&block) stub_finders << block end 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 def stub_finders @stub_finders ||= [] end def self.extended(base) class << base attr_accessor :stubs end base.stubs = [] end end def self.included(base) base.extend(SharedMethods) base.class_eval do attr_accessor :stubs end end def assign_to_stub(request) m = find_stub_from_request(request) # Fallback to global stubs. m ||= self.class.find_stub_from_request(request) if m m.add_request(request) @active_stubs << m m else nil end end private :assign_to_stub include SharedMethods end end end
Version data entries
14 entries across 14 versions & 4 rubygems