wiremock_mapper 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55d9acc4792e98d17662839d6b79f75012069f76
4
- data.tar.gz: 86e81e72776ba7a27d9320529131bc19a5c74a77
3
+ metadata.gz: c55d34c227d457aecbfb8fc48fe1540c4fff8e6a
4
+ data.tar.gz: 7ea5eb65ccde458834d9773833a415d89f4f8985
5
5
  SHA512:
6
- metadata.gz: 14cb6170c8b802ba1ea5d66886f139406fcc43ef10db2afaa8a754cb88bde9dfc9fac0db80c5620f2462642bc4fbc60e6684022505b6516f9aab078e5b46efc9
7
- data.tar.gz: 39c74d269f1d2a76b3fdc8a68f1d950cdeeb61b797cc0c0df88695bf62ef4ae5fafa5e85f3596b4b58068d5c04f35b2c240675b4cf12c2ee56320810c3066a31
6
+ metadata.gz: b465342380e86cf5bcbbe1bfbe33de1d550cb05541c645fd894770b2f65800df035e8d95c914d618987fc8753596e96ece081af0709da76a6755ef3ce8b1641a
7
+ data.tar.gz: 37e5c4cf467e3017efbc48fefe3ed00b1a24b6c538b70463172202100093f65464ed51e2f8fb926446c2ce69bc8388d11b406cb1047d3fc47beaf6fa4975b94b
data/lib/configuration.rb CHANGED
@@ -6,10 +6,16 @@ module WireMockMapper
6
6
  class << self
7
7
  attr_reader :request_headers, :wiremock_url
8
8
 
9
+
10
+ # Add a request header for all future requests
11
+ # @param key [String] header key
12
+ # @return [MatchBuilder] match builder to declare the match on the header
9
13
  def add_request_header(key)
10
14
  @request_headers[key] = MatchBuilder.new(self)
11
15
  end
12
16
 
17
+ # Set the WireMock url
18
+ # @param url [String] the url of the WireMock server
13
19
  def set_wiremock_url(url)
14
20
  @wiremock_url = url
15
21
  end
data/lib/match_builder.rb CHANGED
@@ -7,24 +7,37 @@ module WireMockMapper
7
7
  @options = {}
8
8
  end
9
9
 
10
+ # Match if attribute is absent
11
+ # @return [RequestBuilder] calling request builder for chaining additional attributes
10
12
  def absent
11
13
  @type = :absent
12
14
  @value = true
13
15
  @request_builder
14
16
  end
15
17
 
18
+ # Match if attribute value contains the arg
19
+ # @param value [String] string to match
20
+ # @return [RequestBuilder] calling request builder for chaining additional attributes
16
21
  def containing(value)
17
22
  @type = :contains
18
23
  @value = value
19
24
  @request_builder
20
25
  end
21
26
 
27
+ # Match if attribute value is equal to the arg
28
+ # @param value [String] string to compare against
29
+ # @return [RequestBuilder] calling request builder for chaining additional attributes
22
30
  def equal_to(value)
23
31
  @type = :equalTo
24
32
  @value = value
25
33
  @request_builder
26
34
  end
27
35
 
36
+ # Match if attribute json is equal to the arg
37
+ # @param json [String] json to compare against
38
+ # @param ignore_array_order [true, false] flag to ignore the order of arrays
39
+ # @param ignore_extra_elements [true, false] flag to ignore any extra elements
40
+ # @return [RequestBuilder] calling request builder for chaining additional attributes
28
41
  def equal_to_json(json, ignore_array_order = false, ignore_extra_elements = false)
29
42
  @type = :equalToJson
30
43
  @value = json
@@ -35,30 +48,45 @@ module WireMockMapper
35
48
  @request_builder
36
49
  end
37
50
 
51
+ # Match if attribute xml is equal to the arg
52
+ # @param xml [String] xml to compare against
53
+ # @return [RequestBuilder] calling request builder for chaining additional attributes
38
54
  def equal_to_xml(xml)
39
55
  @type = :equalToXml
40
56
  @value = xml
41
57
  @request_builder
42
58
  end
43
59
 
60
+ # Match if attribute value matches the regex_string
61
+ # @param regex_string [String] xml to match against
62
+ # @return [RequestBuilder] calling request builder for chaining additional attributes
44
63
  def matching(regex_string)
45
64
  @type = :matches
46
65
  @value = regex_string
47
66
  @request_builder
48
67
  end
49
68
 
69
+ # Match if attribute json matches the json_path
70
+ # @param json_path [String] json_path to match against
71
+ # @return [RequestBuilder] calling request builder for chaining additional attributes
50
72
  def matching_json_path(json_path)
51
73
  @type = :matchesJsonPath
52
74
  @value = json_path
53
75
  @request_builder
54
76
  end
55
77
 
78
+ # Match if attribute xml matches the xpath
79
+ # @param xpath [String] xpath to match against
80
+ # @return [RequestBuilder] calling request builder for chaining additional attributes
56
81
  def matching_xpath(xpath)
57
82
  @type = :matchesXPath
58
83
  @value = xpath
59
84
  @request_builder
60
85
  end
61
86
 
87
+ # Match if attribute value does not match
88
+ # @param regex_string [String] regex_string to match against
89
+ # @return [RequestBuilder] calling request builder for chaining additional attributes
62
90
  def not_matching(regex_string)
63
91
  @type = :doesNotMatch
64
92
  @value = regex_string
@@ -8,19 +8,27 @@ module WireMockMapper
8
8
  @options[:headers] = configuration.request_headers if configuration
9
9
  end
10
10
 
