service_mock 0.1

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: 7b37e4d10e20aa30369b8abcd13f39b1d22f69f8
4
+ data.tar.gz: e26de5260f69bb399cbb0397f35e56661ed008c0
5
+ SHA512:
6
+ metadata.gz: 6ea1b4149e6b18bcbe2c6a87baf26d3cdcd0b30c3e01584282925e2ac2c81550ae90c0510f6d7e57a80a77ed2ab70423560a9a458d7e0f1e58f3cd3c21379f3e
7
+ data.tar.gz: a7c25d93585fd9767f742ae4a70a5404f329b0ba8f7dc27c7366ee6b1e9fe60ed1ead56b54ddc8da8db8504411315b881598d5b6a72b4129a69f2640ea50403d
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
11
+ *.xml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.4
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jeff.morgan@leandog.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'guard-rspec'
4
+
5
+ # Specify your gem's dependencies in service_mock.gemspec
6
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,16 @@
1
+
2
+ guard :rspec, cmd: "bundle exec rspec" do
3
+ require "guard/rspec/dsl"
4
+ dsl = Guard::RSpec::Dsl.new(self)
5
+
6
+ # RSpec files
7
+ rspec = dsl.rspec
8
+ watch(rspec.spec_helper) { rspec.spec_dir }
9
+ watch(rspec.spec_support) { rspec.spec_dir }
10
+ watch(rspec.spec_files)
11
+
12
+ # Ruby files
13
+ ruby = dsl.ruby
14
+ dsl.watch_spec_files_for(ruby.lib_files)
15
+
16
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jeff Morgan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # ServiceMock
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/service_mock`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'service_mock'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install service_mock
22
+
23
+ ## Usage
24
+
25
+
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/service_mock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "service_mock"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,89 @@
1
+ module ServiceMock
2
+ module CommandLineOptions
3
+
4
+ OPTIONS = [:port, :https_port, :verbose, :root_dir, :record_mappings, :proxy_all,
5
+ :match_headers, :proxy_via, :https_keystore, :keystore_password,
6
+ :enable_browser_proxying, :preserve_host_header, :https_truststore,
7
+ :truststore_password, :https_require_client_cert, :no_request_journal,
8
+ :max_request_journal_entries]
9
+ NOT_IMPLEMENTED = [:container_threads, :jetty_acceptor_threads, :jetty_accept_queue_size,
10
+ :jetty_header_buffer_size, :extensions, :help]
11
+
12
+ attr_accessor *OPTIONS
13
+
14
+ def command_line_options
15
+ OPTIONS.inject([]) do |value, option|
16
+ value += self.send("#{option}_command") if self.send(option).to_s.size > 0
17
+ value
18
+ end
19
+ end
20
+
21
+ def port_command
22
+ ['--port', port.to_s]
23
+ end
24
+
25
+ def https_port_command
26
+ ['--https-port', https_port.to_s]
27
+ end
28
+
29
+ def verbose_command
30
+ ['--verbose']
31
+ end
32
+
33
+ def root_dir_command
34
+ ['--root-dir', root_dir]
35
+ end
36
+
37
+ def record_mappings_command
38
+ ['--record-mappings']
39
+ end
40
+
41
+ def proxy_all_command
42
+ ["--proxy-all=#{proxy_all.to_s}"]
43
+ end
44
+
45
+ def match_headers_command
46
+ ["--match-headers=\"#{match_headers}\""]
47
+ end
48
+
49
+ def proxy_via_command
50
+ ["--proxy-via #{proxy_via}"]
51
+ end
52
+
53
+ def https_keystore_command
54
+ ["--https-keystore #{https_keystore}"]
55
+ end
56
+
57
+ def keystore_password_command
58
+ ["--keystore-password #{keystore_password}"]
59
+ end
60
+
61
+ def enable_browser_proxying_command
62
+ ['--enable-browser-proxying']
63
+ end
64
+
65
+ def preserve_host_header_command
66
+ ['--preserve-host-header']
67
+ end
68
+
69
+ def https_truststore_command
70
+ ["--https-truststore #{https_truststore}"]
71
+ end
72
+
73
+ def truststore_password_command
74
+ ["--truststore-password #{truststore_password}"]
75
+ end
76
+
77
+ def https_require_client_cert_command
78
+ ['--https-require-client-cert']
79
+ end
80
+
81
+ def no_request_journal_command
82
+ ['--no-request-journal']
83
+ end
84
+
85
+ def max_request_journal_entries_command
86
+ ["--max-request-journal-entries #{max_request_journal_entries}"]
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,21 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'service_mock/server'
4
+
5
+ module ServiceMock
6
+ module Rake
7
+ class BaseTask < ::Rake::TaskLib
8
+ include ::Rake::DSL if defined?(::Rake::DSL)
9
+
10
+ attr_reader :name, :server
11
+
12
+ def initialize(name, wiremock_version, working_directory='config/mocks')
13
+ @name = name
14
+ @server = ::ServiceMock::Server.new(wiremock_version, working_directory)
15
+ yield server if block_given?
16
+ define_task
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'service_mock/server'
4
+ require 'service_mock/rake/base_task'
5
+
6
+ module ServiceMock
7
+ module Rake
8
+ class StartServerTask < ServiceMock::Rake::BaseTask
9
+
10
+ def define_task
11
+ desc 'Start the WireMock Process'
12
+ task name do
13
+ server.start
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'service_mock/server'
4
+ require 'service_mock/rake/base_task'
5
+
6
+ module ServiceMock
7
+ module Rake
8
+ class StopServerTask < ServiceMock::Rake::BaseTask
9
+
10
+ def define_task
11
+ desc 'Stop the WireMock Process'
12
+ task name do
13
+ server.stop
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'erb'
2
+
3
+ module ServiceMock
4
+ module RenderSubTemplate
5
+
6
+ def render(path)
7
+ content = File.read(File.expand_path(path))
8
+ template = ERB.new(content)
9
+ template.result(binding)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,97 @@
1
+ require 'childprocess'
2
+ require 'net/http'
3
+ require 'erb'
4
+ require 'ostruct'
5
+ require 'service_mock/render_subtemplate'
6
+
7
+ module ServiceMock
8
+ class Server
9
+ include CommandLineOptions
10
+
11
+ attr_accessor :inherit_io, :wait_for_process, :remote_host
12
+ attr_reader :wiremock_version, :working_directory, :process
13
+
14
+ def initialize(wiremock_version, working_directory='config/mocks')
15
+ @wiremock_version = wiremock_version
16
+ @working_directory = working_directory
17
+ self.inherit_io = false
18
+ self.wait_for_process = false
19
+ end
20
+
21
+ def start
22
+ yield self if block_given?
23
+ start_process
24
+ end
25
+
26
+ def stop
27
+ yield self if block_given?
28
+ http.post('/__admin/shutdown', '')
29
+ end
30
+
31
+ def stub(message)
32
+ yield self if block_given?
33
+ http.post('/__admin/mappings/new', message)
34
+ end
35
+
36
+ def stub_with_file(filename)
37
+ yield self if block_given?
38
+ content = File.open(filename, 'rb') {|file| file.read}
39
+ stub(content)
40
+ end
41
+
42
+ def stub_with_erb(filename, hsh)
43
+ yield self if block_given?
44
+ template = File.open(filename, 'rb') {|file| file.read}
45
+ erb_content = ERB.new(template).result(data_binding(hsh))
46
+ stub(erb_content)
47
+ end
48
+
49
+ def save
50
+ yield self if block_given?
51
+ http.post('/__admin/mappings/save', '')
52
+ end
53
+
54
+ def reset_mappings
55
+ yield self if block_given?
56
+ http.post('/__admin/mappings/reset', '')
57
+ end
58
+
59
+ def reset_all
60
+ yield self if block_given?
61
+ http.post('/__admin/reset', '')
62
+ end
63
+
64
+ private
65
+
66
+
67
+ def data_binding(hsh)
68
+ OpenStruct.include ::ServiceMock::RenderSubTemplate
69
+ OpenStruct.new(hsh).instance_eval { binding }
70
+ end
71
+
72
+ def start_process
73
+ @process = ChildProcess.build(*(start_command + command_line_options))
74
+ @process.cwd = working_directory
75
+ @process.io.inherit! if inherit_io
76
+ @process.start
77
+ @process.wait if wait_for_process
78
+ end
79
+
80
+ def start_command
81
+ ['java', '-jar', "wiremock-#{wiremock_version}.jar"]
82
+ end
83
+
84
+ def http
85
+ Net::HTTP.new(admin_host, admin_port)
86
+ end
87
+
88
+ def admin_host
89
+ "#{remote_host ? remote_host : 'localhost'}"
90
+ end
91
+
92
+ def admin_port
93
+ "#{port ? port.to_s : '8080'}"
94
+ end
95
+
96
+ end
97
+ end
@@ -0,0 +1,3 @@
1
+ module ServiceMock
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'service_mock/version'
2
+ require 'service_mock/command_line_options'
3
+ require 'service_mock/server'
4
+
5
+ module ServiceMock
6
+
7
+ end
8
+
9
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'service_mock/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "service_mock"
8
+ spec.version = ServiceMock::VERSION
9
+ spec.authors = ["Jeffrey S. Morgan"]
10
+ spec.email = ["jeff.morgan@leandog.com"]
11
+
12
+ spec.summary = %q{Simple wrapper over WireMock}
13
+ spec.description = %q{Simple wrapper over WireMock}
14
+ spec.homepage = "https://github.com/cheezy/service_mock"
15
+
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "childprocess", "~>0.5"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: service_mock
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Jeffrey S. Morgan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: childprocess
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Simple wrapper over WireMock
70
+ email:
71
+ - jeff.morgan@leandog.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Guardfile
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - config/mocks/wiremock-1.58-standalone.jar
88
+ - config/mocks/wiremock-standalone-2.0.10-beta.jar
89
+ - lib/service_mock.rb
90
+ - lib/service_mock/command_line_options.rb
91
+ - lib/service_mock/rake/base_task.rb
92
+ - lib/service_mock/rake/start_server_task.rb
93
+ - lib/service_mock/rake/stop_server_task.rb
94
+ - lib/service_mock/render_subtemplate.rb
95
+ - lib/service_mock/server.rb
96
+ - lib/service_mock/version.rb
97
+ - service_mock.gemspec
98
+ homepage: https://github.com/cheezy/service_mock
99
+ licenses: []
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.3
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Simple wrapper over WireMock
121
+ test_files: []
122
+ has_rdoc: