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

Discussion in 'Ruby' started by Collin Miller, Aug 10, 2007.

  1. 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.
     
    Collin Miller, Aug 10, 2007
    #1
    1. Advertising

  2. Collin Miller

    Guest

    Hi --

    On Sat, 11 Aug 2007, Collin Miller wrote:

    > 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.


    What exactly is on the lines mentioned in the error messages?


    David

    --
    * Books:
    RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
    RUBY FOR RAILS (http://www.manning.com/black)
    * Ruby/Rails training
    & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)
     
    , Aug 10, 2007
    #2
    1. Advertising

  3. 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.
     
    Collin Miller, Aug 10, 2007
    #3
  4. 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 <> 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.
     
    Collin Miller, Aug 10, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edvard Majakari
    Replies:
    4
    Views:
    687
    Edvard Majakari
    Feb 25, 2005
  2. VvanN
    Replies:
    5
    Views:
    489
    Phlip
    Apr 28, 2006
  3. Robert Klemme

    Method test::unit::TestSuite#<<(test)

    Robert Klemme, Aug 6, 2003, in forum: Ruby
    Replies:
    0
    Views:
    104
    Robert Klemme
    Aug 6, 2003
  4. Johan Holmberg
    Replies:
    7
    Views:
    167
    Johan Holmberg
    Sep 15, 2003
  5. timr
    Replies:
    2
    Views:
    167
Loading...

Share This Page