spec/teabag/instrumentation_spec.rb in teabag-0.7.0 vs spec/teabag/instrumentation_spec.rb in teabag-0.7.1
- old
+ new
@@ -1,5 +1,7 @@
+# encoding: utf-8
+
require "spec_helper"
require "rack/test"
describe Teabag::Instrumentation do
@@ -62,36 +64,37 @@
end
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
Teabag::Instrumentation.stub(:add?).and_return(true)
File.stub(:write)
- subject.any_instance.stub(:instrument).and_return("_foo_")
+ subject.any_instance.stub(:instrument).and_return(source + " // instrumented")
path = nil
Dir.mktmpdir { |p| path = p }
Dir.stub(:mktmpdir).and_yield(path)
@output = File.join(path, "instrument.js")
end
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)
end
it "instruments the javascript file" do
subject.any_instance.should_receive(:instrument).with(@output).and_return("_instrumented_")
subject.add_to(response, env)
end
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" => "5"}, asset]
+ expected = [666, {"Content-Type" => "application/javascript", "Content-Length" => "59"}, asset]
subject.add_to(response, env)
expect(response).to eq(expected)
end