[MacRuby] #378: Macruby 0.5 allows instantiation of a Module instance
#378: Macruby 0.5 allows instantiation of a Module instance ---------------------------------------+------------------------------------ Reporter: keith.gautreaux@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: ---------------------------------------+------------------------------------ It seems that MacRuby treats modules differently than Ruby 1.9. You shouldn't be able to instantiate a named module using the new method, i.e. {{{ A = Module.new do def meth1 "hello" end end }}} YARV: {{{ a = A.new => NoMethodError: undefined method `new' for A:Module }}} but it does in MacRuby returning an instance of A:Module which responds to the meth1 call: {{{ a.meth1 =>"hello" }}} I believe the proper behavior (based on the 1.9 pickaxe documentation) is to allow extending of an object with A's methods but not instantiation. {{{ a = NSObject.new a.extend(A) a.meth1 => "hello" }}} Once I figure out how to write specs I'll see if I can submit a failing one. -- Ticket URL: <http://www.macruby.org/trac/ticket/378> MacRuby <http://macruby.org/>
#378: Macruby 0.5 allows instantiation of a Module instance ---------------------------------------+------------------------------------ Reporter: keith.gautreaux@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: ---------------------------------------+------------------------------------ Comment(by keith.gautreaux@…): Note: The above is a new ticket copied from a comment on Ticket #371. -- Ticket URL: <http://www.macruby.org/trac/ticket/378#comment:1> MacRuby <http://macruby.org/>
#378: Macruby 0.5 allows instantiation of a Module instance ---------------------------------------+------------------------------------ Reporter: keith.gautreaux@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: ---------------------------------------+------------------------------------ Comment(by eloy.de.enige@…): Hey, About writing specs, the rubyspec disallows the use of ‘should’. And it should be enough to verify that calling #new results in a NoMethodError, all the others should then fail as well. Also, if you want specify that an exception is raised, you should do so inside a proc. For instance: lambda { Fred.new }.should raise_error(NoMethodError). (For more info see the rubyspec wiki.) However, the rubyspec is about specifying what actually _does_ work on MRI, not about what doesn't. For these cases we have the test_vm test suite. In fact there was already a failing test similar to this case. Nonetheless I've added an extra failing test, based on your example, in r2851. Thanks. -- Ticket URL: <http://www.macruby.org/trac/ticket/378#comment:2> MacRuby <http://macruby.org/>
#378: Macruby 0.5 allows instantiation of a Module instance ---------------------------------------+------------------------------------ Reporter: keith.gautreaux@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: ---------------------------------------+------------------------------------ Comment(by keith.gautreaux@…): Replying to [comment:2 eloy.de.enige@…]:
Hey,
About writing specs, the rubyspec disallows the use of ‘should’. And it should be enough to verify that calling #new results in a NoMethodError, all the others should then fail as well. Also, if you want specify that an exception is raised, you should do so inside a proc. For instance: lambda { Fred.new }.should raise_error(NoMethodError). (For more info see the rubyspec wiki.)
However, the rubyspec is about specifying what actually _does_ work on MRI, not about what doesn't. For these cases we have the test_vm test suite. In fact there was already a failing test similar to this case. Nonetheless I've added an extra failing test, based on your example, in r2851.
Thanks.
Thanks very much for the info. I was unaware of the existing test or the rubyspec recommendations. Sorry, I haven't written any rubyspecs before. I appreciate your time. -- Ticket URL: <http://www.macruby.org/trac/ticket/378#comment:3> MacRuby <http://macruby.org/>
#378: Macruby 0.5 allows instantiation of a Module instance ---------------------------------------+------------------------------------ Reporter: keith.gautreaux@… | Owner: lsansonetti@… Type: defect | Status: new Priority: minor | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: ---------------------------------------+------------------------------------ Comment(by mred@…): Just wanted to point out that the underlying problem here is that 'Module.new' is returning an anonymous class instead of an anonymous module, which is why calls to 'new' are working. The following example shows what's being returned: {{{ a = Module.new do; end puts a }}} Ruby 1.9 prints '#<Module:0x...>' while MacRuby 0.6 prints '#<Class:0x...>' -- Ticket URL: <http://www.macruby.org/trac/ticket/378#comment:4> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby