Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Missing assertions #9

Merged
merged 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 11 deletions.
  1. +28 −11 include/etest_http.hrl
  2. +2 −0  test/etest_http_test.erl
View
39 include/etest_http.hrl
@@ -54,34 +54,52 @@
end
end)())).
-
--define (assert_contains(Needle, Haystack),
+-define (assert_contains_result(Needle, Haystack, ExpectedResult),
((fun() ->
case string:str(Haystack, Needle) of
- 0 -> erlang:error({assert_contains,
- [{module, ?MODULE},
- {line, ?LINE},
- {haystack, (??Haystack)},
- {needle, (??Needle)}] });
+ ExpectedResult -> erlang:error({assert_contains,
+ [{module, ?MODULE},
+ {line, ?LINE},
+ {haystack, (??Haystack)},
+ {needle, (??Needle)}] });
_ -> ok
end
end)())).
--define (assert_body_contains(Needle, Res),
+-define (assert_contains(Needle, Haystack),
+((fun() ->
+ ?assert_contains_result(Needle, Haystack, 0)
+end)())).
+
+-define (assert_not_contains(Needle, Haystack),
+((fun() ->
+ ?assert_contains_result(Needle, Haystack, 1)
+end)())).
+
+-define (assert_body_contains_result(Needle, Res, Result),
((fun(__Res) ->
Body = case __Res#etest_http_res.body of
Binary when is_binary(Binary) -> binary_to_list(Binary);
String -> String
end,
- ?assert_contains(Needle, Body)
+ ?assert_contains_result(Needle, Body, Result)
end)(Res))).
+-define (assert_body_contains(Needle, Res),
+((fun() ->
+ ?assert_body_contains_result(Needle, Res, 0)
+end)())).
+
+-define (assert_body_not_contains(Needle, Res),
+((fun() ->
+ ?assert_body_contains_result(Needle, Res, 1)
+end)())).
+
-define (assert_body(Body, Res),
((fun(__Res) ->
?assert_equal(Body, __Res#etest_http_res.body)
end)(Res))).
-
-define (assert_header(HeaderName, Res),
((fun(__Res) ->
Headers = __Res#etest_http_res.headers,
@@ -96,7 +114,6 @@ end)(Res))).
end
end)(Res))).
-
-define (assert_header_value(HeaderName, HeaderValue0, Res),
((fun(HeaderValue, __Res) ->
__Headers = __Res#etest_http_res.headers,
View
2  test/etest_http_test.erl
@@ -28,6 +28,8 @@ test_response_assertions() ->
?assert_status(200, Res),
?assert_error({assert_status, _}, ?assert_status(400, Res)),
?assert_body_contains("Hello", Res),
+ ?assert_body_not_contains("Olleh", Res),
+
?assert_error({assert_contains, _}, ?assert_body_contains("Olleh", Res)),
?assert_header("date", Res),
Something went wrong with that request. Please try again.