# Test/unit inconsistencies between 1.9 and 1.8

**URL:** <https://www.ruby-forum.com/t/test-unit-inconsistencies-between-1-9-and-1-8/92879>\
**Category:** Ruby\
**Created:** [April 25, 2007, 9:29am UTC](https://www.ruby-forum.com/t/test-unit-inconsistencies-between-1-9-and-1-8/92879 "2007-04-25T09:29:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adambeazley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@adambeazley](https://www.ruby-forum.com/u/adambeazley)\
**Post date:** [April 25, 2007, 9:29am UTC](https://www.ruby-forum.com/t/test-unit-inconsistencies-between-1-9-and-1-8/92879/1 "2007-04-25T09:29:46Z")

</div>

Hello,

We’re having problems with ruby 1.9 and test/unit. It looks like when  
ObjectSpace is scanned that the methods we are defining aren’t being  
seen.

Any suggestions?

Thanks,  
-Adam

% cat 19test.rb  
[~/code/planb/root]  
require ‘test/unit’

class Foo  
attr\_reader :attrs  
def initialize  
@attrs = Hash.new  
(“A”…“Z”).each { |x| @attrs[x] = x.downcase }  
end  
end

tclass = Class.new( Test::Unit::TestCase )  
Foo.const\_set “TestAttr” , tclass

Foo.new.attrs.each\_pair do |key,value|  
tclass.class\_eval do  
define\_method(“test\_#{key}”) do  
assert\_equal(key,value.upcase)  
end  
end  
end

% /usr/bin/ruby -v  
[~/code/planb/root]  
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin8.9.1]  
% /usr/bin/ruby 19test.rb  
[~/code/planb/root]  
Loaded suite 19test  
Started  
…  
Finished in 0.002402 seconds.

26 tests, 26 assertions, 0 failures, 0 errors  
% /opt/bin/ruby -v  
[~/code/planb/root]  
ruby 1.9.0 (2007-04-24 patchlevel 0) [i686-darwin8.9.1]  
% /opt/bin/ruby 19test.rb  
[~/code/planb/root]  
Loaded suite 19test  
Started  
F  
Finished in 0.000685 seconds.

1. Failure:  
default\_test(Foo::TestAttr)  
[/opt/lib/ruby/1.9/test/unit/assertions.rb:48:in `raise' /opt/lib/ruby/1.9/test/unit/assertions.rb:48:in`block in  
assert\_block’  
/opt/lib/ruby/1.9/test/unit/assertions.rb:495:in `_wrap_assertion' /opt/lib/ruby/1.9/test/unit/assertions.rb:11240:in`assert\_block’  
/opt/lib/ruby/1.9/test/unit/assertions.rb:313:in `flunk' /opt/lib/ruby/1.9/test/unit/testcase.rb:107:in`default\_test’  
/opt/lib/ruby/1.9/test/unit/testcase.rb:76:in `run' /opt/lib/ruby/1.9/test/unit/testsuite.rb:34:in`block in run’  
/opt/lib/ruby/1.9/test/unit/testsuite.rb:33:in `each' /opt/lib/ruby/1.9/test/unit/testsuite.rb:33:in`run’  
/opt/lib/ruby/1.9/test/unit/testsuite.rb:34:in `block in run' /opt/lib/ruby/1.9/test/unit/testsuite.rb:33:in`each’  
/opt/lib/ruby/1.9/test/unit/testsuite.rb:33:in `run' /opt/lib/ruby/1.9/test/unit/ui/testrunnermediator.rb:46:in`run\_suite’  
/opt/lib/ruby/1.9/test/unit/ui/console/testrunner.rb:67:in  
`start_mediator' /opt/lib/ruby/1.9/test/unit/ui/console/testrunner.rb:41:in`start’  
/opt/lib/ruby/1.9/test/unit/ui/testrunnerutilities.rb:29:in `run' /opt/lib/ruby/1.9/test/unit/autorunner.rb:215:in`run’  
/opt/lib/ruby/1.9/test/unit/autorunner.rb:12:in `run' /opt/lib/ruby/1.9/test/unit.rb:278:in`block in \<top (required)\>’]:  
No tests were specified.

1 tests, 1 assertions, 1 failures, 0 errors

---

<div class="post-metadata">

**Author:** ![adambeazley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@adambeazley](https://www.ruby-forum.com/u/adambeazley)\
**Post date:** [April 26, 2007, 8:57am UTC](https://www.ruby-forum.com/t/test-unit-inconsistencies-between-1-9-and-1-8/92879/2 "2007-04-26T08:57:10Z")

</div>

I located the problem, below is a small patch ( copy & paste from  
1.8sources ).

It appears that a block/proc with no arguments has arity -1.

irb(main):001:0\> proc { }.arity  
=\> -1  
irb(main):002:0\> proc {|| }.arity  
=\> -1

and that somebody forgot about that below.

-Adam

# Index: lib/test/unit/testcase.rb

— lib/test/unit/testcase.rb (revision 12221)  
+++ lib/test/unit/testcase.rb (working copy)  
@@ -37,7 +37,9 @@  
# Creates a new instance of the fixture for running the  
# test represented by test\_method\_name.  
def initialize(test\_method\_name)

- 

```
   unless(respond_to?(test_method_name) &&

```

method(test\_method\_name).arity == 0)

- 

```
   unless(respond_to?(test_method_name) and

```

- 

```
          (method(test_method_name).arity == 0 ||

```

- 

```
           method(test_method_name).arity == -1))
     throw :invalid_test
   end
   @method_name = test_method_name
```

---

<div class="post-metadata">

**Author:** ![adambeazley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@adambeazley](https://www.ruby-forum.com/u/adambeazley)\
**Post date:** [April 26, 2007, 10:03am UTC](https://www.ruby-forum.com/t/test-unit-inconsistencies-between-1-9-and-1-8/92879/3 "2007-04-26T10:03:20Z")

</div>

On Apr 25, 2007, at 23:56 , Adam B. wrote:

> I located the problem, below is a small patch ( copy & paste from  
> 1.8sources ).

Awesome. Please post the patch to the ruby project on [rubyforge.org](http://rubyforge.org).

thanks!

---

<div class="post-metadata">

**Author:** ![adambeazley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@adambeazley](https://www.ruby-forum.com/u/adambeazley)\
**Post date:** [April 26, 2007, 11:57am UTC](https://www.ruby-forum.com/t/test-unit-inconsistencies-between-1-9-and-1-8/92879/4 "2007-04-26T11:57:35Z")

</div>

On 4/26/07, Mauricio F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> RUBY\_RELEASE\_DATE # =\> “2007-02-07”  
> proc{}.arity # =\> 0  
> proc{||}.arity # =\> 0  
> Proc.new{}.arity # =\> 0

Strange, must be a regression.

irb(main):001:0\> RUBY\_VERSION  
=\> “1.9.0”  
irb(main):002:0\> RUBY\_RELEASE\_DATE  
=\> “2007-04-26”  
irb(main):003:0\> proc{}.arity  
=\> -1  
irb(main):004:0\> proc{||}.arity  
=\> -1  
irb(main):005:0\> Proc.new{}.arity  
=\> -1

---

<div class="post-metadata">

**Author:** ![adambeazley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@adambeazley](https://www.ruby-forum.com/u/adambeazley)\
**Post date:** [April 26, 2007, 11:46am UTC](https://www.ruby-forum.com/t/test-unit-inconsistencies-between-1-9-and-1-8/92879/5 "2007-04-26T11:46:31Z")

</div>

On Thu, Apr 26, 2007 at 03:56:25PM +0900, Adam B. wrote:

> and that somebody forgot about that below.
> 
> -Adam
> 
> # Index: lib/test/unit/testcase.rb
> 
> — lib/test/unit/testcase.rb (revision 12221)  
> +++ lib/test/unit/testcase.rb (working copy)  
> […]

?  
AFAIK #arity was redefined in 1.9 to return 0 for Procs with no  
arguments.  
That patch was applied to 1.8 three years ago but it’s not supposed to  
be  
needed on 1.9, see [ruby-core:2829].

Also,

RUBY\_VERSION # =\> “1.9.0”  
RUBY\_RELEASE\_DATE # =\> “2007-02-07”  
proc{}.arity # =\> 0  
proc{||}.arity # =\> 0  
Proc.new{}.arity # =\> 0  
require ‘test/unit’  
class TC \< Test::Unit::TestCase  
define\_method(“test\_foo”){ assert true }  
end

# \>\> Loaded suite -

# \>\> Started

# \>\> .

# \>\> Finished in 0.001363 seconds.

# \>\>

# \>\> 1 tests, 1 assertions, 0 failures, 0 errors

I can’t see any recent reference to arity in the Changelog, and  
proc\_arity is identical to the one in my build:  
[http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/proc.c?revision=12212&view=markup](http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/proc.c?revision=12212&view=markup)

Has this really changed in the last couple months? If so, there’s a bug,  
either in the Rdoc documentation or the code.

---

<div class="post-metadata">

**Author:** ![adambeazley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@adambeazley](https://www.ruby-forum.com/u/adambeazley)\
**Post date:** [April 26, 2007, 12:29pm UTC](https://www.ruby-forum.com/t/test-unit-inconsistencies-between-1-9-and-1-8/92879/6 "2007-04-26T12:29:37Z")

</div>

On Thu, Apr 26, 2007 at 06:56:45PM +0900, Adam B. wrote:

> =\> “1.9.0”  
> irb(main):002:0\> RUBY\_RELEASE\_DATE  
> =\> “2007-04-26”  
> irb(main):003:0\> proc{}.arity  
> =\> -1  
> irb(main):004:0\> proc{||}.arity  
> =\> -1  
> irb(main):005:0\> Proc.new{}.arity  
> =\> -1

Yes, I’ve traced it back to this:

Wed Mar 21 20:05:07 2007 Koichi Sasada [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

- compile.c, parse.y, eval.c, intern.h, iseq.c, lex.c, node.h,  
proc.c, vm.c, vm\_macro.def, vm\_macro.def, yarvcore.c, yarvcore.h,  
debug.c, debug.h: merge half-baked-1.9 changes. The biggest change  
is to change node structure around NODE\_SCOPE, NODE\_ARGS. Every  
scope (method/class/block) has own NODE\_SCOPE node and NODE\_ARGS  
represents more details of arguments information. I’ll write a  
document about detail of node structure.

I’ve sent a bug report to ruby-core.
