service_mock 0.3.1 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +3 -0
- data/lib/service_mock.rb +3 -0
- data/lib/service_mock/server.rb +5 -5
- data/lib/service_mock/stub_creator.rb +52 -0
- data/lib/service_mock/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1aa60689ebd24a11f48adda0ac0600bbaca64f33
|
4
|
+
data.tar.gz: c5268941a1cb1c4da7625aea988603295d3d43e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97a97333b7bfd3797c94cc6f48ad036ebe1f7efbc7bded9496716f9c48e0ff7aee44eb40957582d15fa4f789073886d2cd454aec12671a069351c1901c59dfcf
|
7
|
+
data.tar.gz: 573c417700a631a1010705ee99df9ca1a92004aa1eea79441ea63cdca2aa473624c918a24cca2eac506bc5644eaa8373b8934264ba7cfdf16a8fb5799ab0eca0
|
data/ChangeLog
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
=== Release 0.4 / 2016-07-20
|
2
|
+
* Added new class (StubCreator) to create a set of stubs from a yaml file
|
3
|
+
|
1
4
|
=== Release 0.3.1 / 2016-06-27
|
2
5
|
* Added remove_newlines method to String as a helper for rendering subtemplates
|
3
6
|
* Added escape_double_quotes method to String as a helper for rendering subtemplates
|
data/lib/service_mock.rb
CHANGED
@@ -3,6 +3,7 @@ require 'service_mock/version'
|
|
3
3
|
require 'service_mock/command_line_options'
|
4
4
|
require 'service_mock/server'
|
5
5
|
require 'service_mock/render_subtemplate'
|
6
|
+
require 'service_mock/stub_creator'
|
6
7
|
require 'service_mock/rake/rake_tasks'
|
7
8
|
|
8
9
|
#
|
@@ -23,6 +24,8 @@ require 'service_mock/rake/rake_tasks'
|
|
23
24
|
#
|
24
25
|
module ServiceMock
|
25
26
|
|
27
|
+
WORKING_DIRECTORY = 'config/mocks'
|
28
|
+
|
26
29
|
end
|
27
30
|
|
28
31
|
|
data/lib/service_mock/server.rb
CHANGED
@@ -17,18 +17,18 @@ require 'service_mock/render_subtemplate'
|
|
17
17
|
# When you create your instance of +ServiceMock::Server+ you need to provide
|
18
18
|
# some information. The required piece of data is the version of WireMock
|
19
19
|
# you will be using. If the name of the WireMock jar file you will be using
|
20
|
-
# is +wiremock-standalone-2.
|
21
|
-
# is +standalone-2.
|
20
|
+
# is +wiremock-standalone-2.1.1-beta.jar+ then the version you should provide
|
21
|
+
# is +standalone-2.1.1-beta+. In other words, take off the initial +wiremock-+
|
22
22
|
# and the trailing +.jar+ and this is your version. The other optional value
|
23
23
|
# you can provide is the working directory - the location where the WireMock
|
24
24
|
# jar is located. By default the working directory is set to +config/mocks+.
|
25
25
|
# You will initialize the server like this:
|
26
26
|
#
|
27
27
|
# # uses default working directory
|
28
|
-
# my_server = ServiceMock::Server.new('standalone-2.
|
28
|
+
# my_server = ServiceMock::Server.new('standalone-2.1.1-beta')
|
29
29
|
#
|
30
30
|
# # or this sets the working directory
|
31
|
-
# my_server = ServiceMock::Server.new('standalone-2.
|
31
|
+
# my_server = ServiceMock::Server.new('standalone-2.1.1-beta', '/path/to/jar')
|
32
32
|
#
|
33
33
|
# There are two additional values (inherit_io and wait_for_process) that
|
34
34
|
# are defaulted to +false+. If set to +true+, +inherit_io+ will cause our
|
@@ -45,7 +45,7 @@ module ServiceMock
|
|
45
45
|
attr_accessor :inherit_io, :wait_for_process, :remote_host
|
46
46
|
attr_reader :wiremock_version, :working_directory, :process
|
47
47
|
|
48
|
-
def initialize(wiremock_version, working_directory=
|
48
|
+
def initialize(wiremock_version, working_directory = ::ServiceMock::WORKING_DIRECTORY )
|
49
49
|
@wiremock_version = wiremock_version
|
50
50
|
@working_directory = working_directory
|
51
51
|
self.inherit_io = false
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
#
|
4
|
+
# ServiceMock::StubCreator is a class that can stub a set
|
5
|
+
# of services by reading a yaml file.
|
6
|
+
#
|
7
|
+
|
8
|
+
module ServiceMock
|
9
|
+
class StubCreator
|
10
|
+
|
11
|
+
attr_reader :server, :data
|
12
|
+
|
13
|
+
def initialize(server)
|
14
|
+
@server = server
|
15
|
+
validate_server
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_stubs_with(data_file)
|
19
|
+
read_data(data_file)
|
20
|
+
create_stubs
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def read_data(data_file)
|
26
|
+
filename = "#{stubs_dir}/data/#{data_file}"
|
27
|
+
data_contents = File.open(filename, 'rb') { |file| file.read }
|
28
|
+
@data = ::YAML.load(data_contents)
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_stubs
|
32
|
+
data.each_key do |key|
|
33
|
+
template_file = "#{stubs_dir}/templates/#{key}"
|
34
|
+
server.stub_with_erb(template_file, data[key])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def stubs_dir
|
39
|
+
File.expand_path("#{::ServiceMock::WORKING_DIRECTORY}/stubs")
|
40
|
+
end
|
41
|
+
|
42
|
+
def validate_server
|
43
|
+
error_message = "You must provide an instance of ::ServiceMock::Server!\n"
|
44
|
+
begin
|
45
|
+
raise error_message unless server.wiremock_version.length > 0 and
|
46
|
+
server.working_directory.length > 0
|
47
|
+
rescue
|
48
|
+
raise error_message
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/service_mock/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeffrey S. Morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: childprocess
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/service_mock/rake/stop_server_task.rb
|
95
95
|
- lib/service_mock/render_subtemplate.rb
|
96
96
|
- lib/service_mock/server.rb
|
97
|
+
- lib/service_mock/stub_creator.rb
|
97
98
|
- lib/service_mock/version.rb
|
98
99
|
- service_mock.gemspec
|
99
100
|
homepage: https://github.com/cheezy/service_mock
|