There is great introduction here:
http://wikimatze.de/testing-helpers-in-padrino.html
However do not forget that helpers are a Sinatra feature, so you might want to search for "sinatra helper testing":
http://stackoverflow.com/a/8575684
Both links are the best way for your "spec/unit" tests. However once my own helpers evolve, I start depending on other helpers (Padrino::Helpers) and features/variables/extensions from my Padrino::Application.
Since that requires lots of mocking, I get lazy and define a "spec/integration" test using the helpers from an instance of my main application (MyWeb::App < Padrino::Application), where everything is already cooked and ready to use.
How you get access to it is a whole adventure:
- MyWeb::App.new seems to be the first idea, but that yields a Sinatra::Wrapper class
- MyWeb::App.new! can give you a straight object of your Padrino application. The Sinatra source code mentions something about avoiding the middleware (Rack??). https://github.com/sinatra/sinatra/blob/v1.3.3/lib/sinatra/base.rb#L1372-1377
- The generated object, provides access to all your helpers: MyWeb::App.new!.tag(:br)
Most applications has some integration/feature tests using a headless browser like Capybara. My current RSpec configuration mounts the application with this Capybara.app = Padrino.application
however that is interesting because Capybara gains access to my app with a Padrino::Router, not with with a Padrino::Application < Sinatra::Base class.
TODO: Since I am not bussy learning Rails, I should make some effort studying how Rack + Rack middleweare works. After all, Padrino/Sinatra is all about exposing you to the full stack.
TODO: Explore how Capybara can pull rendered text for a http request (GET/POST...) out of Padrino::Router
Another great place to learn more about how to test helpers is looking at the tests for the Padrino::Helpers module
https://github.com/padrino/padrino-framework/tree/master/padrino-helpers/test
Just two caveats
- Padrino testing framework is MiniTest
- Padrino headless browser for testing is WebRat.
I believe those choices were quite popular in the past. These days it seems that the most popular combo is RSpec/Capybara, which is the only one I know.
Learning MiniTest/Webrat is critical to understand better Padrino code. However since I started late with Ruby programming, my day to day testing is already solved by RSpec/Capybara, that makes my learning of Padrino codebase testing a secondary thing.
To understand more about Padrino testing from any Test Framework:
http://stackoverflow.com/a/22753937/253098