@@ -2,18 +2,7 @@ defmodule BypassTest do
22 use ExUnit.Case
33 doctest Bypass
44
5- if Code . ensure_loaded? ( ExUnit.CaptureLog ) do
6- defdelegate capture_log ( fun ) , to: ExUnit.CaptureLog
7- else
8- # Shim capture_log for Elixir 1.0
9- defp capture_log ( fun ) do
10- ExUnit.CaptureIO . capture_io ( :user , fn ->
11- fun . ( )
12- Logger . flush ( )
13- end )
14- |> String . strip ( )
15- end
16- end
5+ defdelegate capture_log ( fun ) , to: ExUnit.CaptureLog
176
187 test "show ISSUE #51" do
198 Enum . each (
@@ -37,7 +26,6 @@ defmodule BypassTest do
3726 defp specify_port ( port , expect_fun ) do
3827 bypass = Bypass . open ( port: port )
3928
40- # one of Bypass.expect or Bypass.expect_once
4129 apply ( Bypass , expect_fun , [
4230 bypass ,
4331 fn conn ->
@@ -62,7 +50,6 @@ defmodule BypassTest do
6250 defp down_socket ( expect_fun ) do
6351 bypass = Bypass . open ( )
6452
65- # one of Bypass.expect or Bypass.expect_once
6653 apply ( Bypass , expect_fun , [
6754 bypass ,
6855 fn conn -> Plug.Conn . send_resp ( conn , 200 , "" ) end
@@ -101,13 +88,12 @@ defmodule BypassTest do
10188 defp not_called ( expect_fun ) do
10289 bypass = Bypass . open ( )
10390
104- # one of Bypass.expect or Bypass.expect_once
10591 apply ( Bypass , expect_fun , [
10692 bypass ,
10793 fn _conn -> assert false end
10894 ] )
10995
110- # Override Bypass' on_exit handler
96+ # Override Bypass' on_exit handler.
11197 ExUnit.Callbacks . on_exit ( { Bypass , bypass . pid } , fn ->
11298 exit_result = Bypass.Instance . call ( bypass . pid , :on_exit )
11399 assert { :error , :not_called , { :any , :any } } = exit_result
@@ -125,7 +111,6 @@ defmodule BypassTest do
125111 defp pass ( expect_fun ) do
126112 bypass = Bypass . open ( )
127113
128- # one of Bypass.expect or Bypass.expect_once
129114 apply ( Bypass , expect_fun , [
130115 bypass ,
131116 fn _conn ->
@@ -152,11 +137,10 @@ defmodule BypassTest do
152137 defp closing_in_flight ( expect_fun ) do
153138 bypass = Bypass . open ( )
154139
155- # one of Bypass.expect or Bypass.expect_once
156140 apply ( Bypass , expect_fun , [
157141 bypass ,
158142 fn _conn ->
159- # mark the request as arrived, since we're shutting it down now
143+ # Mark the request as arrived, since we're shutting it down now.
160144 Bypass . pass ( bypass )
161145 Bypass . down ( bypass )
162146 end
@@ -179,7 +163,6 @@ defmodule BypassTest do
179163 ref = make_ref ( )
180164 bypass = Bypass . open ( )
181165
182- # one of Bypass.expect or Bypass.expect_once
183166 apply ( Bypass , expect_fun , [
184167 bypass ,
185168 fn conn ->
@@ -192,8 +175,8 @@ defmodule BypassTest do
192175
193176 assert { :ok , 200 , "" } = request ( bypass . port )
194177
195- # Here we make sure that Bypass.down waits until the plug process finishes its work
196- # before shutting down
178+ # Here we make sure that Bypass.down waits until the plug process finishes
179+ # its work before shutting down.
197180 refute_received ^ ref
198181 Bypass . down ( bypass )
199182 assert_received ^ ref
@@ -236,8 +219,8 @@ defmodule BypassTest do
236219 end )
237220 end )
238221
239- # Here we make sure that Bypass.down waits until the plug process finishes its work
240- # before shutting down
222+ # Here we make sure that Bypass.down waits until the plug process finishes
223+ # its work before shutting down.
241224 refute_received ^ ref
242225 :timer . sleep ( 200 )
243226 Bypass . down ( bypass )
@@ -256,7 +239,7 @@ defmodule BypassTest do
256239 assert { :ok , 500 , "" } = request ( bypass . port )
257240 end )
258241
259- # Override Bypass' on_exit handler
242+ # Override Bypass' on_exit handler.
260243 ExUnit.Callbacks . on_exit ( { Bypass , bypass . pid } , fn ->
261244 exit_result = Bypass.Instance . call ( bypass . pid , :on_exit )
262245 assert { :error , :unexpected_request , { :any , :any } } = exit_result
@@ -282,7 +265,7 @@ defmodule BypassTest do
282265 assert_receive :request_received
283266 end )
284267
285- # Override Bypass' on_exit handler
268+ # Override Bypass' on_exit handler.
286269 ExUnit.Callbacks . on_exit ( { Bypass , bypass . pid } , fn ->
287270 :ok == Bypass.Instance . call ( bypass . pid , :on_exit )
288271 end )
@@ -303,7 +286,7 @@ defmodule BypassTest do
303286 assert_receive :request_received
304287 refute_receive :request_received
305288
306- # Override Bypass' on_exit handler
289+ # Override Bypass' on_exit handler.
307290 ExUnit.Callbacks . on_exit ( { Bypass , bypass . pid } , fn ->
308291 exit_result = Bypass.Instance . call ( bypass . pid , :on_exit )
309292 assert { :error , :too_many_requests , { :any , :any } } = exit_result
@@ -347,7 +330,6 @@ defmodule BypassTest do
347330 method = "POST"
348331 path = "/this"
349332
350- # one of Bypass.expect or Bypass.expect_once
351333 apply ( Bypass , expect_fun , [
352334 bypass ,
353335 method ,
@@ -382,7 +364,6 @@ defmodule BypassTest do
382364 pattern = "/this/:resource/get/:id"
383365 path = "/this/my_resource/get/1234"
384366
385- # one of Bypass.expect or Bypass.expect_once
386367 apply ( Bypass , expect_fun , [
387368 bypass ,
388369 method ,
@@ -421,7 +402,6 @@ defmodule BypassTest do
421402 paths = [ "/this" , "/that" ]
422403
423404 Enum . each ( paths , fn path ->
424- # one of Bypass.expect or Bypass.expect_once
425405 apply ( Bypass , expect_fun , [
426406 bypass ,
427407 method ,
@@ -448,11 +428,11 @@ defmodule BypassTest do
448428 @ doc ~S"""
449429 Open a new HTTP connection and perform the request. We don't want to use httpc, hackney or another
450430 "high-level" HTTP client, since they do connection pooling and we will sometimes get a connection
451- closed error and not a failed to connect error, when we test Bypass.down
431+ closed error and not a failed to connect error, when we test Bypass.down.
452432 """
453433 def request ( port , path \\ "/example_path" , method \\ "POST" ) do
454434 with { :ok , conn } <- Mint.HTTP . connect ( :http , "127.0.0.1" , port ) ,
455- { :ok , conn , ref } = Mint.HTTP . request ( conn , method , path , [ ] , "" ) do
435+ { :ok , conn , ref } <- Mint.HTTP . request ( conn , method , path , [ ] , "" ) do
456436 receive_responses ( conn , ref , 100 , [ ] )
457437 end
458438 end
@@ -490,11 +470,11 @@ defmodule BypassTest do
490470 end
491471 end
492472
493- test "Bypass.expect/4 can be used to define a specific route and then redefined " do
473+ test "Bypass.expect/4 can be used to define a specific route and then redefine it later " do
494474 :expect |> specific_route_redefined
495475 end
496476
497- test "Bypass.expect_once/4 can be used to define a specific route and then redefined " do
477+ test "Bypass.expect_once/4 can be used to define a specific route and then redefine it later " do
498478 :expect_once |> specific_route_redefined
499479 end
500480
@@ -503,7 +483,6 @@ defmodule BypassTest do
503483 method = "POST"
504484 path = "/this"
505485
506- # one of Bypass.expect or Bypass.expect_once
507486 apply ( Bypass , expect_fun , [
508487 bypass ,
509488 method ,
@@ -519,7 +498,7 @@ defmodule BypassTest do
519498 assert { :ok , 200 , "" } = request ( bypass . port , path )
520499 end )
521500
522- # redefining the expect
501+ # Redefine the expect
523502 apply ( Bypass , expect_fun , [
524503 bypass ,
525504 method ,
0 commit comments