[rspec-users] How much test data to use in specs

Nick Hoffman nick at deadorange.com
Fri Aug 29 11:30:06 EDT 2008

On 2008-08-29, at 11:05, David Chelimsky wrote:
> On Fri, Aug 29, 2008 at 9:03 AM, Nick Hoffman <nick at deadorange.com>  
> wrote:
>> On 2008-08-29, at 04:51, Joseph Wilk wrote:
>>> I started using a set of methods to deal with this problem from  
>>> code in
>>> the RadiantCMS(http://radiantcms.org/) project.
>>> http://gist.github.com/7936
>>> I stopped using it after a while finding the tests did not read  
>>> well.
>>> Your method improves on Radiant's which has tempted me to start  
>>> testing
>>> models like this again.
>>> Thanks!
>>> --
>>> Joseph Wilk
>>> http://www.joesniff.co.uk
>> Thanks for the vote of confidence, Joseph! I have two other methods  
>> that go
>> alongside #describe_model_attribute which you might find useful.  
>> I'm in the
>> process of wrapping them up into a plugin. Until that's finished,  
>> I've
>> pasted them at http://pastie.org/262508 and http://pastie.org/ 
>> 262509 .
> Hey Nick - I'm not clear why you need these, given that you already
> have the describe_model_attributes macro, which you can use to handle
> nils and will give you a meaningful error if there is a problem with
> your factory. What's your goal here?

Hi David. My goal with these methods is to automate the speccing of  
model attributes and reduce the amount of code that needs to be written.

I created #describe_model_factory so that there would be a spec  
specifically for the factories that I create, rather than relying on  
other specs to indirectly ensure that my factories work properly.

Looking at the methods again, you're correct that  
#describe_model_attribute includes most of the functionality of  
#check_model_attributes_when_nil . That's not very DRY then, eh? I  
should probably get rid of #check_model_attributes_when_nil , and add  
an argument to #describe_model_attribute that allows the user to  
specify whether or not an error message should exist when the  
attribute being specced is invalid.

How does that sound?

More information about the rspec-users mailing list