Testing problems in Rails


#1

Hello, everyone.

I start using Rails to develop a little project and I have some concerns
while I’m practising TDD.

  • In rails, it seems very common to functional testing contoller without
    unit testing it, and the unit tests and DAO tests of models are mingled
    in
    the “unit test” of model under test/model. I used to seperate the unit
    tests
    and DAO tests because in unit tests we don’t have to load any data into
    the
    database which will make unit tests faster to run. And I am willing to
    unit
    test controller but I haven’t found a good way to do that(How can I mock
    the
    “render” method?). Does anybody have good ideas?

  • Are the functional tests of controllers enough? I don’t think so
    personally. I think we still need functional tests of them. Selenium and
    watir help us in this area. I wonder if and how other people use them.

  • The last question is about testing ajax. Asyncronous call to the
    server
    and some dynamic effects are hard to test. Are there any people who can
    give
    me some good practices?

I have been using Java in several projects. I noticed the difference
between
Java and Ruby and I like them both very much. In Java, mock objects are
widespreadly used in unit tests of domain objects and controllers, but
In
Rails, I haven’t seen people unit testing controllers. Is that
unnecessary
at all? Hope for answers and discussions.