Class: Faraday::Adapter::Test::Stub
- Inherits:
- 
      Struct
      
        - Object
- Struct
- Faraday::Adapter::Test::Stub
 
- Defined in:
- lib/faraday/adapter/test.rb
Overview
Stub request
Instance Attribute Summary collapse
- 
  
    
      #block  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute block. 
- 
  
    
      #body  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute body. 
- 
  
    
      #headers  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute headers. 
- 
  
    
      #host  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute host. 
- 
  
    
      #path  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute path. 
- 
  
    
      #query  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute query. 
- 
  
    
      #strict_mode  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute strict_mode. 
Instance Method Summary collapse
- #body_match?(request_body) ⇒ Boolean
- #headers_match?(request_headers) ⇒ Boolean
- #matches?(env) ⇒ Boolean
- #params_match?(env) ⇒ Boolean
- #path_match?(request_path, meta) ⇒ Boolean
- #to_s ⇒ Object
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
| 187 188 189 | # File 'lib/faraday/adapter/test.rb', line 187 def block @block end | 
#body ⇒ Object
Returns the value of attribute body
| 187 188 189 | # File 'lib/faraday/adapter/test.rb', line 187 def body @body end | 
#headers ⇒ Object
Returns the value of attribute headers
| 187 188 189 | # File 'lib/faraday/adapter/test.rb', line 187 def headers @headers end | 
#host ⇒ Object
Returns the value of attribute host
| 187 188 189 | # File 'lib/faraday/adapter/test.rb', line 187 def host @host end | 
#path ⇒ Object
Returns the value of attribute path
| 187 188 189 | # File 'lib/faraday/adapter/test.rb', line 187 def path @path end | 
#query ⇒ Object
Returns the value of attribute query
| 187 188 189 | # File 'lib/faraday/adapter/test.rb', line 187 def query @query end | 
#strict_mode ⇒ Object
Returns the value of attribute strict_mode
| 187 188 189 | # File 'lib/faraday/adapter/test.rb', line 187 def strict_mode @strict_mode end | 
Instance Method Details
#body_match?(request_body) ⇒ Boolean
| 242 243 244 245 246 247 248 249 250 251 | # File 'lib/faraday/adapter/test.rb', line 242 def body_match?(request_body) return true if body.to_s.empty? case body when Proc body.call(request_body) else request_body == body end end | 
#headers_match?(request_headers) ⇒ Boolean
| 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | # File 'lib/faraday/adapter/test.rb', line 227 def headers_match?(request_headers) if strict_mode headers_with_user_agent = headers.dup.tap do |hs| # NOTE: Set User-Agent in case it's not set when creating Stubs. # Users would not want to set Faraday's User-Agent explicitly. hs[:user_agent] ||= Connection::USER_AGENT end return Set.new(headers_with_user_agent) == Set.new(request_headers) end headers.keys.all? do |key| request_headers[key] == headers[key] end end | 
#matches?(env) ⇒ Boolean
| 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | # File 'lib/faraday/adapter/test.rb', line 189 def matches?(env) request_host = env[:url].host request_path = Faraday::Utils.normalize_path(env[:url].path) request_headers = env.request_headers request_body = env[:body] # meta is a hash used as carrier # that will be yielded to consumer block = {} [(host.nil? || host == request_host) && path_match?(request_path, ) && params_match?(env) && body_match?(request_body) && headers_match?(request_headers), ] end | 
#params_match?(env) ⇒ Boolean
| 214 215 216 217 218 219 220 221 222 223 224 225 | # File 'lib/faraday/adapter/test.rb', line 214 def params_match?(env) request_params = env[:params] params = env.params_encoder.decode(query) || {} if strict_mode return Set.new(params) == Set.new(request_params) end params.keys.all? do |key| request_params[key] == params[key] end end | 
#path_match?(request_path, meta) ⇒ Boolean
| 205 206 207 208 209 210 211 | # File 'lib/faraday/adapter/test.rb', line 205 def path_match?(request_path, ) if path.is_a?(Regexp) !!([:match_data] = path.match(request_path)) else path == request_path end end | 
#to_s ⇒ Object
| 253 254 255 | # File 'lib/faraday/adapter/test.rb', line 253 def to_s "#{path} #{body}" end |