[rspec-users] Testing Models without fixtures

Nathan Sutton nathan.sutton at gmail.com
Tue Nov 20 11:26:15 EST 2007


Err, Scenarios

Nathan Sutton
fowlduck at gmail.com
rspec edge revision 2910
rspec_on_rails edge revision 2909
rails edge revision 8167





On Nov 20, 2007, at 10:22 AM, Scott Taylor wrote:

>
> On Nov 20, 2007, at 11:20 AM, David Chelimsky wrote:
>
>> On Nov 20, 2007 10:20 AM, David Chelimsky <dchelimsky at gmail.com>
>> wrote:
>>> On Nov 20, 2007 10:18 AM, Nathan Sutton <nathan.sutton at gmail.com>
>>> wrote:
>>>> You may want to create a factory method to create users with valid
>>>> parameters, overriding any parameters by passing in options.
>>>>
>>>> ALPHA = ('a'..'z').to_a + ('A'..'Z').to_a
>>>>
>>>> def random_text
>>>>        txt = ""
>>>>        10.times do
>>>>                txt << ALPHA[rand(52)]
>>>>        end
>>>>        txt # maybe a returning block?  can't remember if that
>>>> works here
>>>> end
>>>>
>>>> def create_user(options={})
>>>>        User.create!({ :name =>  random_text,
>>>>                                  :password => random_text}.merge
>>>> (options))
>>>> end
>>>
>>> There are also tools that will do this for you: Exemplar,
>>> ModelStubbing to name two.
>>
>> Actually - those are geared towards avoiding the DB. What you'd want
>> is Scenarios and FixtureScenarios (and others similar).
>>
>
> How about giving FixtureReplacement some love?
>
> Scott
>
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users



More information about the rspec-users mailing list