Class: HttpStub::Server::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/http_stub/server/stub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Stub

Returns a new instance of Stub.



8
9
10
11
12
13
14
15
16
# File 'lib/http_stub/server/stub.rb', line 8

def initialize(args)
  @method      = args["method"]
  @uri         = HttpStub::Server::StubUri.new(args["uri"])
  @headers     = HttpStub::Server::StubHeaders.new(args["headers"])
  @parameters  = HttpStub::Server::StubParameters.new(args["parameters"])
  @response    = HttpStub::Server::StubResponse.create(args["response"])
  @triggers    = HttpStub::Server::StubTriggers.new(args["triggers"])
  @description = args.to_s
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/http_stub/server/stub.rb', line 6

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



6
7
8
# File 'lib/http_stub/server/stub.rb', line 6

def method
  @method
end

#parametersObject (readonly)

Returns the value of attribute parameters.



6
7
8
# File 'lib/http_stub/server/stub.rb', line 6

def parameters
  @parameters
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/http_stub/server/stub.rb', line 6

def response
  @response
end

#triggersObject (readonly)

Returns the value of attribute triggers.



6
7
8
# File 'lib/http_stub/server/stub.rb', line 6

def triggers
  @triggers
end

#uriObject (readonly)

Returns the value of attribute uri.



6
7
8
# File 'lib/http_stub/server/stub.rb', line 6

def uri
  @uri
end

Instance Method Details

#satisfies?(request) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/http_stub/server/stub.rb', line 18

def satisfies?(request)
  @uri.match?(request) &&
      @method.downcase == request.request_method.downcase &&
      @headers.match?(request) &&
      @parameters.match?(request)
end

#to_sObject



25
26
27
# File 'lib/http_stub/server/stub.rb', line 25

def to_s
  @description
end