Walkman v0.2.1 Walkman View Source
Walkman helps you isolate your tests from the outside world.
Getting started
# test/test_helper.exs
Walkman.start_link()
# config/config.exs
config :my_app, my_module: MyModule
Change references to MyModule
in your application to Application.get_env(:my_app, :my_module)
# config/test.exs
config :my_app, my_module: MyModuleWrapper
# test/support/my_module_wrapper.ex
defmodule MyModuleWrapper do
use Walkman.Wrapper, MyModule
end
# test/my_module_test.exs
test "MyModule" do
Walkman.use_tape "MyModule1" do
assert :ok = calls_my_module()
end
end
Recording tapes
The first time you run the tests, Walkman will record test fixtures. You should commit these to your git repository. To re-record your fixtures, delete them and run the tests again (or put Walkman.set_mode(:replay)
in test/test_helper.ex
).
Link to this section Summary
Functions
Set Walkman's mode. The default is :normal
Start walkman (in test/test_helper.ex
)
Load a tape for use in a test
Link to this section Functions
Link to this function
set_mode(mode)
View Source
set_mode(mode)
View Source
set_mode(mode :: :normal | :replay | :record) :: :ok
set_mode(mode :: :normal | :replay | :record) :: :ok
Set Walkman's mode. The default is :normal
.
Walkman has three modes:
:normal
- if a tape is found, then the tape is replayed. If there is no tape, then a new one is made. This is the closest to how Ruby's VCR works.:replay
- only replay, and raise an exception if no pre-recorded tape is found. This should be used when running the tests on the CI.:record
- all calls are passed through to the implementation and record new tapes. This can be used to re-record tapes.:integration
- calls are passed through to the implementation but no new tapes are made. Useful for running integration tests on the CI.
Link to this function
start_link()
View Source
start_link()
View Source
start_link() :: GenServer.on_start()
start_link() :: GenServer.on_start()
Start walkman (in test/test_helper.ex
)
Link to this macro
use_tape(test_id, test_options \\ [], list) View Source (macro)
Load a tape for use in a test.
test "MyModule" do
Walkman.use_tape "MyModule" do
assert {:ok, _} = MyModule.my_function
end
end