https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112019-10-03T21:31:37ZRuby Issue Tracking SystemRuby master - Misc #16235: ENV.assoc spec test does not test invalid namehttps://bugs.ruby-lang.org/issues/16235?journal_id=818812019-10-03T21:31:37Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p>It appears if <code>reserve_names</code> is called with a name that is already an environment variable, <code>release_names</code> will remove that name from the environment, which seems like a bug. Now, that issue exists in the current code (environment variable <code>foo</code> is always modified and removed. But if we are going to handle this, we should probably not set @reserved until after checking the names, and only remove the @reserved entries if the instance variable is defined.</p>
<p>Note that since these changes are only to the specs, you may want to consider submitting them as pull requests to ruby/spec: <a href="https://github.com/ruby/spec/pulls" class="external">https://github.com/ruby/spec/pulls</a></p> Ruby master - Misc #16235: ENV.assoc spec test does not test invalid namehttps://bugs.ruby-lang.org/issues/16235?journal_id=818822019-10-03T21:54:05Zburdettelamar@yahoo.com (Burdette Lamar)burdettelamar@example.com
<ul></ul><p>Method :reserve_names fails if any name is already in use:</p>
<pre><code>def reserve_names(*names)
@reserved = names
@reserved.each do |name|
fail "Name #{name} is already in use" if ENV.include?(name)
end
end
</code></pre>
<p>So, not a problem?</p> Ruby master - Misc #16235: ENV.assoc spec test does not test invalid namehttps://bugs.ruby-lang.org/issues/16235?journal_id=818842019-10-03T23:07:03Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p><a href="mailto:burdettelamar@yahoo.com" class="email">burdettelamar@yahoo.com</a> (Burdette Lamar) wrote:</p>
<blockquote>
<p>Method :reserve_names fails if any name is already in use:</p>
<pre><code>def reserve_names(*names)
@reserved = names
@reserved.each do |name|
fail "Name #{name} is already in use" if ENV.include?(name)
end
end
</code></pre>
<p>So, not a problem?</p>
</blockquote>
<p><code>reserve_names</code> is called in a <code>before :each</code> block. When it fails, the <code>after :each</code> block is called. That block calls <code>release_names</code> which will delete the entry from the environment. In my opinion, if you are checking whether the environment variable is already set, and it is already set, and the spec fails because of this, you probably should not remove the entry from the environment. Otherwise you are making the spec fail for no reason.</p> Ruby master - Misc #16235: ENV.assoc spec test does not test invalid namehttps://bugs.ruby-lang.org/issues/16235?journal_id=818882019-10-04T00:58:28Zburdettelamar@yahoo.com (Burdette Lamar)burdettelamar@example.com
<ul></ul><p>Got it, thanks. Will update the diff.</p> Ruby master - Misc #16235: ENV.assoc spec test does not test invalid namehttps://bugs.ruby-lang.org/issues/16235?journal_id=819082019-10-05T19:08:39Zburdettelamar@yahoo.com (Burdette Lamar)burdettelamar@example.com
<ul></ul><p>Have put this up as a PR, so we're done here.</p> Ruby master - Misc #16235: ENV.assoc spec test does not test invalid namehttps://bugs.ruby-lang.org/issues/16235?journal_id=819112019-10-05T22:53:10Zburdettelamar@yahoo.com (Burdette Lamar)burdettelamar@example.com
<ul></ul><p><a href="https://github.com/ruby/ruby/pull/2527" class="external">https://github.com/ruby/ruby/pull/2527</a></p>