Class: EventMachine::MockHttpRequest

Inherits:
HttpRequest show all
Includes:
HttpEncoding
Defined in:
lib/em-http/mock.rb

Defined Under Namespace

Classes: FakeHttpClient

Constant Summary collapse

@@registry =
nil
@@registry_count =
nil
@@pass_through_requests =
true

Instance Attribute Summary

Attributes inherited from HttpRequest

#method, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HttpRequest

#delete, #get, #head, #initialize, #post, #put

Constructor Details

This class inherits a constructor from EventMachine::HttpRequest

Class Method Details

.count(uri, method, headers) ⇒ Object



57
58
59
60
61
# File 'lib/em-http/mock.rb', line 57

def self.count(uri, method, headers)
  method = method.to_s.upcase
  headers = headers.to_s
  @@registry_count[uri][method][headers] rescue 0
end

.increment_access(query, method, headers) ⇒ Object



71
72
73
# File 'lib/em-http/mock.rb', line 71

def self.increment_access(query, method, headers)
  @@registry_count[query][method][headers] += 1
end

.pass_through_requestsObject



43
44
45
# File 'lib/em-http/mock.rb', line 43

def self.pass_through_requests
  @@pass_through_requests
end

.pass_through_requests=(pass_through_requests) ⇒ Object



39
40
41
# File 'lib/em-http/mock.rb', line 39

def self.pass_through_requests=(pass_through_requests)
  @@pass_through_requests = pass_through_requests
end

.register(uri, method, headers, data) ⇒ Object



47
48
49
50
51
# File 'lib/em-http/mock.rb', line 47

def self.register(uri, method, headers, data)
  method = method.to_s.upcase
  headers = headers.to_s
  @@registry[uri][method][headers] = data
end

.register_file(uri, method, headers, file) ⇒ Object



53
54
55
# File 'lib/em-http/mock.rb', line 53

def self.register_file(uri, method, headers, file)
  register(uri, method, headers, File.read(file))
end

.registered?(query, method, headers) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/em-http/mock.rb', line 63

def self.registered?(query, method, headers)
  @@registry[query] and @@registry[query][method] and @@registry[query][method][headers]
end

.registered_content(query, method, headers) ⇒ Object



67
68
69
# File 'lib/em-http/mock.rb', line 67

def self.registered_content(query, method, headers)
  @@registry[query][method][headers]
end

.reset_counts!Object



22
23
24
25
26
# File 'lib/em-http/mock.rb', line 22

def self.reset_counts!
  @@registry_count = Hash.new do |registry,query| 
    registry[query] = Hash.new{|h,k| h[k] = Hash.new(0)}
  end
end

.reset_registry!Object



28
29
30
31
32
# File 'lib/em-http/mock.rb', line 28

def self.reset_registry!
  @@registry = Hash.new do |registry,query| 
    registry[query] = Hash.new{|h,k| h[k] = {}}
  end
end

Instance Method Details

#real_send_requestObject



75
# File 'lib/em-http/mock.rb', line 75

alias_method :real_send_request, :send_request