ruby on rails - Check if attribute contains 2 letters in RSpec -
what right way test if field contains 2 letter string rspec ? following old example guess worked in rails 2. creates new address
instance, sets invalid value on it, , trigger valid?
on instance , checks if errors
report wrong.
'requires state of length 2' subject = address.new subject.state = 'cal' should_not be_valid subject.errors.on(:state).should_not be_nil end
now, rails 3 doesn't have errors.on, tried
subject.errors[:state].should_not be_nil
but problem here errors[:attribute]
empty array
instead of nil
.
you can still
subject.errors[:state].should_not be_empty
Comments
Post a Comment