Skip to content

Instantly share code, notes, and snippets.

@remi
Created November 27, 2013 12:58
Show Gist options
  • Save remi/7675243 to your computer and use it in GitHub Desktop.
Save remi/7675243 to your computer and use it in GitHub Desktop.
Testing Rack::Date with RSpec and Rack::MockRequest
require "rack"
class Rack::Date
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
headers.merge! 'Date' => Time.now.httpdate
[status, headers, body]
end
end
require "./rack_date.rb"
require "rspec"
describe Rack::Date do
let(:app) { proc{[200,{},['Hello, world.']]} }
let(:stack) { Rack::Date.new(app) }
let(:request) { Rack::MockRequest.new(stack) }
let(:time) { Time.parse('November 19, 2013 11:30:24') }
before { Time.stub(:now).and_return(time) }
describe 'Date header' do
let(:response) { request.get('/') }
it { expect(response.headers['Date']).to eq time.httpdate }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment