defmodule PlugRibbonTest do use ExUnit.Case, async: true use Plug.Test setup do Logger.disable(self()) :ok end @ribbon_string ~s(
) test "injects ribbon in dev environment" do Mix.env(:dev) conn = conn(:get, "/") |> put_resp_content_type("text/html") |> resp(200, "

Phoenix

") |> Plug.Ribbon.call([:dev, :test]) |> send_resp() assert conn.status == 200 assert to_string(conn.resp_body) =~ @ribbon_string end test "injects ribbon in test environment" do Mix.env(:test) conn = conn(:get, "/") |> put_resp_content_type("text/html") |> resp(200, "

Phoenix

") |> Plug.Ribbon.call([:dev, :test]) |> send_resp() assert conn.status == 200 assert to_string(conn.resp_body) =~ @ribbon_string end test "does not inject ribbon in prod environment" do Mix.env(:prod) conn = conn(:get, "/") |> put_resp_content_type("text/html") |> resp(200, "

Phoenix

") |> Plug.Ribbon.call([:dev, :test]) |> send_resp() assert conn.status == 200 refute to_string(conn.resp_body) =~ @ribbon_string end test "does not inject ribbon if html response missing body tag" do Mix.env(:dev) conn = conn(:get, "/") |> put_resp_content_type("text/html") |> resp(200, "

Phoenix

") |> Plug.Ribbon.call([:dev, :test]) |> send_resp() assert conn.status == 200 refute to_string(conn.resp_body) =~ @ribbon_string end test "does not inject ribbon if response is json" do Mix.env(:dev) conn = conn(:get, "/") |> put_resp_content_type("application/json") |> resp(200, "{}") |> Plug.Ribbon.call([:dev, :test]) |> send_resp() assert conn.status == 200 refute to_string(conn.resp_body) =~ @ribbon_string end end