Skip to content

Commit ac2c58e

Browse files
dpepclaude
andcommitted
Address PR feedback: sigil fix and cleanup
- Change `.capture_flamegraph?` to `#capture_flamegraph?` (instance method) - Remove temp directory setup (now handled globally via spec_helper) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 70419fd commit ac2c58e

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

spec/singed/middleware_spec.rb

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
11
# frozen_string_literal: true
22

3-
require "tmpdir"
4-
53
describe Singed::RackMiddleware do
64
subject do
75
instance.call(env)
86
end
97

10-
let(:app) { ->(*) { [200, {"content-type" => "text/plain"}, ["OK"]] } }
8+
let(:app_response) { [200, {"content-type" => "text/plain"}, ["OK"]] }
9+
let(:app) { ->(*) { app_response } }
1110
let(:instance) { described_class.new(app) }
1211
let(:env) { Rack::MockRequest.env_for("/", headers) }
1312
let(:headers) { {} }
1413

15-
before do
16-
allow_any_instance_of(Singed::Flamegraph).to receive(:open)
17-
Singed.output_directory = Dir.mktmpdir("singed-spec")
18-
end
19-
2014
it "returns a proper rack response" do
2115
linted_app = Rack::Lint.new(instance)
2216
expect { linted_app.call(env) }.not_to raise_error
2317
end
2418

25-
it "does not capture a flamegraph by default" do
26-
expect(instance).not_to receive(:flamegraph)
27-
subject
19+
it "passes through the app response unchanged" do
20+
expect(subject).to eq(app_response)
2821
end
2922

3023
context "when enabled" do
31-
before { allow(instance).to receive(:capture_flamegraph?).and_return(true) }
24+
before do
25+
allow_any_instance_of(Singed::Flamegraph).to receive(:open)
26+
allow(instance).to receive(:capture_flamegraph?).and_return(true)
27+
end
3228

3329
it "captures a flamegraph" do
3430
expect(instance).to receive(:flamegraph).and_call_original
3531
subject
3632
end
33+
34+
it "returns a proper rack response" do
35+
linted_app = Rack::Lint.new(instance)
36+
expect { linted_app.call(env) }.not_to raise_error
37+
end
38+
39+
it "passes through the app response unchanged" do
40+
expect(subject).to eq(app_response)
41+
end
3742
end
3843

39-
describe ".capture_flamegraph?" do
44+
describe "#capture_flamegraph?" do
4045
subject { instance.capture_flamegraph?(env) }
4146

4247
it { is_expected.to be false }
@@ -46,5 +51,34 @@
4651

4752
it { is_expected.to be true }
4853
end
54+
55+
context "when SINGED_MIDDLEWARE_ALWAYS_CAPTURE env var is set" do
56+
around do |example|
57+
original = ENV["SINGED_MIDDLEWARE_ALWAYS_CAPTURE"]
58+
described_class.remove_instance_variable(:@always_capture) if described_class.instance_variable_defined?(:@always_capture)
59+
example.run
60+
ensure
61+
if original.nil?
62+
ENV.delete("SINGED_MIDDLEWARE_ALWAYS_CAPTURE")
63+
else
64+
ENV["SINGED_MIDDLEWARE_ALWAYS_CAPTURE"] = original
65+
end
66+
described_class.remove_instance_variable(:@always_capture) if described_class.instance_variable_defined?(:@always_capture)
67+
end
68+
69+
%w[true 1 yes].each do |truthy_value|
70+
context "when SINGED_MIDDLEWARE_ALWAYS_CAPTURE=#{truthy_value}" do
71+
before { ENV["SINGED_MIDDLEWARE_ALWAYS_CAPTURE"] = truthy_value }
72+
73+
it { is_expected.to be true }
74+
end
75+
end
76+
77+
context "when SINGED_MIDDLEWARE_ALWAYS_CAPTURE=false" do
78+
before { ENV["SINGED_MIDDLEWARE_ALWAYS_CAPTURE"] = "false" }
79+
80+
it { is_expected.to be false }
81+
end
82+
end
4983
end
5084
end

0 commit comments

Comments
 (0)