Class: FakeMechanize::ErrorRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/fake_mechanize/error_request.rb

Overview

ErrorRequest is like a traditionnal request, but implements features to match “error” cases : if you have an authentication process which auth user with only one login/password couple, you can define an ErrorRequest which will always match if parameters do not match your login/password. ErrorRequest also implements a match function which compute a matching value given another request.

Instance Attribute Summary collapse

Attributes inherited from Request

#body, #method, #parameters, #request_headers, #response_headers, #status, #uri

Instance Method Summary collapse

Methods inherited from Request

#==

Constructor Details

#initialize(args = {}) ⇒ ErrorRequest

Initialize an ErrorRequest. args takes all Request options and an additionnal :params_not_equal option to define a hash of parameters that should not match.



13
14
15
16
# File 'lib/fake_mechanize/error_request.rb', line 13

def initialize(args = {})
  super
  @params_not_equal = args[:params_not_equal]
end

Instance Attribute Details

#params_not_equalObject (readonly)

List of non matching parameters



8
9
10
# File 'lib/fake_mechanize/error_request.rb', line 8

def params_not_equal
  @params_not_equal
end

Instance Method Details

#match(alt) ⇒ Object

Compute a match between alt and current instance, returning an integer. Computation is based on http method, uri and request_headers. The idea behind this match rate is to find the best ErrorRequest matching a query.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fake_mechanize/error_request.rb', line 21

def match(alt)
  count = 0

  # Simple calculations
  count += 1 if method  == alt.method
  count += 1 if uri     == alt.uri

  # More complicated: evaluates if params are equals or if they are different on purpose
  # TODO : handle headers
  if !parameters.empty? and parameters == alt.parameters
    count += 1
  elsif method == alt.method and uri == alt.uri and parameters != params_not_equal
    count += 1
  end

  count
end