1. Testing ActiveResource

    I am building the xml API for Zena (damn simple since we only have 1 model through which everything passes: Node ). But it’s been a while now that I cannot write code without writing the tests and so I wanted to test my NodeResource .

    How to test ActiveResource ?

    You can either launch you application and then start your tests with “localhost” but… you cannot use transactional fixtures since you do not share the connection to the database. This means that apart from read tests it is pretty useless.

    Use Integration tests !

    I have written a MockConnection that makes your ActiveResource share the connection with the integration test. This means that when your NodeResource does a :put , it’s actually your integration test that executes the “put” method with all the xml data and such.

    If you want to reuse the code:

    Gaspard Bucher

    comments

    1. leave a comment