couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zachary Zolton <zachary.zol...@gmail.com>
Subject Re: Tests/TDD for CouchDB views
Date Mon, 09 Nov 2009 01:49:41 GMT
I've done it by building test scripts—just run 'em on the command line
with SpiderMonkey's js executable—and it feels pretty fast and easy.
All you really need to do is emulate emit() by printing the JSON to
the screen. Right now I just run script while I think I'm breaking
things though, LOL. (^-^)//

Parsing and assigning a JSON document to a script variable should be
super easy to do via STDIN, obviously... Of course, at this point we
could probably be using an RSpec-like library to assert actual
behavior, instead right?

Not sure if this would be easier in Ruby for me.

On Sat, Nov 7, 2009 at 3:58 PM, Brian Candler <B.Candler@pobox.com> wrote:
> On Sat, Nov 07, 2009 at 02:31:04PM +0100, Karel Minařík wrote:
>> So, my questions are basically these:
>>
>> * How do would you write/implement tests for your views?
>
> I don't see in principle why it can't be any different to normal tests. That
> is, you write tests within your application testing framework which:
> - setup a database and some sample data
> - perform a view query
> - check the results are what you expect
>
>> * What is the recommended practice for writing the views? In Futon? In
>> an editor and uploading them to db via couchapp or similar? Via
>> CouchRest or similar layer?
>
> I do the latter (using my own CouchTiny rather than CouchRest). Your views
> are source-controlled together with the rest of your application, your
> application can populate the design docs when required, and you can
> integrate your view tests with your application tests just as you wish.
>
>> * Is it possible to write views "test-first|driven", ie. setting up some
>> fixtures, writing the view, etc? Does it even make sense in CouchDB
>> context?
>
> I think so, if the test is part of your application (e.g. your application
> is in Ruby and you're using something like CouchRest to manage your design
> docs). View tests are just exercising another part of your app.
>
>> * Is there a way to automatically run such test suites? (Via browser, or
>> something like Rhino?)
>
> Same.
>
>> * Regarding application logic itself, what would be the best/preferred
>> way to test CouchDB-backed models in eg. Rails app? Using eg. FakeWeb
>> [4] to mock responses and work with those? Or setting up and using
>> another CouchDB database (like Rails does for *SQL dbs)?
>
> You can set up 'test', 'development' and 'production' environments for
> CouchDB just as ActiveRecord does, and this is how I handle it. See
> http://github.com/candlerb/couchtiny/blob/master/doc/RAILS.rdoc
>
> Note: this is for my own CouchTiny, which is subject to change at my
> personal whim so I wouldn't recommend anyone to depend on it right now, but
> you should be able to apply the same approach to CouchRest.
>
> Regards,
>
> Brian.
>

Mime
View raw message