[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Unwanted behavior with "define" method an Test::Unit

collintmiller

8/10/2007 5:49:00 PM

I'm using "define_method" to build some unit test helpers.

They look as such:

class Test::Unit::TestCase
def self.name_of_test_helper
define_method("test_whatever_for_#{custom_name}") {
assert something_about(custom_name)
}
end
end

When I run my tests I get pages and pages of this:

../test/model_helper.rb:7: warning: multiple values for a block
parameter (0 for 1)
from ./test/unit/../test_helper.rb:54
../test/model_helper.rb:7: warning: multiple values for a block
parameter (0 for 1)
from ./test/unit/../test_helper.rb:53

Everything works out just fine, the tests test what I want them to
test. I just don't want all these errors.

3 Answers

David A. Black

8/10/2007 6:07:00 PM

0

collintmiller

8/10/2007 6:23:00 PM

0

line 7: define_method("create_#{model_name}") { |attrs|

Line 7 seems to be the problem line.

I think I want to do this:
define_method("create_#{model_name}") { |attrs={}|

But I cannot. I can still use the defined method and not send it an
argument, but then Ruby complains.


collintmiller

8/10/2007 6:45:00 PM

0

Found this:

-----------------
Not sure if this is the most elegant way, but:

define_method(:method_name) do |*args|
parameter, parameter2 = *args
parameter2 ||= 'default'
puts parameter
puts parameter2
end
-----------------

That'll do for now.

On Aug 10, 1:23 pm, Collin Miller <collintmil...@gmail.com> wrote:
> line 7: define_method("create_#{model_name}") { |attrs|
>
> Line 7 seems to be the problem line.
>
> I think I want to do this:
> define_method("create_#{model_name}") { |attrs={}|
>
> But I cannot. I can still use the defined method and not send it an
> argument, but then Ruby complains.