wiremock_mapper 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,28 +3,32 @@
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
5
  [![Gem Version](https://badge.fury.io/rb/wiremock_mapper.svg)](https://badge.fury.io/rb/wiremock_mapper)
6
+ [![Documentation](http://inch-ci.org/github/ike18t/wiremock_mapper.svg?branch=master)](http://inch-ci.org/github/ike18t/wiremock_mapper)
6
7
 
7
8
  ##WireMockMapper
8
9
 
9
10
  **Ruby DSL for setting up [WireMock](http://wiremock.org/) mappings**
10
11
 
12
+ ####Documentation
13
+ Can be found at [RubyDoc.info](http://www.rubydoc.info/gems/wiremock_mapper)
14
+
11
15
  ####Usage Example
12
16
  ```ruby
13
17
  WireMockMapper::Configuration.set_wiremock_url('http://my_wiremock.com')
14
18
 
15
19
  WireMockMapper::Configuration.create_global_mapping do |request, respond|
16
20
  request.with_header('Some-Header').equal_to('some_value')
17
- .with_cookie('Some-Cookie').equal_to('some_cookie_value')
21
+ .with_cookie('Some-Cookie').not_matching('some_cookie_value')
18
22
  respond.with_status(200)
19
23
  end
20
24
 
21
25
  WireMockMapper.create_mapping do |request, respond|
22
- request.is_a_post
23
- .with_url_path.equal_to('path/to/stub')
24
- .with_header('Some-Other-Header').equal_to('some_other_value')
25
- .with_cookie('Some-Other-Cookie').equal_to('some_other_cookie_value')
26
- .with_body.equal_to(foo: bar)
27
- respond.with_body('good job!')
26
+ request.is_a_post
27
+ .with_url_path.equal_to('path/to/stub')
28
+ .with_header('Some-Other-Header').equal_to('some_other_value')
29
+ .with_cookie('Some-Other-Cookie').containing('some_other_cookie_value')
30
+ .with_body.equal_to(foo: bar)
31
+ respond.with_body('good job!')
28
32
  end
29
33
  ```
30
34
 
@@ -0,0 +1,10 @@
1
+ module WireMockMapper
2
+ module Builders
3
+ module Helpers
4
+ def self.regexp_to_string regexp
5
+ /^\/(.*)\/$/.match(regexp.inspect)[1]
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -58,12 +58,13 @@ module WireMockMapper
58
58
  @request_builder
59
59
  end
60
60
 
61
- # Match if attribute value matches the regex_string
62
- # @param regex_string [String] xml to match against
61
+ # Match if attribute value matches the regexp
62
+ # @param regexp [String, Regexp] regexp to match against
63
63
  # @return [RequestBuilder] calling request builder for chaining additional attributes
64
- def matching(regex_string)
64
+ def matching(regexp)
65
+ regexp = Helpers.regexp_to_string regexp if regexp.is_a? Regexp
65
66
  @type = :matches
66
- @value = regex_string
67
+ @value = regexp
67
68
  @request_builder
68
69
  end
69
70
 
@@ -86,11 +87,12 @@ module WireMockMapper
86
87
  end
87
88
 
88
89
  # Match if attribute value does not match
89
- # @param regex_string [String] regex_string to match against
90
+ # @param regexp [Regexp, String] regexp to match against
90
91
  # @return [RequestBuilder] calling request builder for chaining additional attributes
91
- def not_matching(regex_string)
92
+ def not_matching(regexp)
93
+ regexp = Helpers.regexp_to_string regexp if regexp.is_a? Regexp
92
94
  @type = :doesNotMatch
93
- @value = regex_string
95
+ @value = regexp
94
96
  @request_builder
95
97
  end
96
98
 
@@ -14,6 +14,14 @@ module WireMockMapper
14
14
  self
15
15
  end
16
16
 
17
+ # Add a response delay
18
+ # @param milliseconds [String, Numeric] the delay duration in milliseconds
19
+ # @return [ResponseBuilder] response builder for chaining
20
+ def with_delay(milliseconds)
21
+ @options[:fixedDelayMilliseconds] = milliseconds
22
+ self
23
+ end
24
+
17
25
  # Add a response header
18
26
  # @param key [String] the key of the header
19
27
  # @param value [String] the value of the header
@@ -18,11 +18,12 @@ module WireMockMapper
18
18
  end
19
19
 
20
20
  # Expect url to match
21
- # @param regex_string [String] regex for url to match against
21
+ # @param regexp [Regexp, String] regex for url to match against
22
22
  # @return [RequestBuilder] calling request builder for chaining additional attributes
23
- def matching(regex_string)
23
+ def matching(regexp)
24
+ regexp = Helpers.regexp_to_string regexp if regexp.is_a? Regexp
24
25
  @type = @path ? :urlPathPattern : :urlPattern
25
- @url_or_pattern = regex_string
26
+ @url_or_pattern = regexp
26
27
  @request_builder
27
28
  end
28
29
 
@@ -53,6 +53,11 @@ describe WireMockMapper::Builders::MatchBuilder do
53
53
  builder.matching 'foo'
54
54
  expect(builder.to_hash).to eq(matches: 'foo')
55
55
  end
56
+
57
+ it 'converts the regex to a string and returns a hash of { matches => value }' do
58
+ builder.matching(/foo(s)?/)
59
+ expect(builder.to_hash).to eq(matches: 'foo(s)?')
60
+ end
56
61
  end
57
62
 
58
63
  describe 'matching_json_path' do
@@ -74,5 +79,10 @@ describe WireMockMapper::Builders::MatchBuilder do
74
79
  builder.not_matching 'foo'
75
80
  expect(builder.to_hash).to eq(doesNotMatch: 'foo')
76
81
  end
82
+
83
+ it 'converts the regex to a string and returns a hash of { doesNotMatch => value }' do
84
+ builder.matching(/foo(s)?/)
85
+ expect(builder.to_hash).to eq(matches: 'foo(s)?')
86
+ end
77
87
  end
78
88
  end
@@ -47,4 +47,12 @@ describe WireMockMapper::Builders::ResponseBuilder do
47
47
  expect(result[:statusMessage]).to eq('message')
48
48
  end
49
49
  end
50
+
51
+ describe 'with_delay' do
52
+ it 'adds the fixed delay milliseconds' do
53
+ builder.with_delay(1200)
54
+ result = builder.to_hash
55
+ expect(result[:fixedDelayMilliseconds]).to eq(1200)
56
+ end
57
+ end
50
58
  end
@@ -34,6 +34,11 @@ describe WireMockMapper::Builders::MatchBuilder do
34
34
  builder.matching '/some/path'
35
35
  expect(builder.to_hash).to eq(urlPattern: '/some/path')
36
36
  end
37
+
38
+ it 'sets the return of to_hash to {urlPattern: value}' do
39
+ builder.matching(/\/some(\/path)?/)
40
+ expect(builder.to_hash).to eq(urlPattern: '\/some(\/path)?')
41
+ end
37
42
  end
38
43
  end
39
44
  end
@@ -2,7 +2,7 @@ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'wiremock_mapper'
5
- spec.version = '0.9.0'
5
+ spec.version = '1.0.0'
6
6
  spec.platform = Gem::Platform::RUBY
7
7
  spec.required_ruby_version = '>= 1.9.3'
8
8
  spec.authors = ['Isaac Datlof']
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.9.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-26 00:00:00.000000000 Z
12
+ date: 2016-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: codeclimate-test-reporter
@@ -155,6 +155,7 @@ files:
155
155
  - LICENSE.txt
156
156
  - README.md
157
157
  - Rakefile
158
+ - lib/builders/helpers.rb
158
159
  - lib/builders/match_builder.rb
159
160
  - lib/builders/request_builder.rb
160
161
  - lib/builders/response_builder.rb