https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112010-04-29T12:17:05ZRuby Issue Tracking SystemRuby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=106272010-04-29T12:17:05Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>=begin<br>
This issue was solved with changeset r27541.<br>
Nobuyoshi, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<p>=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=106282010-04-29T12:18:41Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Category</strong> set to <i>lib</i></li><li><strong>Status</strong> changed from <i>Closed</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>yugui (Yuki Sonoda)</i></li><li><strong>Priority</strong> changed from <i>3</i> to <i>Normal</i></li></ul><p>=begin</p>
<p>=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=106362010-04-29T14:58:57Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>=begin<br>
Hi,</p>
<p>At Thu, 29 Apr 2010 13:58:24 +0900,<br>
Aaron Patterson wrote in <a href="https://blade.ruby-lang.org/ruby-core/29872">[ruby-core:29872]</a>:</p>
<blockquote>
<p>I don't think this is right. test/unit on ruby 1.8 allows non-boolean<br>
values to it's assert method. The following test will pass on 1.8:</p>
</blockquote>
<p>Exactly. I reverted the commit, but found some tests use<br>
nonsense assertions. Although fixed in test/ruby already, I<br>
suspect there might be more mistakes in other tests.</p>
<p>--<br>
Nobu Nakada</p>
<p>=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=106632010-04-30T01:12:13Zcoatl (caleb clausen)
<ul></ul><p>=begin<br>
It is all too easy to write assert(foo, bar) when you meant to write assert_equal(foo, bar). I have made the same mistake myself a number of times. Usually, no error will result because assert allows an optional second parameter (an alternate String to be printed when the assertion fails).</p>
<p>I'd suggest that a better way to detect this problem is for assert to fail if a non-String is passed as the second parameter. This won't detect all cases of using assert when you meant assert_equal, but it should catch at lest 90%.<br>
=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=106782010-05-01T00:46:40Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>=begin<br>
Hi,</p>
<p>At Fri, 30 Apr 2010 06:15:34 +0900,<br>
Roger Pack wrote in <a href="https://blade.ruby-lang.org/ruby-core/29890">[ruby-core:29890]</a>:</p>
<blockquote>
<blockquote>
<p>I'd suggest that a better way to detect this problem is for<br>
assert to fail if a non-String is passed as the second<br>
parameter. This won't detect all cases of using assert when<br>
you meant assert_equal, but it should catch at lest 90%.</p>
</blockquote>
<p>Yeah something like that could work well. When would someone want to<br>
output something that's not a string?</p>
</blockquote>
<p>How do you want to show non-string message? Anyway, you can<br>
use a proc too.</p>
<p>--<br>
Nobu Nakada</p>
<p>=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=106812010-05-01T14:30:37Zdrbrain (Eric Hodel)drbrain@segment7.net
<ul></ul><p>=begin<br>
On Apr 29, 2010, at 09:12, caleb clausen wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: assert now passes non-boolean result (Rejected)" href="https://bugs.ruby-lang.org/issues/3219">#3219</a> has been updated by caleb clausen.</p>
<p>It is all too easy to write assert(foo, bar) when you meant to write assert_equal(foo, bar). I have made the same mistake myself a number of times. Usually, no error will result because assert allows an optional second parameter (an alternate String to be printed when the assertion fails).</p>
</blockquote>
<p>I don't see how you could have this problem if you're following a red, green, refactor type discipline. If the test passed when you forgot to add _equal you should immediately know you did it wrong because it should have failed. How can you trust any of your tests if you haven't ensured they fail when something is wrong?</p>
<blockquote>
<p>I'd suggest that a better way to detect this problem is for assert to fail if a non-String is passed as the second parameter. This won't detect all cases of using assert when you meant assert_equal, but it should catch at lest 90%.</p>
</blockquote>
<p>Why should I have to call #to_s manually when I can pass an object that will print something useful for me?</p>
<p>$ cat t.rb<br>
require 'minitest/autorun'</p>
<p>class TestAssert < MiniTest::Unit::TestCase</p>
<p>def test_assert<br>
o = Object.new<br>
def o.to_s() "something useful" end</p>
<pre><code> assert false, o
</code></pre>
<p>end</p>
<p>end<br>
$ ruby19 t.rb<br>
Loaded suite t<br>
Started<br>
F<br>
Finished in 0.000645 seconds.</p>
<ol>
<li>Failure:<br>
test_assert(TestAssert) [t.rb:9]:<br>
something useful</li>
</ol>
<p>1 tests, 1 assertions, 1 failures, 0 errors, 0 skips</p>
<p>Test run options: --seed 42229</p>
<p>=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=106822010-05-01T15:16:27Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>=begin<br>
Hi,</p>
<p>At Sat, 1 May 2010 14:30:19 +0900,<br>
Eric Hodel wrote in <a href="https://blade.ruby-lang.org/ruby-core/29910">[ruby-core:29910]</a>:</p>
<blockquote>
<p>class TestAssert < MiniTest::Unit::TestCase<br>
def test_assert<br>
o = Object.new<br>
def o.to_s() "something useful" end<br>
assert false, o<br>
end<br>
end</p>
</blockquote>
<p>I can't imagine how it is useful in what situation. Could you<br>
elaborate?</p>
<p>--<br>
Nobu Nakada</p>
<p>=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=107142010-05-03T11:13:50Zyugui (Yuki Sonoda)yugui@yugui.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>=begin<br>
I don't want to merge this to ruby 1.9.1<br>
=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=107152010-05-03T11:38:57Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>=begin<br>
Hi,</p>
<p>At Mon, 3 May 2010 11:13:50 +0900,<br>
Yuki Sonoda wrote in <a href="https://blade.ruby-lang.org/ruby-core/29945">[ruby-core:29945]</a>:</p>
<blockquote>
<p>I don't want to merge this to ruby 1.9.1</p>
</blockquote>
<p>Agreed. But I think the fixes for wrong assertions should be<br>
merged.</p>
<p>--<br>
Nobu Nakada</p>
<p>=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=107322010-05-03T18:07:03Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Closed</i> to <i>Open</i></li></ul><p>=begin<br>
Hi,</p>
<p>I really agree with nobu. I love this feature.<br>
But this is a feature request. This change should not be included<br>
in 1.9.2, IMO. I move this ticket to Feature tracker.</p>
<p>I prefer warning to failing for compatibility reason.</p>
<p>I know minitest aims to be simple, but it would be good to be more<br>
useful with subtle fix. See Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: test/unit redefinition check of test_* method (Closed)" href="https://bugs.ruby-lang.org/issues/2643">#2643</a> :-)</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a><br>
=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=107882010-05-05T08:48:24Zzenspider (Ryan Davis)
<ul></ul><p>=begin</p>
<p>On Apr 30, 2010, at 23:16 , Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>Hi,</p>
<p>At Sat, 1 May 2010 14:30:19 +0900,<br>
Eric Hodel wrote in <a href="https://blade.ruby-lang.org/ruby-core/29910">[ruby-core:29910]</a>:</p>
<blockquote>
<p>class TestAssert < MiniTest::Unit::TestCase<br>
def test_assert<br>
o = Object.new<br>
def o.to_s() "something useful" end<br>
assert false, o<br>
end<br>
end</p>
</blockquote>
<p>I can't imagine how it is useful in what situation. Could you<br>
elaborate?</p>
</blockquote>
<p>Here is one I just wrote:</p>
<blockquote>
<pre><code>root.childNodes.each do |child|
assert child.path, child
end
</code></pre>
</blockquote>
<p>I want to know which child object doesn't have a valid path. I almost never use assertion messages, but when I do, they're almost never Strings.</p>
<p>=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=133272010-09-14T16:01:02Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li></ul><p>=begin</p>
<p>=end</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=261892012-04-25T18:46:19Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/26189/diff?detail_id=19372">diff</a>)</li><li><strong>Assignee</strong> changed from <i>yugui (Yuki Sonoda)</i> to <i>sorah (Sorah Fukumori)</i></li></ul><p>Sorah-san, you can decide this.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=261902012-04-25T18:49:45Zfxn (Xavier Noria)fxn@hashref.com
<ul></ul><p>Not sure I understand this ticket.</p>
<p>If I write a generic predicate foo? whose return value is undocumented and irrelevant, I should be able to test it like this?</p>
<pre><code>assert obj.foo?
</code></pre> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=262082012-04-26T14:05:49Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>=begin<br>
fxn, you can use (({assert_send})) instead and will see better message if it fails.</p>
<p>$ ruby -rtest/unit -e 'class X<Test::Unit::TestCase;def test_fail; assert_send([3, :even?]); end; end'<br>
Run options:</p>
<a name="Running-tests"></a>
<h1 >Running tests:<a href="#Running-tests" class="wiki-anchor">¶</a></h1>
<p>[1/1] X#test_fail</p>
<ol>
<li>Failure:<br>
test_fail(X) [-e:1]:<br>
Expected 3.even? to return true.<br>
=end</li>
</ol> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=262102012-04-26T16:58:24Zfxn (Xavier Noria)fxn@hashref.com
<ul></ul><p>Hmmm... if I have</p>
<pre><code># Returns true if the user has first and last names.
def name_complete?
@first_name && @last_name
end
</code></pre>
<p>I'd like to be able to continue testing that as</p>
<pre><code>assert user.name_complete?
</code></pre>
<p>the alternative</p>
<pre><code>assert_send([user, :name_complete?])
</code></pre>
<p>seems very obscure to me for testing such an ordinary method. (And since the contract says nothing about the return value, there's no point in testing that if true you get the last name.)</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=262122012-04-26T17:07:37Zfxn (Xavier Noria)fxn@hashref.com
<ul></ul><p>In my view those are a kind of predicates that deserve to be tested using a straightforward assertion call. They are common, for example</p>
<pre><code># Says whether there's a user in the session.
def logged_in?
@current_user
end
</code></pre>
<p>or</p>
<pre><code># Says whether the request is Ajax.
def xml_http_request?
@env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
end
</code></pre>
<p>etc.</p>
<p>If true, the former returns a User object, and the latter an integer. But that does not belong to their interfaces and you don't test it. You only test them as predicates.</p> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=332952012-11-20T22:41:16Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Target version</strong> set to <i>2.6</i></li></ul> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=451542014-02-14T10:12:07Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/45154/diff?detail_id=32603">diff</a>)</li></ul> Ruby master - Feature #3219: assert now passes non-boolean resulthttps://bugs.ruby-lang.org/issues/3219?journal_id=679242017-11-27T07:29:36Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul><p>I don't remember this ticket, but I guess this request should be handled in <a href="https://github.com/test-unit/test-unit" class="external">the upstream of test/unit</a>. (Or, if you want to change <code>test/lib/minitest</code>, please change freely.)</p>