Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Added specs for interrupt catching #2132

Merged
merged 1 commit into from
Dec 11, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions spec/rspec/core/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,50 @@ module RSpec::Core
end
end

describe "interrupt catching" do
let(:interrupt_handlers) { [] }

before do
allow(Object).to receive(:trap).with("INT", any_args) do |&block|
interrupt_handlers << block
end
end

def interrupt
interrupt_handlers.each(&:call)
end

it "adds a handler for SIGINT" do
expect(interrupt_handlers).to be_empty
Runner.send(:trap_interrupt)
expect(interrupt_handlers.size).to eq(1)
end

context "with SIGINT once" do
it "aborts processing" do
Runner.send(:trap_interrupt)
expect(Runner).to receive(:handle_interrupt)
interrupt
end

it "does not exit immediately" do
Runner.send(:trap_interrupt)
expect_any_instance_of(Object).not_to receive(:exit)
expect_any_instance_of(Object).not_to receive(:exit!)
interrupt
end
end

context "with SIGINT twice" do
it "exits immediately" do
Runner.send(:trap_interrupt)
expect_any_instance_of(Object).to receive(:exit!).with(1)
interrupt
interrupt
end
end
end

# This is intermittently slow because this method calls out to the network
# interface.
describe ".running_in_drb?", :slow do
Expand Down