[rspec-users] How do I best setup data for Story Runner?
Scott Taylor
mailing_lists at railsnewbie.com
Sat Sep 29 11:46:49 EDT 2007
On Sep 29, 2007, at 12:42 AM, Jonathan Linowes wrote:
> yes, i appreciate all the smartness built into it.
>
> I wonder if this idea could be extended to generate mocks, eg for my
> controller specs
>
> user = mock_user( :email => "foo at example.com" )
> etc
>
> not sure how far you could go with this, eg stubbing basic stuff
> like .find
> Just a thought
Certainly an interesting idea. My guess is that you would need to go
a lot lower then stubbing find, Stubbing the connection parts of
ActiveRecord. (In my ignorance, it ) Looks like a big project to me.
Scott
>
>
> On Sep 28, 2007, at 5:11 PM, Scott Taylor wrote:
>
>>
>> On Sep 28, 2007, at 1:20 PM, Jonathan Linowes wrote:
>>
>>> Scott,
>>> Thanks for the plug-in, http://thmadb.com/public_svn/plugins/
>>> fixture_replacement
>>> I've started using it, replacing my ad hoc factory methods
>>> And I like the idea of putting the factory in db/
>>
>> Thanks for trying it out. I'd love to hear any feedback, or anything
>> that you think should be changed.
>>
>>>
>>> btw, for the record, while the Dan Manges blog was posted Aug 07,
>>> the
>>> first time I saw this technique is as a protected create_user method
>>> in the acts_as_authenticated plugin test/user_test.rb (although not
>>> to replace fixtures but to test against them :)
>>
>> Yeah, I'm sure I've seen that too - so maybe I stole one of the ideas
>> from there, as well. (Actually, I think I got it from topfunky (the
>> TDD peepcode), who in turn got it from technoweenie - Completely
>> forgot about til' now. It's funny how good ideas can become
>> unconscious like that...)
>>
>> The only really cool thing about the plugin is that it uses lambdas
>> so that extra associations aren't created. Plus, it dries up
>> the .create! and merge() that needs to be repeated over and over
>> again (trust me - this will get tiring if you have something like 30
>> models).
>>
>> Regarding the lambdas: With the Dan Manges factory, if I do the
>> following, I end up with two posts (not one):
>>
>> def create_comment(hash = {})
>> Comment.create!(
>> {
>> :post => create_post
>> }.merge(hash)
>> )
>> end
>>
>> # this yield one associated post (as expected)
>> comment = create_comment
>>
>> # this yields an associated post, with an extra one which I don't
>> care about (and which isn't associated)
>> post = create_post
>> comment = create_comment(:post => post)
>>
>> And this is because Ruby isn't lazily evaluated. So if you end up
>> using the Dan Manges method, beware!
>>
>> Scott
>>
>>>
>>
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
More information about the rspec-users
mailing list