Skip to content

Commit 9021a85

Browse files
committed
Merge pull request rspec#2132 from myrridin/myrridin-interrupt-handling
Added specs for interrupt catching
2 parents 2b69cd5 + cf5e585 commit 9021a85

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

spec/rspec/core/runner_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,50 @@ module RSpec::Core
111111
end
112112
end
113113

114+
describe "interrupt catching" do
115+
let(:interrupt_handlers) { [] }
116+
117+
before do
118+
allow(Object).to receive(:trap).with("INT", any_args) do |&block|
119+
interrupt_handlers << block
120+
end
121+
end
122+
123+
def interrupt
124+
interrupt_handlers.each(&:call)
125+
end
126+
127+
it "adds a handler for SIGINT" do
128+
expect(interrupt_handlers).to be_empty
129+
Runner.send(:trap_interrupt)
130+
expect(interrupt_handlers.size).to eq(1)
131+
end
132+
133+
context "with SIGINT once" do
134+
it "aborts processing" do
135+
Runner.send(:trap_interrupt)
136+
expect(Runner).to receive(:handle_interrupt)
137+
interrupt
138+
end
139+
140+
it "does not exit immediately" do
141+
Runner.send(:trap_interrupt)
142+
expect_any_instance_of(Object).not_to receive(:exit)
143+
expect_any_instance_of(Object).not_to receive(:exit!)
144+
interrupt
145+
end
146+
end
147+
148+
context "with SIGINT twice" do
149+
it "exits immediately" do
150+
Runner.send(:trap_interrupt)
151+
expect_any_instance_of(Object).to receive(:exit!).with(1)
152+
interrupt
153+
interrupt
154+
end
155+
end
156+
end
157+
114158
# This is intermittently slow because this method calls out to the network
115159
# interface.
116160
describe ".running_in_drb?", :slow do

0 commit comments

Comments
 (0)