public
Description: IRB Power User Utility Belt
Homepage: http://utilitybelt.rubyforge.org
Clone URL: git://github.com/gilesbowkett/utility-belt.git
gilesbowkett (author)
Tue Feb 26 11:27:51 -0800 2008
utility-belt / spec / pipe_spec.rb
100644 31 lines (24 sloc) 0.843 kb
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
27
28
29
30
31
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), "spec_helper")
 
require 'spec'
require 'irb'
require File.join(File.dirname(__FILE__), '..', 'lib', 'utility_belt', 'pipe')
 
describe "String#|" do
  before :each do
    @pipe = stub(:pipe, :write => nil, :close_write => nil, :read => nil)
    IO.stub!(:popen).and_yield(@pipe).and_return("RESULT")
  end
 
  it "should open a pipe" do
    IO.should_receive(:popen).with("COMMAND", 'r+').and_return(@pipe)
    "foo" | "COMMAND"
  end
 
  it "should write itself to the the pipe, close it, then read from it" do
    @pipe.should_receive(:write).with("foo").ordered
    @pipe.should_receive(:close_write).ordered
    @pipe.should_receive(:read)
 
    "foo" | "COMMAND"
  end
 
  it "should return the result of the IO.popen block" do
    ("foo" | "COMMAND").should == "RESULT"
  end
end