I most certainly appreciate any and all replies and with that in mind,
I hope I didn't come off as coming down hard... Intonation is a hard
thing to communicate in textual media... Anyhow, sorry for sounding
that way. Perhaps an emoticon could have livened it up a bit... Hehe.

Anyway...

I've just ripped out all of my Test::Unit stuff am having a go at
starting fresh with RSpec, Cucumber and Machinist... Please understand
that I've only been casually programming for the past 10 years as a
way to kill time and challenge myself. I have no formal training,
never wrote anything serious and the fact that I've written anything
at all that works is a blessing because before last week - I had never
written a test in my life - let alone put any thought into testing an
entire application. TDD/BDD are both intriguing and believe me - I see
their advantages... I'm just very slow on the uptake right now. It's
not the way I'm used to programming **read that as "I've developed a
lot of bad habits on my own and now I want to break them the right
way**.

SO.

The one thing that keeps coming back to haunt me is that no Factory
framework seems to let you test complete objects from the has_many
side of the association without doing some serious legwork. I see
examples on the Machinist git page that suggest using helper methods
but that brings me to another road block. Where do I write them? How
are they called? What types of things should I not be testing at that
level?

Now, my own personal itch of a project is still small enough that I
don't mind ripping entire sections of tests out and rewriting them
with new frameworks just to learn how. 1) I have the time and 2) I'm
interested in learning how to do it right more than I am in doing
it... If that makes sense. The parts of my app work just fine for me
without tests... but knowing my itch, I'm going to want to add
complexity and knowing how Ruby and Rails works - I want to add it the
right way so that it's fun for me to do...

Anyway - I'm getting off topic again.

Back in my first post I describe a situation that I was trying to
test. Could you tell me how I should be approaching that issue (which
may very well be much different than the way I've been approaching
it). Why is testing from the has_many side so taboo? Is there a
legitimate way of doing it from the belongs_to side?

Thank you for your reply and thank you too Marnen.

You have both given me good food for thought, even if I don't know how
to eat it yet.

Hehe. Thanks,
- FJM

On Aug 11, 6:48 pm, "s.ross" <[email protected]> wrote:
> 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