public
Description: A process execution library which doesn't suck.
Clone URL: git://github.com/codahale/ropen.git
Search Repo:
Added Ropen::Spool, to line up messages for stdin.
codahale (author)
Thu May 15 14:27:52 -0700 2008
commit  04fc99c893e0666254071fbee53be27206aa8652
tree    1501aeac87ad288620772e0c7546fb4fa86b5a19
parent  b18d73130f5f0562b5085cab15fd17c262964868
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
0
@@ -1 +1,21 @@
0
+require "ropen"
0
+
0
+# TODO: document me
0
+
0
+class Ropen::Spool
0
+ def initialize
0
+ @messages = []
0
+ end
0
+
0
+ def method_missing(m, *args, &block)
0
+ @messages << [m, args, block]
0
+ end
0
+
0
+ def replay(stream)
0
+ while message = @messages.shift
0
+ m, args, block = message
0
+ stream.send(m, *args, &block)
0
+ end
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
0
@@ -1 +1,27 @@
0
+require File.join(File.dirname(__FILE__), "..", "spec_helper")
0
+
0
+require "ropen/spool"
0
+
0
+describe Ropen::Spool do
0
+
0
+ before(:each) do
0
+ @spool = Ropen::Spool.new
0
+ @stream = mock(:stream)
0
+ end
0
+
0
+ it "should collect messages and replay them on an object once" do
0
+ block = lambda { @stream.do_it }
0
+ @spool.puts "I'm a message."
0
+ @spool.close
0
+ @spool.run_this_thing(&block)
0
+
0
+ @stream.should_receive(:puts).with("I'm a message.")
0
+ @stream.should_receive(:close)
0
+ @stream.should_receive(:do_it)
0
+ @stream.should_receive(:run_this_thing).with(&block).and_yield
0
+
0
+ @spool.replay(@stream)
0
+ end
0
+
0
+end

Comments

    No one has commented yet.