Skip to content

Instantly share code, notes, and snippets.

@Neil-Aframe
Created February 25, 2013 12:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Neil-Aframe/5029416 to your computer and use it in GitHub Desktop.
Save Neil-Aframe/5029416 to your computer and use it in GitHub Desktop.
Rack Middleware Test example (tweaked to work for me)
class SampleMiddleware
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
request.session['hello'] = 'world'
@app.call(env)
end
end
describe SampleMiddleware do
include Rack::Test::Methods
let(:inner_app) do
lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['All good!']] }
end
let(:app) { SampleMiddleware.new(inner_app) }
it "adds hello:world to session" do
get "/"
last_request.session['hello'].should == 'world'
end
it "makes no change to response status" do
get "/"
last_response.should be_ok
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment