October 30, 2009 by alex
You can declare a view in Couch Potato like this:
This will generate a pair of map/reduce function and push them to Couch Potato. The map function looks something like this:
And here’s a unit test for that function:
As you can see all you have to do is pass a Ruby Hash that looks like your CouchDB document and the expected results. You can also pass in multiple results if you expect your map function to emit multiple key/value pairs.
Testing a reduce function works the same way:
For testing re-reducing you simply call
You can see how it works by looking at the code for the RSpec matchers.