tdd - Is there an rspec test for exact length of an attribute? -
i'm trying test length of zip code attribute ensure 5 characters long. right i'm testing make sure not blank , short 4 characters , long 6 characters.
is there way test being 5 characters? far i've found nothing online or in rspec book.
if you're testing validation on activerecord model, recommend trying out shoulda-matchers
. provides bunch of useful rspec extensions useful rails. write simple 1 line spec zip code attribute:
describe address { should ensure_length_of(:zip_code).is_equal_to(5).with_message(/invalid/) } end
Comments
Post a Comment