diff --git a/lib/teaspoon/instrumentation.rb b/lib/teaspoon/instrumentation.rb index 9f5b3720..3d727c80 100644 --- a/lib/teaspoon/instrumentation.rb +++ b/lib/teaspoon/instrumentation.rb @@ -35,10 +35,8 @@ def instrumented_response result = add_instrumentation(asset) - asset.instance_variable_set(:@source, result) - asset.instance_variable_set(:@length, headers["Content-Length"] = result.bytesize.to_s) - - [status, headers, asset] + headers["Content-Length"] = result.bytesize.to_s + [status, headers, [result]] end protected diff --git a/spec/teaspoon/instrumentation_spec.rb b/spec/teaspoon/instrumentation_spec.rb index aab34c73..28233e8a 100644 --- a/spec/teaspoon/instrumentation_spec.rb +++ b/spec/teaspoon/instrumentation_spec.rb @@ -8,6 +8,7 @@ let(:asset) { double(source: source, filename: "path/to/instrument.js") } let(:source) { "function add(a, b) { return a + b } // ☃ " } + let(:instrumented_source) { source + " // instrumented" } let(:response) { [200, { "Content-Type" => "application/javascript" }, asset] } let(:env) { { "QUERY_STRING" => "instrument=true" } } @@ -21,7 +22,7 @@ expect(asset).to receive(:clone).and_return(asset) allow(File).to receive(:open) - allow_any_instance_of(subject).to receive(:instrument).and_return(source + " // instrumented") + allow_any_instance_of(subject).to receive(:instrument).and_return(instrumented_source) path = nil Dir.mktmpdir { |p| path = p } @@ -43,7 +44,7 @@ it "replaces the response array with the appropriate information" do response = [666, { "Content-Type" => "application/javascript" }, asset] - expected = [666, { "Content-Type" => "application/javascript", "Content-Length" => "59" }, asset] + expected = [666, { "Content-Type" => "application/javascript", "Content-Length" => "59" }, [instrumented_source]] expect(subject.add_to(response, env)).to eq(expected) end @@ -124,10 +125,10 @@ def ignore(paths) it "instruments a file" do pending("needs istanbul to be installed") unless Teaspoon::Instrumentation.executable - status, headers, asset = subject.add_to(response, "QUERY_STRING" => "instrument=true") + status, headers, body = subject.add_to(response, "QUERY_STRING" => "instrument=true") expect(status).to eq(200) expect(headers).to include("Content-Type" => "application/javascript") - expect(asset.source).to match(/var __cov_.+ = \(Function\('return this'\)\)\(\);/) + expect(body.first).to match(/var __cov_.+ = \(Function\('return this'\)\)\(\);/) end it "hooks into sprockets" do