wiremock_mapper 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +11 -7
- data/lib/configuration.rb +2 -2
- data/lib/match_builder.rb +76 -0
- data/lib/request_builder.rb +43 -15
- data/lib/response_builder.rb +17 -1
- data/lib/url_match_builder.rb +30 -0
- data/lib/wiremock_mapper.rb +1 -1
- data/spec/configuration_spec.rb +3 -3
- data/spec/match_builder_spec.rb +87 -0
- data/spec/request_builder_spec.rb +94 -15
- data/spec/response_builder_spec.rb +38 -3
- data/spec/spec_helper.rb +1 -0
- data/spec/url_match_builder_spec.rb +40 -0
- data/spec/wiremock_mapper_spec.rb +4 -3
- data/wiremock_mapper.gemspec +0 -1
- metadata +8 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55d9acc4792e98d17662839d6b79f75012069f76
|
4
|
+
data.tar.gz: 86e81e72776ba7a27d9320529131bc19a5c74a77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14cb6170c8b802ba1ea5d66886f139406fcc43ef10db2afaa8a754cb88bde9dfc9fac0db80c5620f2462642bc4fbc60e6684022505b6516f9aab078e5b46efc9
|
7
|
+
data.tar.gz: 39c74d269f1d2a76b3fdc8a68f1d950cdeeb61b797cc0c0df88695bf62ef4ae5fafa5e85f3596b4b58068d5c04f35b2c240675b4cf12c2ee56320810c3066a31
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,20 +2,24 @@
|
|
2
2
|
[![Code Climate](https://codeclimate.com/github/ike18t/wiremock_mapper/badges/gpa.svg)](https://codeclimate.com/github/ike18t/wiremock_mapper)
|
3
3
|
[![Test Coverage](https://codeclimate.com/github/ike18t/wiremock_mapper/badges/coverage.svg)](https://codeclimate.com/github/ike18t/wiremock_mapper/coverage)
|
4
4
|
[![Dependency Status](https://gemnasium.com/badges/github.com/ike18t/wiremock_mapper.svg)](https://gemnasium.com/github.com/ike18t/wiremock_mapper)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/wiremock_mapper.svg)](https://badge.fury.io/rb/wiremock_mapper)
|
5
6
|
|
6
7
|
##WireMockMapper
|
7
8
|
|
8
|
-
**Ruby DSL for setting up WireMock mappings**
|
9
|
+
**Ruby DSL for setting up [WireMock](http://wiremock.org/) mappings**
|
9
10
|
|
10
|
-
####Usage Example
|
11
|
+
####Usage Example
|
11
12
|
```ruby
|
12
13
|
WireMockMapper::Configuration.set_wiremock_url('http://my_wiremock.com')
|
13
|
-
WireMockMapper::Configuration.
|
14
|
+
WireMockMapper::Configuration.add_request_header('Some-Header').equal_to('some_value')
|
14
15
|
|
15
16
|
WireMockMapper.create_mapping do |request, respond|
|
16
|
-
request.
|
17
|
-
|
18
|
-
|
17
|
+
request.receives_post
|
18
|
+
.with_url_path.equal_to('path/to/stub')
|
19
|
+
.with_header('Some-Other-Header').equal_to('some_other_value')
|
20
|
+
.with_body.equal_to(foo: bar)
|
19
21
|
respond.with_body('good job!')
|
20
22
|
end
|
21
|
-
```
|
23
|
+
```
|
24
|
+
|
25
|
+
###### Special thanks to [Manheim](https://www.manheim.com)'s [Seller Tools](https://sites.google.com/site/sellertoolsteam/home) team for allowing me to work on this during the team Hackathon.
|
data/lib/configuration.rb
CHANGED
@@ -6,8 +6,8 @@ module WireMockMapper
|
|
6
6
|
class << self
|
7
7
|
attr_reader :request_headers, :wiremock_url
|
8
8
|
|
9
|
-
def add_request_header(key
|
10
|
-
@request_headers[key] =
|
9
|
+
def add_request_header(key)
|
10
|
+
@request_headers[key] = MatchBuilder.new(self)
|
11
11
|
end
|
12
12
|
|
13
13
|
def set_wiremock_url(url)
|
@@ -0,0 +1,76 @@
|
|
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
|
+
def absent
|
11
|
+
@type = :absent
|
12
|
+
@value = true
|
13
|
+
@request_builder
|
14
|
+
end
|
15
|
+
|
16
|
+
def containing(value)
|
17
|
+
@type = :contains
|
18
|
+
@value = value
|
19
|
+
@request_builder
|
20
|
+
end
|
21
|
+
|
22
|
+
def equal_to(value)
|
23
|
+
@type = :equalTo
|
24
|
+
@value = value
|
25
|
+
@request_builder
|
26
|
+
end
|
27
|
+
|
28
|
+
def equal_to_json(json, ignore_array_order = false, ignore_extra_elements = false)
|
29
|
+
@type = :equalToJson
|
30
|
+
@value = json
|
31
|
+
|
32
|
+
@options[:ignoreArrayOrder] = true if ignore_array_order
|
33
|
+
@options[:ignoreExtraElements] = true if ignore_extra_elements
|
34
|
+
|
35
|
+
@request_builder
|
36
|
+
end
|
37
|
+
|
38
|
+
def equal_to_xml(xml)
|
39
|
+
@type = :equalToXml
|
40
|
+
@value = xml
|
41
|
+
@request_builder
|
42
|
+
end
|
43
|
+
|
44
|
+
def matching(regex_string)
|
45
|
+
@type = :matches
|
46
|
+
@value = regex_string
|
47
|
+
@request_builder
|
48
|
+
end
|
49
|
+
|
50
|
+
def matching_json_path(json_path)
|
51
|
+
@type = :matchesJsonPath
|
52
|
+
@value = json_path
|
53
|
+
@request_builder
|
54
|
+
end
|
55
|
+
|
56
|
+
def matching_xpath(xpath)
|
57
|
+
@type = :matchesXPath
|
58
|
+
@value = xpath
|
59
|
+
@request_builder
|
60
|
+
end
|
61
|
+
|
62
|
+
def not_matching(regex_string)
|
63
|
+
@type = :doesNotMatch
|
64
|
+
@value = regex_string
|
65
|
+
@request_builder
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_hash(*)
|
69
|
+
{ @type => @value }.merge(@options)
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_json(*)
|
73
|
+
to_hash.to_json
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/request_builder.rb
CHANGED
@@ -1,35 +1,63 @@
|
|
1
|
+
require_relative 'match_builder'
|
2
|
+
require_relative 'url_match_builder'
|
3
|
+
|
1
4
|
module WireMockMapper
|
2
5
|
class RequestBuilder
|
3
6
|
def initialize(configuration = nil)
|
4
7
|
@options = {}
|
5
|
-
@options[
|
6
|
-
@options['headers'] = configuration.request_headers if configuration
|
8
|
+
@options[:headers] = configuration.request_headers if configuration
|
7
9
|
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
HttpVerbs = %w(ANY DELETE GET HEAD OPTIONS POST PUT TRACE).freeze
|
12
|
+
HttpVerbs.each do |verb|
|
13
|
+
define_method("receives_#{verb.downcase}") do
|
14
|
+
@options[:method] = verb
|
15
|
+
self
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
|
-
def
|
16
|
-
@options[
|
19
|
+
def with_basic_auth(username, password)
|
20
|
+
@options[:basicAuth] = { username: username, password: password }
|
17
21
|
self
|
18
22
|
end
|
19
23
|
|
20
|
-
def with_body
|
21
|
-
@options[
|
22
|
-
|
23
|
-
@options[
|
24
|
-
|
24
|
+
def with_body
|
25
|
+
@options[:bodyPatterns] ||= []
|
26
|
+
match_builder = MatchBuilder.new(self)
|
27
|
+
@options[:bodyPatterns] << match_builder
|
28
|
+
match_builder
|
29
|
+
end
|
30
|
+
|
31
|
+
def with_cookie(key)
|
32
|
+
@options[:cookies] ||= {}
|
33
|
+
@options[:cookies][key] = MatchBuilder.new(self)
|
34
|
+
end
|
35
|
+
|
36
|
+
def with_header(key)
|
37
|
+
@options[:headers] ||= {}
|
38
|
+
@options[:headers][key] = MatchBuilder.new(self)
|
39
|
+
end
|
40
|
+
|
41
|
+
def with_query_params(key)
|
42
|
+
@options[:queryParameters] ||= {}
|
43
|
+
@options[:queryParameters][key] = MatchBuilder.new(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def with_url
|
47
|
+
@url_match = UrlMatchBuilder.new(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
def with_url_path
|
51
|
+
@url_match = UrlMatchBuilder.new(self, true)
|
25
52
|
end
|
26
53
|
|
27
54
|
def to_hash(*)
|
28
|
-
@options
|
55
|
+
options_with_url_match = @options.merge(@url_match.to_hash) if @url_match
|
56
|
+
options_with_url_match || @options
|
29
57
|
end
|
30
58
|
|
31
59
|
def to_json(*)
|
32
|
-
|
60
|
+
to_hash.to_json
|
33
61
|
end
|
34
62
|
end
|
35
63
|
end
|
data/lib/response_builder.rb
CHANGED
@@ -6,7 +6,23 @@ module WireMockMapper
|
|
6
6
|
|
7
7
|
def with_body(value)
|
8
8
|
value = value.to_json unless value.is_a? String
|
9
|
-
@options[
|
9
|
+
@options[:body] = value
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def with_header(key, value)
|
14
|
+
@options[:headers] ||= {}
|
15
|
+
@options[:headers][key] = value
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def with_status(status_code)
|
20
|
+
@options[:status] = status_code
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def with_status_message(status_message)
|
25
|
+
@options[:statusMessage] = status_message
|
10
26
|
self
|
11
27
|
end
|
12
28
|
|
@@ -0,0 +1,30 @@
|
|
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
|
+
def equal_to(url)
|
11
|
+
@type = @path ? :urlPath : :url
|
12
|
+
@url_or_pattern = url
|
13
|
+
@request_builder
|
14
|
+
end
|
15
|
+
|
16
|
+
def matching(regex_string)
|
17
|
+
@type = @path ? :urlPathPattern : :urlPattern
|
18
|
+
@url_or_pattern = regex_string
|
19
|
+
@request_builder
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash(*)
|
23
|
+
{ @type => @url_or_pattern }
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json(*)
|
27
|
+
to_hash.to_json
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/wiremock_mapper.rb
CHANGED
data/spec/configuration_spec.rb
CHANGED
@@ -2,9 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe WireMockMapper::Configuration do
|
4
4
|
context 'request_header' do
|
5
|
-
it '
|
6
|
-
WireMockMapper::Configuration.add_request_header('
|
7
|
-
expect(WireMockMapper::Configuration.request_headers).to
|
5
|
+
it 'returns a MatchBuilder' do
|
6
|
+
WireMockMapper::Configuration.add_request_header('some_header')
|
7
|
+
expect(WireMockMapper::Configuration.request_headers['some_header']).to be_a(WireMockMapper::MatchBuilder)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WireMockMapper::MatchBuilder do
|
4
|
+
describe 'absent' do
|
5
|
+
it 'returns a hash of { absent => true }' do
|
6
|
+
builder = WireMockMapper::MatchBuilder.new(nil)
|
7
|
+
builder.absent
|
8
|
+
expect(builder.to_hash).to eq(absent: true)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'containing' do
|
13
|
+
it 'returns a hash of { contains => value }' do
|
14
|
+
builder = WireMockMapper::MatchBuilder.new(nil)
|
15
|
+
builder.containing 'foo'
|
16
|
+
expect(builder.to_hash).to eq(contains: 'foo')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'equal_to' do
|
21
|
+
it 'returns a hash of { equalTo => value }' do
|
22
|
+
builder = WireMockMapper::MatchBuilder.new(nil)
|
23
|
+
builder.equal_to 'foo'
|
24
|
+
expect(builder.to_hash).to eq(equalTo: 'foo')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'equal_to_json' do
|
29
|
+
it 'returns a hash of { equalToJson => value }' do
|
30
|
+
builder = WireMockMapper::MatchBuilder.new(nil)
|
31
|
+
builder.equal_to_json 'foo'
|
32
|
+
expect(builder.to_hash).to eq(equalToJson: 'foo')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns a hash of { equalToJson => value, ignoreArrayOrder => true }' do
|
36
|
+
builder = WireMockMapper::MatchBuilder.new(nil)
|
37
|
+
builder.equal_to_json 'foo', true
|
38
|
+
expect(builder.to_hash).to eq(equalToJson: 'foo', ignoreArrayOrder: true)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns a hash of { equalToJson => value, ignoreExtraElements => true }' do
|
42
|
+
builder = WireMockMapper::MatchBuilder.new(nil)
|
43
|
+
builder.equal_to_json 'foo', false, true
|
44
|
+
expect(builder.to_hash).to eq(equalToJson: 'foo', ignoreExtraElements: true)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'equal_to_xml' do
|
49
|
+
it 'returns a hash of { equalToXml => value }' do
|
50
|
+
builder = WireMockMapper::MatchBuilder.new(nil)
|
51
|
+
builder.equal_to_xml 'foo'
|
52
|
+
expect(builder.to_hash).to eq(equalToXml: 'foo')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'matching' do
|
57
|
+
it 'returns a hash of { matches => value }' do
|
58
|
+
builder = WireMockMapper::MatchBuilder.new(nil)
|
59
|
+
builder.matching 'foo'
|
60
|
+
expect(builder.to_hash).to eq(matches: 'foo')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'matching_json_path' do
|
65
|
+
it 'returns a hash of { matchesJsonPath => value }' do
|
66
|
+
builder = WireMockMapper::MatchBuilder.new(nil)
|
67
|
+
builder.matching_json_path 'foo'
|
68
|
+
expect(builder.to_hash).to eq(matchesJsonPath: 'foo')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'matching_xpath' do
|
73
|
+
it 'returns a hash of { matchesXPath => value }' do
|
74
|
+
builder = WireMockMapper::MatchBuilder.new(nil)
|
75
|
+
builder.matching_xpath 'foo'
|
76
|
+
expect(builder.to_hash).to eq(matchesXPath: 'foo')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'not_matching' do
|
81
|
+
it 'returns a hash of { doesNotMatch => value }' do
|
82
|
+
builder = WireMockMapper::MatchBuilder.new(nil)
|
83
|
+
builder.not_matching 'foo'
|
84
|
+
expect(builder.to_hash).to eq(doesNotMatch: 'foo')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -1,38 +1,117 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WireMockMapper::RequestBuilder do
|
4
|
-
|
4
|
+
describe 'receives_any' do
|
5
5
|
it 'sets the http method and url path' do
|
6
6
|
builder = WireMockMapper::RequestBuilder.new
|
7
|
-
builder.
|
7
|
+
builder.receives_any
|
8
8
|
result = builder.to_hash
|
9
|
-
expect(result[
|
10
|
-
expect(result['urlPath']).to eq('/some/path')
|
9
|
+
expect(result[:method]).to eq('ANY')
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
|
-
it '
|
13
|
+
describe 'receives_delete' do
|
14
|
+
it 'sets the http method and url path' do
|
15
|
+
builder = WireMockMapper::RequestBuilder.new
|
16
|
+
builder.receives_delete
|
17
|
+
result = builder.to_hash
|
18
|
+
expect(result[:method]).to eq('DELETE')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'receives_get' do
|
23
|
+
it 'sets the http method and url path' do
|
24
|
+
builder = WireMockMapper::RequestBuilder.new
|
25
|
+
builder.receives_get
|
26
|
+
result = builder.to_hash
|
27
|
+
expect(result[:method]).to eq('GET')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'receives_head' do
|
32
|
+
it 'sets the http method and url path' do
|
16
33
|
builder = WireMockMapper::RequestBuilder.new
|
17
|
-
builder.
|
34
|
+
builder.receives_head
|
18
35
|
result = builder.to_hash
|
19
|
-
expect(result[
|
36
|
+
expect(result[:method]).to eq('HEAD')
|
20
37
|
end
|
21
38
|
end
|
22
39
|
|
23
|
-
|
24
|
-
it '
|
40
|
+
describe 'receives_options' do
|
41
|
+
it 'sets the http method and url path' do
|
25
42
|
builder = WireMockMapper::RequestBuilder.new
|
26
|
-
builder.
|
43
|
+
builder.receives_options
|
27
44
|
result = builder.to_hash
|
28
|
-
expect(result[
|
45
|
+
expect(result[:method]).to eq('OPTIONS')
|
29
46
|
end
|
47
|
+
end
|
30
48
|
|
31
|
-
|
49
|
+
describe 'receives_put' do
|
50
|
+
it 'sets the http method and url path' do
|
32
51
|
builder = WireMockMapper::RequestBuilder.new
|
33
|
-
builder.
|
52
|
+
builder.receives_put
|
34
53
|
result = builder.to_hash
|
35
|
-
expect(result[
|
54
|
+
expect(result[:method]).to eq('PUT')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'receives_post' do
|
59
|
+
it 'sets the http method and url path' do
|
60
|
+
builder = WireMockMapper::RequestBuilder.new
|
61
|
+
builder.receives_post
|
62
|
+
result = builder.to_hash
|
63
|
+
expect(result[:method]).to eq('POST')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'receives_trace' do
|
68
|
+
it 'sets the http method and url path' do
|
69
|
+
builder = WireMockMapper::RequestBuilder.new
|
70
|
+
builder.receives_trace
|
71
|
+
result = builder.to_hash
|
72
|
+
expect(result[:method]).to eq('TRACE')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'with_basic_auth' do
|
77
|
+
it 'adds basic auth' do
|
78
|
+
builder = WireMockMapper::RequestBuilder.new
|
79
|
+
builder.with_basic_auth('ike', '123456')
|
80
|
+
expect(builder.to_hash[:basicAuth]).to eq(username: 'ike', password: '123456')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'with_body' do
|
85
|
+
it 'returns a MatchBuilder' do
|
86
|
+
builder = WireMockMapper::RequestBuilder.new
|
87
|
+
expect(builder.with_body).to be_a(WireMockMapper::MatchBuilder)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'adds the matcher to bodyPatterns' do
|
91
|
+
builder = WireMockMapper::RequestBuilder.new
|
92
|
+
matcher = builder.with_body
|
93
|
+
expect(builder.to_hash).to eq(bodyPatterns: [matcher])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'with_cookie' do
|
98
|
+
it 'returns a MatchBuilder' do
|
99
|
+
builder = WireMockMapper::RequestBuilder.new
|
100
|
+
expect(builder.with_cookie(:whatever)).to be_a(WireMockMapper::MatchBuilder)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'with_header' do
|
105
|
+
it 'returns a MatchBuilder' do
|
106
|
+
builder = WireMockMapper::RequestBuilder.new
|
107
|
+
expect(builder.with_header(:whatever)).to be_a(WireMockMapper::MatchBuilder)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe 'with_query_params' do
|
112
|
+
it 'returns a MatchBuilder' do
|
113
|
+
builder = WireMockMapper::RequestBuilder.new
|
114
|
+
expect(builder.with_query_params(:whatever)).to be_a(WireMockMapper::MatchBuilder)
|
36
115
|
end
|
37
116
|
end
|
38
117
|
end
|
@@ -1,19 +1,54 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe WireMockMapper::ResponseBuilder do
|
4
|
-
|
4
|
+
describe 'with_body' do
|
5
5
|
it 'adds the body' do
|
6
6
|
builder = WireMockMapper::ResponseBuilder.new
|
7
7
|
builder.with_body('some body')
|
8
8
|
result = builder.to_hash
|
9
|
-
expect(result[
|
9
|
+
expect(result[:body]).to eq('some body')
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'converts value to_json if it is not a string' do
|
13
13
|
builder = WireMockMapper::ResponseBuilder.new
|
14
14
|
builder.with_body(some: 'hash')
|
15
15
|
result = builder.to_hash
|
16
|
-
expect(result[
|
16
|
+
expect(result[:body]).to eq('{"some":"hash"}')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'with_header' do
|
21
|
+
it 'adds the header' do
|
22
|
+
builder = WireMockMapper::ResponseBuilder.new
|
23
|
+
builder.with_header('key', 'value')
|
24
|
+
result = builder.to_hash
|
25
|
+
expect(result[:headers]).to eq('key' => 'value')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'adds multiple headers' do
|
29
|
+
builder = WireMockMapper::ResponseBuilder.new
|
30
|
+
builder.with_header('key', 'value')
|
31
|
+
builder.with_header('another key', 'another value')
|
32
|
+
result = builder.to_hash
|
33
|
+
expect(result[:headers]).to eq('key' => 'value', 'another key' => 'another value')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'with_status' do
|
38
|
+
it 'adds the status code' do
|
39
|
+
builder = WireMockMapper::ResponseBuilder.new
|
40
|
+
builder.with_status(400)
|
41
|
+
result = builder.to_hash
|
42
|
+
expect(result[:status]).to eq(400)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'with_status_message' do
|
47
|
+
it 'adds the status message' do
|
48
|
+
builder = WireMockMapper::ResponseBuilder.new
|
49
|
+
builder.with_status_message('message')
|
50
|
+
result = builder.to_hash
|
51
|
+
expect(result[:statusMessage]).to eq('message')
|
17
52
|
end
|
18
53
|
end
|
19
54
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/url_match_builder'
|
3
|
+
|
4
|
+
describe WireMockMapper::MatchBuilder do
|
5
|
+
context 'initialized with path = true' do
|
6
|
+
let(:builder) { WireMockMapper::UrlMatchBuilder.new(nil, true) }
|
7
|
+
|
8
|
+
describe 'equal_to' do
|
9
|
+
it 'sets the return of to_hash to {urlPath: value}' do
|
10
|
+
builder.equal_to '/some/path'
|
11
|
+
expect(builder.to_hash).to eq(urlPath: '/some/path')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'matching' do
|
16
|
+
it 'sets the return of to_hash to {urlPathPattern: value}' do
|
17
|
+
builder.matching '/some/path'
|
18
|
+
expect(builder.to_hash).to eq(urlPathPattern: '/some/path')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'initialized with path = false' do
|
24
|
+
let(:builder) { WireMockMapper::UrlMatchBuilder.new(nil) }
|
25
|
+
|
26
|
+
describe 'equal_to' do
|
27
|
+
it 'sets the return of to_hash to {url: value}' do
|
28
|
+
builder.equal_to '/some/path'
|
29
|
+
expect(builder.to_hash).to eq(url: '/some/path')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'matching' do
|
34
|
+
it 'sets the return of to_hash to {urlPattern: value}' do
|
35
|
+
builder.matching '/some/path'
|
36
|
+
expect(builder.to_hash).to eq(urlPattern: '/some/path')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -14,9 +14,10 @@ describe WireMockMapper do
|
|
14
14
|
stub_request(:post, "#{url}/__admin/mappings/new").with(body: expected_request_body)
|
15
15
|
|
16
16
|
WireMockMapper.create_mapping(url) do |request, respond|
|
17
|
-
request.
|
18
|
-
.
|
19
|
-
.
|
17
|
+
request.receives_post
|
18
|
+
.with_url_path.equal_to('/some/path')
|
19
|
+
.with_header('some_header').equal_to('some header value')
|
20
|
+
.with_body.matching('some request body')
|
20
21
|
|
21
22
|
respond.with_body('some response body')
|
22
23
|
end
|
data/wiremock_mapper.gemspec
CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
23
|
spec.add_development_dependency 'codeclimate-test-reporter'
|
24
|
-
spec.add_development_dependency 'coveralls'
|
25
24
|
spec.add_development_dependency 'pry'
|
26
25
|
spec.add_development_dependency 'rake'
|
27
26
|
spec.add_development_dependency 'rspec'
|
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.2.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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: coveralls
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: pry
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,13 +111,17 @@ files:
|
|
125
111
|
- README.md
|
126
112
|
- Rakefile
|
127
113
|
- lib/configuration.rb
|
114
|
+
- lib/match_builder.rb
|
128
115
|
- lib/request_builder.rb
|
129
116
|
- lib/response_builder.rb
|
117
|
+
- lib/url_match_builder.rb
|
130
118
|
- lib/wiremock_mapper.rb
|
131
119
|
- spec/configuration_spec.rb
|
120
|
+
- spec/match_builder_spec.rb
|
132
121
|
- spec/request_builder_spec.rb
|
133
122
|
- spec/response_builder_spec.rb
|
134
123
|
- spec/spec_helper.rb
|
124
|
+
- spec/url_match_builder_spec.rb
|
135
125
|
- spec/wiremock_mapper_spec.rb
|
136
126
|
- wiremock_mapper.gemspec
|
137
127
|
homepage: http://github.com/ike18t/wiremock_mapper
|
@@ -160,7 +150,9 @@ specification_version: 4
|
|
160
150
|
summary: Ruby DSL for setting up WireMock mappings
|
161
151
|
test_files:
|
162
152
|
- spec/configuration_spec.rb
|
153
|
+
- spec/match_builder_spec.rb
|
163
154
|
- spec/request_builder_spec.rb
|
164
155
|
- spec/response_builder_spec.rb
|
165
156
|
- spec/spec_helper.rb
|
157
|
+
- spec/url_match_builder_spec.rb
|
166
158
|
- spec/wiremock_mapper_spec.rb
|