require problem with syntax errors

D

David Corbin

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

----
 
P

Pit Capitain

David said:
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
 
D

David Corbin

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
 
P

Pit Capitain

David said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,490
Latest member
Finplus

Latest Threads

Top