From: Massimiliano Mirra Date: 2002-05-24T21:27:37+09:00 Subject: Re: [RDoc etc] automatic documentation: using tests in addition to / instead of comments On Fri, May 24, 2002 at 05:51:00AM +0900, Jean-Hugues ROBERT wrote: > >I usually put each major class in its own file together with its > >tests. The interpreter only sees the tests if the file to be run is > >the one that contains them, not if the file was required in another > >file. > I like that. What happens if code is "loaded" instead of "required" ? Actually I don't know, I never use `load'. > >I do it this way because this allows to iteratively run and develop > >the class being working on. From Emacs it goes like: write test, run > >with C-c s, see test results, modify class, run, and so on. No > >loading or saving involved, speed goes up. > > I do differently. I do C-c C-s once for all. Then I do C-c C-l to load > the file. This way I save the time it takes to start IRB, stop it and > close the *ruby* buffer. Occasionnaly I have to to C-c C-s again, specially > when some constants need to be cleared, but I avoid it most of the > time. When I referred to C-c s I did not mean a shortcut to the run-ruby function, but a shortcut to a function defined in .emacs: (defun ruby-eval-buffer () (interactive) "Evaluate the buffer with ruby." (shell-command-on-region (point-min) (point-max) "ruby")) ...which gets tied to ruby-mode by the following: (defun ruby-custom-setup () (setq tab-width 2) (define-key ruby-mode-map "\C-cs" 'ruby-eval-buffer) ) (add-hook 'ruby-mode-hook 'ruby-custom-setup) This way there is no irb involved and, when a test is successful and there is little output, there is no buffer to be closed because it will disappear at the first keystroke (default emacs behaviour when output buffer contains little stuff) whereas it will stay open when there is much output, presumably errors, giving a chance to locate and check them. I can see the advantage of your method in that it does not need to reload the interpreter each time. Also, running in irb I assume it allows user interaction, whereas just eval'ing the buffer does not. Massimiliano