Class: WireMockMapper::Builders::ResponseBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/builders/response_builder.rb

Instance Method Summary collapse

Constructor Details

#initializeResponseBuilder

Returns a new instance of ResponseBuilder.



4
5
6
# File 'lib/builders/response_builder.rb', line 4

def initialize
  @options = {}
end

Instance Method Details

#to_hashObject



60
61
62
# File 'lib/builders/response_builder.rb', line 60

def to_hash(*)
  @options
end

#to_jsonObject



64
65
66
# File 'lib/builders/response_builder.rb', line 64

def to_json(*)
  @options.to_json
end

#with_body(value) ⇒ ResponseBuilder

Response body

Parameters:

  • value (String)

    the value to set the response body to

Returns:



11
12
13
14
15
# File 'lib/builders/response_builder.rb', line 11

def with_body(value)
  value = value.to_json unless value.is_a? String
  @options[:body] = value
  self
end

#with_delay(milliseconds) ⇒ ResponseBuilder

Add a response delay

Parameters:

  • milliseconds (String, Numeric)

    the delay duration in milliseconds

Returns:



20
21
22
23
# File 'lib/builders/response_builder.rb', line 20

def with_delay(milliseconds)
  @options[:fixedDelayMilliseconds] = milliseconds
  self
end

#with_header(key, value) ⇒ ResponseBuilder

Add a response header

Parameters:

  • key (String)

    the key of the header

  • value (String)

    the value of the header

Returns:



29
30
31
32
33
# File 'lib/builders/response_builder.rb', line 29

def with_header(key, value)
  @options[:headers] ||= {}
  @options[:headers][key] = value
  self
end

#with_status(status_code) ⇒ ResponseBuilder

Add a response http status

Parameters:

  • status_code (String, Numeric)

    the status code to respond with

Returns:



38
39
40
41
# File 'lib/builders/response_builder.rb', line 38

def with_status(status_code)
  @options[:status] = status_code
  self
end

#with_status_message(status_message) ⇒ ResponseBuilder

Add a response http status

Parameters:

  • status_code (String)

    the status message to respond with

Returns:



46
47
48
49
# File 'lib/builders/response_builder.rb', line 46

def with_status_message(status_message)
  @options[:statusMessage] = status_message
  self
end

#with_transformer(transformer) ⇒ ResponseBuilder

Tell wiremock to use a transformer for the response

Parameters:

  • transformer

    name [String]

Returns:



54
55
56
57
58
# File 'lib/builders/response_builder.rb', line 54

def with_transformer(transformer)
  @options[:transformers] ||= []
  @options[:transformers] << transformer
  self
end