ruby-changes:47860
From: eregon <ko1@a...>
Date: Thu, 21 Sep 2017 06:50:20 +0900 (JST)
Subject: [ruby-changes:47860] eregon:r59981 (trunk): Prefer adapting specs to complicating library code
eregon 2017-09-21 06:50:14 +0900 (Thu, 21 Sep 2017) New Revision: 59981 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59981 Log: 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. Modified files: trunk/lib/net/ftp.rb trunk/spec/ruby/library/net/ftp/initialize_spec.rb Index: spec/ruby/library/net/ftp/initialize_spec.rb =================================================================== --- spec/ruby/library/net/ftp/initialize_spec.rb (revision 59980) +++ spec/ruby/library/net/ftp/initialize_spec.rb (revision 59981) @@ -5,6 +5,10 @@ describe "Net::FTP#initialize" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/net/ftp/initialize_spec.rb#L5 before :each do @ftp = Net::FTP.allocate @ftp.stub!(:connect) + @port_args = [] + ruby_version_is "2.5" do + @port_args << 21 + end end it "is private" do @@ -44,14 +48,14 @@ describe "Net::FTP#initialize" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/net/ftp/initialize_spec.rb#L48 describe "when 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") end end describe "when passed host, user" 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") end @@ -63,7 +67,7 @@ describe "Net::FTP#initialize" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/net/ftp/initialize_spec.rb#L67 describe "when passed host, user, password" 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") end @@ -75,7 +79,7 @@ describe "Net::FTP#initialize" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/net/ftp/initialize_spec.rb#L79 describe "when passed host, user" 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") end Index: lib/net/ftp.rb =================================================================== --- lib/net/ftp.rb (revision 59980) +++ lib/net/ftp.rb (revision 59981) @@ -262,13 +262,7 @@ module Net https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L262 @ssl_handshake_timeout = options[:ssl_handshake_timeout] @read_timeout = options[:read_timeout] || 60 if host - if options[: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 + connect(host, options[:port] || FTP_PORT) if options[:username] login(options[:username], options[:password], options[:account]) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/