diff options
author | Benoit Daloze <[email protected]> | 2019-04-27 18:53:23 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2019-04-27 18:53:23 +0200 |
commit | a1b4816759418ca8fe510e8739622fc5d77ab0f0 (patch) | |
tree | 9d4fb6091d0086817f5bde46bf1150e9130d34fd /spec/ruby/library/net | |
parent | 00c33d9c232ed1a79eda17acd7231ac93caa162b (diff) |
Update to ruby/spec@15c9619
Diffstat (limited to 'spec/ruby/library/net')
-rw-r--r-- | spec/ruby/library/net/ftp/initialize_spec.rb | 424 | ||||
-rw-r--r-- | spec/ruby/library/net/ftp/status_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/library/net/http/http/post_spec.rb | 56 |
3 files changed, 240 insertions, 246 deletions
diff --git a/spec/ruby/library/net/ftp/initialize_spec.rb b/spec/ruby/library/net/ftp/initialize_spec.rb index cd6252ac31..507320e494 100644 --- a/spec/ruby/library/net/ftp/initialize_spec.rb +++ b/spec/ruby/library/net/ftp/initialize_spec.rb @@ -89,318 +89,316 @@ describe "Net::FTP#initialize" do end end - ruby_version_is '2.4' do - before :each do - @ftp.stub!(:login) - end + before :each do + @ftp.stub!(:login) + end - describe 'when the host' do - describe 'is set' do - describe 'and port option' do - describe 'is set' do - it 'tries to connect to the host on the specified port' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ port: 8080 }) - @ftp.should_receive(:connect).with('localhost', 8080) + describe 'when the host' do + describe 'is set' do + describe 'and port option' do + describe 'is set' do + it 'tries to connect to the host on the specified port' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ port: 8080 }) + @ftp.should_receive(:connect).with('localhost', 8080) - @ftp.send(:initialize, 'localhost', options) - end + @ftp.send(:initialize, 'localhost', options) end + end - describe 'is not set' do - it 'tries to connect to the host without a port' do - @ftp.should_receive(:connect).with("localhost", *@port_args) + describe 'is not set' do + it 'tries to connect to the host without a port' do + @ftp.should_receive(:connect).with("localhost", *@port_args) - @ftp.send(:initialize, 'localhost') - end + @ftp.send(:initialize, 'localhost') end end + end - describe 'when the username option' do - describe 'is set' do - describe 'and the password option' do - describe 'is set' do - describe 'and the account option' do - describe 'is set' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret', account: 'b' }) - @ftp.should_receive(:login).with('a', 'topsecret', 'b') - - @ftp.send(:initialize, 'localhost', options) - end + describe 'when the username option' do + describe 'is set' do + describe 'and the password option' do + describe 'is set' do + describe 'and the account option' do + describe 'is set' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret', account: 'b' }) + @ftp.should_receive(:login).with('a', 'topsecret', 'b') + + @ftp.send(:initialize, 'localhost', options) end + end - describe 'is unset' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret' }) - @ftp.should_receive(:login).with('a', 'topsecret', nil) + describe 'is unset' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a', password: 'topsecret' }) + @ftp.should_receive(:login).with('a', 'topsecret', nil) - @ftp.send(:initialize, 'localhost', options) - end + @ftp.send(:initialize, 'localhost', options) end end end + end - describe 'is unset' do - describe 'and the account option' do - describe 'is set' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a', account: 'b' }) - @ftp.should_receive(:login).with('a', nil, 'b') + describe 'is unset' do + describe 'and the account option' do + describe 'is set' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a', account: 'b' }) + @ftp.should_receive(:login).with('a', nil, 'b') - @ftp.send(:initialize, 'localhost', options) - end + @ftp.send(:initialize, 'localhost', options) end + end - describe 'is unset' do - it 'tries to log in with the supplied parameters' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ username: 'a'}) - @ftp.should_receive(:login).with('a', nil, nil) + describe 'is unset' do + it 'tries to log in with the supplied parameters' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ username: 'a'}) + @ftp.should_receive(:login).with('a', nil, nil) - @ftp.send(:initialize, 'localhost', options) - end + @ftp.send(:initialize, 'localhost', options) end end end end end + end - describe 'is not set' do - it 'does not try to log in' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({}) - @ftp.should_not_receive(:login) + describe 'is not set' do + it 'does not try to log in' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({}) + @ftp.should_not_receive(:login) - @ftp.send(:initialize, 'localhost', options) - end + @ftp.send(:initialize, 'localhost', options) end end end + end - describe 'is unset' do - it 'does not try to connect' do - @ftp.should_not_receive(:connect) + describe 'is unset' do + it 'does not try to connect' do + @ftp.should_not_receive(:connect) - @ftp.send(:initialize) - end + @ftp.send(:initialize) + end - it 'does not try to log in' do - @ftp.should_not_receive(:login) + it 'does not try to log in' do + @ftp.should_not_receive(:login) - @ftp.send(:initialize) - end + @ftp.send(:initialize) end end + end - describe 'when the passive option' do - describe 'is set' do - describe 'to true' do - it 'sets passive to true' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ passive: true }) - - @ftp.send(:initialize, nil, options) - @ftp.passive.should == true - end - end - - describe 'to false' do - it 'sets passive to false' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ passive: false }) + describe 'when the passive option' do + describe 'is set' do + describe 'to true' do + it 'sets passive to true' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ passive: true }) - @ftp.send(:initialize, nil, options) - @ftp.passive.should == false - end + @ftp.send(:initialize, nil, options) + @ftp.passive.should == true end end - describe 'is unset' do + describe 'to false' do it 'sets passive to false' do - @ftp.send(:initialize) + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ passive: false }) + + @ftp.send(:initialize, nil, options) @ftp.passive.should == false end end end - describe 'when the debug_mode option' do - describe 'is set' do - describe 'to true' do - it 'sets debug_mode to true' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ debug_mode: true }) - - @ftp.send(:initialize, nil, options) - @ftp.debug_mode.should == true - end - end + describe 'is unset' do + it 'sets passive to false' do + @ftp.send(:initialize) + @ftp.passive.should == false + end + end + end - describe 'to false' do - it 'sets debug_mode to false' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ debug_mode: false }) + describe 'when the debug_mode option' do + describe 'is set' do + describe 'to true' do + it 'sets debug_mode to true' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ debug_mode: true }) - @ftp.send(:initialize, nil, options) - @ftp.debug_mode.should == false - end + @ftp.send(:initialize, nil, options) + @ftp.debug_mode.should == true end end - describe 'is unset' do + describe 'to false' do it 'sets debug_mode to false' do - @ftp.send(:initialize) + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ debug_mode: false }) + + @ftp.send(:initialize, nil, options) @ftp.debug_mode.should == false end end end - describe 'when the open_timeout option' do - describe 'is set' do - it 'sets open_timeout to the specified value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ open_timeout: 42 }) + describe 'is unset' do + it 'sets debug_mode to false' do + @ftp.send(:initialize) + @ftp.debug_mode.should == false + end + end + end - @ftp.send(:initialize, nil, options) - @ftp.open_timeout.should == 42 - end + describe 'when the open_timeout option' do + describe 'is set' do + it 'sets open_timeout to the specified value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ open_timeout: 42 }) + + @ftp.send(:initialize, nil, options) + @ftp.open_timeout.should == 42 end + end - describe 'is not set' do - it 'sets open_timeout to nil' do - @ftp.send(:initialize) - @ftp.open_timeout.should == nil - end + describe 'is not set' do + it 'sets open_timeout to nil' do + @ftp.send(:initialize) + @ftp.open_timeout.should == nil end end + end - describe 'when the read_timeout option' do - describe 'is set' do - it 'sets read_timeout to the specified value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ read_timeout: 100 }) + describe 'when the read_timeout option' do + describe 'is set' do + it 'sets read_timeout to the specified value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ read_timeout: 100 }) - @ftp.send(:initialize, nil, options) - @ftp.read_timeout.should == 100 - end + @ftp.send(:initialize, nil, options) + @ftp.read_timeout.should == 100 end + end - describe 'is not set' do - it 'sets read_timeout to the default value' do - @ftp.send(:initialize) - @ftp.read_timeout.should == 60 - end + describe 'is not set' do + it 'sets read_timeout to the default value' do + @ftp.send(:initialize) + @ftp.read_timeout.should == 60 end end + end - describe 'when the ssl_handshake_timeout option' do - describe 'is set' do - it 'sets ssl_handshake_timeout to the specified value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl_handshake_timeout: 23 }) + describe 'when the ssl_handshake_timeout option' do + describe 'is set' do + it 'sets ssl_handshake_timeout to the specified value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl_handshake_timeout: 23 }) - @ftp.send(:initialize, nil, options) - @ftp.ssl_handshake_timeout.should == 23 - end + @ftp.send(:initialize, nil, options) + @ftp.ssl_handshake_timeout.should == 23 end + end - describe 'is not set' do - it 'sets ssl_handshake_timeout to nil' do - @ftp.send(:initialize) - @ftp.ssl_handshake_timeout.should == nil - end + describe 'is not set' do + it 'sets ssl_handshake_timeout to nil' do + @ftp.send(:initialize) + @ftp.ssl_handshake_timeout.should == nil end end + end - describe 'when the ssl option' do - describe 'is set' do - describe "and the ssl option's value is true" do - it 'initializes ssl_context to a blank SSLContext object' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: true }) + describe 'when the ssl option' do + describe 'is set' do + describe "and the ssl option's value is true" do + it 'initializes ssl_context to a blank SSLContext object' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: true }) - ssl_context = OpenSSL::SSL::SSLContext.allocate - ssl_context.stub!(:set_params) + ssl_context = OpenSSL::SSL::SSLContext.allocate + ssl_context.stub!(:set_params) - OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) - ssl_context.should_receive(:set_params).with({}) + OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) + ssl_context.should_receive(:set_params).with({}) - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@ssl_context).should == ssl_context - end + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@ssl_context).should == ssl_context end + end - describe "and the ssl option's value is a hash" do - it 'initializes ssl_context to a configured SSLContext object' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: {key: 'value'} }) + describe "and the ssl option's value is a hash" do + it 'initializes ssl_context to a configured SSLContext object' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: {key: 'value'} }) - ssl_context = OpenSSL::SSL::SSLContext.allocate - ssl_context.stub!(:set_params) + ssl_context = OpenSSL::SSL::SSLContext.allocate + ssl_context.stub!(:set_params) - OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) - ssl_context.should_receive(:set_params).with({key: 'value'}) + OpenSSL::SSL::SSLContext.should_receive(:new).and_return(ssl_context) + ssl_context.should_receive(:set_params).with({key: 'value'}) - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@ssl_context).should == ssl_context - end + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@ssl_context).should == ssl_context end + end - describe 'and private_data_connection' do - describe 'is set' do - it 'sets private_data_connection to that value' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: true, private_data_connection: 'true' }) + describe 'and private_data_connection' do + describe 'is set' do + it 'sets private_data_connection to that value' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: true, private_data_connection: 'true' }) - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@private_data_connection).should == 'true' - end + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == 'true' end + end - describe 'is not set' do - it 'sets private_data_connection to nil' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ ssl: true }) + describe 'is not set' do + it 'sets private_data_connection to nil' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ ssl: true }) - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@private_data_connection).should == true - end + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == true end end end + end - describe 'is not set' do - it 'sets ssl_context to nil' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({}) + describe 'is not set' do + it 'sets ssl_context to nil' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({}) - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@ssl_context).should == nil - end + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@ssl_context).should == nil + end - describe 'private_data_connection' do - describe 'is set' do - it 'raises an ArgumentError' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({ private_data_connection: true }) + describe 'private_data_connection' do + describe 'is set' do + it 'raises an ArgumentError' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({ private_data_connection: true }) - -> { - @ftp.send(:initialize, nil, options) - }.should raise_error(ArgumentError, /private_data_connection can be set to true only when ssl is enabled/) - end + -> { + @ftp.send(:initialize, nil, options) + }.should raise_error(ArgumentError, /private_data_connection can be set to true only when ssl is enabled/) end + end - describe 'is not set' do - it 'sets private_data_connection to false' do - options = mock('ftp initialize options') - options.should_receive(:to_hash).and_return({}) + describe 'is not set' do + it 'sets private_data_connection to false' do + options = mock('ftp initialize options') + options.should_receive(:to_hash).and_return({}) - @ftp.send(:initialize, nil, options) - @ftp.instance_variable_get(:@private_data_connection).should == false - end + @ftp.send(:initialize, nil, options) + @ftp.instance_variable_get(:@private_data_connection).should == false end end end diff --git a/spec/ruby/library/net/ftp/status_spec.rb b/spec/ruby/library/net/ftp/status_spec.rb index 22d0d47254..c3874ea41e 100644 --- a/spec/ruby/library/net/ftp/status_spec.rb +++ b/spec/ruby/library/net/ftp/status_spec.rb @@ -22,10 +22,8 @@ describe "Net::FTP#status" do @ftp.last_response.should == "211 System status, or system help reply. (STAT)\n" end - ruby_version_is "2.4" do - it "sends the STAT command with an optional parameter to the server" do - @ftp.status("/pub").should == "211 System status, or system help reply. (STAT /pub)\n" - end + it "sends the STAT command with an optional parameter to the server" do + @ftp.status("/pub").should == "211 System status, or system help reply. (STAT /pub)\n" end it "returns the received information" do diff --git a/spec/ruby/library/net/http/http/post_spec.rb b/spec/ruby/library/net/http/http/post_spec.rb index c8d41b9617..9f20a03c85 100644 --- a/spec/ruby/library/net/http/http/post_spec.rb +++ b/spec/ruby/library/net/http/http/post_spec.rb @@ -3,40 +3,38 @@ require 'net/http' require 'uri' require_relative 'fixtures/http_server' -ruby_version_is '2.4' do - describe "Net::HTTP.post" do - before :each do - NetHTTPSpecs.start_server - end +describe "Net::HTTP.post" do + before :each do + NetHTTPSpecs.start_server + end - after :each do - NetHTTPSpecs.stop_server - end + after :each do + NetHTTPSpecs.stop_server + end - it "sends post request to the specified URI and returns response" do - response = Net::HTTP.post( - URI("http://localhost:#{NetHTTPSpecs.port}/request"), - '{ "q": "ruby", "max": "50" }', - "Content-Type" => "application/json") - response.body.should == "Request type: POST" - end + it "sends post request to the specified URI and returns response" do + response = Net::HTTP.post( + URI("http://localhost:#{NetHTTPSpecs.port}/request"), + '{ "q": "ruby", "max": "50" }', + "Content-Type" => "application/json") + response.body.should == "Request type: POST" + end - it "returns a Net::HTTPResponse" do - response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request"), "test=test") - response.should be_kind_of(Net::HTTPResponse) - end + it "returns a Net::HTTPResponse" do + response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request"), "test=test") + response.should be_kind_of(Net::HTTPResponse) + end - it "sends Content-Type: application/x-www-form-urlencoded by default" do - response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test") - response.body.should include('"content-type"=>["application/x-www-form-urlencoded"]') - end + it "sends Content-Type: application/x-www-form-urlencoded by default" do + response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test") + response.body.should include('"content-type"=>["application/x-www-form-urlencoded"]') + end - it "does not support HTTP Basic Auth" do - response = Net::HTTP.post( - URI("http://john:qwerty@localhost:#{NetHTTPSpecs.port}/request/basic_auth"), - "test=test") - response.body.should == "username: \npassword: " - end + it "does not support HTTP Basic Auth" do + response = Net::HTTP.post( + URI("http://john:qwerty@localhost:#{NetHTTPSpecs.port}/request/basic_auth"), + "test=test") + response.body.should == "username: \npassword: " end end |