Class: WireMockMapper::Builders::RequestBuilder

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

Instance Method Summary collapse

Constructor Details

#initializeRequestBuilder

Returns a new instance of RequestBuilder.



7
8
9
# File 'lib/builders/request_builder.rb', line 7

def initialize
  @options = {}
end

Instance Method Details

#is_a_anyRequestBuilder

Sets the request HTTP method to ANY

Returns:



# File 'lib/builders/request_builder.rb', line 11

#is_a_deleteRequestBuilder

Sets the request HTTP method to DELETE

Returns:



# File 'lib/builders/request_builder.rb', line 16

#is_a_getRequestBuilder

Sets the request HTTP method to GET

Returns:



# File 'lib/builders/request_builder.rb', line 21

#is_a_headRequestBuilder

Sets the request HTTP method to HEAD

Returns:



# File 'lib/builders/request_builder.rb', line 26

#is_a_optionsRequestBuilder

Sets the request HTTP method to OPTIONS

Returns:



# File 'lib/builders/request_builder.rb', line 31

#is_a_postRequestBuilder

Sets the request HTTP method to POST

Returns:



# File 'lib/builders/request_builder.rb', line 36

#is_a_putRequestBuilder

Sets the request HTTP method to PUT

Returns:



# File 'lib/builders/request_builder.rb', line 41

#is_a_traceRequestBuilder

Sets the request HTTP method to TRACE

Returns:



50
# File 'lib/builders/request_builder.rb', line 50

HTTP_VERBS = %w[ANY DELETE GET HEAD OPTIONS POST PUT TRACE].freeze

#to_hashObject



114
115
116
117
# File 'lib/builders/request_builder.rb', line 114

def to_hash(*)
  options_with_url_match = @options.merge(@url_match.to_hash) if @url_match
  options_with_url_match || @options
end

#to_jsonObject



119
120
121
# File 'lib/builders/request_builder.rb', line 119

def to_json(*)
  to_hash.to_json
end

#with_basic_auth(username, password) ⇒ RequestBuilder

Expect basic auth

Parameters:

  • username (String)

    username to expect

  • password (String)

    password to expect

Returns:



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

def with_basic_auth(username, password)
  @options[:basicAuth] = { username: username, password: password }
  self
end

#with_bodyMatchBuilder

Expect body

Returns:

  • (MatchBuilder)

    match builder to declare the match on the body



71
72
73
74
75
76
# File 'lib/builders/request_builder.rb', line 71

def with_body
  @options[:bodyPatterns] ||= []
  match_builder = MatchBuilder.new(self)
  @options[:bodyPatterns] << match_builder
  match_builder
end

Expect cookie

Parameters:

  • key (String)

    the cookie key

Returns:

  • (MatchBuilder)

    match builder to declare the match on the cookie



81
82
83
84
# File 'lib/builders/request_builder.rb', line 81

def with_cookie(key)
  @options[:cookies] ||= {}
  @options[:cookies][key] = MatchBuilder.new(self)
end

#with_header(key) ⇒ MatchBuilder

Expect header

Parameters:

  • key (String)

    the header key

Returns:

  • (MatchBuilder)

    match builder to declare the match on the header



89
90
91
92
# File 'lib/builders/request_builder.rb', line 89

def with_header(key)
  @options[:headers] ||= {}
  @options[:headers][key] = MatchBuilder.new(self)
end

#with_query_param(key) ⇒ MatchBuilder

Expect query param

Parameters:

  • key (String)

    the query param key

Returns:

  • (MatchBuilder)

    match builder to declare the match on the query param



97
98
99
100
# File 'lib/builders/request_builder.rb', line 97

def with_query_param(key)
  @options[:queryParameters] ||= {}
  @options[:queryParameters][key] = MatchBuilder.new(self)
end

#with_urlUrlMatchBuilder

Expect url path with query params

Returns:



104
105
106
# File 'lib/builders/request_builder.rb', line 104

def with_url
  @url_match = UrlMatchBuilder.new(self)
end

#with_url_pathUrlMatchBuilder

Expect url path only

Returns:



110
111
112
# File 'lib/builders/request_builder.rb', line 110

def with_url_path
  @url_match = UrlMatchBuilder.new(self, true)
end