GithubHelp home page GithubHelp logo

Comments (6)

MSch avatar MSch commented on August 21, 2024

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?

from bypass.

jimsynz avatar jimsynz commented on August 21, 2024

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.

from bypass.

MSch avatar MSch commented on August 21, 2024

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

from bypass.

mwean avatar mwean commented on August 21, 2024

@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

from bypass.

MSch avatar MSch commented on August 21, 2024

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

from bypass.

MSch avatar MSch commented on August 21, 2024

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

from bypass.

Related Issues (20)

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.