http-fake 0.0.0 → 0.1.0

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
  SHA256:
3
- metadata.gz: f068555328be1d8bab977bd4ada2cbfbc67691714681cbf0065a6cdb5ae797bf
4
- data.tar.gz: c28eecb527f8d7588036974c6af8bc87015b4aea516c36c59f5a6a4e5e46789e
3
+ metadata.gz: ab44f133bb42373588a38aef8c48b9e649617b6a8fa8d1e8583b048c6ac9384c
4
+ data.tar.gz: e12977c2e7fdefe4bc6a89cd7f6602c3e2f55e690730d97d4ec20f524db51399
5
5
  SHA512:
6
- metadata.gz: c175d8a7f3c1d910bf4fdb05189bdf509db4f1a6542a678edf521f7ff889378938214408eee380fc8b00e749e8e030a93d2717b69de50c26e54cdf35912402cd
7
- data.tar.gz: 7a9e1828ee3f847caedae2d2f7d73b8ccd7adfba6fa3ec837057ed5fec5c7d64b7c68bcfac854d8822ed33e92e614eebd92f799989e290d4a59be2be3a12f661
6
+ metadata.gz: 3a80c0cba96b9b5f7c55b9de62553b08589a27d864121c6faed25a2b0de53dbbe96a24d0a2f68af31cf34a5a11dcd89dab59b021cb903c8f3c486381efd57dd9
7
+ data.tar.gz: a8f80331944f0eaaa1a248bee50c102170c235d2976c2d23df281124f559d26df0db5c2aac9ee185b602591836e51221b4b0a8fb7854a9cb9dacb994c7984e88
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -6,23 +6,16 @@
6
6
 
7
7
  = HTTP Fake
8
8
 
9
- HTTP Fake is a companion to the {http_link} gem when you want a convenient way to test HTTP requests
10
- by swapping out your _real_ HTTP client with this _fake_ HTTP client. Using a fake allows you to
11
- speed up and simplify your test suite by answering fake responses without hitting a live API. You'll
12
- still want to test against a live API, eventually, within your integration tests but at a lower
13
- level, like your unit tests, you can use this gem instead. This gem is particularly useful when
14
- using _Dependency Injection_, especially when coupled with the
15
- link:https://www.alchemists.io/projects/auto_injector[Auto Injector] gem.
9
+ HTTP Fake is a companion to the {http_link} gem when you want a convenient way to test HTTP requests by swapping out your _real_ HTTP client with this _fake_ HTTP client. Using a fake allows you to improve the performance of your test suite by answering fake responses without hitting a live API. You'll still want to test against a live API, eventually, within your integration tests but at a lower level, like your unit tests, you can use this gem instead. This gem is particularly useful when using _Dependency Injection_, especially when coupled with the link:https://www.alchemists.io/projects/auto_injector[Auto Injector] gem.
16
10
 
17
11
  toc::[]
18
12
 
19
13
  == Features
20
14
 
21
15
  * Provides a fake HTTP client as a testing companion to the {http_link} gem.
22
- * Supports the following HTTP verbs: CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, and
23
- TRACE.
16
+ * Supports the following HTTP verbs: CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, and TRACE.
24
17
  * Uses a simple DSL for defining HTTP endpoints, headers, bodies, and statuses.
25
- * Works well with objects that use _Dependency Injection_.
18
+ * Works well with objects that use Dependency Injection.
26
19
  * Speeds up your test suite when you don't need a live API.
27
20
 
28
21
  == Requirements
@@ -44,9 +37,7 @@ only meant to aid in writing specs.
44
37
 
45
38
  == Usage
46
39
 
47
- This gem works with any test framework and, for demonstration purposes, we'll assume you're using
48
- link:https://rspec.info[RSpec]. You can adapt these examples to your test framework of choice. A
49
- simple spec might look the this:
40
+ This gem works with any test framework. For demonstration purposes, we'll assume you're using link:https://rspec.info[RSpec] but you can adapt these examples to your test framework of choice. A simple spec might look like this:
50
41
 
51
42
  [source,ruby]
52
43
  ----
@@ -79,16 +70,9 @@ RSpec.describe Endpoint do
79
70
  end
80
71
  ----
81
72
 
