Class: WireMockMapper::RequestBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(configuration = nil) ⇒ RequestBuilder

Returns a new instance of RequestBuilder.



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

def initialize(configuration = nil)
  @options = {}
  @options[:headers] = configuration.request_headers if configuration
end

Instance Method Details

#to_hashObject



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

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

#to_jsonObject



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

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:



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

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



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

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



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

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



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

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



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

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

#with_urlUrlMatchBuilder

Expect url path with query params

Returns:



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

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

#with_url_pathUrlMatchBuilder

Expect url path only

Returns:



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

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