Get "The RSpec Book" from Pragmatic Programmers. It really drives home
the BDD/TDD cycle.

Before I really drank the BDD/TDD kool-aid, I was always wary of
modifying a working application. With my test code in place, I am a
lot more comfortable creating a new branch and adding new code/re-
factoring. I can't imagine going back to the old way.

Eric

On Aug 21, 7:43 am, Colin Law <[email protected]> wrote:
> 2009/8/21 bingo bob <[email protected]>:
>
>
>
>
>
> > I really need a step by step guide how to write one or two tests. I'm
> > sure I can take it from there. There's loads of information on the web
> > but nothing I see seems to be really clear about where to get started.
>
> > I have various models key ones User, Advert and Resort models.
>
> > Such that...
>
> > User
> >  has_many adverts
>
> > Advert
> >  belongs_to user
> >  habtm resorts
>
> > Resort
> >  habtm adverts
>
> > ----
>
> > In my app a user registers and then can create an advert (uses
> > authlogic).
>
> > Tests, can think of hundreds, but I guess things like this in English
> > rather than code.
>
> > - Check that only an admin can CRUD resorts (admin boolean in User)
> > - Check that a user cannot CRUD other users adverts only their own
> > (admin can)
>
> Have you seen the rails guide on 
> testing,http://guides.rubyonrails.org/testing.html
>
> Also the testing section in AWDR3 is useful.
>
> Start with unit testing and include tests for every method of your
> models, checking operation under normal conditions and with out of
> range parameters and so on. Try to think of all the possible ways the
> method may be called and test them.  Any time there is a condition
> test in the code check that each branch of the test is exercised in
> tests.  Then move on to functional testing the controllers, checking
> each controller action with normal and unusual parameters.
>
> Any time you find a problem in the code (I guarantee you will find
> some while thinking of the tests to run) add a test that demonstrates
> the problem before fixing it in the code.
>
> It may seem a lot of work, and it is, but you will be amazed
> afterwards how much peace of mind it provides as you tidy up or extend
> the code knowing that you have minimised the likelihood of your
> changes messing something up without you noticing.
>
> Colin
--~--~---------~--~----~------------~-------~--~----~
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