From: Jeremy Bopp Date: 2010-11-03T23:20:12+09:00 Subject: Re: Inversion of Control in Ruby by passing classes - does it make any sense? On 11/3/2010 9:06 AM, Robert Klemme wrote: > On Wed, Nov 3, 2010 at 3:00 PM, Jeremy Bopp wrote: >> On 11/3/2010 5:20 AM, Robert Klemme wrote: >>> On Tue, Nov 2, 2010 at 9:29 PM, Jeremy Bopp wrote: >>>> What I'm about to suggest will generate warnings from Ruby and is >>>> probably not the "best" way, but you could also replace OtherClass with >>>> your MockLoggerClass with a simple assignment during your test: >>>> >>>> OtherClass = MockLoggerClass # This generates a warning... >>>> s = SomeClass.new >>>> s.do_something(1, 2) >>> >>> This is not exactly the same as it does not allow control over the >>> created instance per instance. You basically change global state vs. >>> Manuel's approach with local state. >> >> I agree, but I was approaching this from a minimal unit test standpoint >> rather than a generally applicable part of Manuel's design. Would you >> say that changing the global state in this way or in the other way I >> suggested is still a problem in that case? > > I cannot really tell. Maybe, if you need different loggers in > different unit tests and mix in multi threading to make your test > suite finish faster. :-) > > But I do know that global state is problematic. I guess you can find > plenty of evidence on the web (or reason about it for yourself / > according to your own code). It should be used with extra care. I > try to avoid it whenever possible and that approach has served me > well. I'll keep that in mind. Thanks for the tips. ;-) -Jeremy