就这么简单(不是那么好:)但是如果你想检查一下,然后看看Content-Encoding
响应头,它应该说gzip
. 在 webkit 浏览器中,它位于“网络”下的开发人员工具中,然后选择资源,例如app.min.css
和“标题”选项卡。
以下博客文章中给出了一种对此进行测试的方法:
http://artsy.github.io/blog/2012/02/24/10x-rack-and-rails-output-compression-with-rack-deflater/
我将规范修改为共享示例,因此我可以将它们添加到我真正想要检查的地方:
shared_examples "Compressed pages" do
subject { last_response.headers }
its(["Content-Encoding"]) { should be_nil }
context "After compression" do
before do
get page
@etag = last_response.headers["Etag"]
@content_length = last_response.headers["Content-Length"]
get page, {}, { "HTTP_ACCEPT_ENCODING" => "gzip" }
end
its(["Etag"]) { should == @etag }
its(["Content-Length"]) { should_not == @content_length }
its(["Content-Encoding"]) { should == "gzip"}
end
end
我的主要规格是这样使用它的:
describe "Public pages" do
describe "Home page", :type => :request do
let(:page) { "/" }
it_behaves_like "Compressed pages"
将it_behaves_like "Compressed pages"
运行该共享示例并检查它是否具有正确的标题等。