Skip to content

Commit c77fa5b

Browse files
committed
Format code in README.md
1 parent f44ec27 commit c77fa5b

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

README.md

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ Add bypass to your list of dependencies in mix.exs:
1313

1414
```elixir
1515
def deps do
16-
[{:bypass, "~> 1.0", only: :test}]
16+
[
17+
{:bypass, "~> 1.0", only: :test}
18+
]
1719
end
1820
```
1921

@@ -28,7 +30,7 @@ Bypass supports Elixir 1.6 and OTP 20 and up. It works with Cowboy 1 and 2.
2830
Start Bypass in your `test/test_helper.exs` file to make it available in tests:
2931

3032
```elixir
31-
ExUnit.start
33+
ExUnit.start()
3234
Application.ensure_all_started(:bypass)
3335
```
3436

@@ -52,23 +54,23 @@ You can take any of the following approaches:
5254
Must be called at least once.
5355

5456
```elixir
55-
Bypass.expect bypass, fn conn ->
56-
assert "/1.1/statuses/update.json" == conn.request_path
57-
assert "POST" == conn.method
58-
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
59-
end
57+
Bypass.expect(bypass, fn conn ->
58+
assert "/1.1/statuses/update.json" == conn.request_path
59+
assert "POST" == conn.method
60+
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
61+
end)
6062
```
6163

6264
#### expect_once/2 (bypass_instance, function)
6365

6466
Must be called exactly once.
6567

6668
```elixir
67-
Bypass.expect_once bypass, fn conn ->
68-
assert "/1.1/statuses/update.json" == conn.request_path
69-
assert "POST" == conn.method
70-
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
71-
end
69+
Bypass.expect_once(bypass, fn conn ->
70+
assert "/1.1/statuses/update.json" == conn.request_path
71+
assert "POST" == conn.method
72+
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
73+
end)
7274
```
7375

7476
#### expect/4 (bypass_instance, method, path, function)
@@ -80,10 +82,10 @@ Must be called at least once.
8082
`path` is the endpoint.
8183

8284
```elixir
83-
Bypass.expect bypass, "POST", "/1.1/statuses/update.json", fn conn ->
84-
Agent.get_and_update(AgentModule, fn step_no -> {step_no, step_no+1} end)
85-
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
86-
end
85+
Bypass.expect(bypass, "POST", "/1.1/statuses/update.json", fn conn ->
86+
Agent.get_and_update(AgentModule, fn step_no -> {step_no, step_no + 1} end)
87+
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
88+
end)
8789
```
8890

8991
#### expect_once/4 (bypass_instance, method, path, function)
@@ -95,10 +97,10 @@ Must be called exactly once.
9597
`path` is the endpoint.
9698

9799
```elixir
98-
Bypass.expect_once bypass, "POST", "/1.1/statuses/update.json", fn conn ->
99-
Agent.get_and_update(AgentModule, fn step_no -> {step_no, step_no+1} end)
100-
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
101-
end
100+
Bypass.expect_once(bypass, "POST", "/1.1/statuses/update.json", fn conn ->
101+
Agent.get_and_update(AgentModule, fn step_no -> {step_no, step_no + 1} end)
102+
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
103+
end)
102104
```
103105

104106
#### stub/4 (bypass_instance, method, path, function)
@@ -110,10 +112,10 @@ May be called none or more times.
110112
`path` is the endpoint.
111113

112114
```elixir
113-
Bypass.stub bypass, "POST", "/1.1/statuses/update.json", fn conn ->
114-
Agent.get_and_update(AgentModule, fn step_no -> {step_no, step_no+1} end)
115-
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
116-
end
115+
Bypass.stub(bypass, "POST", "/1.1/statuses/update.json", fn conn ->
116+
Agent.get_and_update(AgentModule, fn step_no -> {step_no, step_no + 1} end)
117+
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
118+
end)
117119
```
118120

119121
### Example
@@ -126,23 +128,25 @@ defmodule TwitterClientTest do
126128
use ExUnit.Case, async: true
127129

128130
setup do
129-
bypass = Bypass.open
131+
bypass = Bypass.open()
130132
{:ok, bypass: bypass}
131133
end
132134

133135
test "client can handle an error response", %{bypass: bypass} do
134-
Bypass.expect_once bypass, "POST", "/1.1/statuses/update.json", fn conn ->
136+
Bypass.expect_once(bypass, "POST", "/1.1/statuses/update.json", fn conn ->
135137
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
136-
end
138+
end)
139+
137140
{:ok, client} = TwitterClient.start_link(url: endpoint_url(bypass.port))
138141
assert {:error, :rate_limited} == TwitterClient.post_tweet(client, "Elixir is awesome!")
139142
end
140143

141144
test "client can recover from server downtime", %{bypass: bypass} do
142-
Bypass.expect bypass, fn conn ->
145+
Bypass.expect(bypass, fn conn ->
143146
# We don't care about `request_path` or `method` for this test.
144147
Plug.Conn.resp(conn, 200, "")
145-
end
148+
end)
149+
146150
{:ok, client} = TwitterClient.start_link(url: endpoint_url(bypass.port))
147151

148152
assert :ok == TwitterClient.post_tweet(client, "Elixir is awesome!")
@@ -198,7 +202,7 @@ defmodule TwitterClientSpec do
198202
use ESpec, async: true
199203

200204
before do
201-
bypass = Bypass.open
205+
bypass = Bypass.open()
202206
{:shared, bypass: bypass}
203207
end
204208

@@ -207,9 +211,10 @@ defmodule TwitterClientSpec do
207211
end
208212

209213
specify "the client can handle an error response" do
210-
Bypass.expect_once shared.bypass, "POST", "/1.1/statuses/update.json", fn conn ->
214+
Bypass.expect_once(shared.bypass, "POST", "/1.1/statuses/update.json", fn conn ->
211215
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
212-
end
216+
end)
217+
213218
{:ok, client} = TwitterClient.start_link(url: endpoint_url(shared.bypass.port))
214219
assert {:error, :rate_limited} == TwitterClient.post_tweet(client, "Elixir is awesome!")
215220
end

0 commit comments

Comments
 (0)