derekkraan / walkman Goto Github PK
View Code? Open in Web Editor NEWIsolate tests from the real world, inspired by Ruby's VCR.
Isolate tests from the real world, inspired by Ruby's VCR.
If this path isn't present, Walkman will exit with an error:
▏ ▏** (exit) exited in: GenServer.call(#PID<0.777.0>, :finish, 5000)
▏ ▏ ▏ ▏** (EXIT) an exception was raised:
▏ ▏ ▏ ▏ ▏ ▏** (File.Error) could not write to file "test/fixtures/walkman/my_tape_name": no such file or directory
▏ ▏ ▏ ▏ ▏ ▏ ▏ ▏(elixir 1.11.2) lib/file.ex:1052: File.write!/3
▏ ▏ ▏ ▏ ▏ ▏ ▏ ▏(walkman 0.3.3) lib/walkman/tape.ex:172: Walkman.Tape.handle_call/3
▏ ▏ ▏ ▏ ▏ ▏ ▏ ▏(stdlib 3.13.2) gen_server.erl:706: :gen_server.try_handle_call/4
▏ ▏ ▏ ▏ ▏ ▏ ▏ ▏(stdlib 3.13.2) gen_server.erl:735: :gen_server.handle_msg/6
▏ ▏ ▏ ▏ ▏ ▏ ▏ ▏(stdlib 3.13.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
It also looks like the directory is hard-coded -- it would be nice to make it configurable.
Thanks for Walkman! 🙇
I trialled it as a replacement for exvcr. Unfortunately I don't think it will work for my use case currently. I have database records which are being auto-generated on each test run, and so they have different IDs on each run (as well as other randomly-generated data that differs on each run).
My code is passing these IDs into an external API which I'm stubbing with Walkman. Once I've recorded my tape on the first run, on the second run I get an error along the lines of: {:walkman_error, "replay found {...} didn't match given mfa {...}
because those IDs don't match.
exvcr, and Ruby's vcr which it is based upon, handle this by configurable "request matching". By default they only match on the URI, so differing params don't cause a problem. Obviously Walkman knows nothing about URIs so this is not a direct option.
I guess I'd like to be able to configure some sort of "call matcher" for Walkman, and perhaps there would be an option to only match by function name/arity. So long as my tape is replayed with the function calls in the same order, Walkman would return the recorded return values. This would probably be sufficient for my use case.
I could also imagine some sort of configurable matcher function for custom logic.
I'm also keen to hear your thoughts about this use case and whether there are workarounds I haven't thought of.
I have an external API under test, let's call it Twitter for the sake of the example.
Suppose my real implementation is MyApp.Twitter.LiveClient
, and I am using Mox to be able to implement mocks around this API. So I also have a behaviour, MyApp.Twitter.Client
, and a stub client MyApp.Twitter.StubClient
. I define a mock client with Mox
:
Mox.defmock(MyApp.Twitter.MockClient, for: MyApp.Twitter.Client)
In test mode, my app code is configured to use MyApp.Twitter.MockClient
, which allows me to enable the stub client:
Mox.stub_with(MyApp.Twitter.MockClient, MyApp.Twitter.StubClient)
And I can also enable the live client:
Mox.stub_with(MyApp.Twitter.MockClient, MyApp.Twitter.LiveClient)
What I'd like to be able to do is have recorded responses when using the live client. So I install Walkman and do this:
Walkman.def_stub(MyApp.Twitter.RecordedClient, for: MyApp.Twitter.LiveClient)
Unfortunately, if I now try to instruct Mox to switch in the recorded client:
Mox.stub_with(MyApp.Twitter.MockClient, MyApp.Twitter.RecordedClient)
I'll get an error, because MyApp.Twitter.RecordedClient
doesn't implement the MyApp.Twitter.Client
behaviour.
I can work around the problem by creating a wrapper module, which does implement the behaviour, and delegates to MyApp.Twitter.RecordedClient
:
defmodule MyApp.Twitter.RecordedClientWrapper do
@behaviour MyApp.Twitter.Client
Enum.each(MyApp.Twitter.Client.behaviour_info(:callbacks), fn {fun, arity} ->
args = Macro.generate_arguments(arity, MyApp.Twitter.Client)
@impl MyApp.Twitter.Client
defdelegate unquote(fun)(unquote_splicing(args)),
to: MyApp.Twitter.RecordedClient
end)
end
And now pass that to Mox:
Mox.stub_with(MyApp.Twitter.MockClient, MyApp.Twitter.RecordedClientWrapper)
It would be nice to have support for this use case baked into Walkman.def_stub
. Perhaps something like this:
Walkman.def_stub(MyApp.Twitter.RecordedClient, for: MyApp.Twitter.LiveClient, impl: MyApp.Twitter.Client)
Or perhaps it's even possible for Walkman to notice that MyApp.Twitter.LiveClient
implements MyApp.Twitter.Client
and act accordingly, I don't know...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.