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.



4
5
6
7
8
9
# File 'lib/builders/match_builder.rb', line 4

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



13
14
15
16
17
# File 'lib/builders/match_builder.rb', line 13

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



22
23
24
25
26
# File 'lib/builders/match_builder.rb', line 22

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



31
32
33
34
35
# File 'lib/builders/match_builder.rb', line 31

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)

    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



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

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



55
56
57
58
59
# File 'lib/builders/match_builder.rb', line 55

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

#matching(regex_string) ⇒ RequestBuilder

Match if attribute value matches the regex_string

Parameters:

  • regex_string (String)

    xml to match against

Returns:

  • (RequestBuilder)

    calling request builder for chaining additional attributes



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

def matching(regex_string)
  @type = :matches
  @value = regex_string
  @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



73
74
75
76
77
# File 'lib/builders/match_builder.rb', line 73

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



82
83
84
85
86
# File 'lib/builders/match_builder.rb', line 82

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

#not_matching(regex_string) ⇒ RequestBuilder

Match if attribute value does not match

Parameters:

  • regex_string (String)

    regex_string to match against

Returns:

  • (RequestBuilder)

    calling request builder for chaining additional attributes



91
92
93
94
95
# File 'lib/builders/match_builder.rb', line 91

def not_matching(regex_string)
  @type = :doesNotMatch
  @value = regex_string
  @request_builder
end

#to_hashObject



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

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

#to_jsonObject



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

def to_json(*)
  to_hash.to_json
end