From 635a9a484b1944e0c419b617429b605b64fe58cf Mon Sep 17 00:00:00 2001 From: Mark Mulder Date: Thu, 9 Feb 2017 11:36:22 +0100 Subject: [PATCH] Re-do most important specs I removed the (very old) dummy rails app in 79293b. --- spec/stopwatch_spec.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 spec/stopwatch_spec.rb diff --git a/spec/stopwatch_spec.rb b/spec/stopwatch_spec.rb new file mode 100644 index 0000000..e999bfe --- /dev/null +++ b/spec/stopwatch_spec.rb @@ -0,0 +1,32 @@ +require_relative './../lib/stopwatch' +require_relative './../lib/load_speed' + +describe Rack::LoadSpeed do + it 'inserts performance data' do + app = lambda { |env| [200, {'Content-Type' => 'text/html'}, ["test"]]} + event = ActiveSupport::Notifications::Event.new('test', 1, 2, '123', { identifier: "app/views/tests/index.html.erb" }) + Stopwatch::Log.reset_query_count + Stopwatch::Log.reset_sub_query_count + Stopwatch::Log.reset_events + + Stopwatch::Log.events << Stopwatch::Event.new(event) + Stopwatch::Log.query_count = 12 + Stopwatch::Log.event = event + + response = Rack::LoadSpeed.new(app).call({}) + + body = response[2][0] + expect(body).to include "performance_code" + expect(body).to include "1000 ms" + expect(body).to include "12 queries" + end + + it 'does nothing for JS' do + app = lambda { |env| [200, {'Content-Type' => 'application/json'}, ["{'id': '1'}"] ] } + event = ActiveSupport::Notifications::Event.new('test', 1, 2, '123', {}) + response = Rack::LoadSpeed.new(app).call({}) + + body = response[2][0] + expect(body).to eq "{'id': '1'}" + end +end