Browse files

Simplify some assertion tests

  • Loading branch information...
1 parent d14687b commit 52d406dac24fa3cff5f4d59f0c721e422c4c45fb @josevalim josevalim committed Sep 7, 2012
Showing with 58 additions and 86 deletions.
  1. +58 −86 lib/ex_unit/test/ex_unit/assertions_test.exs
View
144 lib/ex_unit/test/ex_unit/assertions_test.exs
@@ -182,51 +182,43 @@ defmodule ExUnit.AssertionsTest do
end
test :assert_raise_when_other_error do
- try do
- "This should never be tested" = assert_raise ArgumentError, fn ->
- Certainly.Undefined.function(1,2,3)
- end
- rescue
- error in [ExUnit.AssertionError] ->
- "Expected exception ArgumentError, got UndefinedFunctionError (undefined function: Certainly.Undefined.function/3)" = error.message
+ "This should never be tested" = assert_raise ArgumentError, fn ->
+ Certainly.Undefined.function(1,2,3)
end
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "Expected exception ArgumentError, got UndefinedFunctionError (undefined function: Certainly.Undefined.function/3)" = error.message
end
test :assert_raise_when_erlang_error do
- try do
- assert_raise SyntaxError, fn ->
- List.flatten(1)
- end
- rescue
- error in [ExUnit.AssertionError] ->
- "Expected exception SyntaxError, got FunctionClauseError (no function clause matching: :lists.flatten(1))" = error.message
+ assert_raise SyntaxError, fn ->
+ List.flatten(1)
end
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "Expected exception SyntaxError, got FunctionClauseError (no function clause matching: :lists.flatten(1))" = error.message
end
test :assert_operator_greater_pass do
true = assert 2 > 1
end
test :assert_operator_greater_fail do
- try do
- "This should never be tested" = assert 1 > 2
- rescue
- error in [ExUnit.AssertionError] ->
- "Expected 1 to be more than 2" = error.message
- end
+ "This should never be tested" = assert 1 > 2
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "Expected 1 to be more than 2" = error.message
end
test :assert_operator_less_or_equal_than_pass do
true = assert 1 <= 2
end
test :assert_operator_less_or_equal_than_fail do
- try do
- "This should never be tested" = assert 2 <= 1
- rescue
- error in [ExUnit.AssertionError] ->
- "Expected 2 to be less than or equal to 1" = error.message
- end
+ "This should never be tested" = assert 2 <= 1
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "Expected 2 to be less than or equal to 1" = error.message
end
test :assert_operator_with_expressions do
@@ -235,83 +227,67 @@ defmodule ExUnit.AssertionsTest do
end
test :assert_operator_with_message do
- try do
- "This should never be tested" = assert 1 > 2, "assertion"
- rescue
- error in [ExUnit.AssertionError] ->
- "assertion" = error.message
- end
+ "This should never be tested" = assert 1 > 2, "assertion"
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "assertion" = error.message
end
test :assert_in_delta_pass do
true = assert_in_delta(1.1, 1.2, 0.2)
end
test :assert_in_delta_fail do
- try do
- "This should never be tested" = assert_in_delta(10, 12, 1)
- rescue
- error in [ExUnit.AssertionError] ->
- "Expected |10 - 12| (2) to be < 1" = error.message
- end
+ "This should never be tested" = assert_in_delta(10, 12, 1)
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "Expected |10 - 12| (2) to be < 1" = error.message
end
test :assert_in_delta_with_message do
- try do
- "This should never be tested" = assert_in_delta(10, 12, 1, "test message")
- rescue
- error in [ExUnit.AssertionError] ->
- "test message" = error.message
- end
+ "This should never be tested" = assert_in_delta(10, 12, 1, "test message")
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "test message" = error.message
end
test :refute_in_delta_pass do
false = refute_in_delta(1.1, 1.5, 0.2)
end
test :refute_in_delta_fail do
- try do
- "This should never be tested" = refute_in_delta(10, 11, 2)
- rescue
- error in [ExUnit.AssertionError] ->
- "Expected |10 - 11| (1) to not be < 2" = error.message
- end
+ "This should never be tested" = refute_in_delta(10, 11, 2)
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "Expected |10 - 11| (1) to not be < 2" = error.message
end
test :refute_in_delta_with_message do
- try do
- "This should never be tested" = refute_in_delta(10, 11, 2, "test message")
- rescue
- error in [ExUnit.AssertionError] ->
- "test message" = error.message
- end
+ "This should never be tested" = refute_in_delta(10, 11, 2, "test message")
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "test message" = error.message
end
test :catch_throw_when_no_throw do
- try do
- catch_throw(1)
- rescue
- error in [ExUnit.AssertionError] ->
- "Expected to catch throw, got nothing" = error.message
- end
+ catch_throw(1)
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "Expected to catch throw, got nothing" = error.message
end
test :catch_error_when_no_error do
- try do
- catch_error(1)
- rescue
- error in [ExUnit.AssertionError] ->
- "Expected to catch error, got nothing" = error.message
- end
+ catch_error(1)
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "Expected to catch error, got nothing" = error.message
end
test :catch_exit_when_no_exit do
- try do
- catch_exit(1)
- rescue
- error in [ExUnit.AssertionError] ->
- "Expected to catch exit, got nothing" = error.message
- end
+ catch_exit(1)
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "Expected to catch exit, got nothing" = error.message
end
test :catch_throw_when_throw do
@@ -327,20 +303,16 @@ defmodule ExUnit.AssertionsTest do
end
test :flunk do
- try do
- "This should never be tested" = flunk
- rescue
- error in [ExUnit.AssertionError] ->
- "Epic Fail!" = error.message
- end
+ "This should never be tested" = flunk
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "Epic Fail!" = error.message
end
test :flunk_with_message do
- try do
- "This should never be tested" = flunk "This should raise an error"
- rescue
- error in [ExUnit.AssertionError] ->
- "This should raise an error" = error.message
- end
+ "This should never be tested" = flunk "This should raise an error"
+ rescue
+ error in [ExUnit.AssertionError] ->
+ "This should raise an error" = error.message
end
end

0 comments on commit 52d406d

Please sign in to comment.