Skip to content
Browse files

Merge pull request #9 from wooga/missing_assertions

Missing assertions
  • Loading branch information...
2 parents 99cb89b + 346725c commit 709f8262c15db11f9bc055775bc6a93925d7c94a @johannesh johannesh committed
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),

0 comments on commit 709f826

Please sign in to comment.
Something went wrong with that request. Please try again.