Testing sinatra helpers with rspec
14 February 2014Lately I built a simple Sinatra based demo application (YaSApp) and tried to test some methods within a helpers block
But Rspec keept me sending NoMethod Errors:
NoMethodError:
undefined method `human_date' for #<Sinatra::Application ...
Than I learned in the context of the Padrino framework, that this is a “special” Sinatra feature - so called “shorthand helpers”. Because above statement is shorthand for:
Which is kind of a anonymous module and that way hard to reference or test!
The solution is to make a explicit module and propagate it to the application like this:
and then it is testable in RSpec:
Hope thats helpful for one or the other?