Permalink
Browse files

Fix some assert_raise calls containing messages in Active Support

  • Loading branch information...
1 parent ed80dd7 commit d46f9e37314f18b6ee7b2600b9886ea4d47e555e @carlosantoniodasilva carlosantoniodasilva committed Oct 28, 2012
@@ -89,13 +89,20 @@ class QualifiedConstTest < ActiveSupport::TestCase
end
test "reject absolute paths" do
- assert_raise(NameError, "wrong constant name ::X") { Object.qualified_const_defined?("::X")}
- assert_raise(NameError, "wrong constant name ::X") { Object.qualified_const_defined?("::X::Y")}
+ assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_defined?("::X")}
+ assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_defined?("::X::Y")}
- assert_raise(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X")}
- assert_raise(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X::Y")}
+ assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X")}
+ assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X::Y")}
- assert_raise(NameError, "wrong constant name ::X") { Object.qualified_const_set("::X", nil)}
- assert_raise(NameError, "wrong constant name ::X") { Object.qualified_const_set("::X::Y", nil)}
+ assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_set("::X", nil)}
+ assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_set("::X::Y", nil)}
+ end
+
+ private
+
+ def assert_raise_with_message(expected_exception, expected_message, &block)
+ exception = assert_raise(expected_exception, &block)
+ assert_equal expected_message, exception.message
end
end
@@ -147,7 +147,8 @@ def test_mutual_dependencies_dont_infinite_loop
def test_circular_autoloading_detection
with_autoloading_fixtures do
- assert_raise(RuntimeError, "Circular dependency detected while autoloading constant Circular1") { Circular1 }
+ e = assert_raise(RuntimeError) { Circular1 }
+ assert_equal "Circular dependency detected while autoloading constant Circular1", e.message
end
end

1 comment on commit d46f9e3

@matthewrudy
Contributor

This assert_raise_with_message is something I usually bolt onto projects myself.

Are there enough instances of this to make it worth including into rails?

Please sign in to comment.