Permalink
Browse files

Process monitor starts when enabled

  • Loading branch information...
1 parent fcfa8f2 commit 4cfee5b3c0fd50671a7ca1527d43453d45454e7a @telent committed Apr 22, 2012
Showing with 49 additions and 0 deletions.
  1. +17 −0 lib/lizard/monitor/process.rb
  2. +32 −0 test/unit/process_test.rb
@@ -0,0 +1,17 @@
+class Lizard::Monitor::Process < Lizard::Monitor
+ class << self
+ def start(&blk)
+ define_method :start do
+ instance_eval &blk
+ end
+ end
+ def stop(&blk)
+ define_method :stop do
+ instance_eval &blk
+ end
+ end
+ end
+ listen :enable do
+ start
+ end
+end
View
@@ -0,0 +1,32 @@
+require 'lizard/monitor'
+require 'lizard/monitor/process'
+
+describe Lizard::Monitor::Process do
+ it "#start starts" do
+ started=false
+ m=Class.new(Lizard::Monitor::Process) do
+ start do
+ started=true
+ end
+ stop do
+ started=false
+ end
+ end.new
+ m.start
+ assert started
+ end
+ it "starts when :enable event received" do
+ started=false
+ m=Class.new(Lizard::Monitor::Process) do
+ start do
+ started=true
+ end
+ stop do
+ started=false
+ end
+ end
+ m2=Class.new(m).new
+ m2.notify :enable
+ assert started
+ end
+end

0 comments on commit 4cfee5b

Please sign in to comment.