11
- HttpVerbs = %w(ANY DELETE GET HEAD OPTIONS POST PUT TRACE).freeze
12
- HttpVerbs.each do |verb|
11
+ HTTP_VERBS = %w(ANY DELETE GET HEAD OPTIONS POST PUT TRACE).freeze
12
+ private_constant :HTTP_VERBS
13
+
14
+ HTTP_VERBS.each do |verb|
13
15
  define_method("receives_#{verb.downcase}") do
14
16
  @options[:method] = verb
15
17
  self
16
18
  end
17
19
  end
18
20
 
21
+ # Expect basic auth
22
+ # @param username [String] username to expect
23
+ # @param password [String] password to expect
24
+ # @return [RequestBuilder] request builder for chaining
19
25
  def with_basic_auth(username, password)
20
26
  @options[:basicAuth] = { username: username, password: password }
21
27
  self
22
28
  end
23
29
 
30
+ # Expect body
31
+ # @return [MatchBuilder] match builder to declare the match on the body
24
32
  def with_body
25
33
  @options[:bodyPatterns] ||= []
26
34
  match_builder = MatchBuilder.new(self)
@@ -28,25 +36,38 @@ module WireMockMapper
28
36
  match_builder
29
37
  end
30
38
 
39
+ # Expect cookie
40
+ # @param key [String] the cookie key
41
+ # @return [MatchBuilder] match builder to declare the match on the cookie
31
42
  def with_cookie(key)
32
43
  @options[:cookies] ||= {}
33
44
  @options[:cookies][key] = MatchBuilder.new(self)
34
45
  end
35
46
 
47
+ # Expect header
48
+ # @param key [String] the header key
49
+ # @return [MatchBuilder] match builder to declare the match on the header
36
50
  def with_header(key)
37
51
  @options[:headers] ||= {}
38
52
  @options[:headers][key] = MatchBuilder.new(self)
39
53
  end
40
54
 
41
- def with_query_params(key)
55
+ # Expect query param
56
+ # @param key [String] the query param key
57
+ # @return [MatchBuilder] match builder to declare the match on the query param
58
+ def with_query_param(key)
42
59
  @options[:queryParameters] ||= {}
43
60
  @options[:queryParameters][key] = MatchBuilder.new(self)
44
61
  end
45
62
 
63
+ # Expect url path with query params
64
+ # @return [UrlMatchBuilder] url match builder to declare the match on the url
46
65
  def with_url
47
66
  @url_match = UrlMatchBuilder.new(self)
48
67
  end
49
68
 
69
+ # Expect url path only
70
+ # @return [UrlMatchBuilder] url match builder to declare the match on the url
50
71
  def with_url_path
51
72
  @url_match = UrlMatchBuilder.new(self, true)
52
73
  end
@@ -4,23 +4,36 @@ module WireMockMapper
4
4
  @options = {}
5
5
  end
6
6
 
7
+ # Response body
8
+ # @param value [String] the value to set the response body to
9
+ # @return [ResponseBuilder] response builder for chaining
7
10
  def with_body(value)
8
11
  value = value.to_json unless value.is_a? String
9
12
  @options[:body] = value
10
13
  self
11
14
  end
12
15
 
16
+ # Add a response header
17
+ # @param key [String] the key of the header
18
+ # @param value [String] the value of the header
19
+ # @return [ResponseBuilder] response builder for chaining
13
20
  def with_header(key, value)
14
21
  @options[:headers] ||= {}
15
22
  @options[:headers][key] = value
16
23
  self
17
24
  end
18
25
 
26
+ # Add a response http status
27
+ # @param status_code [String, Numeric] the status code to respond with
28
+ # @return [ResponseBuilder] response builder for chaining
19
29
  def with_status(status_code)
20
30
  @options[:status] = status_code
21
31
  self
22
32
  end
23
33
 
34
+ # Add a response http status
35
+ # @param status_code [String] the status message to respond with
36
+ # @return [ResponseBuilder] response builder for chaining
24
37
  def with_status_message(status_message)
25
38
  @options[:statusMessage] = status_message
26
39
  self
@@ -7,12 +7,18 @@ module WireMockMapper
7
7
  @url_or_pattern = ''
8
8
  end
9
9
 
10
+ # Expect url to equal
11
+ # @param url [String] url to match against
12
+ # @return [RequestBuilder] calling request builder for chaining additional attributes
10
13
  def equal_to(url)
11
14
  @type = @path ? :urlPath : :url
12
15
  @url_or_pattern = url
13
16
  @request_builder
14
17
  end
15
18
 
19
+ # Expect url to match
20
+ # @param regex_string [String] regex for url to match against
21
+ # @return [RequestBuilder] calling request builder for chaining additional attributes
16
22
  def matching(regex_string)
17
23
  @type = @path ? :urlPathPattern : :urlPattern
18
24
  @url_or_pattern = regex_string
@@ -4,7 +4,7 @@ require_relative 'request_builder'
4
4
  require_relative 'response_builder'
5
5
 
6
6
  module WireMockMapper
7
- VERSION = '0.2.0'.freeze
7
+ VERSION = '0.3.0'.freeze
8
8
 
9
9
  def self.create_mapping(url = Configuration.wiremock_url)
10
10
  request_builder = RequestBuilder.new
@@ -108,10 +108,10 @@ describe WireMockMapper::RequestBuilder do
108
108
  end
109
109
  end
110
110
 
111
- describe 'with_query_params' do
111
+ describe 'with_query_param' do
112
112
  it 'returns a MatchBuilder' do
113
113
  builder = WireMockMapper::RequestBuilder.new
114
- expect(builder.with_query_params(:whatever)).to be_a(WireMockMapper::MatchBuilder)
114
+ expect(builder.with_query_param(:whatever)).to be_a(WireMockMapper::MatchBuilder)
115
115
  end
116
116
  end
117
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wiremock_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isaac Datlof