1

I'm writing some specs for my User model but the tests are not passing. I'm fallowing this from the github page of the gem without success. This is my code:

validates :phone, numericality: { only_integer: true }, allow_blank: true, length: { is: 7 }
validates :mobile, numericality: { only_integer: true }, allow_blank: true, length: { is: 10 }

and my specs

it { should ensure_length_of(:phone).is_equal_to(7) }
it { should ensure_length_of(:mobile).is_equal_to(10) }

This validations should only run during the update process.

The errors:

Did not expect errors to include "longitud errónea (debe ser de 7 caracteres)" when telefono is set to "xxxxxxx", got error: longitud errónea (debe ser de 7 caracteres)

Did not expect errors to include "longitud errónea (debe ser de 10 caracteres)" when celular is set to "xxxxxxxxxx", got error: longitud errónea (debe s er de 10 caracteres)

FYI: I've set Spanish Locales; I think this is the cause

Hope someone could help me. Thanks is advance

Ricbermo
  • 815
  • 1
  • 6
  • 28

1 Answers1

0

I think you got the error because shoulda_matcher does not expect that length: { is: 7 } is used with numericality.

PS as for me - it is strange to use numeric for phone numbers, you can use string and use validates with format to be sure in validness data. For example email validation here

gotva
  • 5,919
  • 2
  • 25
  • 35
  • thanks @gotva. I'm new to rails and I thought that phone and mobile number validations must me with numericality. I've fond something for future readers http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation – Ricbermo Feb 20 '14 at 15:54