Closed micah closed 3 years ago
According to 2ce9097a8242d80faf27c6ae7e0a3a6f26569317 that needs to be there for tests, which use a different path to the file given to require
. require
hashes on the argument not the full path (or it did as of 2011 :).
If removing that doesn't introduce warnings on supported rubies, it's fine with me, but it was needed at some point.
well that is not the case for a while ...
$ irb -Ilib
irb(main):001:0> RUBY_VERSION
=> "2.1.5"
irb(main):002:0> require 'gli/version'
=> true
irb(main):003:0> require 'gli/version.rb'
=> false
irb(main):004:0> require './lib/gli/version.rb'
=> false
irb(main):005:0> require Dir.pwd + '/lib/gli/version.rb'
=> false
(require
returns false
when the code you are trying to load is already loaded)
also, requiring code by its explicit path in tests is an anti-pattern that causes other issues, as when you are trying to run the tests against the library that is installed rather than the one in the source directory.
Closing as old and I'm not 100% sure I understand the issue any longer. I don’t see warnings in the test output
Hi,
Any code that loads your gemspec already has a VERSION in its context because in that context
const_defined? :VERSION
will return true if either GLI::VERSION is already defined, or if there is already a VERSION constant defined at the top level.For example:
Since the code in lib/gli/version.rb is always loaded via
require
, there is no need to test for an existing constant, sincerequire
guarantess that no file is loaded twice (e.g. if you dorequire "foo"
twice, the second one is a no-op).It would be better if lib/gli/version.rb was changed to the following: