[rspec-users] validate_presence_of

Zach Dennis zach.dennis at gmail.com
Thu Feb 19 11:05:54 EST 2009


On Thu, Feb 19, 2009 at 10:41 AM, Yi Wen <hayafirst at gmail.com> wrote:
> 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
> tests
>
> 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
> realistic assumption.
>
> 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
>       Person.should_receive(:validates_presence_of).with(:email)
>
> I am not really advocating the view of mockists. Just throw a question here.

This is a good example of strictly testing *your* code. But, to the
last statement--it is not a very good example of when to use mock
expectations. I don't think it advocates an accurate view of
*mockists*.


> :)
>
> Yi
>
> 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
>>   http://www.escapepod.org
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



-- 
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com


More information about the rspec-users mailing list