Class: WireMockMapper::RequestBuilder

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

Instance Method Summary collapse

Constructor Details

#initializeRequestBuilder

Returns a new instance of RequestBuilder.



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

def initialize
  @options = {}
end

Instance Method Details

#to_hashObject



74
75
76
77
# File 'lib/request_builder.rb', line 74

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

#to_jsonObject



79
80
81
# File 'lib/request_builder.rb', line 79

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:



24
25
26
27
# File 'lib/request_builder.rb', line 24

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



31
32
33
34
35
36
# File 'lib/request_builder.rb', line 31

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



41
42
43
44
# File 'lib/request_builder.rb', line 41

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



49
50
51
52
# File 'lib/request_builder.rb', line 49

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



57
58
59
60
# File 'lib/request_builder.rb', line 57

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

#with_urlUrlMatchBuilder

Expect url path with query params

Returns:



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

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

#with_url_pathUrlMatchBuilder

Expect url path only

Returns:



70
71
72
# File 'lib/request_builder.rb', line 70

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