Skip to content

Commit 410ac12

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 410ac12

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

spec/singed/middleware_spec.rb

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "tmpdir"
4-
53
describe Singed::RackMiddleware do
64
subject do
75
instance.call(env)
@@ -12,31 +10,33 @@
1210
let(:env) { Rack::MockRequest.env_for("/", headers) }
1311
let(:headers) { {} }
1412

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

25-
it "does not capture a flamegraph by default" do
26-
expect(instance).not_to receive(:flamegraph)
27-
subject
18+
it "passes through the app response unchanged" do
19+
expect(subject).to eq([200, {"content-type" => "text/plain"}, ["OK"]])
2820
end
2921

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

3328
it "captures a flamegraph" do
3429
expect(instance).to receive(:flamegraph).and_call_original
3530
subject
3631
end
32+
33+
it "returns a proper rack response" do
34+
linted_app = Rack::Lint.new(instance)
35+
expect { linted_app.call(env) }.not_to raise_error
36+
end
3737
end
3838

39-
describe ".capture_flamegraph?" do
39+
describe "#capture_flamegraph?" do
4040
subject { instance.capture_flamegraph?(env) }
4141

4242
it { is_expected.to be false }
@@ -46,5 +46,34 @@
4646

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

0 commit comments

Comments
 (0)