On Tuesday, December 9, 2014 4:05:00 AM UTC-8, Roelof Wobben wrote: > > Hello, > > I like to learn Rspec once again and im using the everydayRails book. > > Now I see that one of the test looks like this : > > expect ( build (:contact, firstname : > nill)).to_have(1).errors.on(:firstname) > > but I wonder why not use this : > > expect ( build (:contact, firstname : nill)).not_to_be valid > > Roelof > > I can't speak to what the author was thinking, but if the point is to test that a `firstname` is required, the second expectation is weaker because it simply validates that the record is invalid but doesn't check why it's invalid. Maybe `build(:contact)` returns a record that's already invalid, regardless of the `firstname` value, and there's no validation on `firstname`. The first expectation explicitly checks that the reason the record is invalid is `firstname`, which might be the point of the test.
HTH, Myron -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/2e3443dc-593c-407a-85c6-3336ed0958bd%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
