Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect content length for the instrumented source #51

Merged
merged 1 commit into from
Apr 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/teabag/instrumentation.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(response)
status, headers, @asset = response status, headers, @asset = response
headers, @asset = [headers.clone, @asset.clone] headers, @asset = [headers.clone, @asset.clone]
result = process_and_instrument result = process_and_instrument
length = result.length.to_s length = result.bytesize.to_s


headers["Content-Length"] = length headers["Content-Length"] = length
@asset.instance_variable_set(:@source, result) @asset.instance_variable_set(:@source, result)
Expand Down
11 changes: 7 additions & 4 deletions spec/teabag/instrumentation_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

require "spec_helper" require "spec_helper"
require "rack/test" require "rack/test"


Expand Down Expand Up @@ -64,13 +66,14 @@


describe ".add_to" do describe ".add_to" do


let(:asset) { mock(source: "function add(a, b) { return a + b }", pathname: 'path/to/instrument.js') } let(:asset) { mock(source: source, pathname: 'path/to/instrument.js') }
let(:source) { "function add(a, b) { return a + b } // ☃ " }


before do before do
Teabag::Instrumentation.stub(:add?).and_return(true) Teabag::Instrumentation.stub(:add?).and_return(true)


File.stub(:write) File.stub(:write)
subject.any_instance.stub(:instrument).and_return("_foo_") subject.any_instance.stub(:instrument).and_return(source + " // instrumented")


path = nil path = nil
Dir.mktmpdir { |p| path = p } Dir.mktmpdir { |p| path = p }
Expand All @@ -79,7 +82,7 @@
end end


it "writes the file to a tmp path" do it "writes the file to a tmp path" do
File.should_receive(:write).with(@output, "function add(a, b) { return a + b }") File.should_receive(:write).with(@output, "function add(a, b) { return a + b } // ☃ ")
subject.add_to(response, env) subject.add_to(response, env)
end end


Expand All @@ -90,7 +93,7 @@


it "replaces the response array with the appropriate information" do it "replaces the response array with the appropriate information" do
response = [666, {"Content-Type" => "application/javascript"}, asset] response = [666, {"Content-Type" => "application/javascript"}, asset]
expected = [666, {"Content-Type" => "application/javascript", "Content-Length" => "5"}, asset] expected = [666, {"Content-Type" => "application/javascript", "Content-Length" => "59"}, asset]


subject.add_to(response, env) subject.add_to(response, env)
expect(response).to eq(expected) expect(response).to eq(expected)
Expand Down