How to test a Padrino controller from Padrino console

1k Views Asked by At

I know in Rails I can do something like

app.get 'url'
app.response

But this does not work in Padrino, nor do any of the regular controller calls because Padrino uses different controller methods than Rails.

What I'm trying to do is test my controller methods from the Ruby Padrino MRI console. For example, I want to store the objects present, call the same method 100 times, then compare what objects are left behind. I'm trying to find a memory leak.

So it would be great to be able to call the method from a Padrino console.

I can't find anything that tells me how to do it in the official documentation or elsewhere.

1

There are 1 best solutions below

0
On

The get in you Padrino::Application is just part of the DSL to define new routes, not to retrieve their contents. What you are trying to achieve is usually part of the Rack::Test library.

Have a look at the Sinatra documentation:

http://www.sinatrarb.com/testing.html

Specially compare the sections about Rack::Test with Mixin VS without Mixin. That should make you understand where the fetching get comes from.

In your case, if you want to test from the console, then it should be something like this part:

require 'rack/test'
browser = Rack::Test::Session.new(Rack::MockSession.new(Padrino::Application))
browser.get '/'

Now, where you see Padrino::Application you must type your own application main class that inherits from that class, not the abstract class itself

Notice that the result will be a Rack::MockSession object, so if you just want to see the html do:

browser.get('/').body