Updated RubySpec source to d6754b35 except language/def_spec.rb.
[rbx.git] / spec / frozen / 1.8 / library / net / ftp / getmultiline_spec.rb
blob9558db2e3f37b8f3686dac582e2618b8014dd88b
1 require File.dirname(__FILE__) + '/../../../spec_helper'
2 require 'net/ftp'
4 describe "Net::FTP#getmultiline" do
5   before(:each) do
6     @socket = mock("Socket")
7     
8     @ftp = Net::FTP.new
9     @ftp.instance_variable_set(:@sock, @socket)
10   end
11   
12   it "is private" do
13     @ftp.private_methods.should include("getmultiline")
14   end
15   
16   it "returns single line responses read from the socket" do
17     @socket.should_receive(:readline).and_return("200 Command okay.")
18     @ftp.send(:getmultiline).should == "200 Command okay.\n"
19   end
21   it "returns multi line responses read from the socket" do
22     responses = [
23       "200-Start of multi line response.",
24       "200-Multi line responses, yay!",
25       "200 End of multi line response."
26     ]
27     
28     @socket.should_receive(:readline).and_return(*responses)
29     @ftp.send(:getmultiline).should == "200-Start of multi line response.\n200-Multi line responses, yay!\n200 End of multi line response.\n"
30   end
31   
32   it "only reads till the end of a multi line response" do
33     responses = [
34       "200-Start of multi line response.",
35       "200 End of multi line response.",
36       "201 Ignored line."
37     ]
39     @socket.stub!(:readline).and_return(*responses)
40     @ftp.send(:getmultiline).should == "200-Start of multi line response.\n200 End of multi line response.\n"
41   end
42   
43   it "outputs the read lines after sanitizing when in debug mode" do
44     @ftp.debug_mode = true
45     
46     responses = [
47       "PASS password",
48       "200-Start of multi line response.",
49       "200 End of multi line response."
50     ]
51     
52     @socket.should_receive(:readline).and_return(*responses)
53     
54     lambda { @ftp.send(:getmultiline) }.should output("get: PASS ********\n")
55     lambda { @ftp.send(:getmultiline) }.should output("get: 200-Start of multi line response.\nget: 200 End of multi line response.\n")
56   end
57 end