Permalink
Browse files

No need to rescue here. Invoking the wrong method in an object can ha…

…ppen anywhere if you are not careful. In other words, test your shit.
  • Loading branch information...
1 parent 5bf3d46 commit df5691aa94f209a59945d60d750a5040b24dbc40 @josevalim josevalim committed Apr 11, 2011
@@ -19,8 +19,6 @@ def validate_each(record, attribute, value)
if exclusions.send(inclusion_method(exclusions), value)
record.errors.add(attribute, :exclusion, options.except(:in).merge!(:value => value))
end
- rescue NoMethodError
- raise ArgumentError, "Exclusion validation for :#{attribute} in #{record.class.name}: #{ERROR_MESSAGE}"
end
private
@@ -19,8 +19,6 @@ def validate_each(record, attribute, value)
raise ArgumentError, "A proc or lambda given to :without option must returns a regular expression"
end
end
- rescue TypeError
- raise ArgumentError, "A proc or lambda given to :with or :without option must returns a regular expression"
end
def check_validity!
@@ -19,8 +19,6 @@ def validate_each(record, attribute, value)
unless exclusions.send(inclusion_method(exclusions), value)
record.errors.add(attribute, :inclusion, options.except(:in).merge!(:value => value))
end
- rescue NoMethodError
- raise ArgumentError, "Exclusion validation for :#{attribute} in #{record.class.name}: #{ERROR_MESSAGE}"
end
private
@@ -54,13 +54,4 @@ def test_validates_exclusion_of_with_lambda
p.title = "wasabi"
assert p.valid?
end
-
- def test_validates_exclustion_with_invalid_lambda_return
- Topic.validates_exclusion_of :title, :in => lambda{ |topic| false }
-
- p = Topic.new
- p.title = "wasabi"
- p.author_name = "sikachu"
- assert_raise(ArgumentError){ p.valid? }
- end
end
@@ -122,22 +122,6 @@ def test_validates_format_of_without_lambda
assert p.valid?
end
- def test_validates_format_of_with_lambda_not_returns_regexp
- Topic.validates_format_of :content, :with => lambda{ |topic| false }
-
- p = Topic.new
- p.content = "Pixies"
- assert_raise(ArgumentError){ p.valid? }
- end
-
- def test_validates_format_of_without_lambda_not_returns_regexp
- Topic.validates_format_of :content, :without => lambda{ |topic| false }
-
- p = Topic.new
- p.content = "Pixies"
- assert_raise(ArgumentError){ p.valid? }
- end
-
def test_validates_format_of_for_ruby_class
Person.validates_format_of :karma, :with => /\A\d+\Z/
@@ -86,13 +86,4 @@ def test_validates_inclusion_of_with_lambda
p.title = "elephant"
assert p.valid?
end
-
- def test_validates_inclustion_with_invalid_lambda_return
- Topic.validates_inclusion_of :title, :in => lambda{ |topic| false }
-
- p = Topic.new
- p.title = "monkey"
- p.author_name = "sikachu"
- assert_raise(ArgumentError){ p.valid? }
- end
end

1 comment on commit df5691a

Member

sikachu commented on df5691a Apr 11, 2011

Hahaha I like the commit message.

Please sign in to comment.