[rspec-users] have_one and have_present

Luis Lavena luislavena at gmail.com
Sat May 5 12:25:57 EDT 2007


On 5/5/07, nicholas a. evans <nick at ekenosen.net> wrote:
> ...
>
> Something doesn't sit right with me for both Jay Field's test
> validations and also
> http://spicycode.com/2007/4/2/rspec-expecation-matchers-part-ii
>
> To me, it feels like both of them are testing the implementation too
> closely, rather than checking the expected behavior.  I think that
> this problem is best exhibited by format_of.  What am I verifying?
> That the production code contains the exact same regex as my spec
> code?  That seems a bit silly to me, when the regex itself is the item
> that should be tested most!  It's what is carrying the behavior.  And,
> while the simple "first character should be a capital letter" may seem
> like a silly one to worry about, what about a more complicated regex,
> such as an email address validation?  I would seriously distrust any
> spec containing a complicated regex which is attempting to validate
> another complicated regex.
>

Nick, most of the validations I do about presence of a field,
uniqueness of a field, or even the associations are based (and most of
them) translated from requirements customer shared with me.

I needed to find a way to show them I'm following they rules, their
requirements, but also be useful for me.

> What I'd *really* like is something a lot simpler (even if more
> verbose), that focuses entirely on examples and the behavior exhibited
> for those examples.  Basically, I want to give a set of invalid
> examples, and verify that they are indeed invalid, as well as some
> valid examples, and verify that they pass validation.
>
> But I'm still having a hard time coming up with a nice syntax for
> this.  I was having a discussion with a coworker about this earlier in
> the week, and I pastied my first thoughts about this here:
> http://pastie.caboo.se/58438  After resting on it a bit, I also came
> up with another syntax, pastied here: http://pastie.caboo.se/59162
>

Both pasties looks interesting, since you're testing for valid and
invalid values, something I disregard on my matchers.

To not generate false possitives, I've should validte them and later
provide a valid value instead... will stick that in my TODO list.

> I'll readily admit that Jay Field's DSL looks much nicer than what
> I've come up with so far... but I'd rather stick with the plain
> vanilla rspec, and be certain that I'm asserting an expected model
> behavior against examples than expect the implementation details of
> which ActiveRecord validation was used.
>
> Am I just making things harder for myself?  Am I missing the boat on a
> useful simplification?

My idea of specs (er, examples) are useful for me and my customer
during the first design/implementation phase, but uses for rspec are
too broad ;-)

Regards and good weekend everyone.

-- 
Luis Lavena
Multimedia systems
-
Leaders are made, they are not born. They are made by hard effort,
which is the price which all of us must pay to achieve any goal that
is worthwhile.
Vince Lombardi


More information about the rspec-users mailing list