|
3 | 3 | RSpec.describe Promenade::Raindrops::Middleware do
|
4 | 4 | let(:app) { double(:app, call: nil) }
|
5 | 5 | let(:listener_address) { "127.0.0.1:#{ENV.fetch('PORT', 3000)}" }
|
6 |
| - let(:pitchfork) { class_double("Pitchfork").as_stubbed_const } |
7 | 6 |
|
8 |
| - before do |
9 |
| - allow(pitchfork).to receive(:listener_names).and_return([listener_address]) |
| 7 | + shared_examples "middleware" do |
| 8 | + it "is add it's instrumentaion to the rack.after_reply" do |
| 9 | + stats = class_spy("Promenade::Raindrops::Stats").as_stubbed_const |
| 10 | + |
| 11 | + after_reply = [] |
| 12 | + described_class.new(app).call({ "rack.after_reply" => after_reply }) |
| 13 | + after_reply.each(&:call) |
| 14 | + |
| 15 | + expect(stats).to have_received(:instrument).with(listener_address: listener_address) |
| 16 | + end |
10 | 17 | end
|
11 | 18 |
|
12 |
| - it "is add it's instrumentaion to the rack.after_reply" do |
13 |
| - stats = class_spy("Promenade::Raindrops::Stats").as_stubbed_const |
| 19 | + context "when Pitchfork is defined" do |
| 20 | + let(:pitchfork) { class_double("Pitchfork").as_stubbed_const } |
| 21 | + |
| 22 | + before do |
| 23 | + allow(pitchfork).to receive(:listener_names).and_return([listener_address]) |
| 24 | + end |
| 25 | + |
| 26 | + it_behaves_like "middleware" |
| 27 | + end |
| 28 | + |
| 29 | + context "when Unicorn is defined" do |
| 30 | + let(:unicorn) { class_double("Unicorn").as_stubbed_const } |
| 31 | + |
| 32 | + before do |
| 33 | + allow(unicorn).to receive(:listener_names).and_return([listener_address]) |
| 34 | + end |
| 35 | + |
| 36 | + it_behaves_like "middleware" |
| 37 | + end |
14 | 38 |
|
15 |
| - after_reply = [] |
16 |
| - described_class.new(app).call({ "rack.after_reply" => after_reply }) |
17 |
| - after_reply.each(&:call) |
| 39 | + context "when neither Pitchfork nor Unicorn is defined" do |
| 40 | + it "raises an error" do |
| 41 | + stats = class_spy("Promenade::Raindrops::Stats").as_stubbed_const |
18 | 42 |
|
19 |
| - expect(stats).to have_received(:instrument).with(listener_address: listener_address) |
| 43 | + expect do |
| 44 | + after_reply = [] |
| 45 | + described_class.new(app).call({ "rack.after_reply" => after_reply }) |
| 46 | + after_reply.each(&:call) |
| 47 | + end.to raise_error "Promenade::Raindrops::Middleware expects either ::Pitchfork or ::Unicorn to be defined" |
| 48 | + end |
20 | 49 | end
|
21 | 50 | end
|
0 commit comments