Browse files

Polish interruptions

  • Loading branch information...
1 parent 70bd3ce commit a82dcac746009ebbdaf037238f4e81b383d945af @txus committed Jan 6, 2011
Showing with 12 additions and 7 deletions.
  1. +5 −1 lib/micetrap/services/base.rb
  2. +5 −5 spec/micetrap/logger_spec.rb
  3. +2 −1 spec/micetrap/services/base_spec.rb
View
6 lib/micetrap/services/base.rb
@@ -28,7 +28,11 @@ def fire port = nil
def listen(server)
# Handle Ctrl-C to exit!
interrupted = false
- trap("INT") { puts "Gracefully exiting..."; exit(0) }
+ trap("INT") do
+ puts "Gracefully exiting...";
+ interrupted = true;
+ Kernel.exit(0)
+ end
while not interrupted do
socket = server.accept
View
10 spec/micetrap/logger_spec.rb
@@ -32,10 +32,10 @@ module Micetrap
Time.stub(:now).and_return now
File.stub(:new).and_return file
- expected_string = "\n#{now} Recorded a probe coming from hackerz.com:5978 containing the following:\n\t\t###EVILPROBE###"
+ expected_string = "\n#{now} Recorded a probe coming from hackerz.com:5978 containing the following: ###EVILPROBE###"
- subject.file.should_receive(:write)
- .with expected_string
+ File.should_receive(:open).and_yield file
+ file.should_receive(:write).with expected_string
subject.log_probe "###EVILPROBE###", "hackerz.com", 5978
end
@@ -50,8 +50,8 @@ module Micetrap
expected_string = "\n#{now} ::: Warning! :::"
- subject.file.should_receive(:write)
- .with expected_string
+ File.should_receive(:open).and_yield file
+ file.should_receive(:write).with expected_string
subject.log_message "Warning!"
end
View
3 spec/micetrap/services/base_spec.rb
@@ -38,13 +38,14 @@ module Services
server = double('server', :addr => [1,2,3])
TCPServer.stub(:open).and_return server
subject.logger.should_receive(:log_message).with do |arg|
- arg.should include('Base micetrap listening')
+ arg.should include('Base trap listening')
end
subject.fire
end
end
describe "#listen", :blocking => true do
it 'calls read_from every time a connection is accepted' do
+ Kernel.stub(:exit)
connection = double('connection')
server = double('server', :addr => [1,2,3], :accept => connection)

0 comments on commit a82dcac

Please sign in to comment.