wiremock_mapper 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86b9b09304308e135c6985a62ce777ad25cd2e34
4
+ data.tar.gz: c01087f79319cdc5db8e754f8ec7574e000ffdca
5
+ SHA512:
6
+ metadata.gz: b6ffe19295fa0caad4fb1e2f7f1b3800566fd743ba6d14d39d2c1573011a1d9f8f93655e852cb0bf43357dd93f7846085e3ab26cce472b2bff64c6082b0bbe5a
7
+ data.tar.gz: 015d5a5678db555717bca635d9a96003ebc00a0a4d4e74029b0c5ab567ae01f3c3f1da1ecad604b85f9618fbbc1148c7761044de40e884be7d2c686ccf9f8cc1
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ tags
2
+ .DS_Store
3
+ vendor
4
+ .bundle
5
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+
4
+ Style/AccessorMethodName:
5
+ Enabled: false
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ Style/FrozenStringLiteralComment:
11
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,21 @@
1
+ language: ruby
2
+ script: 'bundle exec rake'
3
+ cache: bundler
4
+ rvm:
5
+ - 2.0.0
6
+ - 2.3.0
7
+ - ruby-head
8
+ env:
9
+ - RUBY_PLATFORM="x86_64-linux"
10
+ - RUBY_PLATFORM="x86_64-darwin11.3.0"
11
+ - CODECLIMATE_REPO_TOKEN=91712672ab3a13c6201c11ea34ac37697a7758868a3b8fd0eddf9c03bde782af
12
+ before_install:
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: ruby-head
16
+ notifications:
17
+ email:
18
+ recipients:
19
+ - ike18t@gmail.com
20
+ on_success: change
21
+ on_failure: change
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Isaac Datlof
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ [![Build Status](https://travis-ci.org/ike18t/wiremock_mapper.png?branch=master)](https://travis-ci.org/ike18t/wiremock_mapper)
2
+ [![Code Climate](https://codeclimate.com/github/ike18t/wiremock_mapper/badges/gpa.svg)](https://codeclimate.com/github/ike18t/wiremock_mapper)
3
+ [![Test Coverage](https://codeclimate.com/github/ike18t/wiremock_mapper/badges/coverage.svg)](https://codeclimate.com/github/ike18t/wiremock_mapper/coverage)
4
+ [![Dependency Status](https://gemnasium.com/badges/github.com/ike18t/wiremock_mapper.svg)](https://gemnasium.com/github.com/ike18t/wiremock_mapper)
5
+
6
+ ##WireMockMapper
7
+
8
+ **Ruby DSL for setting up WireMock mappings**
9
+
10
+ ####Usage Example####
11
+ ```ruby
12
+ WireMockMapper::Configuration.set_wiremock_url('http://my_wiremock.com')
13
+ WireMockMapper::Configuration.add_header('Some-Header', 'some_value')
14
+
15
+ WireMockMapper.create_mapping do |request, respond|
16
+ request.post_to_path('path/to/stub')
17
+ .with_header('Some-Other-Header', 'some_other_value')
18
+ .with_body(foo: bar)
19
+ respond.with_body('good job!')
20
+ end
21
+ ```
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'rubocop/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
7
+
8
+ RuboCop::RakeTask.new(:rubocop) do |task|
9
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
10
+ task.fail_on_error = true
11
+ end
@@ -0,0 +1,18 @@
1
+ module WireMockMapper
2
+ class Configuration
3
+ @request_headers = {}
4
+ @wiremock_url = ''
5
+
6
+ class << self
7
+ attr_reader :request_headers, :wiremock_url
8
+
9
+ def add_request_header(key, value)
10
+ @request_headers[key] = value
11
+ end
12
+
13
+ def set_wiremock_url(url)
14
+ @wiremock_url = url
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ module WireMockMapper
2
+ class RequestBuilder
3
+ def initialize(configuration = nil)
4
+ @options = {}
5
+ @options['headers'] ||= {}
6
+ @options['headers'] = configuration.request_headers if configuration
7
+ end
8
+
9
+ def posts_to_path(url)
10
+ @options['method'] = 'POST'
11
+ @options['urlPath'] = url
12
+ self
13
+ end
14
+
15
+ def with_header(key, value)
16
+ @options['headers'][key] = { equalTo: value }
17
+ self
18
+ end
19
+
20
+ def with_body(value)
21
+ @options['bodyPatterns'] ||= []
22
+ value = value.to_json unless value.is_a? String
23
+ @options['bodyPatterns'] << { matches: value }
24
+ self
25
+ end
26
+
27
+ def to_hash(*)
28
+ @options
29
+ end
30
+
31
+ def to_json(*)
32
+ @options.to_json
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ module WireMockMapper
2
+ class ResponseBuilder
3
+ def initialize
4
+ @options = {}
5
+ end
6
+
7
+ def with_body(value)
8
+ value = value.to_json unless value.is_a? String
9
+ @options['body'] = value
10
+ self
11
+ end
12
+
13
+ def to_hash(*)
14
+ @options
15
+ end
16
+
17
+ def to_json(*)
18
+ @options.to_json
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ require 'net/http'
2
+ require_relative 'configuration'
3
+ require_relative 'request_builder'
4
+ require_relative 'response_builder'
5
+
6
+ module WireMockMapper
7
+ VERSION = '0.1.0'.freeze
8
+
9
+ def self.create_mapping(url = Configuration.wiremock_url)
10
+ request_builder = RequestBuilder.new
11
+ response_builder = ResponseBuilder.new
12
+
13
+ yield request_builder, response_builder
14
+
15
+ send(url, request: request_builder, response: response_builder)
16
+ end
17
+
18
+ WIREMOCK_NEW_MAPPING_PATH = '__admin/mappings/new'.freeze
19
+ private_constant :WIREMOCK_NEW_MAPPING_PATH
20
+
21
+ def self.send(url, body)
22
+ uri = URI(URI.join(url, WIREMOCK_NEW_MAPPING_PATH))
23
+ http = Net::HTTP.new(uri.host, uri.port)
24
+ request = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
25
+ request.body = body.to_json
26
+ http.request(request)
27
+ end
28
+ private_class_method :send
29
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe WireMockMapper::Configuration do
4
+ context 'request_header' do
5
+ it 'adds the request header' do
6
+ WireMockMapper::Configuration.add_request_header('some', 'header')
7
+ expect(WireMockMapper::Configuration.request_headers).to eq('some' => 'header')
8
+ end
9
+ end
10
+
11
+ context 'wiremock_url' do
12
+ it 'sets the wiremock url' do
13
+ WireMockMapper::Configuration.set_wiremock_url('http://whereever.com')
14
+ expect(WireMockMapper::Configuration.wiremock_url).to eq('http://whereever.com')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe WireMockMapper::RequestBuilder do
4
+ context 'posts_to_path' do
5
+ it 'sets the http method and url path' do
6
+ builder = WireMockMapper::RequestBuilder.new
7
+ builder.posts_to_path('/some/path')
8
+ result = builder.to_hash
9
+ expect(result['method']).to eq('POST')
10
+ expect(result['urlPath']).to eq('/some/path')
11
+ end
12
+ end
13
+
14
+ context 'with_header' do
15
+ it 'adds the header' do
16
+ builder = WireMockMapper::RequestBuilder.new
17
+ builder.with_header('some', 'header')
18
+ result = builder.to_hash
19
+ expect(result['headers']).to eq('some' => { equalTo: 'header' })
20
+ end
21
+ end
22
+
23
+ context 'with_body' do
24
+ it 'adds the body' do
25
+ builder = WireMockMapper::RequestBuilder.new
26
+ builder.with_body('some body')
27
+ result = builder.to_hash
28
+ expect(result['bodyPatterns']).to eq([{ matches: 'some body' }])
29
+ end
30
+
31
+ it 'converts value to_json if it is not a string' do
32
+ builder = WireMockMapper::RequestBuilder.new
33
+ builder.with_body(some: 'hash')
34
+ result = builder.to_hash
35
+ expect(result['bodyPatterns']).to eq([{ matches: '{"some":"hash"}' }])
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe WireMockMapper::ResponseBuilder do
4
+ context 'with_body' do
5
+ it 'adds the body' do
6
+ builder = WireMockMapper::ResponseBuilder.new
7
+ builder.with_body('some body')
8
+ result = builder.to_hash
9
+ expect(result['body']).to eq('some body')
10
+ end
11
+
12
+ it 'converts value to_json if it is not a string' do
13
+ builder = WireMockMapper::ResponseBuilder.new
14
+ builder.with_body(some: 'hash')
15
+ result = builder.to_hash
16
+ expect(result['body']).to eq('{"some":"hash"}')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ require 'webmock/rspec'
2
+ require 'codeclimate-test-reporter'
3
+
4
+ CodeClimate::TestReporter.start
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe WireMockMapper do
4
+ context 'control' do
5
+ it 'posts the correct json to the wiremock url' do
6
+ url = 'http://nowhere.com'
7
+ expected_request_body = { request: { 'method' => 'POST',
8
+ 'urlPath' => '/some/path',
9
+ 'headers' => { 'some_header' => { 'equalTo' => 'some header value' } },
10
+ 'bodyPatterns' => [
11
+ { 'matches' => 'some request body' }
12
+ ] },
13
+ response: { 'body' => 'some response body' } }
14
+ stub_request(:post, "#{url}/__admin/mappings/new").with(body: expected_request_body)
15
+
16
+ WireMockMapper.create_mapping(url) do |request, respond|
17
+ request.posts_to_path('/some/path')
18
+ .with_header('some_header', 'some header value')
19
+ .with_body('some request body')
20
+
21
+ respond.with_body('some response body')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
2
+ require 'wiremock_mapper'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'wiremock_mapper'
6
+ spec.version = WireMockMapper::VERSION
7
+ spec.platform = Gem::Platform::RUBY
8
+ spec.required_ruby_version = '>= 2.0.0'
9
+ spec.authors = ['Isaac Datlof']
10
+ spec.email = 'ike18t@gmail.com'
11
+
12
+ spec.homepage = 'http://github.com/ike18t/wiremock_mapper'
13
+ spec.license = 'MIT'
14
+ spec.summary = 'Ruby DSL for setting up WireMock mappings'
15
+ spec.description = spec.summary
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.extra_rdoc_files = ['LICENSE.txt', 'README.md']
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'codeclimate-test-reporter'
24
+ spec.add_development_dependency 'coveralls'
25
+ spec.add_development_dependency 'pry'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'rubocop'
29
+ spec.add_development_dependency 'webmock'
30
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wiremock_mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Isaac Datlof
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: codeclimate-test-reporter
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Ruby DSL for setting up WireMock mappings
112
+ email: ike18t@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.md
118
+ files:
119
+ - ".gitignore"
120
+ - ".rubocop.yml"
121
+ - ".ruby-version"
122
+ - ".travis.yml"
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - lib/configuration.rb
128
+ - lib/request_builder.rb
129
+ - lib/response_builder.rb
130
+ - lib/wiremock_mapper.rb
131
+ - spec/configuration_spec.rb
132
+ - spec/request_builder_spec.rb
133
+ - spec/response_builder_spec.rb
134
+ - spec/spec_helper.rb
135
+ - spec/wiremock_mapper_spec.rb
136
+ - wiremock_mapper.gemspec
137
+ homepage: http://github.com/ike18t/wiremock_mapper
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: 2.0.0
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.5.1
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Ruby DSL for setting up WireMock mappings
161
+ test_files:
162
+ - spec/configuration_spec.rb
163
+ - spec/request_builder_spec.rb
164
+ - spec/response_builder_spec.rb
165
+ - spec/spec_helper.rb
166
+ - spec/wiremock_mapper_spec.rb