|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "tmpdir" |
| 4 | + |
1 | 5 | describe Singed::RackMiddleware do |
2 | 6 | subject do |
3 | 7 | instance.call(env) |
4 | 8 | end |
5 | 9 |
|
6 | | - let(:app) { ->(*) { [200, {'Content-Type' => 'text/plain'}, ['OK']] } } |
| 10 | + let(:app) { ->(*) { [200, {"content-type" => "text/plain"}, ["OK"]] } } |
7 | 11 | let(:instance) { described_class.new(app) } |
8 | | - let(:env) { Rack::MockRequest.env_for('/', headers) } |
| 12 | + let(:env) { Rack::MockRequest.env_for("/", headers) } |
9 | 13 | let(:headers) { {} } |
10 | 14 |
|
11 | | - it 'returns a proper rack response' do |
12 | | - status, _ = subject |
13 | | - expect(status).to eq 200 |
| 15 | + before do |
| 16 | + allow_any_instance_of(Singed::Flamegraph).to receive(:open) |
| 17 | + Singed.output_directory = Dir.mktmpdir("singed-spec") |
| 18 | + end |
| 19 | + |
| 20 | + it "returns a proper rack response" do |
| 21 | + linted_app = Rack::Lint.new(instance) |
| 22 | + expect { linted_app.call(env) }.not_to raise_error |
14 | 23 | end |
15 | 24 |
|
16 | | - it 'does not capture a flamegraph by default' do |
| 25 | + it "does not capture a flamegraph by default" do |
17 | 26 | expect(instance).not_to receive(:flamegraph) |
18 | 27 | subject |
19 | 28 | end |
20 | 29 |
|
21 | | - context 'when enabled' do |
| 30 | + context "when enabled" do |
22 | 31 | before { allow(instance).to receive(:capture_flamegraph?).and_return(true) } |
23 | 32 |
|
24 | | - it 'captures a flamegraph' do |
25 | | - expect(instance).to receive(:flamegraph) |
| 33 | + it "captures a flamegraph" do |
| 34 | + expect(instance).to receive(:flamegraph).and_call_original |
26 | 35 | subject |
27 | 36 | end |
28 | 37 | end |
29 | 38 |
|
30 | | - describe '.capture_flamegraph?' do |
| 39 | + describe ".capture_flamegraph?" do |
31 | 40 | subject { instance.capture_flamegraph?(env) } |
32 | 41 |
|
33 | 42 | it { is_expected.to be false } |
34 | 43 |
|
35 | | - context 'when HTTP_X_SINGED is true' do |
36 | | - let(:headers) { { 'HTTP_X_SINGED' => 'true' } } |
| 44 | + context "when HTTP_X_SINGED is true" do |
| 45 | + let(:headers) { {"HTTP_X_SINGED" => "true"} } |
37 | 46 |
|
38 | 47 | it { is_expected.to be true } |
39 | 48 | end |
|
0 commit comments