Created
November 27, 2013 12:58
-
-
Save remi/7675243 to your computer and use it in GitHub Desktop.
Testing Rack::Date with RSpec and Rack::MockRequest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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