Prefer adapting specs to complicating library code

* lib/net/ftp.rb (Net::FTP#initialize): simplify as per
  the original intent.
* spec/ruby/library/net/ftp/initialize_spec.rb: adapt specs.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-09-20 21:50:14 +00:00
parent aaf07f7ad5
commit 2dd35a7453
2 changed files with 9 additions and 11 deletions

View File

@ -262,13 +262,7 @@ module Net
@ssl_handshake_timeout = options[:ssl_handshake_timeout] @ssl_handshake_timeout = options[:ssl_handshake_timeout]
@read_timeout = options[:read_timeout] || 60 @read_timeout = options[:read_timeout] || 60
if host if host
if options[:port]
connect(host, options[:port] || FTP_PORT) connect(host, options[:port] || FTP_PORT)
else
# spec/ruby/library/net/ftp/initialize_spec.rb depends on
# the number of arguments passed to connect....
connect(host)
end
if options[:username] if options[:username]
login(options[:username], options[:password], options[:account]) login(options[:username], options[:password], options[:account])
end end

View File

@ -5,6 +5,10 @@ describe "Net::FTP#initialize" do
before :each do before :each do
@ftp = Net::FTP.allocate @ftp = Net::FTP.allocate
@ftp.stub!(:connect) @ftp.stub!(:connect)
@port_args = []
ruby_version_is "2.5" do
@port_args << 21
end
end end
it "is private" do it "is private" do
@ -44,14 +48,14 @@ describe "Net::FTP#initialize" do
describe "when passed host" do describe "when passed host" do
it "tries to connect to the passed host" do it "tries to connect to the passed host" do
@ftp.should_receive(:connect).with("localhost") @ftp.should_receive(:connect).with("localhost", *@port_args)
@ftp.send(:initialize, "localhost") @ftp.send(:initialize, "localhost")
end end
end end
describe "when passed host, user" do describe "when passed host, user" do
it "tries to connect to the passed host" do it "tries to connect to the passed host" do
@ftp.should_receive(:connect).with("localhost") @ftp.should_receive(:connect).with("localhost", *@port_args)
@ftp.send(:initialize, "localhost") @ftp.send(:initialize, "localhost")
end end
@ -63,7 +67,7 @@ describe "Net::FTP#initialize" do
describe "when passed host, user, password" do describe "when passed host, user, password" do
it "tries to connect to the passed host" do it "tries to connect to the passed host" do
@ftp.should_receive(:connect).with("localhost") @ftp.should_receive(:connect).with("localhost", *@port_args)
@ftp.send(:initialize, "localhost") @ftp.send(:initialize, "localhost")
end end
@ -75,7 +79,7 @@ describe "Net::FTP#initialize" do
describe "when passed host, user" do describe "when passed host, user" do
it "tries to connect to the passed host" do it "tries to connect to the passed host" do
@ftp.should_receive(:connect).with("localhost") @ftp.should_receive(:connect).with("localhost", *@port_args)
@ftp.send(:initialize, "localhost") @ftp.send(:initialize, "localhost")
end end