This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,50 @@ module RSpec::Core
111
111
end
112
112
end
113
113
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
+
114
158
# This is intermittently slow because this method calls out to the network
115
159
# interface.
116
160
describe ".running_in_drb?" , :slow do
You can’t perform that action at this time.
0 commit comments