@@ -21,7 +21,25 @@ defmodule Bypass do
2121
2222 Use the other functions in this module to declare which requests are handled
2323 and set expectations on the calls.
24+
25+ ## Options
26+
27+ - `port` - Optional TCP port to listen to requests
28+
29+ ## Examples
30+
31+ ```elixir
32+ bypass = Bypass.open()
33+ ```
34+
35+ Assign a specific port to a Bypass instance to listen on:
36+
37+ ```elixir
38+ bypass = Bypass.open(port: 1234)
39+ ```
40+
2441 """
42+ @ spec open ( Keyword . t ( ) ) :: Bypass . t ( ) | DynamicSupervisor . on_start_child ( )
2543 def open ( opts \\ [ ] ) do
2644 case DynamicSupervisor . start_child ( Bypass.Supervisor , Bypass.Instance . child_spec ( opts ) ) do
2745 { :ok , pid } ->
@@ -51,6 +69,7 @@ defmodule Bypass do
5169
5270 Returns `:ok` on success and raises an error on failure.
5371 """
72+ @ spec verify_expectations! ( Bypass . t ( ) ) :: :ok | no_return ( )
5473 def verify_expectations! ( bypass ) do
5574 verify_expectations! ( test_framework ( ) , bypass )
5675 end
@@ -101,13 +120,21 @@ defmodule Bypass do
101120 @ doc """
102121 Re-opens the TCP socket on the same port. Blocks until the operation is
103122 complete.
123+
124+ ```elixir
125+ Bypass.up(bypass)
126+ ```
104127 """
105128 @ spec up ( Bypass . t ( ) ) :: :ok | { :error , :already_up }
106129 def up ( % Bypass { pid: pid } ) ,
107130 do: Bypass.Instance . call ( pid , :up )
108131
109132 @ doc """
110133 Closes the TCP socket. Blocks until the operation is complete.
134+
135+ ```elixir
136+ Bypass.down(bypass)
137+ ```
111138 """
112139 @ spec down ( Bypass . t ( ) ) :: :ok | { :error , :already_down }
113140 def down ( % Bypass { pid: pid } ) ,
@@ -157,7 +184,7 @@ defmodule Bypass do
157184 end)
158185 ```
159186 """
160- @ spec expect ( Bypass . t ( ) , ( Plug.Conn . t ( ) -> Plug.Conn . t ( ) ) ) :: :ok
187+ @ spec expect_once ( Bypass . t ( ) , ( Plug.Conn . t ( ) -> Plug.Conn . t ( ) ) ) :: :ok
161188 def expect_once ( % Bypass { pid: pid } , fun ) ,
162189 do: Bypass.Instance . call ( pid , { :expect_once , fun } )
163190
0 commit comments