[rspec-users] Another attempt for a succinct model validation DSL

nicholas a. evans nick at ekenosen.net
Fri Jun 1 14:16:46 EDT 2007

On 6/1/07, Joseph Method <tristil at gmail.com> wrote:
> Well, this is what I was thinking: http://pastie.caboo.se/66940

I think that I still prefer dedicating the entire behavior to
validation of a particular field (that's what I do in my current specs
anyway, albeit with far more lines of code).

> > Thoughts?
> Honestly, the extra depth is a big turn-off for me.

Strongly agreed in that regard.  10 extra characters on the front (and
two on the back), repeated over every example.  The whole point of
this is to clean up the syntactic noise to highlight the examples

The reasons I see to use that approach: it matches *very* well with
the standard rspec way of doing things.  At that point, it's really
just the new given/it syntax, and a matcher that looks at some of the
behavior options (to see which fields are being spec'd).  And it gives
an obvious interface for overriding/ignoring the generated example
string.  Likewise, it gives a nice syntax if I want to do some more
advanced assertions on the model with that example.  But I think I
would use the shorthand version for 95% of my validation examples.
And the shorthand could effectively generate the proposed longhand

> > Is it an evil or difficult thing to repurpose "it" to my
> > own dubious ends inside the examples?  I really like the idea of "it"
> > simply returning the result of the block that was previously passed to
> > "given"
> It's not evil, but I don't know how difficult it is. If it's not
> difficult at all, I don't see why it can't be
> it.should_validate :password do

I don't think it would be right to have the behavior method "it"
running double-duty (it is already used to create the examples).
Also, I don't really see much benefit of "it.should_validate" over
"it_should_validate".  But I do like the idea of the example method
"it" getting the results of the "given", and that should be easy (I


More information about the rspec-users mailing list