From: Trans Date: 2005-10-29T01:27:04+09:00 Subject: Re: Cut-based AOP Ed Howland wrote: > > No problem, just something I've been thinking about. Brian Button (and > others,) have said in testing, don't test the disk, and don't test the > I/O subsystem, don't test the OS, and don't test the built-in std > library. So, if the application is supposed to do these things, then > they are hard to test. Which has given rise to many diverse ways of > addressing this via mocking, using interfaces, dependancy injection > and so forth. Which reminds me, I have some tests that are doing this that I need to fix. > Ruby is nice, because you can mess about with its innards, and thus > get around some of these difficulties. Although, with TDDing and > refactoring, you shouldn't paint yourself into corners in the first > place. But for legacy code, this approach has some merit, IMO. > > AOP strategies for unit testing are nothing new: > http://blogs.codehaus.org/people/vmassol/archives/000138_aop_unit_testing_example.html > > Another potential use of AOP with testing is in fault injection: > > cut IMHacker < Kernel > def exec(command, *args) > raise SecurityError "Caught ya, you lazy good-fer-nuthing low-life" > ... > end > end LOL :) IOn this case though Kernel is module, so you can't cut it (cause you can't sublcass it) But of course you could cut Object or use a module and preclude: module IMHacker def exec(command, *args) raise SecurityError "Caught ya, you lazy good-fer-nuthing low-life" ... end end Kernel.preclude IMhacker > def test_catchem > assert_raise(SecurityError) { exec("cat /etc/passwd") } > end > > .. where the exec call would really be buried in another class somewhere. > > Any is there any prototypes of this available anywhere, or is it too > soon to ask that yet? Yes, though it doesn't do everything mentioned in the RCR, but it does the basics: http://rubyforge.org/frs/?group_id=137 > I'd vote for this, but RCRchive won't let me in. Thanks. We've got a good favorable margin so it's okay, but I hope you find out what's wrong. T.