22
33[ ![ Build Status] ( https://travis-ci.org/PSPDFKit-labs/bypass.svg?branch=master )] ( https://travis-ci.org/PSPDFKit-labs/bypass )
44
5- Bypass provides a quick way to create a custom plug that can be put in place instead of an actual
5+ [ Online Documentation] ( https://hexdocs.pm/bypass ) .
6+
7+ <!-- MDOC !-->
8+
9+ ` Bypass ` provides a quick way to create a custom plug that can be put in place instead of an actual
610HTTP server to return prebaked responses to client requests. This is most useful in tests, when you
711want to create a mock HTTP server and test how your HTTP client handles different types of
812responses from the server.
913
10- ## Installation
11-
12- Add bypass to your list of dependencies in mix.exs:
13-
14- ``` elixir
15- def deps do
16- [
17- {:bypass , " ~> 1.0" , only: :test }
18- ]
19- end
20- ```
21-
22- We do not recommended adding ` :bypass ` to the list of applications in your ` mix.exs ` . See below
23- for usage info.
24-
2514Bypass supports Elixir 1.6 and OTP 20 and up. It works with Cowboy 1 and 2.
2615
27-
2816## Usage
2917
3018To use Bypass in a test case, open a connection and use its port to connect your client to it.
@@ -42,75 +30,6 @@ You can take any of the following approaches:
4230* a combination of the above, where the routes will be used first, and then the generic version
4331 will be used as default
4432
45- #### expect/2 (bypass_instance, function)
46-
47- Must be called at least once.
48-
49- ``` elixir
50- Bypass .expect (bypass, fn conn ->
51- assert " /1.1/statuses/update.json" == conn.request_path
52- assert " POST" == conn.method
53- Plug .Conn .resp (conn, 429 , ~s< {"errors": [{"code": 88, "message": "Rate limit exceeded"}]}> )
54- end )
55- ```
56-
57- #### expect_once/2 (bypass_instance, function)
58-
59- Must be called exactly once.
60-
61- ``` elixir
62- Bypass .expect_once (bypass, fn conn ->
63- assert " /1.1/statuses/update.json" == conn.request_path
64- assert " POST" == conn.method
65- Plug .Conn .resp (conn, 429 , ~s< {"errors": [{"code": 88, "message": "Rate limit exceeded"}]}> )
66- end )
67- ```
68-
69- #### expect/4 (bypass_instance, method, path, function)
70-
71- Must be called at least once.
72-
73- ` method ` is one of ` ["GET", "POST", "HEAD", "PUT", "PATCH", "DELETE", "OPTIONS", "CONNECT"] `
74-
75- ` path ` is the endpoint.
76-
77- ``` elixir
78- Bypass .expect (bypass, " POST" , " /1.1/statuses/update.json" , fn conn ->
79- Agent .get_and_update (AgentModule , fn step_no -> {step_no, step_no + 1 } end )
80- Plug .Conn .resp (conn, 429 , ~s< {"errors": [{"code": 88, "message": "Rate limit exceeded"}]}> )
81- end )
82- ```
83-
84- #### expect_once/4 (bypass_instance, method, path, function)
85-
86- Must be called exactly once.
87-
88- ` method ` is one of ` ["GET", "POST", "HEAD", "PUT", "PATCH", "DELETE", "OPTIONS", "CONNECT"] `
89-
90- ` path ` is the endpoint.
91-
92- ``` elixir
93- Bypass .expect_once (bypass, " POST" , " /1.1/statuses/update.json" , fn conn ->
94- Agent .get_and_update (AgentModule , fn step_no -> {step_no, step_no + 1 } end )
95- Plug .Conn .resp (conn, 429 , ~s< {"errors": [{"code": 88, "message": "Rate limit exceeded"}]}> )
96- end )
97- ```
98-
99- #### stub/4 (bypass_instance, method, path, function)
100-
101- May be called none or more times.
102-
103- ` method ` is one of ` ["GET", "POST", "HEAD", "PUT", "PATCH", "DELETE", "OPTIONS", "CONNECT"] `
104-
105- ` path ` is the endpoint.
106-
107- ``` elixir
108- Bypass .stub (bypass, " POST" , " /1.1/statuses/update.json" , fn conn ->
109- Agent .get_and_update (AgentModule , fn step_no -> {step_no, step_no + 1 } end )
110- Plug .Conn .resp (conn, 429 , ~s< {"errors": [{"code": 88, "message": "Rate limit exceeded"}]}> )
111- end )
112- ```
113-
11433### Example
11534
11635In the following example ` TwitterClient.start_link() ` takes the endpoint URL as its argument
@@ -224,6 +143,22 @@ Set `:enable_debug_log` to `true` in the application environment to make Bypass
224143config :bypass , enable_debug_log: true
225144```
226145
146+ <!-- MDOC !-->
147+
148+ ## Installation
149+
150+ Add bypass to your list of dependencies in mix.exs:
151+
152+ ``` elixir
153+ def deps do
154+ [
155+ {:bypass , " ~> 1.0" , only: :test }
156+ ]
157+ end
158+ ```
159+
160+ We do not recommended adding ` :bypass ` to the list of applications in your ` mix.exs ` .
161+
227162## License
228163
229164This software is licensed under [ the MIT license] ( LICENSE ) .
0 commit comments