I'd like to see the default validation error messages that ActiveModel::Errors provides in order that I know what I should expect in order to write test expectations accurately. Can you anyone point me in the right direction please?
Asked
Active
Viewed 50 times
0
-
This seems like you testing the framework. Do you need to do this, is this some type of compliance requirement? – rovermicrover Oct 09 '15 at 20:47
-
Not trying to test the framework, rather just test model validations and doing so by expecting an error message to be present, just trying to state the correct content presence expectation. As you'll gather early days dev'ing for me so perhaps this is not the right way to go about it? – jbk Oct 09 '15 at 20:50
1 Answers
1
I agree with @rovermicrover that you shouldn't do this, but if you really want them they are here:
https://github.com/rails/rails/blob/master/activemodel/lib/active_model/locale/en.yml
I would suggest that you test for the presence of an error on that field and perhaps the key of the error, but not the message itself.
I'd really suggest you look at shoulda-matchers which provides this sort of thing nicely wrapped up. For example validate_presence_of
:
let(:user) { FactoryGirl.create(:user) }
specify { expect(user).to validate_presence_of(:name) }

Philip Hallstrom
- 19,673
- 2
- 42
- 46
-
Thanks for the pointers guys, but how would i test for the presence of the right type of error though? – jbk Oct 10 '15 at 12:42
-
@jbk I would look through the shoulda-matchers source and see how they do it. – Philip Hallstrom Oct 10 '15 at 17:30