Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Console for Rack based ruby web apps
Ruby
tag: 0.9.3

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
lib
README.markdown
Rakefile
VERSION
racksh.gemspec

README.markdown

racksh

About

racksh (Rack::Shell) is a console for Rack based ruby web applications.

It's like Rails' script/console or Merb's merb -i, but for any app built on Rack. You can use it to load application environment for Rails, Merb, Sinatra, Camping, Ramaze or your own framework provided there is config.ru file in app's root directory.

It's purpose is to allow developer to introspect his application and/or make some initial setup. You can for example run DataMapper.auto_migrate! or make a request to "/users/666" and check response details. It's mainly aimed at apps that don't have console-like component (ie. app built with Sinatra) but all frameworks can benefit from interactive Rack stack introspection.

How it works?

It loads whole application environment like Rack web server, but instead of running the app it starts irb session. Additionally it exposes $rack variable which allows you to make simulated HTTP requests to your app.

Installation

gem install racksh -s http://gemcutter.org

Usage

Starting racksh

To start racksh session run following inside rack application directory (containing config.ru file):

% racksh
Rack::Shell v0.9.3 started in development environment.
irb(main):001:0> 

Specifying location of config.ru:

% CONFIG_RU=~/projects/foobar/config.ru racksh

Executing ruby code inside application environment and printing results:

% racksh Order.all
% racksh "Order.first :created_at => Date.today"

Specifying Rack environment (default is development):

% RACK_ENV=production racksh
Rack::Shell v0.9.3 started in production environment.
irb(main):001:0> 

Making simulated HTTP requests to your app:

% racksh
Rack::Shell v0.9.3 started in development environment.
irb(main):001:0> $rack.get "/"
=> #<Rack::MockResponse:0xb68fa7bc @body="<html>...", @headers={"Content-Type"=>"text/html", "Content-Length"=>"1812"}, @status=200, ...

$rack variable contains following methods (thanks to rack-test gem):

# make GET request
$rack.get uri, params, env

# make POST request
$rack.post uri, params, env

# make PUT request
$rack.put uri, params, env

# make DELETE request
$rack.delete uri, params, env

# make HEAD request
$rack.head uri, params, env

# make custom request
$rack.request uri, params, env

# set HTTP header
$rack.header name, value

# set credentials for Basic Authorization
$rack.basic_authorize username, password

# set credentials for Digest Authorization
$rack.digest_authorize username, password

# follow redirect from previous request
$rack.follow_redirect!

# access your Rack app
$rack.app

Check test.rb from brynary's rack-test for implementation of above methods.

Examples:

$rack.get "/", {}, { 'REMOTE_ADDR' => '123.45.67.89' }
$rack.header "User-Agent", "Firefox"
$rack.post "/users", :user => { :name => "Jola", :email => "jola@misi.ak" }

Bugs & feature requests

Please report bugs and/or feature requests on the github issue tracker for the project located here.

Authors

Something went wrong with that request. Please try again.