Skip to content

Commit dcc81ff

Browse files
dpepclaude
andcommitted
Improve middleware spec with Rack::Lint and cleanup
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1d59a59 commit dcc81ff

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

spec/singed/middleware_spec.rb

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
require "tmpdir"
4+
15
describe Singed::RackMiddleware do
26
subject do
37
instance.call(env)
48
end
59

6-
let(:app) { ->(*) { [200, {'Content-Type' => 'text/plain'}, ['OK']] } }
10+
let(:app) { ->(*) { [200, {"content-type" => "text/plain"}, ["OK"]] } }
711
let(:instance) { described_class.new(app) }
8-
let(:env) { Rack::MockRequest.env_for('/', headers) }
12+
let(:env) { Rack::MockRequest.env_for("/", headers) }
913
let(:headers) { {} }
1014

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
1423
end
1524

16-
it 'does not capture a flamegraph by default' do
25+
it "does not capture a flamegraph by default" do
1726
expect(instance).not_to receive(:flamegraph)
1827
subject
1928
end
2029

21-
context 'when enabled' do
30+
context "when enabled" do
2231
before { allow(instance).to receive(:capture_flamegraph?).and_return(true) }
2332

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
2635
subject
2736
end
2837
end
2938

30-
describe '.capture_flamegraph?' do
39+
describe ".capture_flamegraph?" do
3140
subject { instance.capture_flamegraph?(env) }
3241

3342
it { is_expected.to be false }
3443

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"} }
3746

3847
it { is_expected.to be true }
3948
end

0 commit comments

Comments
 (0)