Function Bypass.open/1 is undefined or private

Hi all

I am using bypass to create a http mock server for test.

  setup do
    bypass = Bypass.open(port: 3000)
    {:ok, bypass: bypass}
  end

As you can see, the port is set to 3000 and when I start the test, I’ve got following error:

  1) test Handle user login. (SapOdataService.Auth.UserLoginTest)
     test/auth/user_login_test.exs:31
     ** (UndefinedFunctionError) function Bypass.open/1 is undefined or private. Did you mean one of:

           * open/0

     stacktrace:
       (bypass) Bypass.open([port: 3000])
       test/auth/user_login_test.exs:9: SapOdataService.Auth.UserLoginTest.__ex_unit_setup_0/1
       test/auth/user_login_test.exs:1: SapOdataService.Auth.UserLoginTest.__ex_unit__/2

What am I doing wrong?

Thanks

it looks like Bypass.open/1 is not in a released version yet. you might need to include bypass from github in your mix.exs ({:bypass, github: "PSPDFKit-labs/bypass"}

Fist of all, thanks for your answer. Now an other problem occurs:

  1) test Handle user login. (SapOdataService.Auth.UserLoginTest)
     test/auth/user_login_test.exs:31
     ** (exit) exited in: :gen_server.call(:hackney_manager, {:new_request, #PID<0.222.0>, #Reference<0.0.7.579>, {:client, :undefined, {:metrics_ng, :metrics_dummy}, :hackney_tcp, 'localhost', 3000, "localhost:3000", [], nil, nil, nil, true, :hackney_pool, 5000, false, 5, false, 5, nil, nil, nil, :undefined, :start, nil, :normal, false, false, false, :undefined, false, nil, :waiting, nil, 4096, "", [], :undefined, nil, nil, nil, nil, :undefined, nil}}, :infinity)
         ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
     stacktrace:
       (stdlib) gen_server.erl:212: :gen_server.call/3
       src/hackney_manager.erl:66: :hackney_manager.init_request/1
       src/hackney_manager.erl:56: :hackney_manager.new_request/1
       src/hackney_connect.erl:185: :hackney_connect.socket_from_pool/4
       src/hackney_connect.erl:37: :hackney_connect.connect/5
       src/hackney.erl:328: :hackney.request/5
       lib/httpoison/base.ex:422: HTTPoison.Base.request/9
       (sap_odata_service) lib/auth/user_login.ex:21: SapOdataService.Protocols.Auth.SapOdataService.Auth.UserLogin.sign_in/1
       test/auth/user_login_test.exs:50: (test)

.

Finished in 0.1 seconds
2 tests, 1 failure

It seems like you’ve ommited

# test/test_helper.exs
Application.ensure_all_started(:bypass)

And hackney application as a dependency was not started correctly.

I used bypass recently and encountered the same issues you have. For an example of how I ended up using it feel free to have a look through this.

The actual usage in the test
https://github.com/swelham/cashier/blob/master/test/gateways/paypal_test.exs

You will also need this in your test helper file
Application.ensure_all_started(:bypass)

And this is the dependency I am using
{:bypass, git: "https://github.com/PSPDFKit-labs/bypass.git", only: :test}

1 Like

Thanks so much.

No problem.

I am hoping a new release of bypass might happen at some point, but it looks as though no one is actively maintaining it sadly :icon_sad:

1 Like