Is there an rspec test for exact length of an attribute?

gr0k picture gr0k · Apr 19, 2013 · Viewed 14k times · Source

I'm trying to test the length of a zip code attribute to ensure its 5 characters long. Right now I'm testing to make sure its not blank and then too short with 4 characters and too long with 6 characters.

Is there a way to test it being exactly 5 characters? So far I've found nothing online or in the rspec book.

Answer

Pak picture Pak · Oct 24, 2014

There is no more have matcher in the latest major release of RSpec.

As of RSpec 3.1, the correct way to test this is :

expect("Some string".length).to be(11)