I'm writing a sinatra app and testing it with rspec and rack/test (as described on sinatrarb.com).
It's been great so far, until I moved some rather procedural code from my domain objects to
sinatra helpers.
Since then, I've been trying to figure out how to test these in isolation ?
I've also tried this (which needs to be cleaned up a bit to be reusable) to isolate each helper in its own environment to be tested:
I test my sinatra helpers in isolation by putting the helper methods within its own module. Since my sinatra application is a little bit bigger than the usual hello world example, I need to split it up into smaller parts. A module for the common helpers suits my use case well.
If you write a quick demo, and you define your helper methods within the
helpers { ... }
block, I don't think testing it is absolutely necessary. Any sinatra app in production, may require more modularity anyways.maybe this can help you some way http://japhr.blogspot.com/2009/03/sinatra-innards-deletgator.html
Actually you don't need to do:
Since you can just call
The
helpers
method takes a list of modules to mix-in and an optional block which is class-eval'd in: https://github.com/sinatra/sinatra/blob/75d74a413a36ca2b29beb3723826f48b8f227ea4/lib/sinatra/base.rb#L920-L923