You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Suggestions for testing options in Net::FTP.new #534
I'm working on new specs for the options hash for new made available in Ruby 2.4 as part of #473, and I wanted to get some input on how to approach testing the ssl option, as this has a branching condition based on whether OpenSSL::SSL is defined. Do we have any examples in the codebase where something similar is being tested?
Apologies if this isn't the best place for this, I didn't see any methods of communication mentioned in contributing.md
I think in that case you can just require "openssl" in the examples (the its) that need it.
It's better to not require other libraries at the top-level, as it can prevent loading other specs in the same file.
If you want/need to test with openssl not available, you can use ruby_exe which starts a fresh new Ruby process.
The problem is that I want to test that when the ssl option is passed without openssl being imported, it should raise an exception. Normally the way to do this from what I've seen is to wrap the call you expect to raise the exception in a lambda, but for this I have to make use of ruby_exe as you suggested. Unfortunately this only seems to return string values, rather than raising any exceptions.
I don't see any similar cases like this in the repository, do you have any suggestions on how best to approach this? One option could be to rescue the exception and then return it's string value from the ruby_exe call, but this doesn't feel right to me
So I think it's actually not so useful to test for this condition, it's just a sign of a broken Ruby installation with no openssl.
We generally assume the openssl extension is available in ruby/spec, it's part of the Ruby standard library.
Activity
eregon commentedon Oct 25, 2017
Yes, this is a good place to ask :)
I think in that case you can just
require "openssl"in the examples (theits) that need it.It's better to not require other libraries at the top-level, as it can prevent loading other specs in the same file.
If you want/need to test with openssl not available, you can use
ruby_exewhich starts a fresh new Ruby process.eregon commentedon Oct 25, 2017
Here is a somewhat similar example of YAML requiring OpenStruct in its specs:
spec/library/yaml/dump_spec.rb
Lines 37 to 41 in 81c9b4f
AndrewSpeed commentedon Oct 25, 2017
Perfect, thanks very much @eregon I'll try implementing that tomorrow and hopefully get a PR up shortly afterwards 🙂
AndrewSpeed commentedon Oct 28, 2017
I'm having some difficulty testing a particular branch of the
initializemethod, namely: https://github.com/ruby/ruby/blob/trunk/lib/net/ftp.rb#L223The problem is that I want to test that when the
ssloption is passed withoutopensslbeing imported, it should raise an exception. Normally the way to do this from what I've seen is to wrap the call you expect to raise the exception in a lambda, but for this I have to make use ofruby_exeas you suggested. Unfortunately this only seems to return string values, rather than raising any exceptions.I don't see any similar cases like this in the repository, do you have any suggestions on how best to approach this? One option could be to rescue the exception and then return it's string value from the
ruby_execall, but this doesn't feel right to meeregon commentedon Oct 29, 2017
That sounds like the simplest solution to me.
But actually, this should only happen if the openssl extension is not installed.
That is, lib/net/ftp.rb does
require "openssl"https://github.com/ruby/ruby/blob/5256f7752763249288662c6c5ffc5686d244a535/lib/net/ftp.rb#L23So I think it's actually not so useful to test for this condition, it's just a sign of a broken Ruby installation with no openssl.
We generally assume the openssl extension is available in ruby/spec, it's part of the Ruby standard library.