hayafirst at gmail.com
Thu Feb 19 10:41:26 EST 2009
Good point, that's actually I am debating with myself everyday and haven't
got a clear answer. This is classical "calssic unit tester" vs. mockist war.
Talking about this case:
1. I haven't checked how should valite_presence_of is implemented, but it
could pretty much be checking if the value is left blank. So it is behavior
2. I couldn't see any reason why I would want to write my own version of
check_to_see_if_this_thingy_is_in_my_whatsis. So this is not a very
3. By checking if validation fails when a value is left blank, I am actually
kind of testing Rails and here's why: what if they introduce a bug in
validates_presence_of that makes my test break? What if they have a bug in
valid? to make my test break? To strictly just testing *my* own code, the
test should be something like
I am not really advocating the view of mockists. Just throw a question here.
On Wed, Feb 18, 2009 at 11:40 PM, Stephen Eley <sfeley at gmail.com> wrote:
> On Wed, Feb 18, 2009 at 11:42 PM, Yi Wen <hayafirst at gmail.com> wrote:
> > Without this syntax sugar, we still have to test validates_presence_of to
> > make sure it's there and won't broken, right?
> Wrong. You don't have to test validates_presence_of. What matters,
> and therefore what you should test, is whether the model will complain
> at you if a particular value is left empty.
> validates_presence_of happens to be the name of the method in
> ActiveRecord that does that. But if you decide to write your own
> check_to_see_if_this_thingy_is_in_my_whatsis() method that does the
> same thing, a good *behavior* spec will not break. Because the
> behavior remains the same.
> If your spec breaks because you changed a method call, you're not
> testing behavior any more. You're testing syntax.
> Have Fun,
> Steve Eley (sfeley at gmail.com)
> ESCAPE POD - The Science Fiction Podcast Magazine
> rspec-users mailing list
> rspec-users at rubyforge.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users