On Aug 11, 2009, at 6:58 AM, Frank J. Mattia wrote:

>
> C'mon guys, I know this problem can't be that hard to tackle. Is there
> anyone out there with some helpful insight?

Don't come down too hard on everyone for not answering right away.  
Type "rails test factory" into Google and you can do some independent  
research.

I personally use Machinist and Faker (good article: 
http://toolmantim.com/articles/fixtureless_datas_with_machinist_and_sham) 
. Others swear by Factory Girl (read: 
http://www.thoughtbot.com/projects/factory_girl) 
  and still love Object Mother (read: 
http://jeffperrin.com/2009/07/08/object-mother-testing-pattern-in-rails/) 
. You may even like Fixjour (read: 
http://www.elctech.com/snippets/fixjour-another-fixture-replacement) 
.

> On Aug 11, 1:35 am, "[email protected]" <[email protected]>
> wrote:
>> A little background:
>> I've been enjoying rails for about a year now tinkering on  
>> meaningless
>> projects here solely for the purpose of learning the framework... not
>> because I actually needed to use those apps for anything serious. Now
>> that I started writing my first serious app, naturally I want to dive
>> into test driven development ("finally" I know - please, no  
>> harassment
>> - I'm trying). Now the way I see it, the standard testing framework  
>> is
>> more than sufficient for my needs and as time goes on it's only going
>> to improve. So while things like RSpec and Cucumber are all well and
>> good - they don't really fit my needs.
>>

There are far more lively communities surrounding rSpec and Cuke, so  
if you want help, you'll find a lot of people willing to answer  
questions. I personally feel the thinking behind spec first makes more  
sense than test first. At the execution level it's the same, but what  
you are writing is a spec for code that doesn't yet exist, not a test.  
Cucumber is a whole level of goodness that is orthogonal (in most  
ways) to either rSpec or Test::Unit. Acceptance testing can be a  
lifesaver. You'd be surprised how often a good set of stories can  
either flush out poorly designed features or save your bacon if you  
break something.

>> With that out of the way - I dove right into creating fixtures and --
>> halt. Fixtures, while improving - are still cumbersome for nested
>> models. Take for example my Quote model - it has_many
>> QuotableOperations and QuotableQuantities. When I test them I want to
>> have complete associations... Fixtures don't seem to like assigning  
>> to
>> has_many unless I do it from the belongs_to side (which feels
>> unnatural) so I gave up on fixtures and started working with  
>> Factories
>> (Factory Girl)... Now, a few days into Factory Girl and it also seems
>> too cumbersome for the job at hand. I'm not sure, but it seems like
>> either:
>>
>> *I'm doing it wrong*
>>
>> or
>>
>> *There's a better way*

Most will concede that fixtures that describe associations are brittle  
and coupled too tightly to a particular implementation. That's why the  
fixture replacements are so popular. Also consider using a mocking/ 
stubbing framework. rSpec comes with one baked in, or you can use  
Mocha or FlexMock. Best to only mock and stub in unit tests, as  
acceptance tests are supposed to exercise the whole stack. Of course,  
if your app needs to reach out over the network or something like  
that, you might have to use something like FakeWeb or a mock/stub for  
the service you don't want to hit with your test.

>> Can anyone point me towards the light?
>>
>> Take this very simple test for example:
>>
>> I have a
>>
>> Quote(:description => "Some job to quote")
>> - with one QuotableOperation(:operation_name => "Engineering")
>> - and two QuotableQuantities(:quantity => "5", :rate => "0.21") &
>> QuotableQuantities(:quantity => "10", :rate => "0.21")
>>
>> :description, :quote_operations and :quote_quantities are
>> validate_presence_of'd on the Quote model.
>>
>> SO - a simple test like:
>>
>> test "the description of the quote is not blank" do
>>     ***test***
>> end
>>
>> seems to be more trouble than it's worth because I need a fully
>> associated Quote object.
>>
>> A helping hand in the right direction would be more than appreciated.
>>
>> Thanks,
>> - FJM
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to