require problem with syntax errors

Discussion in 'Ruby' started by David Corbin, Jul 1, 2005.

  1. David Corbin

    David Corbin Guest

    I have written a little "test suite" for my use in developing a rails
    application (I know about "rake test_units", but that won't work in my IDE of
    choice). So, if I run unitTest.rb, all my tests run.

    The problem I'm having, is if I have syntax errors, I still get a green bar
    (fewer tests are shown), and there is NO indication of syntax errors, if one
    of the required test files has syntax errors.

    Help me understand why the there's no trace of syntax error when the required
    file has one.

    Thanks
    David

    -- begin unitTestSuite.rb--
    require "test_helper"
    require "test_builder"

    requireAllTests("test/unit/**/*.rb")

    --end--
    --begin test_builder.rb--
    def requireAllTests(pattern)
    Dir.glob(pattern).each do |file|
    require file
    end
    end

    ----
     
    David Corbin, Jul 1, 2005
    #1
    1. Advertising

  2. David Corbin

    Pit Capitain Guest

    David Corbin schrieb:
    > The problem I'm having, is if I have syntax errors, I still get a green bar
    > (fewer tests are shown), and there is NO indication of syntax errors, if one
    > of the required test files has syntax errors.
    >
    > Help me understand why the there's no trace of syntax error when the required
    > file has one.
    >
    > def requireAllTests(pattern)
    > Dir.glob(pattern).each do |file|
    > require file
    > end
    > end


    Hi David,

    I haven't looked where this happens, but it seems that test/unit
    discards those errors. When this happened to me, I simply catched the
    load errors myself and reported them with puts.

    You write that you get a green bar, so I assume you're running a
    graphical frontend. In this case, I guess a simple puts wouldn't be
    enough. You could try the following code, which creates a new TestCase
    class for each load error in order to present them as a failing test:

    def requireAllTests(pattern)
    Dir.glob(pattern).each do |file|
    begin
    require file
    rescue Exception => e
    Class.new(Test::Unit::TestCase) do
    define_method:)test_load) do ||
    flunk("#{file}: #{e}")
    end
    public :test_load
    end
    end
    end
    end

    Regards,
    Pit
     
    Pit Capitain, Jul 2, 2005
    #2
    1. Advertising

  3. David Corbin

    David Corbin Guest

    On Saturday 02 July 2005 01:54 am, Pit Capitain wrote:
    > David Corbin schrieb:
    > > The problem I'm having, is if I have syntax errors, I still get a green
    > > bar (fewer tests are shown), and there is NO indication of syntax errors,
    > > if one of the required test files has syntax errors.
    > >
    > > Help me understand why the there's no trace of syntax error when the
    > > required file has one.
    > >
    > > def requireAllTests(pattern)
    > > Dir.glob(pattern).each do |file|
    > > require file
    > > end
    > > end

    >
    > Hi David,
    >
    > I haven't looked where this happens, but it seems that test/unit
    > discards those errors. When this happened to me, I simply catched the
    > load errors myself and reported them with puts.


    There don't seem to be any errors raised. I tried the puts, and I do have a
    console window, but nothing shows up.

    I tried your example too, and get nothing.

    David
     
    David Corbin, Jul 2, 2005
    #3
  4. David Corbin

    Pit Capitain Guest

    David Corbin schrieb:
    > There don't seem to be any errors raised. I tried the puts, and I do have a
    > console window, but nothing shows up.
    >
    > I tried your example too, and get nothing.


    Weird. If you want, you can send your files to my mail address and I'll
    have a short look.

    Regards,
    Pit
     
    Pit Capitain, Jul 3, 2005
    #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. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    964
    Mark Goldin
    Jan 17, 2004
  2. SenthilVel
    Replies:
    0
    Views:
    947
    SenthilVel
    Jun 7, 2006
  3. yawnmoth
    Replies:
    97
    Views:
    4,727
    Bent C Dalager
    Feb 27, 2009
  4. David Naseby

    Require errors for rubygems

    David Naseby, Nov 16, 2004, in forum: Ruby
    Replies:
    1
    Views:
    114
    Gavin Sinclair
    Nov 16, 2004
  5. James Adam
    Replies:
    15
    Views:
    262
Loading...

Share This Page