Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support config option to start without ExUnit hooks. #9

Closed
jimsynz opened this issue Jan 28, 2016 · 6 comments
Closed

Support config option to start without ExUnit hooks. #9

jimsynz opened this issue Jan 28, 2016 · 6 comments

Comments

@jimsynz
Copy link

jimsynz commented Jan 28, 2016

Hi there.

I'm using Bypass with espec. It'd be amazing if it were possible to just call Bypass.open without it exploding - I'm currently starting and stopping the bypass supervisor in my test setup and teardown.

@MSch
Copy link
Member

MSch commented Jan 28, 2016

Hi James,

Bypass needs ExUnit's on_exit callbacks to check if a request actually arrived at the started Plug (and to rethrow an exception that happened). If you can come up with a solution that makes Bypass work with ExUnit as well was espec I'd be happy to merge it. I'm assuming adding an application configuration to tell bypass whether it's running in ExUnit or espec would make sense, what do you think?

@jimsynz
Copy link
Author

jimsynz commented Feb 3, 2016

Okay. I'll have a think about how we could have it work. I'd suggest that we abstract it into separate "drivers" for each test framework.

@MSch
Copy link
Member

MSch commented Apr 1, 2016

Hi @jamesotron, just wanted to check if you found a workaround in the meantime?

@mwean
Copy link

mwean commented Dec 30, 2016

@MSch this is what I did that seems to work against master:

  before_all do
    Application.ensure_all_started(:bypass)
  end

  let :bypass, do: start_bypass

  finally do
    case Bypass.Instance.call(bypass.pid, :on_exit) do
      :ok ->
        :ok
      :ok_call ->
        :ok
      {:error, :not_called} ->
        raise ESpec.AssertionError, "No HTTP request arrived at Bypass"
      {:error, :unexpected_request} ->
        raise ESpec.AssertionError, "Bypass got an HTTP request but wasn't expecting one"
      {:exit, {class, reason, stacktrace}} ->
        :erlang.raise(class, reason, stacktrace)
    end
  end

  def start_bypass do
    case Supervisor.start_child(Bypass.Supervisor, []) do
      {:ok, pid} ->
        port = Bypass.Instance.call(pid, :port)
        %Bypass{pid: pid, port: port}
      other ->
        other
    end
  end

@MSch
Copy link
Member

MSch commented Jun 21, 2017

This looks excellent. We are not using espec ourselves, but if you submit a PR on top of #36 we can merge this in. 👍

@MSch
Copy link
Member

MSch commented Jul 19, 2017

FYI I just released 0.8.0 of bypass with @tompave's ESpec support included ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants