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

nicholas a. evans nick at ekenosen.net
Fri Jun 1 10:34:23 EDT 2007

On 6/1/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> I put up a third version: http://pastie.caboo.se/66776

I looks like you lost the ability to know which field was being
validated, so I changed it back to it_should_validate_that :field,
"satisfies rule"

> Why not just stick it in a module and let the user decide where to
> make it available?

That makes sense.

> Not yet. I was just bouncing off  your proposal. Let's see how this
> works in practice before we start creating conventions :)

Good point.  :-)

> That seems like you're telling the user to use a specific message
> rather than generally expecting it, which is what I *think* you mean.
> Am I missing it?

You're right... I'll worry about that feature later, then.  :-)

> I think you can get all that. The #given method has a handle on the
> object before it yields to the block, the should_reject and
> should_accept methods can be configured to create examples at run
> time. Make sense?

Yeah, but we've also added a string via "it_should_validate_that"...
What would the specdoc look like?  We don't have a mechanism for
nesting 3 levels deep, do we?

> > My approach assumed that if you were only working with one field, we
> > should only check for errors on that one field (it's okay if the
> > object is otherwise invalid).  But if you are working with multiple
> > fields, you should check to see if the entire object is valid, and
> > check against all error messages.  Do you think that is a safe and
> > reasonable convention?
> This could get quite complicated. Which is probably why nobody has
> tackled this in a generic way yet - at least that I've seen.

True... but it feels like we're getting close to something that is
very good and simple.  It doesn't need to solve 100% of the world's
validation needs... just 85% of my rails validation needs.  For
anything more complicated, I can always fall back on vanilla rspec
(still pretty tasty!).  For my tastes and intuition, I prefer that
validation specs against a single field check only that single field's
validity, and validations specs against multiple fields check the
model's validity.  But I would be fine if it were simplified to
normally check only the fields under inspection, but could be easily
changed to check for any errors on the object.

Here are my next several attempts:

Playing off of your approach and including a number of proposed
specdoc outputs: http://pastie.caboo.se/66855

But here's my current favorite approach: http://pastie.caboo.se/66862


More information about the rspec-users mailing list