mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
75bfc6440d
commit
1d15d5f080
4370 changed files with 0 additions and 0 deletions
8
spec/ruby/library/net/FTPError_spec.rb
Normal file
8
spec/ruby/library/net/FTPError_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'net/ftp'
|
||||
|
||||
describe "Net::FTPError" do
|
||||
it "is an Exception" do
|
||||
Net::FTPError.should < Exception
|
||||
end
|
||||
end
|
12
spec/ruby/library/net/FTPPermError_spec.rb
Normal file
12
spec/ruby/library/net/FTPPermError_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'net/ftp'
|
||||
|
||||
describe "Net::FTPPermError" do
|
||||
it "is an Exception" do
|
||||
Net::FTPPermError.should < Exception
|
||||
end
|
||||
|
||||
it "is a subclass of Net::FTPError" do
|
||||
Net::FTPPermError.should < Net::FTPError
|
||||
end
|
||||
end
|
12
spec/ruby/library/net/FTPProtoError_spec.rb
Normal file
12
spec/ruby/library/net/FTPProtoError_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'net/ftp'
|
||||
|
||||
describe "Net::FTPProtoError" do
|
||||
it "is an Exception" do
|
||||
Net::FTPProtoError.should < Exception
|
||||
end
|
||||
|
||||
it "is a subclass of Net::FTPError" do
|
||||
Net::FTPPermError.should < Net::FTPError
|
||||
end
|
||||
end
|
12
spec/ruby/library/net/FTPReplyError_spec.rb
Normal file
12
spec/ruby/library/net/FTPReplyError_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'net/ftp'
|
||||
|
||||
describe "Net::FTPReplyError" do
|
||||
it "is an Exception" do
|
||||
Net::FTPReplyError.should < Exception
|
||||
end
|
||||
|
||||
it "is a subclass of Net::FTPError" do
|
||||
Net::FTPPermError.should < Net::FTPError
|
||||
end
|
||||
end
|
12
spec/ruby/library/net/FTPTempError_spec.rb
Normal file
12
spec/ruby/library/net/FTPTempError_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../spec_helper', __FILE__)
|
||||
require 'net/ftp'
|
||||
|
||||
describe "Net::FTPTempError" do
|
||||
it "is an Exception" do
|
||||
Net::FTPTempError.should < Exception
|
||||
end
|
||||
|
||||
it "is a subclass of Net::FTPError" do
|
||||
Net::FTPPermError.should < Net::FTPError
|
||||
end
|
||||
end
|
62
spec/ruby/library/net/ftp/abort_spec.rb
Normal file
62
spec/ruby/library/net/ftp/abort_spec.rb
Normal file
|
@ -0,0 +1,62 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#abort" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the ABOR command to the server" do
|
||||
lambda { @ftp.abort }.should_not raise_error
|
||||
end
|
||||
|
||||
it "ignores the response" do
|
||||
@ftp.abort
|
||||
@ftp.last_response.should == "220 Dummy FTP Server ready!\n"
|
||||
end
|
||||
|
||||
it "returns the full response" do
|
||||
@ftp.abort.should == "226 Closing data connection. (ABOR)\n"
|
||||
end
|
||||
|
||||
it "does not raise any error when the response code is 225" do
|
||||
@server.should_receive(:abor).and_respond("225 Data connection open; no transfer in progress.")
|
||||
lambda { @ftp.abort }.should_not raise_error
|
||||
end
|
||||
|
||||
it "does not raise any error when the response code is 226" do
|
||||
@server.should_receive(:abor).and_respond("226 Closing data connection.")
|
||||
lambda { @ftp.abort }.should_not raise_error
|
||||
end
|
||||
|
||||
it "raises a Net::FTPProtoError when the response code is 500" do
|
||||
@server.should_receive(:abor).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPProtoError when the response code is 501" do
|
||||
@server.should_receive(:abor).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPProtoError when the response code is 502" do
|
||||
@server.should_receive(:abor).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPProtoError when the response code is 421" do
|
||||
@server.should_receive(:abor).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
|
||||
end
|
||||
end
|
58
spec/ruby/library/net/ftp/acct_spec.rb
Normal file
58
spec/ruby/library/net/ftp/acct_spec.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#acct" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "writes the ACCT command to the server" do
|
||||
@ftp.acct("my_account")
|
||||
@ftp.last_response.should == "230 User 'my_account' logged in, proceed. (ACCT)\n"
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.acct("my_account").should == nil
|
||||
end
|
||||
|
||||
it "does not raise any error when the response code is 230" do
|
||||
@server.should_receive(:acct).and_respond("230 User logged in, proceed.")
|
||||
lambda { @ftp.acct("my_account") }.should_not raise_error
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:acct).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 503" do
|
||||
@server.should_receive(:acct).and_respond("503 Bad sequence of commands.")
|
||||
lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:acct).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
end
|
24
spec/ruby/library/net/ftp/binary_spec.rb
Normal file
24
spec/ruby/library/net/ftp/binary_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
|
||||
describe "Net::FTP#binary" do
|
||||
it "returns true when self is in binary mode" do
|
||||
ftp = Net::FTP.new
|
||||
ftp.binary.should be_true
|
||||
|
||||
ftp.binary = false
|
||||
ftp.binary.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "Net::FTP#binary=" do
|
||||
it "sets self to binary mode when passed true" do
|
||||
ftp = Net::FTP.new
|
||||
|
||||
ftp.binary = true
|
||||
ftp.binary.should be_true
|
||||
|
||||
ftp.binary = false
|
||||
ftp.binary.should be_false
|
||||
end
|
||||
end
|
99
spec/ruby/library/net/ftp/chdir_spec.rb
Normal file
99
spec/ruby/library/net/ftp/chdir_spec.rb
Normal file
|
@ -0,0 +1,99 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#chdir" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
describe "when switching to the parent directory" do
|
||||
it "sends the 'CDUP' command to the server" do
|
||||
@ftp.chdir("..")
|
||||
@ftp.last_response.should == "200 Command okay. (CDUP)\n"
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.chdir("..").should be_nil
|
||||
end
|
||||
|
||||
it "does not raise a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:cdup).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.chdir("..") }.should_not raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:cdup).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:cdup).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:cdup).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.chdir("..") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:cdup).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 550" do
|
||||
@server.should_receive(:cdup).and_respond("550 Requested action not taken.")
|
||||
lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
|
||||
it "writes the 'CWD' command with the passed directory to the socket" do
|
||||
@ftp.chdir("test")
|
||||
@ftp.last_response.should == "200 Command okay. (CWD test)\n"
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.chdir("test").should be_nil
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:cwd).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:cwd).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:cwd).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:cwd).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.chdir("test") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:cwd).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 550" do
|
||||
@server.should_receive(:cwd).and_respond("550 Requested action not taken.")
|
||||
lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
30
spec/ruby/library/net/ftp/close_spec.rb
Normal file
30
spec/ruby/library/net/ftp/close_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
|
||||
describe "Net::FTP#close" do
|
||||
before :each do
|
||||
@socket = mock("Socket")
|
||||
@socket.stub!(:closed?).and_return(false)
|
||||
@socket.stub!(:read_timeout).and_return(60)
|
||||
@socket.stub!(:read_timeout=).and_return(3)
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.instance_variable_set(:@sock, @socket)
|
||||
end
|
||||
|
||||
it "closes the socket" do
|
||||
@socket.should_receive(:close)
|
||||
@ftp.close.should be_nil
|
||||
end
|
||||
|
||||
it "does not try to close the socket if it has already been closed" do
|
||||
@socket.should_receive(:closed?).and_return(true)
|
||||
@socket.should_not_receive(:close)
|
||||
@ftp.close.should be_nil
|
||||
end
|
||||
|
||||
it "does not try to close the socket if it is nil" do
|
||||
@ftp.instance_variable_set(:@sock, nil)
|
||||
@ftp.close.should be_nil
|
||||
end
|
||||
end
|
21
spec/ruby/library/net/ftp/closed_spec.rb
Normal file
21
spec/ruby/library/net/ftp/closed_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
|
||||
describe "Net::FTP#closed?" do
|
||||
before :each do
|
||||
@socket = mock("Socket")
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.instance_variable_set(:@sock, @socket)
|
||||
end
|
||||
|
||||
it "returns true when the socket is closed" do
|
||||
@socket.should_receive(:closed?).and_return(true)
|
||||
@ftp.closed?.should be_true
|
||||
end
|
||||
|
||||
it "returns true when the socket is nil" do
|
||||
@ftp.instance_variable_set(:@sock, nil)
|
||||
@ftp.closed?.should be_true
|
||||
end
|
||||
end
|
49
spec/ruby/library/net/ftp/connect_spec.rb
Normal file
49
spec/ruby/library/net/ftp/connect_spec.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
# TODO: Add specs for using the SOCKSSocket
|
||||
describe "Net::FTP#connect" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
end
|
||||
|
||||
after :each do
|
||||
@server.connect_message = nil
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "tries to connect to the FTP Server on the given host and port" do
|
||||
lambda { @ftp.connect(@server.hostname, @server.server_port) }.should_not raise_error
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.connect(@server.hostname, @server.server_port).should be_nil
|
||||
end
|
||||
|
||||
it "prints a small debug line when in debug mode" do
|
||||
@ftp.debug_mode = true
|
||||
lambda { @ftp.connect(@server.hostname, @server.server_port) }.should output(/#{"connect: "}#{@server.hostname}#{", "}#{@server.server_port}#{"\\nget: 220 Dummy FTP Server ready!"}/)
|
||||
@ftp.debug_mode = false
|
||||
end
|
||||
|
||||
it "does not raise any error when the response code is 220" do
|
||||
@server.connect_message = "220 Dummy FTP Server ready!"
|
||||
lambda { @ftp.connect(@server.hostname, @server.server_port) }.should_not raise_error
|
||||
end
|
||||
|
||||
it "raises a Net::FTPReplyError when the response code is 120" do
|
||||
@server.connect_message = "120 Service ready in nnn minutes."
|
||||
lambda { @ftp.connect(@server.hostname, @server.server_port) }.should raise_error(Net::FTPReplyError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.connect_message = "421 Service not available, closing control connection."
|
||||
lambda { @ftp.connect(@server.hostname, @server.server_port) }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
end
|
23
spec/ruby/library/net/ftp/debug_mode_spec.rb
Normal file
23
spec/ruby/library/net/ftp/debug_mode_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
|
||||
describe "Net::FTP#debug_mode" do
|
||||
it "returns true when self is in debug mode" do
|
||||
ftp = Net::FTP.new
|
||||
ftp.debug_mode.should be_false
|
||||
|
||||
ftp.debug_mode = true
|
||||
ftp.debug_mode.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe "Net::FTP#debug_mode=" do
|
||||
it "sets self into debug mode when passed true" do
|
||||
ftp = Net::FTP.new
|
||||
ftp.debug_mode = true
|
||||
ftp.debug_mode.should be_true
|
||||
|
||||
ftp.debug_mode = false
|
||||
ftp.debug_mode.should be_false
|
||||
end
|
||||
end
|
10
spec/ruby/library/net/ftp/default_passive_spec.rb
Normal file
10
spec/ruby/library/net/ftp/default_passive_spec.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
|
||||
ruby_version_is "2.3" do
|
||||
describe "Net::FTP#default_passive" do
|
||||
it "is true by default" do
|
||||
ruby_exe(fixture(__FILE__, "default_passive.rb")).should == "true\ntrue\n"
|
||||
end
|
||||
end
|
||||
end
|
59
spec/ruby/library/net/ftp/delete_spec.rb
Normal file
59
spec/ruby/library/net/ftp/delete_spec.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#delete" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the DELE command with the passed filename to the server" do
|
||||
@ftp.delete("test.file")
|
||||
@ftp.last_response.should == "250 Requested file action okay, completed. (DELE test.file)\n"
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 450" do
|
||||
@server.should_receive(:dele).and_respond("450 Requested file action not taken.")
|
||||
lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 550" do
|
||||
@server.should_receive(:dele).and_respond("550 Requested action not taken.")
|
||||
lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:dele).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:dele).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:dele).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:dele).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:dele).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
8
spec/ruby/library/net/ftp/dir_spec.rb
Normal file
8
spec/ruby/library/net/ftp/dir_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
require File.expand_path('../shared/list', __FILE__)
|
||||
|
||||
describe "Net::FTP#dir" do
|
||||
it_behaves_like :net_ftp_list, :dir
|
||||
end
|
3
spec/ruby/library/net/ftp/fixtures/default_passive.rb
Normal file
3
spec/ruby/library/net/ftp/fixtures/default_passive.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
require "net/ftp"
|
||||
puts Net::FTP.default_passive
|
||||
puts Net::FTP.new.passive
|
2
spec/ruby/library/net/ftp/fixtures/passive.rb
Normal file
2
spec/ruby/library/net/ftp/fixtures/passive.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
require "net/ftp"
|
||||
print Net::FTP.new.passive
|
3
spec/ruby/library/net/ftp/fixtures/putbinaryfile
Normal file
3
spec/ruby/library/net/ftp/fixtures/putbinaryfile
Normal file
|
@ -0,0 +1,3 @@
|
|||
This is an example file
|
||||
which is going to be transmitted
|
||||
using #putbinaryfile.
|
3
spec/ruby/library/net/ftp/fixtures/puttextfile
Normal file
3
spec/ruby/library/net/ftp/fixtures/puttextfile
Normal file
|
@ -0,0 +1,3 @@
|
|||
This is an example file
|
||||
which is going to be transmitted
|
||||
using #puttextfile.
|
273
spec/ruby/library/net/ftp/fixtures/server.rb
Normal file
273
spec/ruby/library/net/ftp/fixtures/server.rb
Normal file
|
@ -0,0 +1,273 @@
|
|||
module NetFTPSpecs
|
||||
class DummyFTP
|
||||
attr_accessor :connect_message
|
||||
attr_reader :login_user, :login_pass, :login_acct
|
||||
|
||||
# hostname or IP address
|
||||
attr_reader :hostname
|
||||
# port number
|
||||
attr_reader :server_port
|
||||
|
||||
def initialize
|
||||
@hostname = "localhost"
|
||||
@server = TCPServer.new(@hostname, 0)
|
||||
@server_port = @server.addr[1]
|
||||
|
||||
@handlers = {}
|
||||
@commands = []
|
||||
@connect_message = nil
|
||||
end
|
||||
|
||||
def serve_once
|
||||
@thread = Thread.new do
|
||||
@socket = @server.accept
|
||||
@socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, 1)
|
||||
begin
|
||||
handle_request
|
||||
ensure
|
||||
@socket.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def handle_request
|
||||
# Send out the welcome message.
|
||||
response @connect_message || "220 Dummy FTP Server ready!"
|
||||
|
||||
begin
|
||||
while command = @socket.recv(1024)
|
||||
command, argument = command.chomp.split(" ", 2)
|
||||
|
||||
if command == "QUIT"
|
||||
self.response("221 OK, bye")
|
||||
break
|
||||
elsif proc_handler = @handlers[command.downcase.to_sym]
|
||||
if argument.nil?
|
||||
proc_handler.call(self)
|
||||
else
|
||||
proc_handler.call(self, argument)
|
||||
end
|
||||
else
|
||||
if argument.nil?
|
||||
self.send(command.downcase.to_sym)
|
||||
else
|
||||
self.send(command.downcase.to_sym, argument)
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
self.error_response("Exception: #{e} #{e.backtrace.inspect}")
|
||||
end
|
||||
end
|
||||
|
||||
def error_response(text)
|
||||
self.response("451 #{text}")
|
||||
end
|
||||
|
||||
def response(text)
|
||||
@socket.puts(text) unless @socket.closed?
|
||||
end
|
||||
|
||||
def stop
|
||||
@datasocket.close unless @datasocket.nil? || @datasocket.closed?
|
||||
@server.close
|
||||
@thread.join
|
||||
end
|
||||
|
||||
|
||||
##
|
||||
def handle(sym, &block)
|
||||
@handlers[sym] = block
|
||||
end
|
||||
|
||||
def should_receive(method)
|
||||
@handler_for = method
|
||||
self
|
||||
end
|
||||
|
||||
def and_respond(text)
|
||||
@handlers[@handler_for] = lambda { |s, *args| s.response(text) }
|
||||
end
|
||||
|
||||
##
|
||||
# FTP methods
|
||||
##
|
||||
|
||||
def abor
|
||||
self.response("226 Closing data connection. (ABOR)")
|
||||
end
|
||||
|
||||
def acct(account)
|
||||
@login_acct = account
|
||||
self.response("230 User '#{account}' logged in, proceed. (ACCT)")
|
||||
end
|
||||
|
||||
def cdup
|
||||
self.response("200 Command okay. (CDUP)")
|
||||
end
|
||||
|
||||
def cwd(dir)
|
||||
self.response("200 Command okay. (CWD #{dir})")
|
||||
end
|
||||
|
||||
def dele(file)
|
||||
self.response("250 Requested file action okay, completed. (DELE #{file})")
|
||||
end
|
||||
|
||||
def eprt(arg)
|
||||
_, _, host, port = arg.split("|")
|
||||
|
||||
@datasocket = TCPSocket.new(host, port)
|
||||
self.response("200 port opened")
|
||||
end
|
||||
|
||||
def help(param = :default)
|
||||
if param == :default
|
||||
self.response("211 System status, or system help reply. (HELP)")
|
||||
else
|
||||
self.response("211 System status, or system help reply. (HELP #{param})")
|
||||
end
|
||||
end
|
||||
|
||||
def list(folder)
|
||||
self.response("150 opening ASCII connection for file list")
|
||||
@datasocket.puts("-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb")
|
||||
@datasocket.puts("-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb")
|
||||
@datasocket.puts("-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb")
|
||||
@datasocket.close()
|
||||
self.response("226 transfer complete (LIST #{folder})")
|
||||
end
|
||||
|
||||
def mdtm(filename)
|
||||
self.response("213 19980705132316")
|
||||
end
|
||||
|
||||
def mkd(foldername)
|
||||
self.response(%Q{257 "#{foldername.gsub('"', '""')}" created.})
|
||||
end
|
||||
|
||||
def nlst(folder = nil)
|
||||
self.response("150 opening ASCII connection for file list")
|
||||
@datasocket.puts("last_response_code.rb")
|
||||
@datasocket.puts("list.rb")
|
||||
@datasocket.puts("pwd.rb")
|
||||
@datasocket.close()
|
||||
self.response("226 transfer complete (NLST#{folder ? " #{folder}" : ""})")
|
||||
end
|
||||
|
||||
def noop
|
||||
self.response("200 Command okay. (NOOP)")
|
||||
end
|
||||
|
||||
def pass(password)
|
||||
@login_pass = password
|
||||
self.response("230 User logged in, proceed. (PASS #{password})")
|
||||
end
|
||||
|
||||
def port(arg)
|
||||
nums = arg.split(",")
|
||||
|
||||
if nums[0] == "::1"
|
||||
# IPv6
|
||||
port = nums[1].to_i * 256 + nums[2].to_i
|
||||
host = nums[0]
|
||||
else
|
||||
# IPv4
|
||||
port = nums[4].to_i * 256 + nums[5].to_i
|
||||
host = nums[0..3].join(".")
|
||||
end
|
||||
|
||||
@datasocket = TCPSocket.new(host, port)
|
||||
self.response("200 port opened")
|
||||
end
|
||||
|
||||
def pwd
|
||||
self.response('257 "/some/dir/" - current directory')
|
||||
end
|
||||
|
||||
def retr(file)
|
||||
self.response("125 Data transfer starting")
|
||||
if @restart_at && @restart_at == 20
|
||||
@datasocket.puts("of the file named '#{file}'.")
|
||||
@restart_at = nil
|
||||
else
|
||||
@datasocket.puts("This is the content")
|
||||
@datasocket.puts("of the file named '#{file}'.")
|
||||
end
|
||||
@datasocket.close()
|
||||
self.response("226 Closing data connection. (RETR #{file})")
|
||||
end
|
||||
|
||||
def rest(at_bytes)
|
||||
@restart_at = at_bytes.to_i
|
||||
self.response("350 Requested file action pending further information. (REST)")
|
||||
end
|
||||
|
||||
def rmd(folder)
|
||||
self.response("250 Requested file action okay, completed. (RMD #{folder})")
|
||||
end
|
||||
|
||||
def rnfr(from)
|
||||
@rename_from = from
|
||||
self.response("350 Requested file action pending further information.")
|
||||
end
|
||||
|
||||
def rnto(to)
|
||||
self.response("250 Requested file action okay, completed. (Renamed #{@rename_from} to #{to})")
|
||||
@rename_from = nil
|
||||
end
|
||||
|
||||
def site(param)
|
||||
self.response("200 Command okay. (SITE #{param})")
|
||||
end
|
||||
|
||||
def size(filename)
|
||||
if filename == "binary"
|
||||
self.response("213 24")
|
||||
else
|
||||
self.response("213 1024")
|
||||
end
|
||||
end
|
||||
|
||||
def stat
|
||||
self.response("211 System status, or system help reply. (STAT)")
|
||||
end
|
||||
|
||||
def stor(file)
|
||||
tmp_file = tmp("#{file}file", false)
|
||||
|
||||
self.response("125 Data transfer starting.")
|
||||
|
||||
mode = @restart_at ? "a" : "w"
|
||||
|
||||
File.open(tmp_file, mode + "b") do |f|
|
||||
loop do
|
||||
data = @datasocket.recv(1024)
|
||||
break if !data || data.empty?
|
||||
f << data
|
||||
end
|
||||
end
|
||||
|
||||
#@datasocket.close()
|
||||
self.response("200 OK, Data received. (STOR #{file})")
|
||||
end
|
||||
|
||||
def appe(file)
|
||||
@restart_at = true
|
||||
stor(file)
|
||||
end
|
||||
|
||||
def syst
|
||||
self.response("215 FTP Dummy Server (SYST)")
|
||||
end
|
||||
|
||||
def type(type)
|
||||
self.response("200 TYPE switched to #{type}")
|
||||
end
|
||||
|
||||
def user(name)
|
||||
@login_user = name
|
||||
self.response("230 User logged in, proceed. (USER #{name})")
|
||||
end
|
||||
end
|
||||
end
|
21
spec/ruby/library/net/ftp/get_spec.rb
Normal file
21
spec/ruby/library/net/ftp/get_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
require File.expand_path('../shared/gettextfile', __FILE__)
|
||||
require File.expand_path('../shared/getbinaryfile', __FILE__)
|
||||
|
||||
describe "Net::FTP#get (binary mode)" do
|
||||
before :each do
|
||||
@binary_mode = true
|
||||
end
|
||||
|
||||
it_behaves_like :net_ftp_getbinaryfile, :get
|
||||
end
|
||||
|
||||
describe "Net::FTP#get (text mode)" do
|
||||
before :each do
|
||||
@binary_mode = false
|
||||
end
|
||||
|
||||
it_behaves_like :net_ftp_gettextfile, :get
|
||||
end
|
8
spec/ruby/library/net/ftp/getbinaryfile_spec.rb
Normal file
8
spec/ruby/library/net/ftp/getbinaryfile_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
require File.expand_path('../shared/getbinaryfile', __FILE__)
|
||||
|
||||
describe "Net::FTP#getbinaryfile" do
|
||||
it_behaves_like :net_ftp_getbinaryfile, :getbinaryfile
|
||||
end
|
7
spec/ruby/library/net/ftp/getdir_spec.rb
Normal file
7
spec/ruby/library/net/ftp/getdir_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/pwd', __FILE__)
|
||||
|
||||
describe "Net::FTP#getdir" do
|
||||
it_behaves_like :net_ftp_pwd, :getdir
|
||||
end
|
8
spec/ruby/library/net/ftp/gettextfile_spec.rb
Normal file
8
spec/ruby/library/net/ftp/gettextfile_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
require File.expand_path('../shared/gettextfile', __FILE__)
|
||||
|
||||
describe "Net::FTP#gettextfile" do
|
||||
it_behaves_like :net_ftp_gettextfile, :gettextfile
|
||||
end
|
66
spec/ruby/library/net/ftp/help_spec.rb
Normal file
66
spec/ruby/library/net/ftp/help_spec.rb
Normal file
|
@ -0,0 +1,66 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#help" do
|
||||
def with_connection
|
||||
yield
|
||||
end
|
||||
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "writes the HELP command to the server" do
|
||||
@ftp.help
|
||||
@ftp.last_response.should == "211 System status, or system help reply. (HELP)\n"
|
||||
end
|
||||
|
||||
it "returns the server's response" do
|
||||
@ftp.help.should == "211 System status, or system help reply. (HELP)\n"
|
||||
end
|
||||
|
||||
it "writes the HELP command with an optional parameter to the socket" do
|
||||
@ftp.help("some parameter").should == "211 System status, or system help reply. (HELP some parameter)\n"
|
||||
end
|
||||
|
||||
it "does not raise any error when the response code is 211" do
|
||||
@server.should_receive(:help).and_respond("211 System status, or system help reply.")
|
||||
lambda { @ftp.help }.should_not raise_error
|
||||
end
|
||||
|
||||
it "does not raise any error when the response code is 214" do
|
||||
@server.should_receive(:help).and_respond("214 Help message.")
|
||||
lambda { @ftp.help }.should_not raise_error
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.help }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:help).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.help }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:help).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.help }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:help).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.help }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
end
|
87
spec/ruby/library/net/ftp/initialize_spec.rb
Normal file
87
spec/ruby/library/net/ftp/initialize_spec.rb
Normal file
|
@ -0,0 +1,87 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
|
||||
describe "Net::FTP#initialize" do
|
||||
before :each do
|
||||
@ftp = Net::FTP.allocate
|
||||
@ftp.stub!(:connect)
|
||||
end
|
||||
|
||||
it "is private" do
|
||||
Net::FTP.should have_private_instance_method(:initialize)
|
||||
end
|
||||
|
||||
it "sets self into binary mode" do
|
||||
@ftp.binary.should be_nil
|
||||
@ftp.send(:initialize)
|
||||
@ftp.binary.should be_true
|
||||
end
|
||||
|
||||
it "sets self into active mode" do
|
||||
@ftp.passive.should be_nil
|
||||
@ftp.send(:initialize)
|
||||
@ftp.passive.should be_false
|
||||
end
|
||||
|
||||
it "sets self into non-debug mode" do
|
||||
@ftp.debug_mode.should be_nil
|
||||
@ftp.send(:initialize)
|
||||
@ftp.debug_mode.should be_false
|
||||
end
|
||||
|
||||
it "sets self to not resume file uploads/downloads" do
|
||||
@ftp.resume.should be_nil
|
||||
@ftp.send(:initialize)
|
||||
@ftp.resume.should be_false
|
||||
end
|
||||
|
||||
describe "when passed no arguments" do
|
||||
it "does not try to connect" do
|
||||
@ftp.should_not_receive(:connect)
|
||||
@ftp.send(:initialize)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed host" do
|
||||
it "tries to connect to the passed host" do
|
||||
@ftp.should_receive(:connect).with("localhost")
|
||||
@ftp.send(:initialize, "localhost")
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed host, user" do
|
||||
it "tries to connect to the passed host" do
|
||||
@ftp.should_receive(:connect).with("localhost")
|
||||
@ftp.send(:initialize, "localhost")
|
||||
end
|
||||
|
||||
it "tries to login with the passed username" do
|
||||
@ftp.should_receive(:login).with("rubyspec", nil, nil)
|
||||
@ftp.send(:initialize, "localhost", "rubyspec")
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed host, user, password" do
|
||||
it "tries to connect to the passed host" do
|
||||
@ftp.should_receive(:connect).with("localhost")
|
||||
@ftp.send(:initialize, "localhost")
|
||||
end
|
||||
|
||||
it "tries to login with the passed username and password" do
|
||||
@ftp.should_receive(:login).with("rubyspec", "rocks", nil)
|
||||
@ftp.send(:initialize, "localhost", "rubyspec", "rocks")
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed host, user" do
|
||||
it "tries to connect to the passed host" do
|
||||
@ftp.should_receive(:connect).with("localhost")
|
||||
@ftp.send(:initialize, "localhost")
|
||||
end
|
||||
|
||||
it "tries to login with the passed username, password and account" do
|
||||
@ftp.should_receive(:login).with("rubyspec", "rocks", "account")
|
||||
@ftp.send(:initialize, "localhost", "rubyspec", "rocks", "account")
|
||||
end
|
||||
end
|
||||
end
|
8
spec/ruby/library/net/ftp/last_response_code_spec.rb
Normal file
8
spec/ruby/library/net/ftp/last_response_code_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/last_response_code', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#last_response_code" do
|
||||
it_behaves_like :net_ftp_last_response_code, :last_response_code
|
||||
end
|
25
spec/ruby/library/net/ftp/last_response_spec.rb
Normal file
25
spec/ruby/library/net/ftp/last_response_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#last_response" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "returns the last response" do
|
||||
@ftp.last_response.should == "220 Dummy FTP Server ready!\n"
|
||||
@ftp.help
|
||||
@ftp.last_response.should == "211 System status, or system help reply. (HELP)\n"
|
||||
end
|
||||
end
|
8
spec/ruby/library/net/ftp/lastresp_spec.rb
Normal file
8
spec/ruby/library/net/ftp/lastresp_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/last_response_code', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#lastresp" do
|
||||
it_behaves_like :net_ftp_last_response_code, :lastresp
|
||||
end
|
8
spec/ruby/library/net/ftp/list_spec.rb
Normal file
8
spec/ruby/library/net/ftp/list_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
require File.expand_path('../shared/list', __FILE__)
|
||||
|
||||
describe "Net::FTP#list" do
|
||||
it_behaves_like :net_ftp_list, :list
|
||||
end
|
195
spec/ruby/library/net/ftp/login_spec.rb
Normal file
195
spec/ruby/library/net/ftp/login_spec.rb
Normal file
|
@ -0,0 +1,195 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#login" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
describe "when passed no arguments" do
|
||||
it "sends the USER command with 'anonymous' as name to the server" do
|
||||
@ftp.login
|
||||
@server.login_user.should == "anonymous"
|
||||
end
|
||||
|
||||
it "sends 'anonymous@' as a password when required" do
|
||||
@server.should_receive(:user).and_respond("331 User name okay, need password.")
|
||||
@ftp.login
|
||||
@server.login_pass.should == "anonymous@"
|
||||
end
|
||||
|
||||
it "raises a Net::FTPReplyError when the server requests an account" do
|
||||
@server.should_receive(:user).and_respond("331 User name okay, need password.")
|
||||
@server.should_receive(:pass).and_respond("332 Need account for login.")
|
||||
lambda { @ftp.login }.should raise_error(Net::FTPReplyError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed name" do
|
||||
it "sends the USER command with the passed name to the server" do
|
||||
@ftp.login("rubyspec")
|
||||
@server.login_user.should == "rubyspec"
|
||||
end
|
||||
|
||||
it "raises a Net::FTPReplyError when the server requests a password, but none was given" do
|
||||
@server.should_receive(:user).and_respond("331 User name okay, need password.")
|
||||
lambda { @ftp.login("rubyspec") }.should raise_error(Net::FTPReplyError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPReplyError when the server requests an account, but none was given" do
|
||||
@server.should_receive(:user).and_respond("331 User name okay, need password.")
|
||||
@server.should_receive(:pass).and_respond("332 Need account for login.")
|
||||
lambda { @ftp.login("rubyspec") }.should raise_error(Net::FTPReplyError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed name, password" do
|
||||
it "sends the USER command with the passed name to the server" do
|
||||
@ftp.login("rubyspec", "rocks")
|
||||
@server.login_user.should == "rubyspec"
|
||||
end
|
||||
|
||||
it "sends the passed password when required" do
|
||||
@server.should_receive(:user).and_respond("331 User name okay, need password.")
|
||||
@ftp.login("rubyspec", "rocks")
|
||||
@server.login_pass.should == "rocks"
|
||||
end
|
||||
|
||||
it "raises a Net::FTPReplyError when the server requests an account" do
|
||||
@server.should_receive(:user).and_respond("331 User name okay, need password.")
|
||||
@server.should_receive(:pass).and_respond("332 Need account for login.")
|
||||
lambda { @ftp.login("rubyspec", "rocks") }.should raise_error(Net::FTPReplyError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed name, password, account" do
|
||||
it "sends the USER command with the passed name to the server" do
|
||||
@ftp.login("rubyspec", "rocks", "account")
|
||||
@server.login_user.should == "rubyspec"
|
||||
end
|
||||
|
||||
it "sends the passed password when required" do
|
||||
@server.should_receive(:user).and_respond("331 User name okay, need password.")
|
||||
@ftp.login("rubyspec", "rocks", "account")
|
||||
@server.login_pass.should == "rocks"
|
||||
end
|
||||
|
||||
it "sends the passed account when required" do
|
||||
@server.should_receive(:user).and_respond("331 User name okay, need password.")
|
||||
@server.should_receive(:pass).and_respond("332 Need account for login.")
|
||||
@ftp.login("rubyspec", "rocks", "account")
|
||||
@server.login_acct.should == "account"
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the USER command fails" do
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:user).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:user).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:user).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:user).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:user).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the PASS command fails" do
|
||||
before :each do
|
||||
@server.should_receive(:user).and_respond("331 User name okay, need password.")
|
||||
end
|
||||
|
||||
it "does not raise an Error when the response code is 202" do
|
||||
@server.should_receive(:pass).and_respond("202 Command not implemented, superfluous at this site.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should_not raise_error
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:pass).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:pass).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:pass).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:pass).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:pass).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the ACCT command fails" do
|
||||
before :each do
|
||||
@server.should_receive(:user).and_respond("331 User name okay, need password.")
|
||||
@server.should_receive(:pass).and_respond("332 Need account for login.")
|
||||
end
|
||||
|
||||
it "does not raise an Error when the response code is 202" do
|
||||
@server.should_receive(:acct).and_respond("202 Command not implemented, superfluous at this site.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should_not raise_error
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:acct).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:acct).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:acct).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
end
|
8
spec/ruby/library/net/ftp/ls_spec.rb
Normal file
8
spec/ruby/library/net/ftp/ls_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
require File.expand_path('../shared/list', __FILE__)
|
||||
|
||||
describe "Net::FTP#ls" do
|
||||
it_behaves_like :net_ftp_list, :ls
|
||||
end
|
38
spec/ruby/library/net/ftp/mdtm_spec.rb
Normal file
38
spec/ruby/library/net/ftp/mdtm_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#mdtm" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the MDTM with the passed filename command to the server" do
|
||||
@ftp.mdtm("test.file")
|
||||
@ftp.last_response.should == "213 19980705132316\n"
|
||||
end
|
||||
|
||||
it "returns the last modification time of the passed file" do
|
||||
@ftp.mdtm("test.file").should == "19980705132316"
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 550" do
|
||||
@server.should_receive(:mdtm).and_respond("550 Requested action not taken.")
|
||||
lambda { @ftp.mdtm("test.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:mdtm).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.mdtm("test.file") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
end
|
61
spec/ruby/library/net/ftp/mkdir_spec.rb
Normal file
61
spec/ruby/library/net/ftp/mkdir_spec.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#mkdir" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the MKD command with the passed pathname to the server" do
|
||||
@ftp.mkdir("test.folder")
|
||||
@ftp.last_response.should == %{257 "test.folder" created.\n}
|
||||
end
|
||||
|
||||
it "returns the path to the newly created directory" do
|
||||
@ftp.mkdir("test.folder").should == "test.folder"
|
||||
@ftp.mkdir("/absolute/path/to/test.folder").should == "/absolute/path/to/test.folder"
|
||||
@ftp.mkdir("relative/path/to/test.folder").should == "relative/path/to/test.folder"
|
||||
@ftp.mkdir('/usr/dm/foo"bar').should == '/usr/dm/foo"bar'
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:mkd).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:mkd).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:mkd).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:mkd).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:mkd).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 550" do
|
||||
@server.should_receive(:mkd).and_respond("550 Requested action not taken.")
|
||||
lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
50
spec/ruby/library/net/ftp/mtime_spec.rb
Normal file
50
spec/ruby/library/net/ftp/mtime_spec.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#mtime" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the MDTM with the passed filename command to the server" do
|
||||
@ftp.mtime("test.file")
|
||||
@ftp.last_response.should == "213 19980705132316\n"
|
||||
end
|
||||
|
||||
describe "when passed filename" do
|
||||
it "returns the last modification time of the passed file as a Time object in the local time" do
|
||||
@ftp.mtime("test.file").should == Time.gm("1998", "07", "05", "13", "23", "16")
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed filename, local_time" do
|
||||
it "returns the last modification time as a Time object in UTC when local_time is true" do
|
||||
@ftp.mtime("test.file", true).should == Time.local("1998", "07", "05", "13", "23", "16")
|
||||
end
|
||||
|
||||
it "returns the last modification time as a Time object in the local time when local_time is false" do
|
||||
@ftp.mtime("test.file", false).should == Time.gm("1998", "07", "05", "13", "23", "16")
|
||||
end
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 550" do
|
||||
@server.should_receive(:mdtm).and_respond("550 Requested action not taken.")
|
||||
lambda { @ftp.mtime("test.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:mdtm).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.mtime("test.file") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
end
|
92
spec/ruby/library/net/ftp/nlst_spec.rb
Normal file
92
spec/ruby/library/net/ftp/nlst_spec.rb
Normal file
|
@ -0,0 +1,92 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#nlst" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.passive = false
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
describe "when passed no arguments" do
|
||||
it "returns an Array containing a list of files in the current dir" do
|
||||
@ftp.nlst.should == ["last_response_code.rb", "list.rb", "pwd.rb"]
|
||||
@ftp.last_response.should == "226 transfer complete (NLST)\n"
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed dir" do
|
||||
it "returns an Array containing a list of files in the passed dir" do
|
||||
@ftp.nlst("test.folder").should == ["last_response_code.rb", "list.rb", "pwd.rb"]
|
||||
@ftp.last_response.should == "226 transfer complete (NLST test.folder)\n"
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the NLST command fails" do
|
||||
it "raises a Net::FTPTempError when the response code is 450" do
|
||||
@server.should_receive(:nlst).and_respond("450 Requested file action not taken..")
|
||||
lambda { @ftp.nlst }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:nlst).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:nlst).and_respond("501 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:nlst).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:nlst).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.nlst }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:nlst).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when opening the data port fails" do
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
|
||||
@server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
|
||||
@server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
|
||||
@server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.nlst }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:eprt).and_respond("530 Not logged in.")
|
||||
@server.should_receive(:port).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
end
|
38
spec/ruby/library/net/ftp/noop_spec.rb
Normal file
38
spec/ruby/library/net/ftp/noop_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#noop" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the NOOP command to the server" do
|
||||
@ftp.noop
|
||||
@ftp.last_response.should == "200 Command okay. (NOOP)\n"
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.noop.should be_nil
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:noop).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.noop }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:noop).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.noop }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
end
|
55
spec/ruby/library/net/ftp/open_spec.rb
Normal file
55
spec/ruby/library/net/ftp/open_spec.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
|
||||
describe "Net::FTP.open" do
|
||||
before :each do
|
||||
@ftp = mock("Net::FTP instance")
|
||||
Net::FTP.stub!(:new).and_return(@ftp)
|
||||
end
|
||||
|
||||
describe "when passed no block" do
|
||||
it "returns a new Net::FTP instance" do
|
||||
Net::FTP.open("localhost").should equal(@ftp)
|
||||
end
|
||||
|
||||
it "passes the passed arguments down to Net::FTP.new" do
|
||||
Net::FTP.should_receive(:new).with("localhost", "user", "password", "account")
|
||||
Net::FTP.open("localhost", "user", "password", "account")
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed a block" do
|
||||
before :each do
|
||||
@ftp.stub!(:close)
|
||||
end
|
||||
|
||||
it "yields a new Net::FTP instance to the passed block" do
|
||||
yielded = false
|
||||
Net::FTP.open("localhost") do |ftp|
|
||||
yielded = true
|
||||
ftp.should equal(@ftp)
|
||||
end
|
||||
yielded.should be_true
|
||||
end
|
||||
|
||||
it "closes the Net::FTP instance after yielding" do
|
||||
Net::FTP.open("localhost") do |ftp|
|
||||
ftp.should_receive(:close)
|
||||
end
|
||||
end
|
||||
|
||||
it "closes the Net::FTP instance even if an exception is raised while yielding" do
|
||||
begin
|
||||
Net::FTP.open("localhost") do |ftp|
|
||||
ftp.should_receive(:close)
|
||||
raise ArgumentError, "some exception"
|
||||
end
|
||||
rescue ArgumentError
|
||||
end
|
||||
end
|
||||
|
||||
it "returns the block's return value" do
|
||||
Net::FTP.open("localhost") { :test }.should == :test
|
||||
end
|
||||
end
|
||||
end
|
36
spec/ruby/library/net/ftp/passive_spec.rb
Normal file
36
spec/ruby/library/net/ftp/passive_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
|
||||
describe "Net::FTP#passive" do
|
||||
it "returns true when self is in passive mode" do
|
||||
ftp = Net::FTP.new
|
||||
ftp.passive.should be_false
|
||||
|
||||
ftp.passive = true
|
||||
ftp.passive.should be_true
|
||||
end
|
||||
|
||||
ruby_version_is ""..."2.3" do
|
||||
it "is false by default" do
|
||||
ruby_exe(fixture(__FILE__, "passive.rb")).should == "false"
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "2.3" do
|
||||
it "is the value of Net::FTP.default_value by default" do
|
||||
ruby_exe(fixture(__FILE__, "passive.rb")).should == "true"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Net::FTP#passive=" do
|
||||
it "sets self to passive mode when passed true" do
|
||||
ftp = Net::FTP.new
|
||||
|
||||
ftp.passive = true
|
||||
ftp.passive.should be_true
|
||||
|
||||
ftp.passive = false
|
||||
ftp.passive.should be_false
|
||||
end
|
||||
end
|
21
spec/ruby/library/net/ftp/put_spec.rb
Normal file
21
spec/ruby/library/net/ftp/put_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
require File.expand_path('../shared/puttextfile', __FILE__)
|
||||
require File.expand_path('../shared/putbinaryfile', __FILE__)
|
||||
|
||||
describe "Net::FTP#put (binary mode)" do
|
||||
before :each do
|
||||
@binary_mode = true
|
||||
end
|
||||
|
||||
it_behaves_like :net_ftp_putbinaryfile, :put
|
||||
end
|
||||
|
||||
describe "Net::FTP#put (text mode)" do
|
||||
before :each do
|
||||
@binary_mode = false
|
||||
end
|
||||
|
||||
it_behaves_like :net_ftp_puttextfile, :put
|
||||
end
|
8
spec/ruby/library/net/ftp/putbinaryfile_spec.rb
Normal file
8
spec/ruby/library/net/ftp/putbinaryfile_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
require File.expand_path('../shared/putbinaryfile', __FILE__)
|
||||
|
||||
describe "Net::FTP#putbinaryfile" do
|
||||
it_behaves_like :net_ftp_putbinaryfile, :putbinaryfile
|
||||
end
|
8
spec/ruby/library/net/ftp/puttextfile_spec.rb
Normal file
8
spec/ruby/library/net/ftp/puttextfile_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
require File.expand_path('../shared/puttextfile', __FILE__)
|
||||
|
||||
describe "Net::FTP#puttextfile" do
|
||||
it_behaves_like :net_ftp_puttextfile, :puttextfile
|
||||
end
|
53
spec/ruby/library/net/ftp/pwd_spec.rb
Normal file
53
spec/ruby/library/net/ftp/pwd_spec.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#pwd" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the PWD command to the server" do
|
||||
@ftp.pwd
|
||||
@ftp.last_response.should == "257 \"/some/dir/\" - current directory\n"
|
||||
end
|
||||
|
||||
it "returns the current directory" do
|
||||
@ftp.pwd.should == "/some/dir/"
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:pwd).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.pwd }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:pwd).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.pwd }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:pwd).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.pwd }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:pwd).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.pwd }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 550" do
|
||||
@server.should_receive(:pwd).and_respond("550 Requested action not taken.")
|
||||
lambda { @ftp.pwd }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
33
spec/ruby/library/net/ftp/quit_spec.rb
Normal file
33
spec/ruby/library/net/ftp/quit_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#quit" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the QUIT command to the server" do
|
||||
@ftp.quit
|
||||
@ftp.last_response.should == "221 OK, bye\n"
|
||||
end
|
||||
|
||||
it "does not close the socket automagically" do
|
||||
@ftp.quit
|
||||
@ftp.closed?.should be_false
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.quit.should be_nil
|
||||
end
|
||||
end
|
94
spec/ruby/library/net/ftp/rename_spec.rb
Normal file
94
spec/ruby/library/net/ftp/rename_spec.rb
Normal file
|
@ -0,0 +1,94 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#rename" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
describe "when passed from_name, to_name" do
|
||||
it "sends the RNFR command with the passed from_name and the RNTO command with the passed to_name to the server" do
|
||||
@ftp.rename("from.file", "to.file")
|
||||
@ftp.last_response.should == "250 Requested file action okay, completed. (Renamed from.file to to.file)\n"
|
||||
end
|
||||
|
||||
it "returns something" do
|
||||
@ftp.rename("from.file", "to.file").should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the RNFR command fails" do
|
||||
it "raises a Net::FTPTempError when the response code is 450" do
|
||||
@server.should_receive(:rnfr).and_respond("450 Requested file action not taken.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 550" do
|
||||
@server.should_receive(:rnfr).and_respond("550 Requested action not taken.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:rnfr).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:rnfr).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:rnfr).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:rnfr).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the RNTO command fails" do
|
||||
it "raises a Net::FTPPermError when the response code is 532" do
|
||||
@server.should_receive(:rnfr).and_respond("532 Need account for storing files.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 553" do
|
||||
@server.should_receive(:rnto).and_respond("553 Requested action not taken.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:rnto).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:rnto).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:rnto).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:rnto).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
end
|
23
spec/ruby/library/net/ftp/resume_spec.rb
Normal file
23
spec/ruby/library/net/ftp/resume_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
|
||||
describe "Net::FTP#resume" do
|
||||
it "returns true when self is set to resume uploads/downloads" do
|
||||
ftp = Net::FTP.new
|
||||
ftp.resume.should be_false
|
||||
|
||||
ftp.resume = true
|
||||
ftp.resume.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe "Net::FTP#resume=" do
|
||||
it "sets self to resume uploads/downloads when set to true" do
|
||||
ftp = Net::FTP.new
|
||||
ftp.resume = true
|
||||
ftp.resume.should be_true
|
||||
|
||||
ftp.resume = false
|
||||
ftp.resume.should be_false
|
||||
end
|
||||
end
|
30
spec/ruby/library/net/ftp/retrbinary_spec.rb
Normal file
30
spec/ruby/library/net/ftp/retrbinary_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#retrbinary" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the passed command to the server" do
|
||||
@ftp.retrbinary("RETR test", 4096) {}
|
||||
@ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
|
||||
end
|
||||
|
||||
it "yields the received content as binary blocks of the passed size" do
|
||||
res = []
|
||||
@ftp.retrbinary("RETR test", 10) { |bin| res << bin }
|
||||
res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ]
|
||||
end
|
||||
end
|
34
spec/ruby/library/net/ftp/retrlines_spec.rb
Normal file
34
spec/ruby/library/net/ftp/retrlines_spec.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#retrlines" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the passed command over the socket" do
|
||||
@ftp.retrlines("LIST test.dir") {}
|
||||
@ftp.last_response.should == "226 transfer complete (LIST test.dir)\n"
|
||||
end
|
||||
|
||||
it "yields each received line to the passed block" do
|
||||
res = []
|
||||
@ftp.retrlines("LIST test.dir") { |x| res << x }
|
||||
res.should == [
|
||||
"-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
|
||||
"-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
|
||||
"-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
|
||||
]
|
||||
end
|
||||
end
|
24
spec/ruby/library/net/ftp/return_code_spec.rb
Normal file
24
spec/ruby/library/net/ftp/return_code_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
|
||||
describe "Net::FTP#return_code" do
|
||||
before :each do
|
||||
@ftp = Net::FTP.new
|
||||
end
|
||||
|
||||
it "outputs a warning and returns a newline" do
|
||||
lambda do
|
||||
@ftp.return_code.should == "\n"
|
||||
end.should complain("warning: Net::FTP#return_code is obsolete and do nothing\n")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Net::FTP#return_code=" do
|
||||
before :each do
|
||||
@ftp = Net::FTP.new
|
||||
end
|
||||
|
||||
it "outputs a warning" do
|
||||
lambda { @ftp.return_code = 123 }.should complain("warning: Net::FTP#return_code= is obsolete and do nothing\n")
|
||||
end
|
||||
end
|
58
spec/ruby/library/net/ftp/rmdir_spec.rb
Normal file
58
spec/ruby/library/net/ftp/rmdir_spec.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#rmdir" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the RMD command with the passed pathname to the server" do
|
||||
@ftp.rmdir("test.folder")
|
||||
@ftp.last_response.should == "250 Requested file action okay, completed. (RMD test.folder)\n"
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.rmdir("test.folder").should be_nil
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:rmd).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:rmd).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:rmd).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:rmd).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:rmd).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 550" do
|
||||
@server.should_receive(:rmd).and_respond("550 Requested action not taken.")
|
||||
lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
54
spec/ruby/library/net/ftp/sendcmd_spec.rb
Normal file
54
spec/ruby/library/net/ftp/sendcmd_spec.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#sendcmd" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the passed command to the server" do
|
||||
@ftp.sendcmd("HELP")
|
||||
@ftp.last_response.should == "211 System status, or system help reply. (HELP)\n"
|
||||
end
|
||||
|
||||
it "returns the server's response" do
|
||||
@ftp.sendcmd("HELP").should == "211 System status, or system help reply. (HELP)\n"
|
||||
end
|
||||
|
||||
it "raises no error when the response code is 1xx, 2xx or 3xx" do
|
||||
@server.should_receive(:help).and_respond("120 Service ready in nnn minutes.")
|
||||
lambda { @ftp.sendcmd("HELP") }.should_not raise_error
|
||||
|
||||
@server.should_receive(:help).and_respond("200 Command okay.")
|
||||
lambda { @ftp.sendcmd("HELP") }.should_not raise_error
|
||||
|
||||
@server.should_receive(:help).and_respond("350 Requested file action pending further information.")
|
||||
lambda { @ftp.sendcmd("HELP") }.should_not raise_error
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 4xx" do
|
||||
@server.should_receive(:help).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 5xx" do
|
||||
@server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPProtoError when the response code is not between 1xx-5xx" do
|
||||
@server.should_receive(:help).and_respond("999 Invalid response.")
|
||||
lambda { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPProtoError)
|
||||
end
|
||||
end
|
8
spec/ruby/library/net/ftp/set_socket_spec.rb
Normal file
8
spec/ruby/library/net/ftp/set_socket_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
|
||||
describe "Net::FTP#set_socket" do
|
||||
# TODO: I won't spec this method, as it is not used
|
||||
# anywhere and it should be private anyway.
|
||||
#it "needs to be reviewed for spec completeness"
|
||||
end
|
150
spec/ruby/library/net/ftp/shared/getbinaryfile.rb
Normal file
150
spec/ruby/library/net/ftp/shared/getbinaryfile.rb
Normal file
|
@ -0,0 +1,150 @@
|
|||
describe :net_ftp_getbinaryfile, shared: :true do
|
||||
before :each do
|
||||
@fixture_file = File.dirname(__FILE__) + "/../fixtures/getbinaryfile"
|
||||
@tmp_file = tmp("getbinaryfile")
|
||||
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
@ftp.binary = @binary_mode
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
|
||||
rm_r @tmp_file
|
||||
end
|
||||
|
||||
it "sends the RETR command to the server" do
|
||||
@ftp.send(@method, "test", @tmp_file)
|
||||
@ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.send(@method, "test", @tmp_file).should be_nil
|
||||
end
|
||||
|
||||
it "saves the contents of the passed remote file to the passed local file" do
|
||||
@ftp.send(@method, "test", @tmp_file)
|
||||
File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
|
||||
end
|
||||
|
||||
describe "when passed a block" do
|
||||
it "yields the received content as binary blocks of the passed size" do
|
||||
res = []
|
||||
@ftp.send(@method, "test", @tmp_file, 10) { |bin| res << bin }
|
||||
res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ]
|
||||
end
|
||||
end
|
||||
|
||||
describe "when resuming an existing file" do
|
||||
before :each do
|
||||
@tmp_file = tmp("getbinaryfile_resume")
|
||||
|
||||
File.open(@tmp_file, "wb") do |f|
|
||||
f << "This is the content\n"
|
||||
end
|
||||
|
||||
@ftp.resume = true
|
||||
end
|
||||
|
||||
it "saves the remaining content of the passed remote file to the passed local file" do
|
||||
@ftp.send(@method, "test", @tmp_file)
|
||||
File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
|
||||
end
|
||||
|
||||
describe "and the REST command fails" do
|
||||
it "raises a Net::FTPProtoError when the response code is 550" do
|
||||
@server.should_receive(:rest).and_respond("Requested action not taken.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:rest).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:rest).and_respond("501 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:rest).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:rest).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:rest).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the RETR command fails" do
|
||||
it "raises a Net::FTPTempError when the response code is 450" do
|
||||
@server.should_receive(:retr).and_respond("450 Requested file action not taken.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPProtoError when the response code is 550" do
|
||||
@server.should_receive(:retr).and_respond("Requested action not taken.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:retr).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:retr).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when opening the data port fails" do
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
|
||||
@server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
|
||||
@server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
|
||||
@server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:eprt).and_respond("530 Not logged in.")
|
||||
@server.should_receive(:port).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
end
|
100
spec/ruby/library/net/ftp/shared/gettextfile.rb
Normal file
100
spec/ruby/library/net/ftp/shared/gettextfile.rb
Normal file
|
@ -0,0 +1,100 @@
|
|||
describe :net_ftp_gettextfile, shared: :true do
|
||||
before :each do
|
||||
@tmp_file = tmp("gettextfile")
|
||||
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
@ftp.binary = @binary_mode
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
|
||||
rm_r @tmp_file
|
||||
end
|
||||
|
||||
it "sends the RETR command to the server" do
|
||||
@ftp.send(@method, "test", @tmp_file)
|
||||
@ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.send(@method, "test", @tmp_file).should be_nil
|
||||
end
|
||||
|
||||
it "saves the contents of the passed remote file to the passed local file" do
|
||||
@ftp.send(@method, "test", @tmp_file)
|
||||
File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
|
||||
end
|
||||
|
||||
describe "when passed a block" do
|
||||
it "yields each line of the retrieved file to the passed block" do
|
||||
res = []
|
||||
@ftp.send(@method, "test", @tmp_file) { |line| res << line }
|
||||
res.should == [ "This is the content", "of the file named 'test'."]
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the RETR command fails" do
|
||||
it "raises a Net::FTPTempError when the response code is 450" do
|
||||
@server.should_receive(:retr).and_respond("450 Requested file action not taken.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPProtoError when the response code is 550" do
|
||||
@server.should_receive(:retr).and_respond("Requested action not taken.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:retr).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:retr).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when opening the data port fails" do
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
|
||||
@server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
|
||||
@server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
|
||||
@server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:eprt).and_respond("530 Not logged in.")
|
||||
@server.should_receive(:port).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
end
|
25
spec/ruby/library/net/ftp/shared/last_response_code.rb
Normal file
25
spec/ruby/library/net/ftp/shared/last_response_code.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
describe :net_ftp_last_response_code, shared: true do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "returns the response code for the last response" do
|
||||
@server.should_receive(:help).and_respond("200 Command okay.")
|
||||
@ftp.help
|
||||
@ftp.send(@method).should == "200"
|
||||
|
||||
@server.should_receive(:help).and_respond("212 Directory status.")
|
||||
@ftp.help
|
||||
@ftp.send(@method).should == "212"
|
||||
end
|
||||
end
|
104
spec/ruby/library/net/ftp/shared/list.rb
Normal file
104
spec/ruby/library/net/ftp/shared/list.rb
Normal file
|
@ -0,0 +1,104 @@
|
|||
describe :net_ftp_list, shared: true do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.passive = false
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
describe "when passed a block" do
|
||||
it "yields each file in the list of files in the passed dir" do
|
||||
expected = [
|
||||
"-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
|
||||
"-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
|
||||
"-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
|
||||
]
|
||||
|
||||
res = []
|
||||
@ftp.send(@method, "test.folder") { |line| res << line}
|
||||
res.should == expected
|
||||
|
||||
@ftp.last_response.should == "226 transfer complete (LIST test.folder)\n"
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed no block" do
|
||||
it "returns an Array containing a list of files in the passed dir" do
|
||||
expected = [
|
||||
"-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
|
||||
"-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
|
||||
"-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
|
||||
]
|
||||
|
||||
@ftp.send(@method, "test.folder").should == expected
|
||||
|
||||
@ftp.last_response.should == "226 transfer complete (LIST test.folder)\n"
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the LIST command fails" do
|
||||
it "raises a Net::FTPTempError when the response code is 450" do
|
||||
@server.should_receive(:list).and_respond("450 Requested file action not taken..")
|
||||
lambda { @ftp.send(@method) }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:list).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:list).and_respond("501 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:list).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:list).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method) }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:list).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when opening the data port fails" do
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
|
||||
@server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
|
||||
@server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
|
||||
@server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method) }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:eprt).and_respond("530 Not logged in.")
|
||||
@server.should_receive(:port).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
end
|
167
spec/ruby/library/net/ftp/shared/putbinaryfile.rb
Normal file
167
spec/ruby/library/net/ftp/shared/putbinaryfile.rb
Normal file
|
@ -0,0 +1,167 @@
|
|||
describe :net_ftp_putbinaryfile, shared: :true do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@local_fixture_file = File.dirname(__FILE__) + "/../fixtures/putbinaryfile"
|
||||
@remote_tmp_file = tmp("binaryfile", false)
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
@ftp.binary = @binary_mode
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
|
||||
rm_r @remote_tmp_file
|
||||
end
|
||||
|
||||
it "sends the STOR command to the server" do
|
||||
@ftp.send(@method, @local_fixture_file, "binary")
|
||||
@ftp.last_response.should == "200 OK, Data received. (STOR binary)\n"
|
||||
end
|
||||
|
||||
it "sends the contents of the passed local_file, without modifications" do
|
||||
@ftp.send(@method, @local_fixture_file, "binary")
|
||||
|
||||
remote_lines = File.readlines(@remote_tmp_file)
|
||||
local_lines = File.readlines(@local_fixture_file)
|
||||
|
||||
remote_lines.should == local_lines
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.send(@method, @local_fixture_file, "binary").should be_nil
|
||||
end
|
||||
|
||||
describe "when passed a block" do
|
||||
it "yields the transmitted content as binary blocks of the passed size" do
|
||||
res = []
|
||||
@ftp.send(@method, @local_fixture_file, "binary", 10) { |x| res << x }
|
||||
res.should == [
|
||||
"This is an", " example f",
|
||||
"ile\nwhich ", "is going t",
|
||||
"o be trans", "mitted\nusi",
|
||||
"ng #putbin", "aryfile.\n"
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "when resuming an existing file" do
|
||||
before :each do
|
||||
File.open(@remote_tmp_file, "w") do |f|
|
||||
f << "This is an example file\n"
|
||||
end
|
||||
|
||||
@ftp.resume = true
|
||||
end
|
||||
|
||||
it "sends the remaining content of the passed local_file to the passed remote_file" do
|
||||
@ftp.send(@method, @local_fixture_file, "binary")
|
||||
File.read(@remote_tmp_file).should == File.read(@local_fixture_file)
|
||||
end
|
||||
|
||||
describe "and the APPE command fails" do
|
||||
it "raises a Net::FTPProtoError when the response code is 550" do
|
||||
@server.should_receive(:appe).and_respond("Requested action not taken.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPProtoError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:appe).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:appe).and_respond("501 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:appe).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:appe).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:appe).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the STOR command fails" do
|
||||
it "raises a Net::FTPPermError when the response code is 532" do
|
||||
@server.should_receive(:stor).and_respond("532 Need account for storing files.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 450" do
|
||||
@server.should_receive(:stor).and_respond("450 Requested file action not taken.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 452" do
|
||||
@server.should_receive(:stor).and_respond("452 Requested action not taken.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 553" do
|
||||
@server.should_receive(:stor).and_respond("553 Requested action not taken.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:stor).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:stor).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when opening the data port fails" do
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
|
||||
@server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
|
||||
@server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
|
||||
@server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:eprt).and_respond("530 Not logged in.")
|
||||
@server.should_receive(:port).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
end
|
120
spec/ruby/library/net/ftp/shared/puttextfile.rb
Normal file
120
spec/ruby/library/net/ftp/shared/puttextfile.rb
Normal file
|
@ -0,0 +1,120 @@
|
|||
describe :net_ftp_puttextfile, shared: true do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@local_fixture_file = File.dirname(__FILE__) + "/../fixtures/puttextfile"
|
||||
@remote_tmp_file = tmp("textfile", false)
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
@ftp.binary = @binary_mode
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
|
||||
rm_r @remote_tmp_file
|
||||
end
|
||||
|
||||
it "sends the STOR command to the server" do
|
||||
@ftp.send(@method, @local_fixture_file, "text")
|
||||
@ftp.last_response.should == "200 OK, Data received. (STOR text)\n"
|
||||
end
|
||||
|
||||
it "sends the contents of the passed local_file, using \\r\\n as the newline separator" do
|
||||
@ftp.send(@method, @local_fixture_file, "text")
|
||||
|
||||
remote_lines = open(@remote_tmp_file, "rb") {|f| f.read }
|
||||
local_lines = open(@local_fixture_file, "rb") {|f| f.read }
|
||||
|
||||
remote_lines.should_not == local_lines
|
||||
remote_lines.should == local_lines.gsub("\n", "\r\n")
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.send(@method, @local_fixture_file, "text").should be_nil
|
||||
end
|
||||
|
||||
describe "when passed a block" do
|
||||
it "yields each transmitted line" do
|
||||
res = []
|
||||
@ftp.send(@method, @local_fixture_file, "text") { |x| res << x }
|
||||
res.should == [
|
||||
"This is an example file\r\n",
|
||||
"which is going to be transmitted\r\n",
|
||||
"using #puttextfile.\r\n"
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the STOR command fails" do
|
||||
it "raises a Net::FTPPermError when the response code is 532" do
|
||||
@server.should_receive(:stor).and_respond("532 Need account for storing files.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 450" do
|
||||
@server.should_receive(:stor).and_respond("450 Requested file action not taken.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 452" do
|
||||
@server.should_receive(:stor).and_respond("452 Requested action not taken.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 553" do
|
||||
@server.should_receive(:stor).and_respond("553 Requested action not taken.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:stor).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:stor).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when opening the data port fails" do
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
|
||||
@server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
|
||||
@server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
|
||||
@server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:eprt).and_respond("530 Not logged in.")
|
||||
@server.should_receive(:port).and_respond("530 Not logged in.")
|
||||
lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
||||
end
|
3
spec/ruby/library/net/ftp/shared/pwd.rb
Normal file
3
spec/ruby/library/net/ftp/shared/pwd.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
describe :net_ftp_pwd, shared: true do
|
||||
|
||||
end
|
53
spec/ruby/library/net/ftp/site_spec.rb
Normal file
53
spec/ruby/library/net/ftp/site_spec.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#site" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the SITE command with the passed argument to the server" do
|
||||
@ftp.site("param")
|
||||
@ftp.last_response.should == "200 Command okay. (SITE param)\n"
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@ftp.site("param").should be_nil
|
||||
end
|
||||
|
||||
it "does not raise an error when the response code is 202" do
|
||||
@server.should_receive(:site).and_respond("202 Command not implemented, superfluous at this site.")
|
||||
lambda { @ftp.site("param") }.should_not raise_error
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:site).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.site("param") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:site).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.site("param") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:site).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.site("param") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:site).and_respond("530 Requested action not taken.")
|
||||
lambda { @ftp.site("param") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
48
spec/ruby/library/net/ftp/size_spec.rb
Normal file
48
spec/ruby/library/net/ftp/size_spec.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#size" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the SIZE command to the server" do
|
||||
@ftp.size("test.file")
|
||||
@ftp.last_response.should == "213 1024\n"
|
||||
end
|
||||
|
||||
it "returns the size of the passed file as Integer" do
|
||||
@ftp.size("test.file").should eql(1024)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:size).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.size("test.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:size).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.size("test.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:size).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.size("test.file") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 550" do
|
||||
@server.should_receive(:size).and_respond("550 Requested action not taken.")
|
||||
lambda { @ftp.size("test.file") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
5
spec/ruby/library/net/ftp/spec_helper.rb
Normal file
5
spec/ruby/library/net/ftp/spec_helper.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require "net/ftp"
|
||||
|
||||
if defined?(Net::FTP.default_passive)
|
||||
Net::FTP.default_passive = false
|
||||
end
|
63
spec/ruby/library/net/ftp/status_spec.rb
Normal file
63
spec/ruby/library/net/ftp/status_spec.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#status" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the STAT command to the server" do
|
||||
@ftp.status
|
||||
@ftp.last_response.should == "211 System status, or system help reply. (STAT)\n"
|
||||
end
|
||||
|
||||
it "returns the received information" do
|
||||
@ftp.status.should == "211 System status, or system help reply. (STAT)\n"
|
||||
end
|
||||
|
||||
it "does not raise an error when the response code is 212" do
|
||||
@server.should_receive(:stat).and_respond("212 Directory status.")
|
||||
lambda { @ftp.status }.should_not raise_error
|
||||
end
|
||||
|
||||
it "does not raise an error when the response code is 213" do
|
||||
@server.should_receive(:stat).and_respond("213 File status.")
|
||||
lambda { @ftp.status }.should_not raise_error
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:stat).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.status }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:stat).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.status }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:stat).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.status }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:stat).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.status }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 530" do
|
||||
@server.should_receive(:stat).and_respond("530 Requested action not taken.")
|
||||
lambda { @ftp.status }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
end
|
48
spec/ruby/library/net/ftp/storbinary_spec.rb
Normal file
48
spec/ruby/library/net/ftp/storbinary_spec.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#storbinary" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@local_fixture_file = File.dirname(__FILE__) + "/fixtures/putbinaryfile"
|
||||
@tmp_file = tmp("binaryfile", false)
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
|
||||
rm_r @tmp_file
|
||||
end
|
||||
|
||||
it "sends the passed command and the passed File object's content to the server" do
|
||||
File.open(@local_fixture_file) do |f|
|
||||
f.binmode
|
||||
|
||||
@ftp.storbinary("STOR binary", f, 4096) {}
|
||||
@ftp.last_response.should == "200 OK, Data received. (STOR binary)\n"
|
||||
end
|
||||
end
|
||||
|
||||
it "yields the transmitted content as binary blocks of the passed size" do
|
||||
File.open(@local_fixture_file) do |f|
|
||||
f.binmode
|
||||
|
||||
res = []
|
||||
@ftp.storbinary("STOR binary", f, 10) { |x| res << x }
|
||||
res.should == [
|
||||
"This is an", " example f",
|
||||
"ile\nwhich ", "is going t",
|
||||
"o be trans", "mitted\nusi",
|
||||
"ng #putbin", "aryfile.\n"
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
43
spec/ruby/library/net/ftp/storlines_spec.rb
Normal file
43
spec/ruby/library/net/ftp/storlines_spec.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#storlines" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@local_fixture_file = File.dirname(__FILE__) + "/fixtures/puttextfile"
|
||||
@tmp_file = tmp("textfile", false)
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
|
||||
rm_r @tmp_file
|
||||
end
|
||||
|
||||
it "sends the passed command and the passed File object's content to the server" do
|
||||
File.open(@local_fixture_file) do |f|
|
||||
@ftp.storlines("STOR text", f) {}
|
||||
@ftp.last_response.should == "200 OK, Data received. (STOR text)\n"
|
||||
end
|
||||
end
|
||||
|
||||
it "yields each line of the transmitted content" do
|
||||
File.open(@local_fixture_file) do |f|
|
||||
res = []
|
||||
@ftp.storlines("STOR text", f) { |x| res << x }
|
||||
res.should == [
|
||||
"This is an example file\r\n",
|
||||
"which is going to be transmitted\r\n",
|
||||
"using #puttextfile.\r\n"
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
48
spec/ruby/library/net/ftp/system_spec.rb
Normal file
48
spec/ruby/library/net/ftp/system_spec.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#system" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the SYST command to the server" do
|
||||
@ftp.system
|
||||
@ftp.last_response.should =~ /\A215 FTP Dummy Server \(SYST\)\Z/
|
||||
end
|
||||
|
||||
it "returns the received information" do
|
||||
@ftp.system.should =~ /\AFTP Dummy Server \(SYST\)\Z/
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 500" do
|
||||
@server.should_receive(:syst).and_respond("500 Syntax error, command unrecognized.")
|
||||
lambda { @ftp.system }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 501" do
|
||||
@server.should_receive(:syst).and_respond("501 Syntax error in parameters or arguments.")
|
||||
lambda { @ftp.system }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 502" do
|
||||
@server.should_receive(:syst).and_respond("502 Command not implemented.")
|
||||
lambda { @ftp.system }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 421" do
|
||||
@server.should_receive(:syst).and_respond("421 Service not available, closing control connection.")
|
||||
lambda { @ftp.system }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
end
|
54
spec/ruby/library/net/ftp/voidcmd_spec.rb
Normal file
54
spec/ruby/library/net/ftp/voidcmd_spec.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#voidcmd" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "sends the passed command to the server" do
|
||||
@server.should_receive(:help).and_respond("2xx Does not raise.")
|
||||
lambda { @ftp.voidcmd("HELP") }.should_not raise_error
|
||||
end
|
||||
|
||||
it "returns nil" do
|
||||
@server.should_receive(:help).and_respond("2xx Does not raise.")
|
||||
@ftp.voidcmd("HELP").should be_nil
|
||||
end
|
||||
|
||||
it "raises a Net::FTPReplyError when the response code is 1xx" do
|
||||
@server.should_receive(:help).and_respond("1xx Does raise a Net::FTPReplyError.")
|
||||
lambda { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPReplyError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPReplyError when the response code is 3xx" do
|
||||
@server.should_receive(:help).and_respond("3xx Does raise a Net::FTPReplyError.")
|
||||
lambda { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPReplyError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPTempError when the response code is 4xx" do
|
||||
@server.should_receive(:help).and_respond("4xx Does raise a Net::FTPTempError.")
|
||||
lambda { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPTempError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPPermError when the response code is 5xx" do
|
||||
@server.should_receive(:help).and_respond("5xx Does raise a Net::FTPPermError.")
|
||||
lambda { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPPermError)
|
||||
end
|
||||
|
||||
it "raises a Net::FTPProtoError when the response code is not valid" do
|
||||
@server.should_receive(:help).and_respond("999 Does raise a Net::FTPProtoError.")
|
||||
lambda { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPProtoError)
|
||||
end
|
||||
end
|
25
spec/ruby/library/net/ftp/welcome_spec.rb
Normal file
25
spec/ruby/library/net/ftp/welcome_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require File.expand_path('../spec_helper', __FILE__)
|
||||
require File.expand_path('../fixtures/server', __FILE__)
|
||||
|
||||
describe "Net::FTP#welcome" do
|
||||
before :each do
|
||||
@server = NetFTPSpecs::DummyFTP.new
|
||||
@server.serve_once
|
||||
|
||||
@ftp = Net::FTP.new
|
||||
@ftp.connect(@server.hostname, @server.server_port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@ftp.quit rescue nil
|
||||
@ftp.close
|
||||
@server.stop
|
||||
end
|
||||
|
||||
it "returns the server's welcome message" do
|
||||
@ftp.welcome.should be_nil
|
||||
@ftp.login
|
||||
@ftp.welcome.should == "230 User logged in, proceed. (USER anonymous)\n"
|
||||
end
|
||||
end
|
8
spec/ruby/library/net/http/HTTPBadResponse_spec.rb
Normal file
8
spec/ruby/library/net/http/HTTPBadResponse_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTPBadResponse" do
|
||||
it "is a subclass of StandardError" do
|
||||
Net::HTTPBadResponse.should < StandardError
|
||||
end
|
||||
end
|
12
spec/ruby/library/net/http/HTTPError_spec.rb
Normal file
12
spec/ruby/library/net/http/HTTPError_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTPError" do
|
||||
it "is a subclass of Net::ProtocolError" do
|
||||
Net::HTTPError.should < Net::ProtocolError
|
||||
end
|
||||
|
||||
it "includes the Net::HTTPExceptions module" do
|
||||
Net::HTTPError.should < Net::HTTPExceptions
|
||||
end
|
||||
end
|
12
spec/ruby/library/net/http/HTTPFatalError_spec.rb
Normal file
12
spec/ruby/library/net/http/HTTPFatalError_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTPFatalError" do
|
||||
it "is a subclass of Net::ProtoFatalError" do
|
||||
Net::HTTPFatalError.should < Net::ProtoFatalError
|
||||
end
|
||||
|
||||
it "includes the Net::HTTPExceptions module" do
|
||||
Net::HTTPFatalError.should < Net::HTTPExceptions
|
||||
end
|
||||
end
|
8
spec/ruby/library/net/http/HTTPHeaderSyntaxError_spec.rb
Normal file
8
spec/ruby/library/net/http/HTTPHeaderSyntaxError_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTPHeaderSyntaxError" do
|
||||
it "is a subclass of StandardError" do
|
||||
Net::HTTPHeaderSyntaxError.should < StandardError
|
||||
end
|
||||
end
|
12
spec/ruby/library/net/http/HTTPRetriableError_spec.rb
Normal file
12
spec/ruby/library/net/http/HTTPRetriableError_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTPRetriableError" do
|
||||
it "is a subclass of Net::ProtoRetriableError" do
|
||||
Net::HTTPRetriableError.should < Net::ProtoRetriableError
|
||||
end
|
||||
|
||||
it "includes the Net::HTTPExceptions module" do
|
||||
Net::HTTPRetriableError.should < Net::HTTPExceptions
|
||||
end
|
||||
end
|
12
spec/ruby/library/net/http/HTTPServerException_spec.rb
Normal file
12
spec/ruby/library/net/http/HTTPServerException_spec.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path('../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTPServerException" do
|
||||
it "is a subclass of Net::ProtoServerError" do
|
||||
Net::HTTPServerException.should < Net::ProtoServerError
|
||||
end
|
||||
|
||||
it "includes the Net::HTTPExceptions module" do
|
||||
Net::HTTPServerException.should < Net::HTTPExceptions
|
||||
end
|
||||
end
|
35
spec/ruby/library/net/http/http/Proxy_spec.rb
Normal file
35
spec/ruby/library/net/http/http/Proxy_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTP.Proxy" do
|
||||
it "returns a new subclass of Net::HTTP" do
|
||||
Net::HTTP.Proxy("localhost").should < Net::HTTP
|
||||
end
|
||||
|
||||
it "returns Net::HTTP when the passed address is nil" do
|
||||
Net::HTTP.Proxy(nil).should == Net::HTTP
|
||||
end
|
||||
|
||||
it "sets the returned subclasses' proxy options based on the passed arguments" do
|
||||
http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
|
||||
http_with_proxy.proxy_address.should == "localhost"
|
||||
http_with_proxy.proxy_port.should eql(1234)
|
||||
http_with_proxy.proxy_user.should == "rspec"
|
||||
http_with_proxy.proxy_pass.should == "rocks"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Net::HTTP#proxy?" do
|
||||
describe "when self is no proxy class instance" do
|
||||
it "returns false" do
|
||||
Net::HTTP.new("localhost", 3333).proxy?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "when self is a proxy class instance" do
|
||||
it "returns false" do
|
||||
http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
|
||||
http_with_proxy.new("localhost", 3333).proxy?.should be_true
|
||||
end
|
||||
end
|
||||
end
|
8
spec/ruby/library/net/http/http/active_spec.rb
Normal file
8
spec/ruby/library/net/http/http/active_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
require File.expand_path('../shared/started', __FILE__)
|
||||
|
||||
describe "Net::HTTP#active?" do
|
||||
it_behaves_like :net_http_started_p, :active?
|
||||
end
|
9
spec/ruby/library/net/http/http/address_spec.rb
Normal file
9
spec/ruby/library/net/http/http/address_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTP#address" do
|
||||
it "returns the current host name" do
|
||||
net = Net::HTTP.new("localhost")
|
||||
net.address.should == "localhost"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTP#close_on_empty_response" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
||||
|
||||
describe "Net::HTTP#close_on_empty_response=" do
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
21
spec/ruby/library/net/http/http/copy_spec.rb
Normal file
21
spec/ruby/library/net/http/http/copy_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
|
||||
describe "Net::HTTP#copy" do
|
||||
before :each do
|
||||
NetHTTPSpecs.start_server
|
||||
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@http.finish if @http.started?
|
||||
NetHTTPSpecs.stop_server
|
||||
end
|
||||
|
||||
it "sends a COPY request to the passed path and returns the response" do
|
||||
response = @http.copy("/request")
|
||||
response.should be_kind_of(Net::HTTPResponse)
|
||||
response.body.should == "Request type: COPY"
|
||||
end
|
||||
end
|
8
spec/ruby/library/net/http/http/default_port_spec.rb
Normal file
8
spec/ruby/library/net/http/http/default_port_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTP.default_port" do
|
||||
it "returns 80" do
|
||||
Net::HTTP.http_default_port.should eql(80)
|
||||
end
|
||||
end
|
21
spec/ruby/library/net/http/http/delete_spec.rb
Normal file
21
spec/ruby/library/net/http/http/delete_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
|
||||
describe "Net::HTTP#delete" do
|
||||
before :each do
|
||||
NetHTTPSpecs.start_server
|
||||
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@http.finish if @http.started?
|
||||
NetHTTPSpecs.stop_server
|
||||
end
|
||||
|
||||
it "sends a DELETE request to the passed path and returns the response" do
|
||||
response = @http.delete("/request")
|
||||
response.should be_kind_of(Net::HTTPResponse)
|
||||
response.body.should == "Request type: DELETE"
|
||||
end
|
||||
end
|
29
spec/ruby/library/net/http/http/finish_spec.rb
Normal file
29
spec/ruby/library/net/http/http/finish_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
|
||||
describe "Net::HTTP#finish" do
|
||||
before :each do
|
||||
NetHTTPSpecs.start_server
|
||||
@http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@http.finish if @http.started?
|
||||
NetHTTPSpecs.stop_server
|
||||
end
|
||||
|
||||
describe "when self has been started" do
|
||||
it "closes the tcp connection" do
|
||||
@http.start
|
||||
@http.finish
|
||||
@http.started?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "when self has not been started yet" do
|
||||
it "raises an IOError" do
|
||||
lambda { @http.finish }.should raise_error(IOError)
|
||||
end
|
||||
end
|
||||
end
|
93
spec/ruby/library/net/http/http/fixtures/http_server.rb
Normal file
93
spec/ruby/library/net/http/http/fixtures/http_server.rb
Normal file
|
@ -0,0 +1,93 @@
|
|||
require 'webrick'
|
||||
require 'webrick/httpservlet/abstract'
|
||||
|
||||
module NetHTTPSpecs
|
||||
class NullWriter
|
||||
def <<(s) end
|
||||
def puts(*args) end
|
||||
def print(*args) end
|
||||
def printf(*args) end
|
||||
end
|
||||
|
||||
class SpecServlet < WEBrick::HTTPServlet::AbstractServlet
|
||||
def handle(req, res)
|
||||
reply(req, res)
|
||||
end
|
||||
|
||||
%w{ do_GET do_HEAD do_POST do_PUT do_PROPPATCH do_LOCK do_UNLOCK
|
||||
do_OPTIONS do_PROPFIND do_DELETE do_MOVE do_COPY
|
||||
do_MKCOL do_TRACE }.each do |method|
|
||||
alias_method method.to_sym, :handle
|
||||
end
|
||||
end
|
||||
|
||||
class RequestServlet < SpecServlet
|
||||
def reply(req, res)
|
||||
res.content_type = "text/plain"
|
||||
res.body = "Request type: #{req.request_method}"
|
||||
end
|
||||
end
|
||||
|
||||
class RequestBodyServlet < SpecServlet
|
||||
def reply(req, res)
|
||||
res.content_type = "text/plain"
|
||||
res.body = req.body
|
||||
end
|
||||
end
|
||||
|
||||
class RequestHeaderServlet < SpecServlet
|
||||
def reply(req, res)
|
||||
res.content_type = "text/plain"
|
||||
res.body = req.header.inspect
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
@server = nil
|
||||
@server_thread = nil
|
||||
|
||||
def port
|
||||
raise "server not started" unless @server
|
||||
@server.config[:Port]
|
||||
end
|
||||
|
||||
def start_server
|
||||
server_config = {
|
||||
BindAddress: "localhost",
|
||||
Port: 0,
|
||||
Logger: WEBrick::Log.new(NullWriter.new),
|
||||
AccessLog: [],
|
||||
ServerType: Thread
|
||||
}
|
||||
|
||||
@server = WEBrick::HTTPServer.new(server_config)
|
||||
|
||||
@server.mount_proc('/') do |req, res|
|
||||
res.content_type = "text/plain"
|
||||
res.body = "This is the index page."
|
||||
end
|
||||
@server.mount('/request', RequestServlet)
|
||||
@server.mount("/request/body", RequestBodyServlet)
|
||||
@server.mount("/request/header", RequestHeaderServlet)
|
||||
|
||||
@server_thread = @server.start
|
||||
end
|
||||
|
||||
def stop_server
|
||||
if @server
|
||||
begin
|
||||
@server.shutdown
|
||||
rescue Errno::EPIPE
|
||||
# Because WEBrick is not thread-safe and only catches IOError
|
||||
end
|
||||
@server = nil
|
||||
end
|
||||
if @server_thread
|
||||
@server_thread.join
|
||||
@server_thread = nil
|
||||
end
|
||||
timeout = WEBrick::Utils::TimeoutHandler
|
||||
timeout.terminate if timeout.respond_to?(:terminate)
|
||||
end
|
||||
end
|
||||
end
|
8
spec/ruby/library/net/http/http/get2_spec.rb
Normal file
8
spec/ruby/library/net/http/http/get2_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
require File.expand_path('../shared/request_get', __FILE__)
|
||||
|
||||
describe "Net::HTTP#get2" do
|
||||
it_behaves_like :net_ftp_request_get, :get2
|
||||
end
|
30
spec/ruby/library/net/http/http/get_print_spec.rb
Normal file
30
spec/ruby/library/net/http/http/get_print_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
|
||||
describe "Net::HTTP.get_print" do
|
||||
before :each do
|
||||
NetHTTPSpecs.start_server
|
||||
@port = NetHTTPSpecs.port
|
||||
end
|
||||
|
||||
after :each do
|
||||
NetHTTPSpecs.stop_server
|
||||
end
|
||||
|
||||
describe "when passed URI" do
|
||||
it "it prints the body of the specified uri to $stdout" do
|
||||
lambda do
|
||||
Net::HTTP.get_print URI.parse("http://localhost:#{@port}/")
|
||||
end.should output(/This is the index page\./)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed host, path, port" do
|
||||
it "it prints the body of the specified uri to $stdout" do
|
||||
lambda do
|
||||
Net::HTTP.get_print 'localhost', "/", @port
|
||||
end.should output(/This is the index page\./)
|
||||
end
|
||||
end
|
||||
end
|
30
spec/ruby/library/net/http/http/get_response_spec.rb
Normal file
30
spec/ruby/library/net/http/http/get_response_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
|
||||
describe "Net::HTTP.get_response" do
|
||||
before :each do
|
||||
NetHTTPSpecs.start_server
|
||||
@port = NetHTTPSpecs.port
|
||||
end
|
||||
|
||||
after :each do
|
||||
NetHTTPSpecs.stop_server
|
||||
end
|
||||
|
||||
describe "when passed URI" do
|
||||
it "returns the response for the specified uri" do
|
||||
res = Net::HTTP.get_response(URI.parse("http://localhost:#{@port}/"))
|
||||
res.content_type.should == "text/plain"
|
||||
res.body.should == "This is the index page."
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed host, path, port" do
|
||||
it "returns the response for the specified host-path-combination" do
|
||||
res = Net::HTTP.get_response('localhost', "/", @port)
|
||||
res.content_type.should == "text/plain"
|
||||
res.body.should == "This is the index page."
|
||||
end
|
||||
end
|
||||
end
|
26
spec/ruby/library/net/http/http/get_spec.rb
Normal file
26
spec/ruby/library/net/http/http/get_spec.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
|
||||
describe "Net::HTTP.get when passed URI" do
|
||||
before :each do
|
||||
NetHTTPSpecs.start_server
|
||||
@port = NetHTTPSpecs.port
|
||||
end
|
||||
|
||||
after :each do
|
||||
NetHTTPSpecs.stop_server
|
||||
end
|
||||
|
||||
describe "when passed URI" do
|
||||
it "returns the body of the specified uri" do
|
||||
Net::HTTP.get(URI.parse("http://localhost:#{@port}/")).should == "This is the index page."
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed host, path, port" do
|
||||
it "returns the body of the specified host-path-combination" do
|
||||
Net::HTTP.get('localhost', "/", @port).should == "This is the index page."
|
||||
end
|
||||
end
|
||||
end
|
9
spec/ruby/library/net/http/http/head2_spec.rb
Normal file
9
spec/ruby/library/net/http/http/head2_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
require File.expand_path('../shared/request_head', __FILE__)
|
||||
|
||||
describe "Net::HTTP#head2" do
|
||||
it_behaves_like :net_ftp_request_head, :head2
|
||||
end
|
||||
|
25
spec/ruby/library/net/http/http/head_spec.rb
Normal file
25
spec/ruby/library/net/http/http/head_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
|
||||
describe "Net::HTTP#head" do
|
||||
before :each do
|
||||
NetHTTPSpecs.start_server
|
||||
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@http.finish if @http.started?
|
||||
NetHTTPSpecs.stop_server
|
||||
end
|
||||
|
||||
it "sends a HEAD request to the passed path and returns the response" do
|
||||
response = @http.head("/request")
|
||||
# HEAD requests have no responses
|
||||
response.body.should be_nil
|
||||
end
|
||||
|
||||
it "returns a Net::HTTPResponse" do
|
||||
@http.head("/request").should be_kind_of(Net::HTTPResponse)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTP.http_default_port" do
|
||||
it "returns 80" do
|
||||
Net::HTTP.http_default_port.should eql(80)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTP.https_default_port" do
|
||||
it "returns 443" do
|
||||
Net::HTTP.https_default_port.should eql(443)
|
||||
end
|
||||
end
|
46
spec/ruby/library/net/http/http/initialize_spec.rb
Normal file
46
spec/ruby/library/net/http/http/initialize_spec.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTP#initialize" do
|
||||
it "is private" do
|
||||
Net::HTTP.should have_private_instance_method(:initialize)
|
||||
end
|
||||
|
||||
describe "when passed address" do
|
||||
before :each do
|
||||
@net = Net::HTTP.allocate
|
||||
@net.send(:initialize, "localhost")
|
||||
end
|
||||
|
||||
it "sets the new Net::HTTP instance's address to the passed address" do
|
||||
@net.address.should == "localhost"
|
||||
end
|
||||
|
||||
it "sets the new Net::HTTP instance's port to the default HTTP port" do
|
||||
@net.port.should eql(Net::HTTP.default_port)
|
||||
end
|
||||
|
||||
it "does not start the new Net::HTTP instance" do
|
||||
@net.started?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed address, port" do
|
||||
before :each do
|
||||
@net = Net::HTTP.allocate
|
||||
@net.send(:initialize, "localhost", 3333)
|
||||
end
|
||||
|
||||
it "sets the new Net::HTTP instance's address to the passed address" do
|
||||
@net.address.should == "localhost"
|
||||
end
|
||||
|
||||
it "sets the new Net::HTTP instance's port to the passed port" do
|
||||
@net.port.should eql(3333)
|
||||
end
|
||||
|
||||
it "does not start the new Net::HTTP instance" do
|
||||
@net.started?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
24
spec/ruby/library/net/http/http/inspect_spec.rb
Normal file
24
spec/ruby/library/net/http/http/inspect_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
|
||||
describe "Net::HTTP#inspect" do
|
||||
before :each do
|
||||
NetHTTPSpecs.start_server
|
||||
@port = NetHTTPSpecs.port
|
||||
@http = Net::HTTP.new("localhost", @port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@http.finish if @http.started?
|
||||
NetHTTPSpecs.stop_server
|
||||
end
|
||||
|
||||
it "returns a String representation of self" do
|
||||
@http.inspect.should be_kind_of(String)
|
||||
@http.inspect.should == "#<Net::HTTP localhost:#{@port} open=false>"
|
||||
|
||||
@http.start
|
||||
@http.inspect.should == "#<Net::HTTP localhost:#{@port} open=true>"
|
||||
end
|
||||
end
|
7
spec/ruby/library/net/http/http/is_version_1_1_spec.rb
Normal file
7
spec/ruby/library/net/http/http/is_version_1_1_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../shared/version_1_1', __FILE__)
|
||||
|
||||
describe "Net::HTTP.is_version_1_1?" do
|
||||
it_behaves_like :net_http_version_1_1_p, :is_version_1_1?
|
||||
end
|
7
spec/ruby/library/net/http/http/is_version_1_2_spec.rb
Normal file
7
spec/ruby/library/net/http/http/is_version_1_2_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../shared/version_1_2', __FILE__)
|
||||
|
||||
describe "Net::HTTP.is_version_1_2?" do
|
||||
it_behaves_like :net_http_version_1_2_p, :is_version_1_2?
|
||||
end
|
21
spec/ruby/library/net/http/http/lock_spec.rb
Normal file
21
spec/ruby/library/net/http/http/lock_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
|
||||
describe "Net::HTTP#lock" do
|
||||
before :each do
|
||||
NetHTTPSpecs.start_server
|
||||
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@http.finish if @http.started?
|
||||
NetHTTPSpecs.stop_server
|
||||
end
|
||||
|
||||
it "sends a LOCK request to the passed path and returns the response" do
|
||||
response = @http.lock("/request", "test=test")
|
||||
response.should be_kind_of(Net::HTTPResponse)
|
||||
response.body.should == "Request type: LOCK"
|
||||
end
|
||||
end
|
21
spec/ruby/library/net/http/http/mkcol_spec.rb
Normal file
21
spec/ruby/library/net/http/http/mkcol_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
|
||||
describe "Net::HTTP#mkcol" do
|
||||
before :each do
|
||||
NetHTTPSpecs.start_server
|
||||
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@http.finish if @http.started?
|
||||
NetHTTPSpecs.stop_server
|
||||
end
|
||||
|
||||
it "sends a MKCOL request to the passed path and returns the response" do
|
||||
response = @http.mkcol("/request")
|
||||
response.should be_kind_of(Net::HTTPResponse)
|
||||
response.body.should == "Request type: MKCOL"
|
||||
end
|
||||
end
|
25
spec/ruby/library/net/http/http/move_spec.rb
Normal file
25
spec/ruby/library/net/http/http/move_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
require File.expand_path('../fixtures/http_server', __FILE__)
|
||||
|
||||
describe "Net::HTTP#head" do
|
||||
before :each do
|
||||
NetHTTPSpecs.start_server
|
||||
@http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
|
||||
end
|
||||
|
||||
after :each do
|
||||
@http.finish if @http.started?
|
||||
NetHTTPSpecs.stop_server
|
||||
end
|
||||
|
||||
it "sends a MOVE request to the passed path and returns the response" do
|
||||
response = @http.move("/request")
|
||||
# HEAD requests have no responses
|
||||
response.body.should == "Request type: MOVE"
|
||||
end
|
||||
|
||||
it "returns a Net::HTTPResponse" do
|
||||
@http.move("/request").should be_kind_of(Net::HTTPResponse)
|
||||
end
|
||||
end
|
86
spec/ruby/library/net/http/http/new_spec.rb
Normal file
86
spec/ruby/library/net/http/http/new_spec.rb
Normal file
|
@ -0,0 +1,86 @@
|
|||
require File.expand_path('../../../../../spec_helper', __FILE__)
|
||||
require 'net/http'
|
||||
|
||||
describe "Net::HTTP.new" do
|
||||
describe "when passed address" do
|
||||
before :each do
|
||||
@http = Net::HTTP.new("localhost")
|
||||
end
|
||||
|
||||
it "returns a Net::HTTP instance" do
|
||||
@http.proxy?.should be_false
|
||||
@http.instance_of?(Net::HTTP).should be_true
|
||||
end
|
||||
|
||||
it "sets the new Net::HTTP instance's address to the passed address" do
|
||||
@http.address.should == "localhost"
|
||||
end
|
||||
|
||||
it "sets the new Net::HTTP instance's port to the default HTTP port" do
|
||||
@http.port.should eql(Net::HTTP.default_port)
|
||||
end
|
||||
|
||||
it "does not start the new Net::HTTP instance" do
|
||||
@http.started?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed address, port" do
|
||||
before :each do
|
||||
@http = Net::HTTP.new("localhost", 3333)
|
||||
end
|
||||
|
||||
it "returns a Net::HTTP instance" do
|
||||
@http.proxy?.should be_false
|
||||
@http.instance_of?(Net::HTTP).should be_true
|
||||
end
|
||||
|
||||
it "sets the new Net::HTTP instance's address to the passed address" do
|
||||
@http.address.should == "localhost"
|
||||
end
|
||||
|
||||
it "sets the new Net::HTTP instance's port to the passed port" do
|
||||
@http.port.should eql(3333)
|
||||
end
|
||||
|
||||
it "does not start the new Net::HTTP instance" do
|
||||
@http.started?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "when passed address, port, *proxy_options" do
|
||||
it "returns a Net::HTTP instance" do
|
||||
http = Net::HTTP.new("localhost", 3333, "localhost")
|
||||
http.proxy?.should be_true
|
||||
http.instance_of?(Net::HTTP).should be_true
|
||||
http.should be_kind_of(Net::HTTP)
|
||||
end
|
||||
|
||||
it "correctly sets the passed Proxy options" do
|
||||
http = Net::HTTP.new("localhost", 3333, "localhost")
|
||||
http.proxy_address.should == "localhost"
|
||||
http.proxy_port.should eql(80)
|
||||
http.proxy_user.should be_nil
|
||||
http.proxy_pass.should be_nil
|
||||
|
||||
http = Net::HTTP.new("localhost", 3333, "localhost", 1234)
|
||||
http.proxy_address.should == "localhost"
|
||||
http.proxy_port.should eql(1234)
|
||||
http.proxy_user.should be_nil
|
||||
http.proxy_pass.should be_nil
|
||||
|
||||
http = Net::HTTP.new("localhost", 3333, "localhost", 1234, "rubyspec")
|
||||
http.proxy_address.should == "localhost"
|
||||
http.proxy_port.should eql(1234)
|
||||
http.proxy_user.should == "rubyspec"
|
||||
http.proxy_pass.should be_nil
|
||||
|
||||
http = Net::HTTP.new("localhost", 3333, "localhost", 1234, "rubyspec", "rocks")
|
||||
http.proxy_address.should == "localhost"
|
||||
http.proxy_port.should eql(1234)
|
||||
http.proxy_user.should == "rubyspec"
|
||||
http.proxy_pass.should == "rocks"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue