Class: WireMockMapper::Builders::MatchBuilder

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

Instance Method Summary collapse

Constructor Details

#initialize(request_builder) ⇒ MatchBuilder

Returns a new instance of MatchBuilder.



6
7
8
9
10
11
# File 'lib/builders/match_builder.rb', line 6

def initialize(request_builder)
  @request_builder = request_builder
  @type = ''
  @value = ''
  @options = {}
end

Instance Method Details

#absentRequestBuilder

Match if attribute is absent

Returns:

  • (RequestBuilder)

    calling request builder for chaining additional attributes



15
16
17
18
19
# File 'lib/builders/match_builder.rb', line 15

def absent
  @type = :absent
  @value = true
  @request_builder
end

#containing(value) ⇒ RequestBuilder

Match if attribute value contains the arg

Parameters:

  • value (String)

    string to match

Returns:

  • (RequestBuilder)

    calling request builder for chaining additional attributes



24
25
26
27
28
# File 'lib/builders/match_builder.rb', line 24

def containing(value)
  @type = :contains
  @value = value
  @request_builder
end

#equal_to(value) ⇒ RequestBuilder

Match if attribute value is equal to the arg

Parameters:

  • value (String)

    string to compare against

Returns:

  • (RequestBuilder)

    calling request builder for chaining additional attributes



33
34
35
36
37
# File 'lib/builders/match_builder.rb', line 33

def equal_to(value)
  @type = :equalTo
  @value = value
  @request_builder
end

#equal_to_json(json, ignore_array_order = false, ignore_extra_elements = false) ⇒ RequestBuilder

Match if attribute json is equal to the arg

Parameters:

  • json (String, Hash)

    json to compare against

  • ignore_array_order (true, false) (defaults to: false)

    flag to ignore the order of arrays

  • ignore_extra_elements (true, false) (defaults to: false)

    flag to ignore any extra elements

Returns:

  • (RequestBuilder)

    calling request builder for chaining additional attributes



44
45
46
47
48
49
50
51
52
# File 'lib/builders/match_builder.rb', line 44

def equal_to_json(json, ignore_array_order = false, ignore_extra_elements = false)
  @type = :equalToJson
  @value = json

  @options[:ignoreArrayOrder] = true if ignore_array_order
  @options[:ignoreExtraElements] = true if ignore_extra_elements

  @request_builder
end

#equal_to_xml(xml) ⇒ RequestBuilder

Match if attribute xml is equal to the arg

Parameters:

  • xml (String)

    xml to compare against

Returns:

  • (RequestBuilder)

    calling request builder for chaining additional attributes



57
58
59
60
61
# File 'lib/builders/match_builder.rb', line 57

def equal_to_xml(xml)
  @type = :equalToXml
  @value = xml
  @request_builder
end

#matching(regexp) ⇒ RequestBuilder

Match if attribute value matches the regexp

Parameters:

  • regexp (String, Regexp)

    regexp to match against

Returns:

  • (RequestBuilder)

    calling request builder for chaining additional attributes



66
67
68
69
70
71
# File 'lib/builders/match_builder.rb', line 66

def matching(regexp)
  regexp = Helpers.regexp_to_string regexp if regexp.is_a? Regexp
  @type = :matches
  @value = regexp
  @request_builder
end

#matching_json_path(json_path) ⇒ RequestBuilder

Match if attribute json matches the json_path

Parameters:

  • json_path (String)

    json_path to match against

Returns:

  • (RequestBuilder)

    calling request builder for chaining additional attributes



76
77
78
79
80
# File 'lib/builders/match_builder.rb', line 76

def matching_json_path(json_path)
  @type = :matchesJsonPath
  @value = json_path
  @request_builder
end

#matching_xpath(xpath) ⇒ RequestBuilder

Match if attribute xml matches the xpath

Parameters:

  • xpath (String)

    xpath to match against

Returns:

  • (RequestBuilder)

    calling request builder for chaining additional attributes



85
86
87
88
89
# File 'lib/builders/match_builder.rb', line 85

def matching_xpath(xpath)
  @type = :matchesXPath
  @value = xpath
  @request_builder
end

#not_matching(regexp) ⇒ RequestBuilder

Match if attribute value does not match

Parameters:

  • regexp (Regexp, String)

    regexp to match against

Returns:

  • (RequestBuilder)

    calling request builder for chaining additional attributes



94
95
96
97
98
99
# File 'lib/builders/match_builder.rb', line 94

def not_matching(regexp)
  regexp = Helpers.regexp_to_string regexp if regexp.is_a? Regexp
  @type = :doesNotMatch
  @value = regexp
  @request_builder
end

#to_hashObject



101
102
103
# File 'lib/builders/match_builder.rb', line 101

def to_hash(*)
  { @type => @value }.merge(@options)
end

#to_jsonObject



105
106
107
# File 'lib/builders/match_builder.rb', line 105

def to_json(*)
  to_hash.to_json
end