       Code.string_to_quoted!(expr, line: line, file: file)
     rescue e ->
       quote do
-        raise ExUnit.ExpectationError,
-          [ prelude: "Expected doctest",
-            expr: unquote(String.strip(expr)),
-            expected: "successfully",
-            assertion: "compile",
-            actual: unquote("** #{inspect e.__record__(:name)} #{e.message}") ],
+        raise ExUnit.AssertionError,
+          [ message: "Doctest failed",
+            expr: "#{unquote(String.strip(expr))} did now compile",
+            left: unquote("** #{inspect e.__record__(:name)} #{e.message}") ],
           unquote(stack)
       end
     end

      exception = inspect(unquote(exception)) <> " with message " <> inspect(unquote(message))
      try do
        v = unquote(expr_ast)
        raise ExUnit.ExpectationError,
          [ prelude: "Expected doctest",
            expr: expr,
            expected: exception,
            assertion: "raise",
            actual: inspect(v) ],
          stack
      rescue
        error in [unquote(exception)] ->
          unless error.message == unquote(message) do
            raise ExUnit.ExpectationError,
              [ prelude: "Expected doctest",
                expr: expr,
                expected: exception,
                assertion: "raise",
                actual: inspect(elem(error, 0)) <> " with message " <> inspect(error.message) ],
              stack
          end


        # Put all tests into one context
        unquote_splicing(tests)
      rescue
        e in [ExUnit.AssertionError] ->
          raise e, [], stack

        error ->
          raise ExUnit.AssertionError,
            [ message: "Doctest failed—incorrect assertion generated",
              expr: unquote(whole_expr),
              left: unquote(exception),
              # We're using a combined message here because all expressions
              # (those that are expected to raise and those that aren't) are in
              # the same try block above.
              right: inspect(elem(error, 0)) <> " with message " <> error.message ],
            stack
      end
    end
