     doctest = "\n" <> formatted <> "\n" <> expected
     expr_ast = string_to_quoted(location, stack, expr, doctest) |> insert_assertions()
     expected_ast = string_to_quoted(location, stack, expected, doctest)
-    last_expr_ast = Macro.to_string(last_expr(expr_ast))
+    last_expr = Macro.to_string(last_expr(expr_ast))
 
     quote do
+      value = unquote(expr_ast)
       expected = unquote(expected_ast)
-      value = unquote(expr_ast)
-      doctest = unquote(doctest)
-      expr = <<"inspect(", unquote(last_expr_ast), ") === ", unquote(String.trim(expected))>>
+      formatted = unquote(formatted)
+      last_expr = unquote(last_expr)
+      expected_expr = unquote(expected)
       stack = unquote(stack)
 
-      ExUnit.DocTest.__inspect__(value, expected, doctest, expr, stack)
+      ExUnit.DocTest.__inspect__(value, expected, formatted, last_expr, expected_expr, stack)
     end
   end
 

        actual_exception = error.__struct__
        actual_message = Exception.message(error)

        message =
          cond do
            actual_exception != exception ->
              "Doctest failed: expected exception #{inspect(exception)} but got " <>


    quote do
      stack = unquote(stack)
      message = unquote(message)
      formatted = unquote(formatted)
      exception = unquote(exception)
      ExUnit.DocTest.__error__(fn -> unquote(expr_ast) end, message, exception, formatted, stack)
    end
  end

  @doc false
  def __test__(value, expected, formatted, last_expr, expected_expr, stack) do
    case value do
      ^expected ->
        :ok

      _ ->
        error = [
          message: "Doctest failed",
          doctest: "\n" <> formatted <> "\n" <> expected_expr,
          expr: "#{last_expr} === #{String.trim(expected_expr)}",
          left: value,
          right: expected
        ]

