Grynszpan
Grynszpan

Reputation: 147

How do I test Sinatra helpers from irb?

I am trying to call a helper method in my Sinatra application from irb in order to test its output. I know I can get a console using this tip, and I've tried racksh as well. But if I do a "defined? my_helper" I always get nil. There must be some simple way of getting at those helpers. I have a feeling that this means digging through the architecture of Rack a little bit. Any hints?

Upvotes: 2

Views: 2058

Answers (2)

briangonzalez
briangonzalez

Reputation: 1616

You can of course test your Sinatra helpers via IRB.

Suppose you had a modular Sinatra app with a helper method foo that printed "baz":

require "my-app.rb"
MyApp.new.helpers.foo # => "baz" 

Upvotes: 4

nicholaides
nicholaides

Reputation: 19519

I am trying to call a helper method in my Sinatra application from irb in order to test its output

Instead of testing it over the command line, use RSpec. See How can I test helpers blocks in Sinatra, using Rspec?

Upvotes: 0

Related Questions