For those who use Rails 3.2.1 and higher, do I prefer to use the method ? :
assert record.errors.added? :name, :blank
I am using a test assistant that looks like this:
def assert_invalid(record, options) assert_predicate record, :invalid? options.each do |attribute, message| assert record.errors.added?(attribute, message), "Expected #{attribute} to have the following error: #{message}" end end
Which allows me to write tests as follows:
test "should be invalid without a name" do user = User.new(name: '') assert_invalid user, name: :blank end
Jeremy baker
source share