/
iex.ex
39 lines (34 loc) · 980 Bytes
/
iex.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
defmodule ExVCR.IEx do
@moduledoc """
Provides helper functions for IEx.
"""
alias ExVCR.Recorder
@doc """
Provides helper for monitoring http request/response in cassette json format.
"""
defmacro print(options \\ [], test) do
adapter = options[:adapter] || ExVCR.Adapter.IBrowse
method_name = :"ExVCR.IEx.Sample#{ExVCR.Util.uniq_id()}"
quote do
defmodule unquote(method_name) do
use ExVCR.Mock, adapter: unquote(adapter)
def run do
recorder = Recorder.start(
unquote(options) ++ [fixture: "", adapter: unquote(adapter)])
try do
ExVCR.Mock.mock_methods(recorder, unquote(adapter))
unquote(test)
after
ExVCR.MockLock.release_lock()
Recorder.get(recorder)
|> JSX.encode!
|> JSX.prettify!
|> IO.puts
end
:ok
end
end
unquote(method_name).run()
end
end
end