wiremock_mapper 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/builders/match_builder.rb +106 -0
- data/lib/builders/request_builder.rb +124 -0
- data/lib/builders/response_builder.rb +52 -0
- data/lib/builders/url_match_builder.rb +38 -0
- data/lib/configuration.rb +4 -11
- data/lib/version.rb +3 -0
- data/lib/wiremock_mapper.rb +0 -4
- data/spec/configuration_spec.rb +3 -2
- data/spec/match_builder_spec.rb +3 -12
- data/spec/request_builder_spec.rb +26 -19
- data/spec/response_builder_spec.rb +3 -7
- data/spec/spec_helper.rb +6 -2
- data/spec/url_match_builder_spec.rb +3 -4
- data/spec/wiremock_mapper_spec.rb +4 -4
- data/wiremock_mapper.gemspec +4 -2
- metadata +21 -6
- data/lib/match_builder.rb +0 -104
- data/lib/request_builder.rb +0 -83
- data/lib/response_builder.rb +0 -50
- data/lib/url_match_builder.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f120074815585f809be94a0c688f74dab08a525
|
4
|
+
data.tar.gz: 3aa65a0f6e7f0b48b68093a4d424dd694447cbf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cc94dd1aa580de748d23ff5231cfd612a950b0134cb9d6714e0a070670766e7a3aaff11f384ee712ef9e3dc763d2598cc070b54b09b67364bbbcc2a3c923541
|
7
|
+
data.tar.gz: 876d7d72b05cdd6c15a5da27ff9e1a55e5bfe2df554b0e1541afb70a1c4d4c82ebfff2a76ec466a031b9e8c278ba5618df42ef920c8629e265df7be7b28cb3d7
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module WireMockMapper
|
2
|
+
module Builders
|
3
|
+
class MatchBuilder
|
4
|
+
def initialize(request_builder)
|
5
|
+
@request_builder = request_builder
|
6
|
+
@type = ''
|
7
|
+
@value = ''
|
8
|
+
@options = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Match if attribute is absent
|
12
|
+
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
13
|
+
def absent
|
14
|
+
@type = :absent
|
15
|
+
@value = true
|
16
|
+
@request_builder
|
17
|
+
end
|
18
|
+
|
19
|
+
# Match if attribute value contains the arg
|
20
|
+
# @param value [String] string to match
|
21
|
+
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
22
|
+
def containing(value)
|
23
|
+
@type = :contains
|
24
|
+
@value = value
|
25
|
+
@request_builder
|
26
|
+
end
|
27
|
+
|
28
|
+
# Match if attribute value is equal to the arg
|
29
|
+
# @param value [String] string to compare against
|
30
|
+
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
31
|
+
def equal_to(value)
|
32
|
+
@type = :equalTo
|
33
|
+
@value = value
|
34
|
+
@request_builder
|
35
|
+
end
|
36
|
+
|
37
|
+
# Match if attribute json is equal to the arg
|
38
|
+
# @param json [String] json to compare against
|
39
|
+
# @param ignore_array_order [true, false] flag to ignore the order of arrays
|
40
|
+
# @param ignore_extra_elements [true, false] flag to ignore any extra elements
|
41
|
+
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
42
|
+
def equal_to_json(json, ignore_array_order = false, ignore_extra_elements = false)
|
43
|
+
@type = :equalToJson
|
44
|
+
@value = json
|
45
|
+
|
46
|
+
@options[:ignoreArrayOrder] = true if ignore_array_order
|
47
|
+
@options[:ignoreExtraElements] = true if ignore_extra_elements
|
48
|
+
|
49
|
+
@request_builder
|
50
|
+
end
|
51
|
+
|
52
|
+
# Match if attribute xml is equal to the arg
|
53
|
+
# @param xml [String] xml to compare against
|
54
|
+
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
55
|
+
def equal_to_xml(xml)
|
56
|
+
@type = :equalToXml
|
57
|
+
@value = xml
|
58
|
+
@request_builder
|
59
|
+
end
|
60
|
+
|
61
|
+
# Match if attribute value matches the regex_string
|
62
|
+
# @param regex_string [String] xml to match against
|
63
|
+
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
64
|
+
def matching(regex_string)
|
65
|
+
@type = :matches
|
66
|
+
@value = regex_string
|
67
|
+
@request_builder
|
68
|
+
end
|
69
|
+
|
70
|
+
# Match if attribute json matches the json_path
|
71
|
+
# @param json_path [String] json_path to match against
|
72
|
+
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
73
|
+
def matching_json_path(json_path)
|
74
|
+
@type = :matchesJsonPath
|
75
|
+
@value = json_path
|
76
|
+
@request_builder
|
77
|
+
end
|
78
|
+
|
79
|
+
# Match if attribute xml matches the xpath
|
80
|
+
# @param xpath [String] xpath to match against
|
81
|
+
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
82
|
+
def matching_xpath(xpath)
|
83
|
+
@type = :matchesXPath
|
84
|
+
@value = xpath
|
85
|
+
@request_builder
|
86
|
+
end
|
87
|
+
|
88
|
+
# Match if attribute value does not match
|
89
|
+
# @param regex_string [String] regex_string to match against
|
90
|
+
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
91
|
+
def not_matching(regex_string)
|
92
|
+
@type = :doesNotMatch
|
93
|
+
@value = regex_string
|
94
|
+
@request_builder
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_hash(*)
|
98
|
+
{ @type => @value }.merge(@options)
|
99
|
+
end
|
100
|
+
|
101
|
+
def to_json(*)
|
102
|
+
to_hash.to_json
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require_relative 'match_builder'
|
2
|
+
require_relative 'url_match_builder'
|
3
|
+
|
4
|
+
module WireMockMapper
|
5
|
+
module Builders
|
6
|
+
class RequestBuilder
|
7
|
+
def initialize
|
8
|
+
@options = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
##
|
12
|
+
# @!method receives_any
|
13
|
+
# Sets the request HTTP method to ANY
|
14
|
+
# @return [RequestBuilder] request builder for chaining
|
15
|
+
|
16
|
+
##
|
17
|
+
# @!method receives_delete
|
18
|
+
# Sets the request HTTP method to DELETE
|
19
|
+
# @return [RequestBuilder] request builder for chaining
|
20
|
+
|
21
|
+
##
|
22
|
+
# @!method receives_get
|
23
|
+
# Sets the request HTTP method to GET
|
24
|
+
# @return [RequestBuilder] request builder for chaining
|
25
|
+
|
26
|
+
##
|
27
|
+
# @!method receives_head
|
28
|
+
# Sets the request HTTP method to HEAD
|
29
|
+
# @return [RequestBuilder] request builder for chaining
|
30
|
+
|
31
|
+
##
|
32
|
+
# @!method receives_options
|
33
|
+
# Sets the request HTTP method to OPTIONS
|
34
|
+
# @return [RequestBuilder] request builder for chaining
|
35
|
+
|
36
|
+
##
|
37
|
+
# @!method receives_post
|
38
|
+
# Sets the request HTTP method to POST
|
39
|
+
# @return [RequestBuilder] request builder for chaining
|
40
|
+
|
41
|
+
##
|
42
|
+
# @!method receives_put
|
43
|
+
# Sets the request HTTP method to PUT
|
44
|
+
# @return [RequestBuilder] request builder for chaining
|
45
|
+
|
46
|
+
##
|
47
|
+
# @!method receives_trace
|
48
|
+
# Sets the request HTTP method to TRACE
|
49
|
+
# @return [RequestBuilder] request builder for chaining
|
50
|
+
HTTP_VERBS = %w(ANY DELETE GET HEAD OPTIONS POST PUT TRACE).freeze
|
51
|
+
private_constant :HTTP_VERBS
|
52
|
+
|
53
|
+
HTTP_VERBS.each do |verb|
|
54
|
+
define_method("receives_#{verb.downcase}") do
|
55
|
+
@options[:method] = verb
|
56
|
+
self
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Expect basic auth
|
61
|
+
# @param username [String] username to expect
|
62
|
+
# @param password [String] password to expect
|
63
|
+
# @return [RequestBuilder] request builder for chaining
|
64
|
+
def with_basic_auth(username, password)
|
65
|
+
@options[:basicAuth] = { username: username, password: password }
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
# Expect body
|
70
|
+
# @return [MatchBuilder] match builder to declare the match on the body
|
71
|
+
def with_body
|
72
|
+
@options[:bodyPatterns] ||= []
|
73
|
+
match_builder = MatchBuilder.new(self)
|
74
|
+
@options[:bodyPatterns] << match_builder
|
75
|
+
match_builder
|
76
|
+
end
|
77
|
+
|
78
|
+
# Expect cookie
|
79
|
+
# @param key [String] the cookie key
|
80
|
+
# @return [MatchBuilder] match builder to declare the match on the cookie
|
81
|
+
def with_cookie(key)
|
82
|
+
@options[:cookies] ||= {}
|
83
|
+
@options[:cookies][key] = MatchBuilder.new(self)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Expect header
|
87
|
+
# @param key [String] the header key
|
88
|
+
# @return [MatchBuilder] match builder to declare the match on the header
|
89
|
+
def with_header(key)
|
90
|
+
@options[:headers] ||= {}
|
91
|
+
@options[:headers][key] = MatchBuilder.new(self)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Expect query param
|
95
|
+
# @param key [String] the query param key
|
96
|
+
# @return [MatchBuilder] match builder to declare the match on the query param
|
97
|
+
def with_query_param(key)
|
98
|
+
@options[:queryParameters] ||= {}
|
99
|
+
@options[:queryParameters][key] = MatchBuilder.new(self)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Expect url path with query params
|
103
|
+
# @return [UrlMatchBuilder] url match builder to declare the match on the url
|
104
|
+
def with_url
|
105
|
+
@url_match = UrlMatchBuilder.new(self)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Expect url path only
|
109
|
+
# @return [UrlMatchBuilder] url match builder to declare the match on the url
|
110
|
+
def with_url_path
|
111
|
+
@url_match = UrlMatchBuilder.new(self, true)
|
112
|
+
end
|
113
|
+
|
114
|
+
def to_hash(*)
|
115
|
+
options_with_url_match = @options.merge(@url_match.to_hash) if @url_match
|
116
|
+
options_with_url_match || @options
|
117
|
+
end
|
118
|
+
|
119
|
+
def to_json(*)
|
120
|
+
to_hash.to_json
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module WireMockMapper
|
2
|
+
module Builders
|
3
|
+
class ResponseBuilder
|
4
|
+
def initialize
|
5
|
+
@options = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
# Response body
|
9
|
+
# @param value [String] the value to set the response body to
|
10
|
+
# @return [ResponseBuilder] response builder for chaining
|
11
|
+
def with_body(value)
|
12
|
+
value = value.to_json unless value.is_a? String
|
13
|
+
@options[:body] = value
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
# Add a response header
|
18
|
+
# @param key [String] the key of the header
|
19
|
+
# @param value [String] the value of the header
|
20
|
+
# @return [ResponseBuilder] response builder for chaining
|
21
|
+
def with_header(key, value)
|
22
|
+
@options[:headers] ||= {}
|
23
|
+
@options[:headers][key] = value
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
# Add a response http status
|
28
|
+
# @param status_code [String, Numeric] the status code to respond with
|
29
|
+
# @return [ResponseBuilder] response builder for chaining
|
30
|
+
def with_status(status_code)
|
31
|
+
@options[:status] = status_code
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# Add a response http status
|
36
|
+
# @param status_code [String] the status message to respond with
|
37
|
+
# @return [ResponseBuilder] response builder for chaining
|
38
|
+
def with_status_message(status_message)
|
39
|
+
@options[:statusMessage] = status_message
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_hash(*)
|
44
|
+
@options
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_json(*)
|
48
|
+
@options.to_json
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module WireMockMapper
|
2
|
+
module Builders
|
3
|
+
class UrlMatchBuilder
|
4
|
+
def initialize(request_builder, path = false)
|
5
|
+
@request_builder = request_builder
|
6
|
+
@path = path
|
7
|
+
@type = ''
|
8
|
+
@url_or_pattern = ''
|
9
|
+
end
|
10
|
+
|
11
|
+
# Expect url to equal
|
12
|
+
# @param url [String] url to match against
|
13
|
+
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
14
|
+
def equal_to(url)
|
15
|
+
@type = @path ? :urlPath : :url
|
16
|
+
@url_or_pattern = url
|
17
|
+
@request_builder
|
18
|
+
end
|
19
|
+
|
20
|
+
# Expect url to match
|
21
|
+
# @param regex_string [String] regex for url to match against
|
22
|
+
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
23
|
+
def matching(regex_string)
|
24
|
+
@type = @path ? :urlPathPattern : :urlPattern
|
25
|
+
@url_or_pattern = regex_string
|
26
|
+
@request_builder
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_hash(*)
|
30
|
+
{ @type => @url_or_pattern }
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_json(*)
|
34
|
+
to_hash.to_json
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/configuration.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require_relative 'request_builder'
|
2
|
-
require_relative 'response_builder'
|
1
|
+
require_relative 'builders/request_builder'
|
2
|
+
require_relative 'builders/response_builder'
|
3
3
|
|
4
4
|
module WireMockMapper
|
5
5
|
class Configuration
|
6
6
|
@wiremock_url = ''
|
7
7
|
|
8
|
-
@request_builder = RequestBuilder.new
|
9
|
-
@response_builder = ResponseBuilder.new
|
8
|
+
@request_builder = Builders::RequestBuilder.new
|
9
|
+
@response_builder = Builders::ResponseBuilder.new
|
10
10
|
|
11
11
|
class << self
|
12
12
|
attr_reader :request_builder, :response_builder, :wiremock_url
|
@@ -16,13 +16,6 @@ module WireMockMapper
|
|
16
16
|
yield @request_builder, @response_builder
|
17
17
|
end
|
18
18
|
|
19
|
-
# Add a request header for all future requests
|
20
|
-
# @param key [String] header key
|
21
|
-
# @return [MatchBuilder] match builder to declare the match on the header
|
22
|
-
def add_request_header(key)
|
23
|
-
@request_headers[key] = MatchBuilder.new(self)
|
24
|
-
end
|
25
|
-
|
26
19
|
# Set the WireMock url
|
27
20
|
# @param url [String] the url of the WireMock server
|
28
21
|
def set_wiremock_url(url)
|
data/lib/version.rb
ADDED
data/lib/wiremock_mapper.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require_relative 'configuration'
|
3
|
-
require_relative 'request_builder'
|
4
|
-
require_relative 'response_builder'
|
5
3
|
|
6
4
|
module WireMockMapper
|
7
|
-
VERSION = '0.4.0'.freeze
|
8
|
-
|
9
5
|
def self.create_mapping(url = Configuration.wiremock_url)
|
10
6
|
request_builder = deep_clone(Configuration.request_builder)
|
11
7
|
response_builder = deep_clone(Configuration.response_builder)
|
data/spec/configuration_spec.rb
CHANGED
@@ -10,10 +10,11 @@ describe WireMockMapper::Configuration do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
header_key_value = WireMockMapper::Configuration.request_builder.to_hash[:headers]['foo']
|
13
|
-
expect(header_key_value).to be_a(WireMockMapper::MatchBuilder)
|
13
|
+
expect(header_key_value).to be_a(WireMockMapper::Builders::MatchBuilder)
|
14
14
|
|
15
15
|
# BOOOOOO!
|
16
|
-
WireMockMapper::Configuration.instance_variable_set(:@request_builder,
|
16
|
+
WireMockMapper::Configuration.instance_variable_set(:@request_builder,
|
17
|
+
WireMockMapper::Builders::RequestBuilder.new)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
data/spec/match_builder_spec.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe WireMockMapper::MatchBuilder do
|
3
|
+
describe WireMockMapper::Builders::MatchBuilder do
|
4
|
+
let(:builder) { WireMockMapper::Builders::MatchBuilder.new(nil) }
|
5
|
+
|
4
6
|
describe 'absent' do
|
5
7
|
it 'returns a hash of { absent => true }' do
|
6
|
-
builder = WireMockMapper::MatchBuilder.new(nil)
|
7
8
|
builder.absent
|
8
9
|
expect(builder.to_hash).to eq(absent: true)
|
9
10
|
end
|
@@ -11,7 +12,6 @@ describe WireMockMapper::MatchBuilder do
|
|
11
12
|
|
12
13
|
describe 'containing' do
|
13
14
|
it 'returns a hash of { contains => value }' do
|
14
|
-
builder = WireMockMapper::MatchBuilder.new(nil)
|
15
15
|
builder.containing 'foo'
|
16
16
|
expect(builder.to_hash).to eq(contains: 'foo')
|
17
17
|
end
|
@@ -19,7 +19,6 @@ describe WireMockMapper::MatchBuilder do
|
|
19
19
|
|
20
20
|
describe 'equal_to' do
|
21
21
|
it 'returns a hash of { equalTo => value }' do
|
22
|
-
builder = WireMockMapper::MatchBuilder.new(nil)
|
23
22
|
builder.equal_to 'foo'
|
24
23
|
expect(builder.to_hash).to eq(equalTo: 'foo')
|
25
24
|
end
|
@@ -27,19 +26,16 @@ describe WireMockMapper::MatchBuilder do
|
|
27
26
|
|
28
27
|
describe 'equal_to_json' do
|
29
28
|
it 'returns a hash of { equalToJson => value }' do
|
30
|
-
builder = WireMockMapper::MatchBuilder.new(nil)
|
31
29
|
builder.equal_to_json 'foo'
|
32
30
|
expect(builder.to_hash).to eq(equalToJson: 'foo')
|
33
31
|
end
|
34
32
|
|
35
33
|
it 'returns a hash of { equalToJson => value, ignoreArrayOrder => true }' do
|
36
|
-
builder = WireMockMapper::MatchBuilder.new(nil)
|
37
34
|
builder.equal_to_json 'foo', true
|
38
35
|
expect(builder.to_hash).to eq(equalToJson: 'foo', ignoreArrayOrder: true)
|
39
36
|
end
|
40
37
|
|
41
38
|
it 'returns a hash of { equalToJson => value, ignoreExtraElements => true }' do
|
42
|
-
builder = WireMockMapper::MatchBuilder.new(nil)
|
43
39
|
builder.equal_to_json 'foo', false, true
|
44
40
|
expect(builder.to_hash).to eq(equalToJson: 'foo', ignoreExtraElements: true)
|
45
41
|
end
|
@@ -47,7 +43,6 @@ describe WireMockMapper::MatchBuilder do
|
|
47
43
|
|
48
44
|
describe 'equal_to_xml' do
|
49
45
|
it 'returns a hash of { equalToXml => value }' do
|
50
|
-
builder = WireMockMapper::MatchBuilder.new(nil)
|
51
46
|
builder.equal_to_xml 'foo'
|
52
47
|
expect(builder.to_hash).to eq(equalToXml: 'foo')
|
53
48
|
end
|
@@ -55,7 +50,6 @@ describe WireMockMapper::MatchBuilder do
|
|
55
50
|
|
56
51
|
describe 'matching' do
|
57
52
|
it 'returns a hash of { matches => value }' do
|
58
|
-
builder = WireMockMapper::MatchBuilder.new(nil)
|
59
53
|
builder.matching 'foo'
|
60
54
|
expect(builder.to_hash).to eq(matches: 'foo')
|
61
55
|
end
|
@@ -63,7 +57,6 @@ describe WireMockMapper::MatchBuilder do
|
|
63
57
|
|
64
58
|
describe 'matching_json_path' do
|
65
59
|
it 'returns a hash of { matchesJsonPath => value }' do
|
66
|
-
builder = WireMockMapper::MatchBuilder.new(nil)
|
67
60
|
builder.matching_json_path 'foo'
|
68
61
|
expect(builder.to_hash).to eq(matchesJsonPath: 'foo')
|
69
62
|
end
|
@@ -71,7 +64,6 @@ describe WireMockMapper::MatchBuilder do
|
|
71
64
|
|
72
65
|
describe 'matching_xpath' do
|
73
66
|
it 'returns a hash of { matchesXPath => value }' do
|
74
|
-
builder = WireMockMapper::MatchBuilder.new(nil)
|
75
67
|
builder.matching_xpath 'foo'
|
76
68
|
expect(builder.to_hash).to eq(matchesXPath: 'foo')
|
77
69
|
end
|
@@ -79,7 +71,6 @@ describe WireMockMapper::MatchBuilder do
|
|
79
71
|
|
80
72
|
describe 'not_matching' do
|
81
73
|
it 'returns a hash of { doesNotMatch => value }' do
|
82
|
-
builder = WireMockMapper::MatchBuilder.new(nil)
|
83
74
|
builder.not_matching 'foo'
|
84
75
|
expect(builder.to_hash).to eq(doesNotMatch: 'foo')
|
85
76
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe WireMockMapper::RequestBuilder do
|
3
|
+
describe WireMockMapper::Builders::RequestBuilder do
|
4
|
+
let(:builder) { WireMockMapper::Builders::RequestBuilder.new }
|
5
|
+
|
4
6
|
describe 'receives_any' do
|
5
7
|
it 'sets the http method and url path' do
|
6
|
-
builder = WireMockMapper::RequestBuilder.new
|
7
8
|
builder.receives_any
|
8
9
|
result = builder.to_hash
|
9
10
|
expect(result[:method]).to eq('ANY')
|
@@ -12,7 +13,6 @@ describe WireMockMapper::RequestBuilder do
|
|
12
13
|
|
13
14
|
describe 'receives_delete' do
|
14
15
|
it 'sets the http method and url path' do
|
15
|
-
builder = WireMockMapper::RequestBuilder.new
|
16
16
|
builder.receives_delete
|
17
17
|
result = builder.to_hash
|
18
18
|
expect(result[:method]).to eq('DELETE')
|
@@ -21,7 +21,6 @@ describe WireMockMapper::RequestBuilder do
|
|
21
21
|
|
22
22
|
describe 'receives_get' do
|
23
23
|
it 'sets the http method and url path' do
|
24
|
-
builder = WireMockMapper::RequestBuilder.new
|
25
24
|
builder.receives_get
|
26
25
|
result = builder.to_hash
|
27
26
|
expect(result[:method]).to eq('GET')
|
@@ -30,7 +29,6 @@ describe WireMockMapper::RequestBuilder do
|
|
30
29
|
|
31
30
|
describe 'receives_head' do
|
32
31
|
it 'sets the http method and url path' do
|
33
|
-
builder = WireMockMapper::RequestBuilder.new
|
34
32
|
builder.receives_head
|
35
33
|
result = builder.to_hash
|
36
34
|
expect(result[:method]).to eq('HEAD')
|
@@ -39,7 +37,6 @@ describe WireMockMapper::RequestBuilder do
|
|
39
37
|
|
40
38
|
describe 'receives_options' do
|
41
39
|
it 'sets the http method and url path' do
|
42
|
-
builder = WireMockMapper::RequestBuilder.new
|
43
40
|
builder.receives_options
|
44
41
|
result = builder.to_hash
|
45
42
|
expect(result[:method]).to eq('OPTIONS')
|
@@ -48,7 +45,6 @@ describe WireMockMapper::RequestBuilder do
|
|
48
45
|
|
49
46
|
describe 'receives_put' do
|
50
47
|
it 'sets the http method and url path' do
|
51
|
-
builder = WireMockMapper::RequestBuilder.new
|
52
48
|
builder.receives_put
|
53
49
|
result = builder.to_hash
|
54
50
|
expect(result[:method]).to eq('PUT')
|
@@ -57,7 +53,6 @@ describe WireMockMapper::RequestBuilder do
|
|
57
53
|
|
58
54
|
describe 'receives_post' do
|
59
55
|
it 'sets the http method and url path' do
|
60
|
-
builder = WireMockMapper::RequestBuilder.new
|
61
56
|
builder.receives_post
|
62
57
|
result = builder.to_hash
|
63
58
|
expect(result[:method]).to eq('POST')
|
@@ -66,7 +61,6 @@ describe WireMockMapper::RequestBuilder do
|
|
66
61
|
|
67
62
|
describe 'receives_trace' do
|
68
63
|
it 'sets the http method and url path' do
|
69
|
-
builder = WireMockMapper::RequestBuilder.new
|
70
64
|
builder.receives_trace
|
71
65
|
result = builder.to_hash
|
72
66
|
expect(result[:method]).to eq('TRACE')
|
@@ -75,7 +69,6 @@ describe WireMockMapper::RequestBuilder do
|
|
75
69
|
|
76
70
|
describe 'with_basic_auth' do
|
77
71
|
it 'adds basic auth' do
|
78
|
-
builder = WireMockMapper::RequestBuilder.new
|
79
72
|
builder.with_basic_auth('ike', '123456')
|
80
73
|
expect(builder.to_hash[:basicAuth]).to eq(username: 'ike', password: '123456')
|
81
74
|
end
|
@@ -83,12 +76,10 @@ describe WireMockMapper::RequestBuilder do
|
|
83
76
|
|
84
77
|
describe 'with_body' do
|
85
78
|
it 'returns a MatchBuilder' do
|
86
|
-
builder
|
87
|
-
expect(builder.with_body).to be_a(WireMockMapper::MatchBuilder)
|
79
|
+
expect(builder.with_body).to be_a(WireMockMapper::Builders::MatchBuilder)
|
88
80
|
end
|
89
81
|
|
90
82
|
it 'adds the matcher to bodyPatterns' do
|
91
|
-
builder = WireMockMapper::RequestBuilder.new
|
92
83
|
matcher = builder.with_body
|
93
84
|
expect(builder.to_hash).to eq(bodyPatterns: [matcher])
|
94
85
|
end
|
@@ -96,22 +87,38 @@ describe WireMockMapper::RequestBuilder do
|
|
96
87
|
|
97
88
|
describe 'with_cookie' do
|
98
89
|
it 'returns a MatchBuilder' do
|
99
|
-
builder
|
100
|
-
expect(builder.with_cookie(:whatever)).to be_a(WireMockMapper::MatchBuilder)
|
90
|
+
expect(builder.with_cookie(:whatever)).to be_a(WireMockMapper::Builders::MatchBuilder)
|
101
91
|
end
|
102
92
|
end
|
103
93
|
|
104
94
|
describe 'with_header' do
|
105
95
|
it 'returns a MatchBuilder' do
|
106
|
-
builder
|
107
|
-
|
96
|
+
expect(builder.with_header(:whatever)).to be_a(WireMockMapper::Builders::MatchBuilder)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe 'with_url' do
|
101
|
+
it 'should return a UrlMatchBuilder' do
|
102
|
+
expect(builder.with_url).to be_a(WireMockMapper::Builders::UrlMatchBuilder)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'with_url_path' do
|
107
|
+
it 'should return a UrlMatchBuilder' do
|
108
|
+
expect(builder.with_url_path).to be_a(WireMockMapper::Builders::UrlMatchBuilder)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'to_hash' do
|
113
|
+
it 'should merge in url_match info' do
|
114
|
+
builder.with_url.equal_to('foo')
|
115
|
+
expect(builder.to_hash).to eq(url: 'foo')
|
108
116
|
end
|
109
117
|
end
|
110
118
|
|
111
119
|
describe 'with_query_param' do
|
112
120
|
it 'returns a MatchBuilder' do
|
113
|
-
builder
|
114
|
-
expect(builder.with_query_param(:whatever)).to be_a(WireMockMapper::MatchBuilder)
|
121
|
+
expect(builder.with_query_param(:whatever)).to be_a(WireMockMapper::Builders::MatchBuilder)
|
115
122
|
end
|
116
123
|
end
|
117
124
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe WireMockMapper::ResponseBuilder do
|
3
|
+
describe WireMockMapper::Builders::ResponseBuilder do
|
4
|
+
let(:builder) { WireMockMapper::Builders::ResponseBuilder.new }
|
5
|
+
|
4
6
|
describe 'with_body' do
|
5
7
|
it 'adds the body' do
|
6
|
-
builder = WireMockMapper::ResponseBuilder.new
|
7
8
|
builder.with_body('some body')
|
8
9
|
result = builder.to_hash
|
9
10
|
expect(result[:body]).to eq('some body')
|
10
11
|
end
|
11
12
|
|
12
13
|
it 'converts value to_json if it is not a string' do
|
13
|
-
builder = WireMockMapper::ResponseBuilder.new
|
14
14
|
builder.with_body(some: 'hash')
|
15
15
|
result = builder.to_hash
|
16
16
|
expect(result[:body]).to eq('{"some":"hash"}')
|
@@ -19,14 +19,12 @@ describe WireMockMapper::ResponseBuilder do
|
|
19
19
|
|
20
20
|
describe 'with_header' do
|
21
21
|
it 'adds the header' do
|
22
|
-
builder = WireMockMapper::ResponseBuilder.new
|
23
22
|
builder.with_header('key', 'value')
|
24
23
|
result = builder.to_hash
|
25
24
|
expect(result[:headers]).to eq('key' => 'value')
|
26
25
|
end
|
27
26
|
|
28
27
|
it 'adds multiple headers' do
|
29
|
-
builder = WireMockMapper::ResponseBuilder.new
|
30
28
|
builder.with_header('key', 'value')
|
31
29
|
builder.with_header('another key', 'another value')
|
32
30
|
result = builder.to_hash
|
@@ -36,7 +34,6 @@ describe WireMockMapper::ResponseBuilder do
|
|
36
34
|
|
37
35
|
describe 'with_status' do
|
38
36
|
it 'adds the status code' do
|
39
|
-
builder = WireMockMapper::ResponseBuilder.new
|
40
37
|
builder.with_status(400)
|
41
38
|
result = builder.to_hash
|
42
39
|
expect(result[:status]).to eq(400)
|
@@ -45,7 +42,6 @@ describe WireMockMapper::ResponseBuilder do
|
|
45
42
|
|
46
43
|
describe 'with_status_message' do
|
47
44
|
it 'adds the status message' do
|
48
|
-
builder = WireMockMapper::ResponseBuilder.new
|
49
45
|
builder.with_status_message('message')
|
50
46
|
result = builder.to_hash
|
51
47
|
expect(result[:statusMessage]).to eq('message')
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require_relative '../lib/url_match_builder'
|
3
2
|
|
4
|
-
describe WireMockMapper::MatchBuilder do
|
3
|
+
describe WireMockMapper::Builders::MatchBuilder do
|
5
4
|
context 'initialized with path = true' do
|
6
|
-
let(:builder) { WireMockMapper::UrlMatchBuilder.new(nil, true) }
|
5
|
+
let(:builder) { WireMockMapper::Builders::UrlMatchBuilder.new(nil, true) }
|
7
6
|
|
8
7
|
describe 'equal_to' do
|
9
8
|
it 'sets the return of to_hash to {urlPath: value}' do
|
@@ -21,7 +20,7 @@ describe WireMockMapper::MatchBuilder do
|
|
21
20
|
end
|
22
21
|
|
23
22
|
context 'initialized with path = false' do
|
24
|
-
let(:builder) { WireMockMapper::UrlMatchBuilder.new(nil) }
|
23
|
+
let(:builder) { WireMockMapper::Builders::UrlMatchBuilder.new(nil) }
|
25
24
|
|
26
25
|
describe 'equal_to' do
|
27
26
|
it 'sets the return of to_hash to {url: value}' do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WireMockMapper do
|
4
|
-
|
4
|
+
describe 'create_mapping' do
|
5
5
|
it 'posts the correct json to the wiremock url' do
|
6
6
|
url = 'http://nowhere.com'
|
7
7
|
expected_request_body = { request: { 'method' => 'POST',
|
@@ -27,7 +27,7 @@ describe WireMockMapper do
|
|
27
27
|
it 'posts the correct json with configured global mappings to the wiremock url' do
|
28
28
|
url = 'http://nowhere.com'
|
29
29
|
expected_request_body = { request: { 'method' => 'POST',
|
30
|
-
'
|
30
|
+
'url' => '/some/url',
|
31
31
|
'headers' => { 'some_global_header' => { 'equalTo' => 'some global header value' },
|
32
32
|
'some_header' => { 'equalTo' => 'some header value' } },
|
33
33
|
'bodyPatterns' => [
|
@@ -36,12 +36,12 @@ describe WireMockMapper do
|
|
36
36
|
response: { 'body' => 'some response body' } }
|
37
37
|
stub_request(:post, "#{url}/__admin/mappings/new").with(body: expected_request_body)
|
38
38
|
|
39
|
-
request_builder = WireMockMapper::RequestBuilder.new.with_header('some_global_header').equal_to('some global header value')
|
39
|
+
request_builder = WireMockMapper::Builders::RequestBuilder.new.with_header('some_global_header').equal_to('some global header value')
|
40
40
|
expect(WireMockMapper::Configuration).to receive(:request_builder).and_return(request_builder)
|
41
41
|
|
42
42
|
WireMockMapper.create_mapping(url) do |request, respond|
|
43
43
|
request.receives_post
|
44
|
-
.
|
44
|
+
.with_url.equal_to('/some/url')
|
45
45
|
.with_header('some_header').equal_to('some header value')
|
46
46
|
.with_body.matching('some request body')
|
47
47
|
|
data/wiremock_mapper.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
|
2
|
-
|
2
|
+
|
3
|
+
require 'version'
|
3
4
|
|
4
5
|
Gem::Specification.new do |spec|
|
5
6
|
spec.name = 'wiremock_mapper'
|
@@ -14,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
14
15
|
spec.summary = 'Ruby DSL for setting up WireMock mappings'
|
15
16
|
spec.description = spec.summary
|
16
17
|
|
17
|
-
spec.files = `git ls-files`.split(
|
18
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
21
|
spec.extra_rdoc_files = ['LICENSE.txt', 'README.md']
|
@@ -23,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
23
24
|
spec.add_development_dependency 'codeclimate-test-reporter'
|
24
25
|
spec.add_development_dependency 'pry'
|
25
26
|
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'require_all'
|
26
28
|
spec.add_development_dependency 'rspec'
|
27
29
|
spec.add_development_dependency 'rubocop'
|
28
30
|
spec.add_development_dependency 'webmock'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wiremock_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Datlof
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: require_all
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,11 +124,12 @@ files:
|
|
110
124
|
- LICENSE.txt
|
111
125
|
- README.md
|
112
126
|
- Rakefile
|
127
|
+
- lib/builders/match_builder.rb
|
128
|
+
- lib/builders/request_builder.rb
|
129
|
+
- lib/builders/response_builder.rb
|
130
|
+
- lib/builders/url_match_builder.rb
|
113
131
|
- lib/configuration.rb
|
114
|
-
- lib/
|
115
|
-
- lib/request_builder.rb
|
116
|
-
- lib/response_builder.rb
|
117
|
-
- lib/url_match_builder.rb
|
132
|
+
- lib/version.rb
|
118
133
|
- lib/wiremock_mapper.rb
|
119
134
|
- spec/configuration_spec.rb
|
120
135
|
- spec/match_builder_spec.rb
|
data/lib/match_builder.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
module WireMockMapper
|
2
|
-
class MatchBuilder
|
3
|
-
def initialize(request_builder)
|
4
|
-
@request_builder = request_builder
|
5
|
-
@type = ''
|
6
|
-
@value = ''
|
7
|
-
@options = {}
|
8
|
-
end
|
9
|
-
|
10
|
-
# Match if attribute is absent
|
11
|
-
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
12
|
-
def absent
|
13
|
-
@type = :absent
|
14
|
-
@value = true
|
15
|
-
@request_builder
|
16
|
-
end
|
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
|
21
|
-
def containing(value)
|
22
|
-
@type = :contains
|
23
|
-
@value = value
|
24
|
-
@request_builder
|
25
|
-
end
|
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
|
30
|
-
def equal_to(value)
|
31
|
-
@type = :equalTo
|
32
|
-
@value = value
|
33
|
-
@request_builder
|
34
|
-
end
|
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
|
41
|
-
def equal_to_json(json, ignore_array_order = false, ignore_extra_elements = false)
|
42
|
-
@type = :equalToJson
|
43
|
-
@value = json
|
44
|
-
|
45
|
-
@options[:ignoreArrayOrder] = true if ignore_array_order
|
46
|
-
@options[:ignoreExtraElements] = true if ignore_extra_elements
|
47
|
-
|
48
|
-
@request_builder
|
49
|
-
end
|
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
|
54
|
-
def equal_to_xml(xml)
|
55
|
-
@type = :equalToXml
|
56
|
-
@value = xml
|
57
|
-
@request_builder
|
58
|
-
end
|
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
|
63
|
-
def matching(regex_string)
|
64
|
-
@type = :matches
|
65
|
-
@value = regex_string
|
66
|
-
@request_builder
|
67
|
-
end
|
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
|
72
|
-
def matching_json_path(json_path)
|
73
|
-
@type = :matchesJsonPath
|
74
|
-
@value = json_path
|
75
|
-
@request_builder
|
76
|
-
end
|
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
|
81
|
-
def matching_xpath(xpath)
|
82
|
-
@type = :matchesXPath
|
83
|
-
@value = xpath
|
84
|
-
@request_builder
|
85
|
-
end
|
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
|
90
|
-
def not_matching(regex_string)
|
91
|
-
@type = :doesNotMatch
|
92
|
-
@value = regex_string
|
93
|
-
@request_builder
|
94
|
-
end
|
95
|
-
|
96
|
-
def to_hash(*)
|
97
|
-
{ @type => @value }.merge(@options)
|
98
|
-
end
|
99
|
-
|
100
|
-
def to_json(*)
|
101
|
-
to_hash.to_json
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
data/lib/request_builder.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require_relative 'match_builder'
|
2
|
-
require_relative 'url_match_builder'
|
3
|
-
|
4
|
-
module WireMockMapper
|
5
|
-
class RequestBuilder
|
6
|
-
def initialize
|
7
|
-
@options = {}
|
8
|
-
end
|
9
|
-
|
10
|
-
HTTP_VERBS = %w(ANY DELETE GET HEAD OPTIONS POST PUT TRACE).freeze
|
11
|
-
private_constant :HTTP_VERBS
|
12
|
-
|
13
|
-
HTTP_VERBS.each do |verb|
|
14
|
-
define_method("receives_#{verb.downcase}") do
|
15
|
-
@options[:method] = verb
|
16
|
-
self
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# Expect basic auth
|
21
|
-
# @param username [String] username to expect
|
22
|
-
# @param password [String] password to expect
|
23
|
-
# @return [RequestBuilder] request builder for chaining
|
24
|
-
def with_basic_auth(username, password)
|
25
|
-
@options[:basicAuth] = { username: username, password: password }
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
# Expect body
|
30
|
-
# @return [MatchBuilder] match builder to declare the match on the body
|
31
|
-
def with_body
|
32
|
-
@options[:bodyPatterns] ||= []
|
33
|
-
match_builder = MatchBuilder.new(self)
|
34
|
-
@options[:bodyPatterns] << match_builder
|
35
|
-
match_builder
|
36
|
-
end
|
37
|
-
|
38
|
-
# Expect cookie
|
39
|
-
# @param key [String] the cookie key
|
40
|
-
# @return [MatchBuilder] match builder to declare the match on the cookie
|
41
|
-
def with_cookie(key)
|
42
|
-
@options[:cookies] ||= {}
|
43
|
-
@options[:cookies][key] = MatchBuilder.new(self)
|
44
|
-
end
|
45
|
-
|
46
|
-
# Expect header
|
47
|
-
# @param key [String] the header key
|
48
|
-
# @return [MatchBuilder] match builder to declare the match on the header
|
49
|
-
def with_header(key)
|
50
|
-
@options[:headers] ||= {}
|
51
|
-
@options[:headers][key] = MatchBuilder.new(self)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Expect query param
|
55
|
-
# @param key [String] the query param key
|
56
|
-
# @return [MatchBuilder] match builder to declare the match on the query param
|
57
|
-
def with_query_param(key)
|
58
|
-
@options[:queryParameters] ||= {}
|
59
|
-
@options[:queryParameters][key] = MatchBuilder.new(self)
|
60
|
-
end
|
61
|
-
|
62
|
-
# Expect url path with query params
|
63
|
-
# @return [UrlMatchBuilder] url match builder to declare the match on the url
|
64
|
-
def with_url
|
65
|
-
@url_match = UrlMatchBuilder.new(self)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Expect url path only
|
69
|
-
# @return [UrlMatchBuilder] url match builder to declare the match on the url
|
70
|
-
def with_url_path
|
71
|
-
@url_match = UrlMatchBuilder.new(self, true)
|
72
|
-
end
|
73
|
-
|
74
|
-
def to_hash(*)
|
75
|
-
options_with_url_match = @options.merge(@url_match.to_hash) if @url_match
|
76
|
-
options_with_url_match || @options
|
77
|
-
end
|
78
|
-
|
79
|
-
def to_json(*)
|
80
|
-
to_hash.to_json
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/lib/response_builder.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module WireMockMapper
|
2
|
-
class ResponseBuilder
|
3
|
-
def initialize
|
4
|
-
@options = {}
|
5
|
-
end
|
6
|
-
|
7
|
-
# Response body
|
8
|
-
# @param value [String] the value to set the response body to
|
9
|
-
# @return [ResponseBuilder] response builder for chaining
|
10
|
-
def with_body(value)
|
11
|
-
value = value.to_json unless value.is_a? String
|
12
|
-
@options[:body] = value
|
13
|
-
self
|
14
|
-
end
|
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
|
20
|
-
def with_header(key, value)
|
21
|
-
@options[:headers] ||= {}
|
22
|
-
@options[:headers][key] = value
|
23
|
-
self
|
24
|
-
end
|
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
|
29
|
-
def with_status(status_code)
|
30
|
-
@options[:status] = status_code
|
31
|
-
self
|
32
|
-
end
|
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
|
37
|
-
def with_status_message(status_message)
|
38
|
-
@options[:statusMessage] = status_message
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
def to_hash(*)
|
43
|
-
@options
|
44
|
-
end
|
45
|
-
|
46
|
-
def to_json(*)
|
47
|
-
@options.to_json
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/lib/url_match_builder.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module WireMockMapper
|
2
|
-
class UrlMatchBuilder
|
3
|
-
def initialize(request_builder, path = false)
|
4
|
-
@request_builder = request_builder
|
5
|
-
@path = path
|
6
|
-
@type = ''
|
7
|
-
@url_or_pattern = ''
|
8
|
-
end
|
9
|
-
|
10
|
-
# Expect url to equal
|
11
|
-
# @param url [String] url to match against
|
12
|
-
# @return [RequestBuilder] calling request builder for chaining additional attributes
|
13
|
-
def equal_to(url)
|
14
|
-
@type = @path ? :urlPath : :url
|
15
|
-
@url_or_pattern = url
|
16
|
-
@request_builder
|
17
|
-
end
|
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
|
22
|
-
def matching(regex_string)
|
23
|
-
@type = @path ? :urlPathPattern : :urlPattern
|
24
|
-
@url_or_pattern = regex_string
|
25
|
-
@request_builder
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_hash(*)
|
29
|
-
{ @type => @url_or_pattern }
|
30
|
-
end
|
31
|
-
|
32
|
-
def to_json(*)
|
33
|
-
to_hash.to_json
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|