From: patrick-may@... (Patrick May) Date: 2002-08-12T12:06:39+09:00 Subject: Re: Testing for mod_ruby (was "how do i mock the presence / absence of a constant w/out getting warnings?") nobu.nokada@softhome.net wrote in message news:<200208110541.g7B5fvr27108@sharui.nakada.kanuma.tochigi.jp>... > Hi, > > At Sun, 11 Aug 2002 13:04:29 +0900, > Patrick May wrote: > > Thanks, this worked for me. Unfortunately, after I did > > > > Object.const_set( :MOD_RUBY, true ) > > > > in the context of the test, the check in my code (different context): > > > > if (defined? MOD_RUBY) > > > > continued to be false. If I checked in the body of the test method, > > this check returned true. Is this the expected behaviour? > > What are the contexts? This is roughly what was happening. A bit later this week, I'm going to sit down and really examine this problem. I was doing something like this: (note that this code is from memory. I'm not sure if this will run correctly or if it will reproduce my problem) class TestRequest < RUNIT::TestCase def teardown if (defined? MOD_RUBY) Object.module_eval{ remove_const :MOD_RUBY } end end def test_parse_with_mod_ruby Object.const_set( :MOD_RUBY, true ) assert( defined? MOD_RUBY ) # <= this was true assert( CGI::Request.mod_ruby? ) # <= this was false? end end class CGI class Request def Request.mod_ruby? defined? MOD_RUBY end end end By the end of this week, I'm going to sit down and examine this problem further. Then I will double check my code, and try to get a clear demonstration of my problem. Thanks, Patrick