Dwight Watson's blog

Request specs for Rack::Deflate

This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.

I've been tinkering about with Rack::Deflate after reading Thoughtbot's post on the topic. Works a charm, but I noticed a lot of the example specs for Rack::Deflate are now out-of-date for RSpec 3.

As such, I've got an updated request spec that will check that the your content is encoded when the browser indicates that it will be supported. Just pop this in spec/requests/compression_spec.rb:

require "rails_helper"

RSpec.describe "Compression", type: :request do
scenario "a visitor has a browser that supports compression" do
get root_path, headers: { HTTP_ACCEPT_ENCODING: "gzip" }
expect(response.headers).to have_key "Content-Encoding"
end

scenario "a visitor's browser does not support compression" do
get root_path
expect(response.headers).to_not have_key "Content-Encoding"
end
end

A blog about Laravel & Rails by Dwight Watson;

Picture of Dwight Watson

Follow me on Twitter, or GitHub.