stub_requests 0.1.1 → 0.1.2
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 +4 -4
- data/.gitignore +5 -2
- data/.reek.yml +1 -0
- data/.rubocop.yml +33 -35
- data/.simplecov +14 -8
- data/.yardopts +1 -1
- data/CHANGELOG.md +4 -1
- data/README.md +19 -11
- data/Rakefile +1 -3
- data/bin/update_docs.sh +16 -0
- data/gemfiles/webmock_2.3.gemfile.lock +1 -1
- data/gemfiles/webmock_3.5.gemfile.lock +1 -1
- data/gemfiles/webmock_develop.gemfile.lock +1 -1
- data/lib/rspec/subject_as_lambda.rb +138 -0
- data/lib/stub_requests/api.rb +42 -8
- data/lib/stub_requests/argument_validation.rb +17 -6
- data/lib/stub_requests/configuration.rb +21 -0
- data/lib/stub_requests/core_ext/all.rb +4 -0
- data/lib/stub_requests/core_ext/array/extract_options.rb +32 -0
- data/lib/stub_requests/core_ext/class/attribute.rb +61 -0
- data/lib/stub_requests/core_ext/kernel/singleton_class.rb +12 -0
- data/lib/stub_requests/core_ext/module/redefine_method.rb +44 -0
- data/lib/stub_requests/core_ext/object/blank.rb +99 -155
- data/lib/stub_requests/endpoint.rb +28 -30
- data/lib/stub_requests/endpoint_registry.rb +18 -16
- data/lib/stub_requests/exceptions.rb +84 -0
- data/lib/stub_requests/hash_util.rb +2 -0
- data/lib/stub_requests/metrics/endpoint_stat.rb +97 -0
- data/lib/stub_requests/metrics/registry.rb +132 -0
- data/lib/stub_requests/metrics/stub_stat.rb +80 -0
- data/lib/stub_requests/metrics.rb +32 -0
- data/lib/stub_requests/property/validator.rb +136 -0
- data/lib/stub_requests/property.rb +99 -0
- data/lib/stub_requests/service.rb +12 -53
- data/lib/stub_requests/service_registry.rb +8 -9
- data/lib/stub_requests/stub_requests.rb +23 -51
- data/lib/stub_requests/uri/builder.rb +5 -1
- data/lib/stub_requests/uri/scheme.rb +3 -1
- data/lib/stub_requests/uri/suffix.rb +5 -0
- data/lib/stub_requests/uri/validator.rb +3 -1
- data/lib/stub_requests/uri.rb +34 -0
- data/lib/stub_requests/version.rb +1 -1
- data/lib/stub_requests/webmock/builder.rb +116 -0
- data/lib/stub_requests/webmock/stub_registry_extension.rb +46 -0
- data/lib/stub_requests.rb +21 -3
- metadata +19 -49
- data/docs/.gitkeep +0 -0
- data/docs/Array.html +0 -137
- data/docs/FalseClass.html +0 -232
- data/docs/Hash.html +0 -137
- data/docs/NilClass.html +0 -232
- data/docs/Numeric.html +0 -233
- data/docs/Object.html +0 -396
- data/docs/String.html +0 -298
- data/docs/StubRequests/API.html +0 -651
- data/docs/StubRequests/ArgumentValidation.html +0 -309
- data/docs/StubRequests/Endpoint.html +0 -1187
- data/docs/StubRequests/EndpointNotFound.html +0 -157
- data/docs/StubRequests/EndpointRegistry.html +0 -1527
- data/docs/StubRequests/Error.html +0 -153
- data/docs/StubRequests/HashUtil.html +0 -304
- data/docs/StubRequests/InvalidType.html +0 -252
- data/docs/StubRequests/InvalidUri.html +0 -252
- data/docs/StubRequests/Service.html +0 -1307
- data/docs/StubRequests/ServiceHaveEndpoints.html +0 -244
- data/docs/StubRequests/ServiceNotFound.html +0 -252
- data/docs/StubRequests/ServiceRegistry.html +0 -1031
- data/docs/StubRequests/URI/Builder.html +0 -1194
- data/docs/StubRequests/URI/Scheme.html +0 -315
- data/docs/StubRequests/URI/Suffix.html +0 -315
- data/docs/StubRequests/URI/Validator.html +0 -770
- data/docs/StubRequests/URI.html +0 -144
- data/docs/StubRequests/UriSegmentMismatch.html +0 -157
- data/docs/StubRequests/WebMockBuilder.html +0 -887
- data/docs/StubRequests.html +0 -452
- data/docs/Time.html +0 -232
- data/docs/TrueClass.html +0 -232
- data/docs/_config.yml +0 -1
- data/docs/_index.html +0 -391
- data/docs/class_list.html +0 -51
- data/docs/css/common.css +0 -1
- data/docs/css/full_list.css +0 -58
- data/docs/css/style.css +0 -496
- data/docs/file.README.html +0 -225
- data/docs/file_list.html +0 -56
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -225
- data/docs/js/app.js +0 -292
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -707
- data/docs/top-level-namespace.html +0 -112
- data/lib/stub_requests/webmock_builder.rb +0 -108
data/docs/file.README.html
DELETED
@@ -1,225 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="UTF-8">
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<title>
|
7
|
-
File: README
|
8
|
-
|
9
|
-
— Documentation by YARD 0.9.18
|
10
|
-
|
11
|
-
</title>
|
12
|
-
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
-
|
17
|
-
<script type="text/javascript" charset="utf-8">
|
18
|
-
pathId = "README";
|
19
|
-
relpath = '';
|
20
|
-
</script>
|
21
|
-
|
22
|
-
|
23
|
-
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
-
|
25
|
-
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
-
|
27
|
-
|
28
|
-
</head>
|
29
|
-
<body>
|
30
|
-
<div class="nav_wrap">
|
31
|
-
<iframe id="nav" src="file_list.html?1"></iframe>
|
32
|
-
<div id="resizer"></div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="main" tabindex="-1">
|
36
|
-
<div id="header">
|
37
|
-
<div id="menu">
|
38
|
-
|
39
|
-
<a href="_index.html">Index</a> »
|
40
|
-
<span class="title">File: README</span>
|
41
|
-
|
42
|
-
</div>
|
43
|
-
|
44
|
-
<div id="search">
|
45
|
-
|
46
|
-
<a class="full_list_link" id="class_list_link"
|
47
|
-
href="class_list.html">
|
48
|
-
|
49
|
-
<svg width="24" height="24">
|
50
|
-
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
-
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
-
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
-
</svg>
|
54
|
-
</a>
|
55
|
-
|
56
|
-
</div>
|
57
|
-
<div class="clear"></div>
|
58
|
-
</div>
|
59
|
-
|
60
|
-
<div id="content"><div id='filecontents'><h1>StubRequests</h1>
|
61
|
-
|
62
|
-
<h2>Badges</h2>
|
63
|
-
|
64
|
-
<p><a href="https://travis-ci.org/mhenrixon/stub_requests"><img src="https://travis-ci.org/mhenrixon/stub_requests.svg?branch=master" alt="Build Status"></a> <a href="https://codeclimate.com/github/mhenrixon/stub_requests/maintainability"><img src="https://api.codeclimate.com/v1/badges/c9217e458c2a77fff1bc/maintainability" alt="Maintainability"></a> <a href="https://codeclimate.com/github/mhenrixon/stub_requests/test_coverage"><img src="https://api.codeclimate.com/v1/badges/c9217e458c2a77fff1bc/test_coverage" alt="Test Coverage"></a></p>
|
65
|
-
|
66
|
-
<p>This gem attempts to solve a problem I've had for the time with WebMock.</p>
|
67
|
-
|
68
|
-
<p>When something changes, I have to update every single stub_request.</p>
|
69
|
-
|
70
|
-
<p>This gem allows me to only update the crucial parts while abstracting away things like service URI's, endpoint definitions and focus on the important things.</p>
|
71
|
-
|
72
|
-
<p>This is achieve by keeping a registry over the service endpoints.</p>
|
73
|
-
|
74
|
-
<!-- MarkdownTOC -->
|
75
|
-
|
76
|
-
<ul>
|
77
|
-
<li><a href="#installation">Installation</a></li>
|
78
|
-
<li><a href="#usage">Usage</a></li>
|
79
|
-
<li><a href="#future-improvements">Future Improvements</a>
|
80
|
-
|
81
|
-
<ul>
|
82
|
-
<li><a href="#api-client-gem">API Client Gem</a></li>
|
83
|
-
<li><a href="#debugging">Debugging</a></li>
|
84
|
-
</ul></li>
|
85
|
-
<li><a href="#development">Development</a></li>
|
86
|
-
<li><a href="#contributing">Contributing</a></li>
|
87
|
-
<li><a href="#license">License</a></li>
|
88
|
-
<li><a href="#code-of-conduct">Code of Conduct</a></li>
|
89
|
-
</ul>
|
90
|
-
|
91
|
-
<!-- /MarkdownTOC -->
|
92
|
-
|
93
|
-
<p><a id="installation"></a></p>
|
94
|
-
|
95
|
-
<h2>Installation</h2>
|
96
|
-
|
97
|
-
<p>Add this line to your application's Gemfile:</p>
|
98
|
-
|
99
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>stub_requests</span><span class='tstring_end'>"</span></span>
|
100
|
-
</code></pre>
|
101
|
-
|
102
|
-
<p>And then execute:</p>
|
103
|
-
|
104
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span>
|
105
|
-
</code></pre>
|
106
|
-
|
107
|
-
<p>Or install it yourself as:</p>
|
108
|
-
|
109
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_stub_requests'>stub_requests</span>
|
110
|
-
</code></pre>
|
111
|
-
|
112
|
-
<p><a id="usage"></a></p>
|
113
|
-
|
114
|
-
<h2>Usage</h2>
|
115
|
-
|
116
|
-
<p>To use the gem we need to register some service endpoints. In the following example we are connecting to a rails inspired service.</p>
|
117
|
-
|
118
|
-
<p>The naming of the <code>service_id</code> and <code>endpoint_id</code>'s is irrelevant. This is just how we look things up in the registry.</p>
|
119
|
-
|
120
|
-
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="StubRequests.html" title="StubRequests (module)">StubRequests</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register_service'><span class='object_link'><a href="StubRequests/API.html#register_service-instance_method" title="StubRequests::API#register_service (method)">register_service</a></span></span><span class='lparen'>(</span><span class='symbol'>:google_ads</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>https://api.google.com/v5</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
121
|
-
<span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='symbol'>:index</span><span class='comma'>,</span> <span class='symbol'>:get</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ads</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
122
|
-
<span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='symbol'>:show</span><span class='comma'>,</span> <span class='symbol'>:get</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ads/:id</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
123
|
-
<span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='symbol'>:update</span><span class='comma'>,</span> <span class='symbol'>:patch</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ads/:id</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
124
|
-
<span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='symbol'>:create</span><span class='comma'>,</span> <span class='symbol'>:post</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ads</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
125
|
-
<span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='symbol'>:destroy</span><span class='comma'>,</span> <span class='symbol'>:delete</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ads/:id</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
126
|
-
<span class='kw'>end</span>
|
127
|
-
</code></pre>
|
128
|
-
|
129
|
-
<p>Now we have a list of endpoints we can stub.</p>
|
130
|
-
|
131
|
-
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="StubRequests.html" title="StubRequests (module)">StubRequests</a></span></span><span class='period'>.</span><span class='id identifier rubyid_stub_endpoint'><span class='object_link'><a href="StubRequests/API.html#stub_endpoint-instance_method" title="StubRequests::API#stub_endpoint (method)">stub_endpoint</a></span></span><span class='lparen'>(</span><span class='symbol'>:google_ads</span><span class='comma'>,</span> <span class='symbol'>:index</span><span class='rparen'>)</span>
|
132
|
-
<span class='period'>.</span><span class='id identifier rubyid_to_return'>to_return</span><span class='lparen'>(</span><span class='label'>code:</span> <span class='int'>204</span><span class='comma'>,</span> <span class='label'>body:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
133
|
-
|
134
|
-
<span class='comment'># This is the equivalent of doing the following in WebMock
|
135
|
-
</span><span class='const'>Settings</span><span class='period'>.</span><span class='id identifier rubyid_google_ads_base_uri'>google_ads_base_uri</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>https://api.google.com/v5</span><span class='tstring_end'>"</span></span>
|
136
|
-
|
137
|
-
<span class='const'>WebMock</span><span class='period'>.</span><span class='id identifier rubyid_stub_request'>stub_request</span><span class='lparen'>(</span><span class='symbol'>:get</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='const'>Settings</span><span class='period'>.</span><span class='id identifier rubyid_google_ads_base_uri'>google_ads_base_uri</span><span class='embexpr_end'>}</span><span class='tstring_content'>/ads</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
138
|
-
<span class='period'>.</span><span class='id identifier rubyid_to_return'>to_return</span><span class='lparen'>(</span><span class='label'>status:</span> <span class='int'>204</span><span class='comma'>,</span> <span class='label'>body:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
139
|
-
</code></pre>
|
140
|
-
|
141
|
-
<p>So far so good but not much of a gain yet. The real power comes when we don't have to interpolate a bunch of URLs all the time.</p>
|
142
|
-
|
143
|
-
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="StubRequests.html" title="StubRequests (module)">StubRequests</a></span></span><span class='period'>.</span><span class='id identifier rubyid_stub_endpoint'><span class='object_link'><a href="StubRequests/API.html#stub_endpoint-instance_method" title="StubRequests::API#stub_endpoint (method)">stub_endpoint</a></span></span><span class='lparen'>(</span><span class='symbol'>:google_ads</span><span class='comma'>,</span> <span class='symbol'>:update</span><span class='comma'>,</span> <span class='label'>id:</span> <span class='int'>1</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
144
|
-
<span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='label'>body:</span> <span class='id identifier rubyid_request_body'>request_body</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
|
145
|
-
<span class='id identifier rubyid_to_return'>to_return</span><span class='lparen'>(</span><span class='label'>code:</span> <span class='int'>200</span><span class='comma'>,</span> <span class='label'>body:</span> <span class='id identifier rubyid_response_body'>response_body</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
|
146
|
-
<span class='kw'>end</span>
|
147
|
-
|
148
|
-
<span class='comment'># This is the equivalent of doing the following in WebMock
|
149
|
-
</span><span class='const'>Settings</span><span class='period'>.</span><span class='id identifier rubyid_google_ads_base_uri'>google_ads_base_uri</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>https://api.google.com/v5</span><span class='tstring_end'>"</span></span>
|
150
|
-
|
151
|
-
<span class='const'>WebMock</span><span class='period'>.</span><span class='id identifier rubyid_stub_request'>stub_request</span><span class='lparen'>(</span><span class='symbol'>:patch</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='const'>Settings</span><span class='period'>.</span><span class='id identifier rubyid_google_ads_base_uri'>google_ads_base_uri</span><span class='embexpr_end'>}</span><span class='tstring_content'>/ads/</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_id'>id</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
152
|
-
<span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='label'>body:</span> <span class='id identifier rubyid_request_body'>request_body</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
|
153
|
-
<span class='period'>.</span><span class='id identifier rubyid_to_return'>to_return</span><span class='lparen'>(</span><span class='label'>status:</span> <span class='int'>200</span><span class='comma'>,</span> <span class='label'>body:</span> <span class='id identifier rubyid_response_body'>response_body</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
|
154
|
-
</code></pre>
|
155
|
-
|
156
|
-
<p>First of all we reduce a lot of duplication.</p>
|
157
|
-
|
158
|
-
<p>Imagine a code base with thousands of stubbed request. You always have to look at the defined URL to understand which request is actually being called.</p>
|
159
|
-
|
160
|
-
<p>Madness!!</p>
|
161
|
-
|
162
|
-
<p><a id="future-improvements"></a></p>
|
163
|
-
|
164
|
-
<h2>Future Improvements</h2>
|
165
|
-
|
166
|
-
<p><a id="api-client-gem"></a></p>
|
167
|
-
|
168
|
-
<h3>API Client Gem</h3>
|
169
|
-
|
170
|
-
<p>Since we have a service + endpoint registry, I was thinking it might make
|
171
|
-
sense to make this into an API client. Not sure yet, maybe this will become multiple gems in the future so that someone can pick and choose.</p>
|
172
|
-
|
173
|
-
<p>Anyway, the idea was to provide endpoint calls in production and stubbed
|
174
|
-
requests in tests using the same registry.</p>
|
175
|
-
|
176
|
-
<p><a id="debugging"></a></p>
|
177
|
-
|
178
|
-
<h3>Debugging</h3>
|
179
|
-
|
180
|
-
<p>I want to provide information about where a request stub was created from. In the project I am currently working this would have saved me a days work already.</p>
|
181
|
-
|
182
|
-
<p><a id="development"></a></p>
|
183
|
-
|
184
|
-
<h2>Development</h2>
|
185
|
-
|
186
|
-
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies.</p>
|
187
|
-
|
188
|
-
<p>Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an
|
189
|
-
interactive prompt that will allow you to experiment.</p>
|
190
|
-
|
191
|
-
<p>To install this gem onto your local machine run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and tags, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
|
192
|
-
|
193
|
-
<p><a id="contributing"></a></p>
|
194
|
-
|
195
|
-
<h2>Contributing</h2>
|
196
|
-
|
197
|
-
<p>Bug reports and pull requests are welcome on GitHub at:
|
198
|
-
<a href="https://github.com/mhenrixon/stub_requests">issues</a>.</p>
|
199
|
-
|
200
|
-
<p>This project is intended to be a safe, welcoming space for collaboration, and
|
201
|
-
contributors are expected to adhere to the <a href="cc">Contributor Covenant</a> code of conduct.</p>
|
202
|
-
|
203
|
-
<p><a id="license"></a></p>
|
204
|
-
|
205
|
-
<h2>License</h2>
|
206
|
-
|
207
|
-
<p>The gem is available as open source under the terms of the <a href="mit">MIT License</a>.</p>
|
208
|
-
|
209
|
-
<p><a id="code-of-conduct"></a></p>
|
210
|
-
|
211
|
-
<h2>Code of Conduct</h2>
|
212
|
-
|
213
|
-
<p>Everyone interacting in the StubRequests project’s codebases, issue trackers,
|
214
|
-
chat rooms and mailing lists is expected to follow the <a href="coc">code of conduct</a>.</p>
|
215
|
-
</div></div>
|
216
|
-
|
217
|
-
<div id="footer">
|
218
|
-
Generated on Fri Feb 1 19:57:29 2019 by
|
219
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
220
|
-
0.9.18 (ruby-2.5.3).
|
221
|
-
</div>
|
222
|
-
|
223
|
-
</div>
|
224
|
-
</body>
|
225
|
-
</html>
|
data/docs/file_list.html
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
-
<meta charset="utf-8" />
|
6
|
-
|
7
|
-
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
-
|
9
|
-
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
-
|
15
|
-
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
-
|
17
|
-
|
18
|
-
<title>File List</title>
|
19
|
-
<base id="base_target" target="_parent" />
|
20
|
-
</head>
|
21
|
-
<body>
|
22
|
-
<div id="content">
|
23
|
-
<div class="fixed_header">
|
24
|
-
<h1 id="full_list_header">File List</h1>
|
25
|
-
<div id="full_list_nav">
|
26
|
-
|
27
|
-
<span><a target="_self" href="class_list.html">
|
28
|
-
Classes
|
29
|
-
</a></span>
|
30
|
-
|
31
|
-
<span><a target="_self" href="method_list.html">
|
32
|
-
Methods
|
33
|
-
</a></span>
|
34
|
-
|
35
|
-
<span><a target="_self" href="file_list.html">
|
36
|
-
Files
|
37
|
-
</a></span>
|
38
|
-
|
39
|
-
</div>
|
40
|
-
|
41
|
-
<div id="search">Search: <input type="text" /></div>
|
42
|
-
</div>
|
43
|
-
|
44
|
-
<ul id="full_list" class="file">
|
45
|
-
|
46
|
-
|
47
|
-
<li id="object_README" class="odd">
|
48
|
-
<div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
|
49
|
-
</li>
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
</ul>
|
54
|
-
</div>
|
55
|
-
</body>
|
56
|
-
</html>
|
data/docs/frames.html
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<title>Documentation by YARD 0.9.18</title>
|
6
|
-
</head>
|
7
|
-
<script type="text/javascript" charset="utf-8">
|
8
|
-
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
9
|
-
var name = match ? match[1] : 'index.html';
|
10
|
-
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
11
|
-
window.top.location = name;
|
12
|
-
</script>
|
13
|
-
<noscript>
|
14
|
-
<h1>Oops!</h1>
|
15
|
-
<h2>YARD requires JavaScript!</h2>
|
16
|
-
</noscript>
|
17
|
-
</html>
|
data/docs/index.html
DELETED
@@ -1,225 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="UTF-8">
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<title>
|
7
|
-
File: README
|
8
|
-
|
9
|
-
— Documentation by YARD 0.9.18
|
10
|
-
|
11
|
-
</title>
|
12
|
-
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
-
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
-
|
17
|
-
<script type="text/javascript" charset="utf-8">
|
18
|
-
pathId = "README";
|
19
|
-
relpath = '';
|
20
|
-
</script>
|
21
|
-
|
22
|
-
|
23
|
-
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
-
|
25
|
-
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
-
|
27
|
-
|
28
|
-
</head>
|
29
|
-
<body>
|
30
|
-
<div class="nav_wrap">
|
31
|
-
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
-
<div id="resizer"></div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="main" tabindex="-1">
|
36
|
-
<div id="header">
|
37
|
-
<div id="menu">
|
38
|
-
|
39
|
-
<a href="_index.html">Index</a> »
|
40
|
-
<span class="title">File: README</span>
|
41
|
-
|
42
|
-
</div>
|
43
|
-
|
44
|
-
<div id="search">
|
45
|
-
|
46
|
-
<a class="full_list_link" id="class_list_link"
|
47
|
-
href="class_list.html">
|
48
|
-
|
49
|
-
<svg width="24" height="24">
|
50
|
-
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
-
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
-
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
-
</svg>
|
54
|
-
</a>
|
55
|
-
|
56
|
-
</div>
|
57
|
-
<div class="clear"></div>
|
58
|
-
</div>
|
59
|
-
|
60
|
-
<div id="content"><div id='filecontents'><h1>StubRequests</h1>
|
61
|
-
|
62
|
-
<h2>Badges</h2>
|
63
|
-
|
64
|
-
<p><a href="https://travis-ci.org/mhenrixon/stub_requests"><img src="https://travis-ci.org/mhenrixon/stub_requests.svg?branch=master" alt="Build Status"></a> <a href="https://codeclimate.com/github/mhenrixon/stub_requests/maintainability"><img src="https://api.codeclimate.com/v1/badges/c9217e458c2a77fff1bc/maintainability" alt="Maintainability"></a> <a href="https://codeclimate.com/github/mhenrixon/stub_requests/test_coverage"><img src="https://api.codeclimate.com/v1/badges/c9217e458c2a77fff1bc/test_coverage" alt="Test Coverage"></a></p>
|
65
|
-
|
66
|
-
<p>This gem attempts to solve a problem I've had for the time with WebMock.</p>
|
67
|
-
|
68
|
-
<p>When something changes, I have to update every single stub_request.</p>
|
69
|
-
|
70
|
-
<p>This gem allows me to only update the crucial parts while abstracting away things like service URI's, endpoint definitions and focus on the important things.</p>
|
71
|
-
|
72
|
-
<p>This is achieve by keeping a registry over the service endpoints.</p>
|
73
|
-
|
74
|
-
<!-- MarkdownTOC -->
|
75
|
-
|
76
|
-
<ul>
|
77
|
-
<li><a href="#installation">Installation</a></li>
|
78
|
-
<li><a href="#usage">Usage</a></li>
|
79
|
-
<li><a href="#future-improvements">Future Improvements</a>
|
80
|
-
|
81
|
-
<ul>
|
82
|
-
<li><a href="#api-client-gem">API Client Gem</a></li>
|
83
|
-
<li><a href="#debugging">Debugging</a></li>
|
84
|
-
</ul></li>
|
85
|
-
<li><a href="#development">Development</a></li>
|
86
|
-
<li><a href="#contributing">Contributing</a></li>
|
87
|
-
<li><a href="#license">License</a></li>
|
88
|
-
<li><a href="#code-of-conduct">Code of Conduct</a></li>
|
89
|
-
</ul>
|
90
|
-
|
91
|
-
<!-- /MarkdownTOC -->
|
92
|
-
|
93
|
-
<p><a id="installation"></a></p>
|
94
|
-
|
95
|
-
<h2>Installation</h2>
|
96
|
-
|
97
|
-
<p>Add this line to your application's Gemfile:</p>
|
98
|
-
|
99
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>stub_requests</span><span class='tstring_end'>"</span></span>
|
100
|
-
</code></pre>
|
101
|
-
|
102
|
-
<p>And then execute:</p>
|
103
|
-
|
104
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span>
|
105
|
-
</code></pre>
|
106
|
-
|
107
|
-
<p>Or install it yourself as:</p>
|
108
|
-
|
109
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_stub_requests'>stub_requests</span>
|
110
|
-
</code></pre>
|
111
|
-
|
112
|
-
<p><a id="usage"></a></p>
|
113
|
-
|
114
|
-
<h2>Usage</h2>
|
115
|
-
|
116
|
-
<p>To use the gem we need to register some service endpoints. In the following example we are connecting to a rails inspired service.</p>
|
117
|
-
|
118
|
-
<p>The naming of the <code>service_id</code> and <code>endpoint_id</code>'s is irrelevant. This is just how we look things up in the registry.</p>
|
119
|
-
|
120
|
-
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="StubRequests.html" title="StubRequests (module)">StubRequests</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register_service'><span class='object_link'><a href="StubRequests/API.html#register_service-instance_method" title="StubRequests::API#register_service (method)">register_service</a></span></span><span class='lparen'>(</span><span class='symbol'>:google_ads</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>https://api.google.com/v5</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
|
121
|
-
<span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='symbol'>:index</span><span class='comma'>,</span> <span class='symbol'>:get</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ads</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
122
|
-
<span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='symbol'>:show</span><span class='comma'>,</span> <span class='symbol'>:get</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ads/:id</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
123
|
-
<span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='symbol'>:update</span><span class='comma'>,</span> <span class='symbol'>:patch</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ads/:id</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
124
|
-
<span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='symbol'>:create</span><span class='comma'>,</span> <span class='symbol'>:post</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ads</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
125
|
-
<span class='id identifier rubyid_register'>register</span><span class='lparen'>(</span><span class='symbol'>:destroy</span><span class='comma'>,</span> <span class='symbol'>:delete</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>ads/:id</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
126
|
-
<span class='kw'>end</span>
|
127
|
-
</code></pre>
|
128
|
-
|
129
|
-
<p>Now we have a list of endpoints we can stub.</p>
|
130
|
-
|
131
|
-
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="StubRequests.html" title="StubRequests (module)">StubRequests</a></span></span><span class='period'>.</span><span class='id identifier rubyid_stub_endpoint'><span class='object_link'><a href="StubRequests/API.html#stub_endpoint-instance_method" title="StubRequests::API#stub_endpoint (method)">stub_endpoint</a></span></span><span class='lparen'>(</span><span class='symbol'>:google_ads</span><span class='comma'>,</span> <span class='symbol'>:index</span><span class='rparen'>)</span>
|
132
|
-
<span class='period'>.</span><span class='id identifier rubyid_to_return'>to_return</span><span class='lparen'>(</span><span class='label'>code:</span> <span class='int'>204</span><span class='comma'>,</span> <span class='label'>body:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
133
|
-
|
134
|
-
<span class='comment'># This is the equivalent of doing the following in WebMock
|
135
|
-
</span><span class='const'>Settings</span><span class='period'>.</span><span class='id identifier rubyid_google_ads_base_uri'>google_ads_base_uri</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>https://api.google.com/v5</span><span class='tstring_end'>"</span></span>
|
136
|
-
|
137
|
-
<span class='const'>WebMock</span><span class='period'>.</span><span class='id identifier rubyid_stub_request'>stub_request</span><span class='lparen'>(</span><span class='symbol'>:get</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='const'>Settings</span><span class='period'>.</span><span class='id identifier rubyid_google_ads_base_uri'>google_ads_base_uri</span><span class='embexpr_end'>}</span><span class='tstring_content'>/ads</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
138
|
-
<span class='period'>.</span><span class='id identifier rubyid_to_return'>to_return</span><span class='lparen'>(</span><span class='label'>status:</span> <span class='int'>204</span><span class='comma'>,</span> <span class='label'>body:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
139
|
-
</code></pre>
|
140
|
-
|
141
|
-
<p>So far so good but not much of a gain yet. The real power comes when we don't have to interpolate a bunch of URLs all the time.</p>
|
142
|
-
|
143
|
-
<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="StubRequests.html" title="StubRequests (module)">StubRequests</a></span></span><span class='period'>.</span><span class='id identifier rubyid_stub_endpoint'><span class='object_link'><a href="StubRequests/API.html#stub_endpoint-instance_method" title="StubRequests::API#stub_endpoint (method)">stub_endpoint</a></span></span><span class='lparen'>(</span><span class='symbol'>:google_ads</span><span class='comma'>,</span> <span class='symbol'>:update</span><span class='comma'>,</span> <span class='label'>id:</span> <span class='int'>1</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
144
|
-
<span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='label'>body:</span> <span class='id identifier rubyid_request_body'>request_body</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
|
145
|
-
<span class='id identifier rubyid_to_return'>to_return</span><span class='lparen'>(</span><span class='label'>code:</span> <span class='int'>200</span><span class='comma'>,</span> <span class='label'>body:</span> <span class='id identifier rubyid_response_body'>response_body</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
|
146
|
-
<span class='kw'>end</span>
|
147
|
-
|
148
|
-
<span class='comment'># This is the equivalent of doing the following in WebMock
|
149
|
-
</span><span class='const'>Settings</span><span class='period'>.</span><span class='id identifier rubyid_google_ads_base_uri'>google_ads_base_uri</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>https://api.google.com/v5</span><span class='tstring_end'>"</span></span>
|
150
|
-
|
151
|
-
<span class='const'>WebMock</span><span class='period'>.</span><span class='id identifier rubyid_stub_request'>stub_request</span><span class='lparen'>(</span><span class='symbol'>:patch</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='const'>Settings</span><span class='period'>.</span><span class='id identifier rubyid_google_ads_base_uri'>google_ads_base_uri</span><span class='embexpr_end'>}</span><span class='tstring_content'>/ads/</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_id'>id</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
152
|
-
<span class='period'>.</span><span class='id identifier rubyid_with'>with</span><span class='lparen'>(</span><span class='label'>body:</span> <span class='id identifier rubyid_request_body'>request_body</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
|
153
|
-
<span class='period'>.</span><span class='id identifier rubyid_to_return'>to_return</span><span class='lparen'>(</span><span class='label'>status:</span> <span class='int'>200</span><span class='comma'>,</span> <span class='label'>body:</span> <span class='id identifier rubyid_response_body'>response_body</span><span class='period'>.</span><span class='id identifier rubyid_to_json'>to_json</span><span class='rparen'>)</span>
|
154
|
-
</code></pre>
|
155
|
-
|
156
|
-
<p>First of all we reduce a lot of duplication.</p>
|
157
|
-
|
158
|
-
<p>Imagine a code base with thousands of stubbed request. You always have to look at the defined URL to understand which request is actually being called.</p>
|
159
|
-
|
160
|
-
<p>Madness!!</p>
|
161
|
-
|
162
|
-
<p><a id="future-improvements"></a></p>
|
163
|
-
|
164
|
-
<h2>Future Improvements</h2>
|
165
|
-
|
166
|
-
<p><a id="api-client-gem"></a></p>
|
167
|
-
|
168
|
-
<h3>API Client Gem</h3>
|
169
|
-
|
170
|
-
<p>Since we have a service + endpoint registry, I was thinking it might make
|
171
|
-
sense to make this into an API client. Not sure yet, maybe this will become multiple gems in the future so that someone can pick and choose.</p>
|
172
|
-
|
173
|
-
<p>Anyway, the idea was to provide endpoint calls in production and stubbed
|
174
|
-
requests in tests using the same registry.</p>
|
175
|
-
|
176
|
-
<p><a id="debugging"></a></p>
|
177
|
-
|
178
|
-
<h3>Debugging</h3>
|
179
|
-
|
180
|
-
<p>I want to provide information about where a request stub was created from. In the project I am currently working this would have saved me a days work already.</p>
|
181
|
-
|
182
|
-
<p><a id="development"></a></p>
|
183
|
-
|
184
|
-
<h2>Development</h2>
|
185
|
-
|
186
|
-
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies.</p>
|
187
|
-
|
188
|
-
<p>Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an
|
189
|
-
interactive prompt that will allow you to experiment.</p>
|
190
|
-
|
191
|
-
<p>To install this gem onto your local machine run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and tags, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
|
192
|
-
|
193
|
-
<p><a id="contributing"></a></p>
|
194
|
-
|
195
|
-
<h2>Contributing</h2>
|
196
|
-
|
197
|
-
<p>Bug reports and pull requests are welcome on GitHub at:
|
198
|
-
<a href="https://github.com/mhenrixon/stub_requests">issues</a>.</p>
|
199
|
-
|
200
|
-
<p>This project is intended to be a safe, welcoming space for collaboration, and
|
201
|
-
contributors are expected to adhere to the <a href="cc">Contributor Covenant</a> code of conduct.</p>
|
202
|
-
|
203
|
-
<p><a id="license"></a></p>
|
204
|
-
|
205
|
-
<h2>License</h2>
|
206
|
-
|
207
|
-
<p>The gem is available as open source under the terms of the <a href="mit">MIT License</a>.</p>
|
208
|
-
|
209
|
-
<p><a id="code-of-conduct"></a></p>
|
210
|
-
|
211
|
-
<h2>Code of Conduct</h2>
|
212
|
-
|
213
|
-
<p>Everyone interacting in the StubRequests project’s codebases, issue trackers,
|
214
|
-
chat rooms and mailing lists is expected to follow the <a href="coc">code of conduct</a>.</p>
|
215
|
-
</div></div>
|
216
|
-
|
217
|
-
<div id="footer">
|
218
|
-
Generated on Fri Feb 1 19:57:29 2019 by
|
219
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
220
|
-
0.9.18 (ruby-2.5.3).
|
221
|
-
</div>
|
222
|
-
|
223
|
-
</div>
|
224
|
-
</body>
|
225
|
-
</html>
|