class Inferno::DSL::HTTPClientBuilder

This module contains the HTTP DSL available to test writers.

Attributes

runnable[RW]

Public Instance Methods

build(runnable, block) click to toggle source

@api private

# File lib/inferno/dsl/http_client_builder.rb, line 8
def build(runnable, block)
  self.runnable = runnable
  instance_exec(self, &block)

  params = { url: url }
  params.merge!(headers: headers) if headers

  Faraday.new(params)
end
headers(headers = nil) click to toggle source

Define custom headers for a client

@param headers [Hash] @return [void]

# File lib/inferno/dsl/http_client_builder.rb, line 37
def headers(headers = nil)
  @headers ||= headers
end
method_missing(name, *args, &block) click to toggle source

@api private

Calls superclass method
# File lib/inferno/dsl/http_client_builder.rb, line 42
def method_missing(name, *args, &block)
  return runnable.call(name, *args, &block) if runnable.respond_to? name

  super
end
respond_to_missing?(name) click to toggle source

@api private

Calls superclass method
# File lib/inferno/dsl/http_client_builder.rb, line 49
def respond_to_missing?(name)
  runnable.respond_to?(name) || super
end
url(url = nil) click to toggle source

Define the base url for an HTTP client. A string or symbol can be provided. A string is interpreted as a url. A symbol is interpreted as the name of an input to the Runnable.

@param url [String, Symbol] @return [void]

# File lib/inferno/dsl/http_client_builder.rb, line 24
def url(url = nil)
  @url ||=
    if url.is_a? Symbol
      runnable.send(url)
    else
      url
    end
end