service_mock 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1aa60689ebd24a11f48adda0ac0600bbaca64f33
4
- data.tar.gz: c5268941a1cb1c4da7625aea988603295d3d43e2
3
+ metadata.gz: 02725e586c231125f3699c7d4a7c05eb5e24f021
4
+ data.tar.gz: d9b6df172a003051ef464d7238d71d0517cf4297
5
5
  SHA512:
6
- metadata.gz: 97a97333b7bfd3797c94cc6f48ad036ebe1f7efbc7bded9496716f9c48e0ff7aee44eb40957582d15fa4f789073886d2cd454aec12671a069351c1901c59dfcf
7
- data.tar.gz: 573c417700a631a1010705ee99df9ca1a92004aa1eea79441ea63cdca2aa473624c918a24cca2eac506bc5644eaa8373b8934264ba7cfdf16a8fb5799ab0eca0
6
+ metadata.gz: b59f560562bb2faf846a365862553fbf863222461205ea1334a16101422d4e236123e7b33ee490aa045b3012814e2d8c90941c3f652d0b8804013b170b43f681
7
+ data.tar.gz: 0d83e2092a146c20ed86e89f517b4f166de73c41ef9cf3e2a7e8fc2488a45a2b19b6aae2450393f1ce76fbc987d3df266efdd3bd3d12bc0031a3001c8a6b9c75
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ === Release 0.5
2
+ * Added new helper method to remove all whitespace
3
+ * Added ability to merge data when creating a set of stubs with StubCreator
4
+ * Added ability to change default working directory
5
+
1
6
  === Release 0.4 / 2016-07-20
2
7
  * Added new class (StubCreator) to create a set of stubs from a yaml file
3
8
 
data/README.md CHANGED
@@ -138,6 +138,42 @@ my_server.stub(string_containing_json_stub) do |server|
138
138
  end
139
139
  ```
140
140
 
141
+ ### Stubbing multiple services
142
+
143
+ It is often necessary to stub multiple service calls in order to
144
+ complete a test. ServiceMock has created a simple way to do this.
145
+ It is implemented in a class named `ServiceMock::StubCreator`.
146
+ This class has a single public method `create_stubs_with` which
147
+ takes the name of the name of a file that has the data for all
148
+ of the stubs you wish to create and optional data to merge with
149
+ that file. Also, when you create an instance of the class it
150
+ requires you to pass an instance of `ServiceMock::Server`.
151
+
152
+ At this time you need to setup everything in a specific directory
153
+ structure. The directory it looks for is `config/mocks/stubs`.
154
+ Inside that directory it looks for two additional directories -
155
+ `data` and `templates`. The data file needed by the call needs
156
+ be located in the `data` directory and the `ERB` files (templates)
157
+ that it references needs to be in the `templates` directory.
158
+
159
+ The structure of the data file drives the stubbing. Let's start
160
+ with an example.
161
+
162
+ ```yml
163
+ service1.erb:
164
+ first_name: Mickey
165
+ last_name: Mouse
166
+
167
+ service2.erb:
168
+ username: mmouse
169
+ password: secret
170
+ ```
171
+
172
+ With the above file the method call will mock to services. It will first
173
+ of all read the file `service1.erb` from the `templates` directory and
174
+ stub it passing the data that is associated. Next it will read the next
175
+ template file, etc.
176
+
141
177
  ### Other capabilities
142
178
 
143
179
  There are additional methods that provide access to the running WireMock
@@ -7,4 +7,8 @@ class String
7
7
  def escape_double_quotes
8
8
  self.gsub('"', "\\\"")
9
9
  end
10
+
11
+ def remove_whitespace
12
+ self.gsub("\n", "").gsub("\r", "").gsub("\t", "").gsub(" ", "")
13
+ end
10
14
  end
@@ -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 = ::ServiceMock::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
@@ -4,6 +4,40 @@ require 'yaml'
4
4
  # ServiceMock::StubCreator is a class that can stub a set
5
5
  # of services by reading a yaml file.
6
6
  #
7
+ # It is often necessary to stub multiple service calls in order to
8
+ # complete a test. ServiceMock has created a simple way to do this.
9
+ # It is implemented in a class named `ServiceMock::StubCreator`.
10
+ # This class has a single public method `create_stubs_with` which
11
+ # takes the name of the name of a file that has the data for all
12
+ # of the stubs you wish to create and optional data to merge with
13
+ # that file. Also, when you create an instance of the class it
14
+ # requires you to pass an instance of `ServiceMock::Server`.
15
+ #
16
+ # At this time you need to setup everything in a specific directory
17
+ # structure. The directory it looks for is `config/mocks/stubs`.
18
+ # Inside that directory it looks for two additional directories -
19
+ # `data` and `templates`. The data file needed by the call needs
20
+ # be located in the `data` directory and the `ERB` files (templates)
21
+ # that it references needs to be in the `templates` directory.
22
+ #
23
+ # The structure of the data file drives the stubbing. Let's start
24
+ # with an example.
25
+ #
26
+ # ```yml
27
+ # service1.erb:
28
+ # first_name: Mickey
29
+ # last_name: Mouse
30
+ #
31
+ # service2.erb:
32
+ # username: mmouse
33
+ # password: secret
34
+ # ```
35
+ #
36
+ # With the above file the method call will mock to services. It will first
37
+ # of all read the file `service1.erb` from the `templates` directory and
38
+ # stub it passing the data that is associated. Next it will read the next
39
+ # template file, etc.
40
+ #
7
41
 
8
42
  module ServiceMock
9
43
  class StubCreator
@@ -15,8 +49,9 @@ module ServiceMock
15
49
  validate_server
16
50
  end
17
51
 
18
- def create_stubs_with(data_file)
52
+ def create_stubs_with(data_file, to_merge = {})
19
53
  read_data(data_file)
54
+ merge_data(to_merge) unless to_merge.empty?
20
55
  create_stubs
21
56
  end
22
57
 
@@ -28,6 +63,12 @@ module ServiceMock
28
63
  @data = ::YAML.load(data_contents)
29
64
  end
30
65
 
66
+ def merge_data(to_merge)
67
+ data.each_key do |key|
68
+ data[key].merge!(to_merge[key])
69
+ end
70
+ end
71
+
31
72
  def create_stubs
32
73
  data.each_key do |key|
33
74
  template_file = "#{stubs_dir}/templates/#{key}"
@@ -36,7 +77,7 @@ module ServiceMock
36
77
  end
37
78
 
38
79
  def stubs_dir
39
- File.expand_path("#{::ServiceMock::WORKING_DIRECTORY}/stubs")
80
+ File.expand_path("#{::ServiceMock.working_directory}/stubs")
40
81
  end
41
82
 
42
83
  def validate_server
@@ -1,3 +1,3 @@
1
1
  module ServiceMock
2
- VERSION = "0.4"
2
+ VERSION = "0.5"
3
3
  end
data/lib/service_mock.rb CHANGED
@@ -24,8 +24,13 @@ require 'service_mock/rake/rake_tasks'
24
24
  #
25
25
  module ServiceMock
26
26
 
27
- WORKING_DIRECTORY = 'config/mocks'
27
+ def self.working_directory
28
+ @working_directory ||= 'config/mocks'
29
+ end
28
30
 
31
+ def working_directory=(value)
32
+ @working_directory = value
33
+ end
29
34
  end
30
35
 
31
36
 
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'
4
+ version: '0.5'
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-07-21 00:00:00.000000000 Z
11
+ date: 2016-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: childprocess