Filed under  //   rack   ruby   tech   testing  

Comments [0]

Testing a rackup (config.ru) file with Rack::Test

The ever useful rack-test gem let's you easily integration test any rack project.  All you have to do is include the Rack::Test::Methods and define an app method that returns your rack app.  So people usually have a config.ru that just references their my_application.rb that they reference in their config.ru and then in their test file they can also reference that app and return it.  Something to to this effect:

I had a project where I was actually trying to better breakdown a more complex app, and I wanted to just be able to use Rack's built-in map method at the top level of my config.ru to route to different apps.  And in at least some of the cases I wanted to be able to test the whole thing.  Also, I figured sometimes it's useful to actually be able to test your rackup file itself, all routing/mapping included.  So I dug around in the rack code and found how the rackup command handles the .ru file, and came up with this:

Update

If you are running off of a new enough version of rack, you could also just use Rack::Builder.parse_file

Filed under  //   rack   ruby   tech   testing  

Comments [0]

Filed under  //   ruby   tech   testing  

Comments [0]

Filed under  //   plugins   ruby   rubyonrails   tech   testing  

Comments [0]

Filed under  //   ruby   rubyonrails   tech   testing  

Comments [0]

Filed under  //   ruby   rubyonrails   tech   testing  

Comments [0]

Filed under  //   ruby   rubyonrails   tech   testing  

Comments [0]

Filed under  //   rake   ruby   tech   testing  

Comments [0]

Filed under  //   rake   ruby   tech   testing  

Comments [0]

Filed under  //   blerb   merb   ruby   tech   testing  

Comments [0]