82
- As you can see, our _fake_ `http` client has been defined and injected into our `endpoint` subject.
83
- When the fake is defined, the path, headers, status, and body are registered as well. This
84
- allows the fake to match against your real implementation's URL path and swap out making a real HTTP
85
- call with the canned response defined by the fake. When asking the endpoint for its customers, we
86
- get back the response as defined by the fake with all of the normal capabilities as if we were using
87
- the real HTTP client. This works because this gem uses
88
- link:https://github.com/sinatra/mustermann[Mustermann] for pattern matching against the routes you
89
- define. This means you can defined routes that are explicit -- as shown above -- or fuzzy based on
90
- your testing needs. You can also define multiple endpoints for the same fake in case your
91
- implementation needs to test multiple endpoints at once. Example:
73
+ As you can see, our _fake_ `http` client has been defined and injected into our `endpoint` subject. When the fake is defined, the path, headers, status, and body are registered as well. This allows the fake to match against your real implementation's URL path and swap out acquiring a real HTTP response with fake response instead. When asking the endpoint for its customers, we get back the fake response with all of the normal capabilities of the real HTTP client. This works because this gem uses link:https://github.com/sinatra/mustermann[Mustermann] for pattern matching against the routes you define and also means you can define routes that are explicit -- as shown above -- or fuzzy based on your testing needs.
74
+
75
+ Here's an example where multiple endpoints are defined for the same fake in case your implementation needs to test multiple endpoints at once:
92
76
 
93
77
  [source,ruby]
94
78
  ----
@@ -134,13 +118,12 @@ let :http do
134
118
  end
135
119
  ----
136
120
 
137
- Lastly, in the examples above, I've been showing how you can work with JSON responses but you might
138
- want to use other MIME types. For example, XML:
121
+ So far you've only seen usage of JSON responses but you might want to use other MIME types. For example, XML:
139
122
 
140
123
  [source,ruby]
141
124
  ----
142
125
  HTTP::Fake::Client.new do
143
- get "/customers" do
126
+ get "/customers/1" do
144
127
  headers["Content-Type"] = "application/xml"
145
128
  status 200
146
129
 
@@ -164,6 +147,33 @@ HTTP::Fake::Client.new do
164
147
  status 200
165
148
 
166
149
  "1 - Jill Smith"
150
+ "2 - Tom Bombadill"
151
+ end
152
+ end
153
+ ----
154
+
155
+ You might even want to import a fixture which is especially handy when the response is verbose or needs to be reused in different ways. Example:
156
+
157
+ [source,ruby]
158
+ ----
159
+ # Single
160
+ HTTP::Fake::Client.new do
161
+ get "/customers/1" do
162
+ headers["Content-Type"] = "application/json"
163
+ status 200
164
+ Bundler.root.join("spec/support/fixtures/customer.json").read
165
+ end
166
+ end
167
+
168
+ # Multiple
169
+ HTTP::Fake::Client.new do
170
+ get "/customers" do
171
+ headers["Content-Type"] = "application/json"
172
+ status 200
173
+
174
+ <<~JSON
175
+ [#{Bundler.root.join("spec/support/fixtures/customer.json").read}]
176
+ JSON
167
177
  end
168
178
  end
169
179
  ----
data/http-fake.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "http-fake"
5
- spec.version = "0.0.0"
5
+ spec.version = "0.1.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://www.alchemists.io/projects/http-fake"
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.required_ruby_version = "~> 3.1"
26
26
  spec.add_dependency "http", "~> 5.0"
27
27
  spec.add_dependency "mustermann", "~> 1.1"
28
- spec.add_dependency "refinements", "~> 9.4"
28
+ spec.add_dependency "refinements", "~> 9.6"
29
29
  spec.add_dependency "zeitwerk", "~> 2.5"
30
30
 
31
31
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
data.tar.gz.sig CHANGED
@@ -1 +1,4 @@
1
- ���@Fp.�S锡���!���`�)5[��a�{�oa0Ƒ��uwj;WH49G~t ��d�n~�#]<�A�ރ-l�v���³k��+�b9*��]�qg>��%�}W�8���U6.X����4�({��j�;
1
+ tMU�����X� a�8*v�~�lv�*�B��#�2��{�M9v�=�.�� 83��W��u1����Q#nP)6E2�F с�7��h�d��DI���$̫SFd�����X̛ ubyEY�f��w��(rZ��l��/vl����
2
+ ~C�<3Q�t�(1a:D�PDE.���5eȡ����S��x��Q��,iE��\&����7E
3
+ _y�~�<�������
4
+ ^��c MK��`��hH,u��A
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-fake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  CxDe2+VuChj4I1nvIHdu+E6XoEVlanUPKmSg6nddhkKn2gC45Kyzh6FZqnzH/CRp
29
29
  RFE=
30
30
  -----END CERTIFICATE-----
31
- date: 2022-05-15 00:00:00.000000000 Z
31
+ date: 2022-07-17 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: http
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '9.4'
67
+ version: '9.6'
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '9.4'
74
+ version: '9.6'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: zeitwerk
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  requirements: []
133
- rubygems_version: 3.3.13
133
+ rubygems_version: 3.3.18
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Provides a fake but equivalent implementation of the HTTP gem for test suites.
metadata.gz.sig CHANGED
Binary file