Git Product home page Git Product logo

walkman's People

Contributors

caioceccon avatar derekkraan avatar fidr avatar sobolevn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

walkman's Issues

Create `test/fixtures/walkman/` if it doesn't exist

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.

Handle scenarios where the inputs change on each test run

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.

Allow Walkman to play nicely with Mox

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...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.