From: GOTO Kentaro Date: 2002-08-08T15:13:18+09:00 Subject: Re: how do i mock the presence / absence of a constant w/out getting warnings? At Thu, 8 Aug 2002 13:25:41 +0900, Patrick May wrote: > I need to write tests for some behavior that needs to check a > constant: > > if (MOD_RUBY) > .... do stuff > else > .... do something else > end > > I can do it by having this sort of thing: > > MOD_RUBY = true > > and > > MOD_RUBY = false > > but I don't want to get the ruby warnings. What's another way for me > to mock this constant? Though I'm not sure what your goal is, how about: (1) ignore that warning. (2) do testing in different namespaces if it is possible. (3) use Module#remove_const: class C MOD_RUBY = true remove_const :MOD_RUBY MOD_RUBY = false end (4) use a class variable instead of a constant in the product. Hope this helps, -- Gotoken