tags:

views:

106

answers:

1

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?

+1  A: 

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 http://stackoverflow.com/questions/2878818/how-can-i-test-helpers-blocks-in-sinatra-using-rspec

nicholaides
RSpec seems like one of several possibilities for doing unit testing. However, I really am not interested in unit testing right now. I really need the ability to take a look at the output of some methods dynamically, from an interactive console, manipulating that output as I choose. I think what I'm looking to do should be possible.
Grynszpan
Okay, upon a closer reading of the link, I see how it provides a way to do what I want. I break off my helpers into a separate helpermethods.rb file, storing them in a HelperMethods module within that file. Then within my "irb -r helpermethods.rb" session I can call "require HelperMethods" do import all my helpers as class methods of Object, and call them wherever I want.In short, thanks for pointing me in the right direction.
Grynszpan