Lately I was converting some of my projects to ruby 1.9, and I found that this code is no longer working:
raise if defined?(Test::Unit)
Throws:
uninitialized constant Test (NameError)
Ruby 1.8 silently works with that code. So, how do I need to handle this kind of checks in 1.9?
For now as a workaround I changed Test::Unit to Test and it works fine.
···
--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Spam Here -> postmaster@sco.com
In message "defined? in ruby-1.9" on 04/07/30, "Dmitry V. Sabanin" <sdmitry@lrn.ru> writes:
Lately I was converting some of my projects to ruby 1.9, and I found that this code is no longer working:
raise if defined?(Test::Unit)
Throws:
uninitialized constant Test (NameError)
Ruby 1.8 silently works with that code. So, how do I need to handle this kind of checks in 1.9?
For now as a workaround I changed Test::Unit to Test and it works fine.
Because 1.8 silently ignores NameError in the check for Test::Unit.
Well, no.. this code is used in exception-catching framework, so the point is to re-raise exception
if code is used for tests or to log it if it's in standalone use.
Sorry for providing non-obvious example
···
On Friday 30 July 2004 15:06, Robert Klemme wrote:
"Dmitry V. Sabanin" <sdmitry@lrn.ru> schrieb im Newsbeitrag
news:200407301222.10852.sdmitry@lrn.ru...
> Hi,
>
> Lately I was converting some of my projects to ruby 1.9, and I found
that this code is no longer working:
> raise if defined?(Test::Unit)
I guess you intended to write
raise unless defined? Test::Unit
--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Spam Here -> postmaster@sco.com
but isn't that what 'defined?' is for? to determine if the compiler has seen
a 'name' yet?
-a
···
On Fri, 30 Jul 2004, Yukihiro Matsumoto wrote:
Hi,
In message "defined? in ruby-1.9" > on 04/07/30, "Dmitry V. Sabanin" <sdmitry@lrn.ru> writes:
>Lately I was converting some of my projects to ruby 1.9, and I found that this code is no longer working:
> raise if defined?(Test::Unit)
>Throws:
> uninitialized constant Test (NameError)
>
>Ruby 1.8 silently works with that code. So, how do I need to handle this kind of checks in 1.9?
>For now as a workaround I changed Test::Unit to Test and it works fine.
Because 1.8 silently ignores NameError in the check for Test::Unit.
matz.
--
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen
"Dmitry V. Sabanin" <sdmitry@lrn.ru> schrieb im Newsbeitrag
news:200407301527.31849.sdmitry@lrn.ru...
> "Dmitry V. Sabanin" <sdmitry@lrn.ru> schrieb im Newsbeitrag
> news:200407301222.10852.sdmitry@lrn.ru...
>
> > Hi,
> >
> > Lately I was converting some of my projects to ruby 1.9, and I found
>
> that this code is no longer working:
> > raise if defined?(Test::Unit)
>
> I guess you intended to write
>
> raise unless defined? Test::Unit
Well, no.. this code is used in exception-catching framework, so the
point is to re-raise exception
if code is used for tests or to log it if it's in standalone use.
You have test specific code in production code? That sounds odd at
minimum. Care to uncover some more details?
Regards
robert
···
On Friday 30 July 2004 15:06, Robert Klemme wrote:
In message "defined? in ruby-1.9" >> on 04/07/30, "Dmitry V. Sabanin" <sdmitry@lrn.ru> writes:
>Lately I was converting some of my projects to ruby 1.9, and I found that this code is no longer working:
> raise if defined?(Test::Unit)
>Throws:
> uninitialized constant Test (NameError)
>
>Ruby 1.8 silently works with that code. So, how do I need to handle this kind of checks in 1.9?
>For now as a workaround I changed Test::Unit to Test and it works fine.
Because 1.8 silently ignores NameError in the check for Test::Unit.
matz.
but isn't that what 'defined?' is for? to determine if the compiler has seen
a 'name' yet?
I supposed the rational is that by running
defined?(Test::Unit)
You are checking if the Test class/module contains a constant Unit. If Test doesn't exist then Ruby can't check this, so it throws a NameError.
The obvious, though verbose, workaround would be to do
"Dmitry V. Sabanin" <sdmitry@lrn.ru> schrieb im Newsbeitrag
news:200407301527.31849.sdmitry@lrn.ru...
> > "Dmitry V. Sabanin" <sdmitry@lrn.ru> schrieb im Newsbeitrag
> > news:200407301222.10852.sdmitry@lrn.ru...
> >
> > > Hi,
> > >
> > > Lately I was converting some of my projects to ruby 1.9, and I found
> >
> > that this code is no longer working:
> > > raise if defined?(Test::Unit)
> >
> > I guess you intended to write
> >
> > raise unless defined? Test::Unit
>
> Well, no.. this code is used in exception-catching framework, so the
point is to re-raise exception
> if code is used for tests or to log it if it's in standalone use.
You have test specific code in production code? That sounds odd at
minimum. Care to uncover some more details?
I agree, but there's no other way to test modules for my web-framework, because it manages
exceptions raised in modules by itself. And the only test specific option in production code I
have is that line
···
On Friday 30 July 2004 16:31, Robert Klemme wrote:
> On Friday 30 July 2004 15:06, Robert Klemme wrote:
Regards
robert
--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Spam Here -> postmaster@sco.com
ah - hadn't thought of that. that it better than failing silently.
cheers.
-a
···
On Fri, 30 Jul 2004, Mark Sparshatt wrote:
Ara.T.Howard wrote:
On Fri, 30 Jul 2004, Yukihiro Matsumoto wrote:
Hi,
In message "defined? in ruby-1.9" >>> on 04/07/30, "Dmitry V. Sabanin" <sdmitry@lrn.ru> writes:
>Lately I was converting some of my projects to ruby 1.9, and I found
that this code is no longer working:
> raise if defined?(Test::Unit)
>Throws:
> uninitialized constant Test (NameError)
>
>Ruby 1.8 silently works with that code. So, how do I need to handle
this kind of checks in 1.9?
>For now as a workaround I changed Test::Unit to Test and it works
fine.
Because 1.8 silently ignores NameError in the check for Test::Unit.
matz.
but isn't that what 'defined?' is for? to determine if the compiler
has seen
a 'name' yet?
I supposed the rational is that by running
defined?(Test::Unit)
You are checking if the Test class/module contains a constant Unit. If
Test doesn't exist then Ruby can't check this, so it throws a NameError.
The obvious, though verbose, workaround would be to do
defined?(Test) && defined(Test::Unit)
--
Mark Sparshatt
--
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen
"Dmitry V. Sabanin" <sdmitry@lrn.ru> schrieb im Newsbeitrag
news:200407301939.15247.sdmitry@lrn.ru...
> "Dmitry V. Sabanin" <sdmitry@lrn.ru> schrieb im Newsbeitrag
> news:200407301527.31849.sdmitry@lrn.ru...
>
> > > "Dmitry V. Sabanin" <sdmitry@lrn.ru> schrieb im Newsbeitrag
> > > news:200407301222.10852.sdmitry@lrn.ru...
> > >
> > > > Hi,
> > > >
> > > > Lately I was converting some of my projects to ruby 1.9, and I
found
> > >
> > > that this code is no longer working:
> > > > raise if defined?(Test::Unit)
> > >
> > > I guess you intended to write
> > >
> > > raise unless defined? Test::Unit
> >
> > Well, no.. this code is used in exception-catching framework, so the
>
> point is to re-raise exception
>
> > if code is used for tests or to log it if it's in standalone use.
>
> You have test specific code in production code? That sounds odd at
> minimum. Care to uncover some more details?
I agree, but there's no other way to test modules for my web-framework,
because it manages
exceptions raised in modules by itself.
Ah, I see.
And the only test specific option in production code I
have is that line
Swear it by Ruby's life, that it's really the only line! (Sorry, the
heat might have damaged my brain... ;-))
Spam Here -> postmaster@sco.com
Hehe...
robert
···
On Friday 30 July 2004 16:31, Robert Klemme wrote:
> > On Friday 30 July 2004 15:06, Robert Klemme wrote: