I am using Ruby on Rails 3.0.9 and RSpec 2. I know that there are some known problems on using RSpec and a before_validation callback, because the before_validation seems not to be triggered when run in spec files. You can find a lot of similar issues (for example, by doing a Google search).
I am wondering if, at this time, anyone has come up with a solution to this problem?
P.S.: I have read that some people have proposed to use mocks, others people to switch from a before_validation to some other callback (eg: to a before_save) or to use the save(:validate => false) method (so to skip validations)… and so on… but no one seems to have solved the “real” problem. What do you think should be done in such cases in order to solve the issue?
if you can’t get around using mocks, try reloading your instance using the reload method and after that your test.