eigenclass logo
MAIN  Index  Search  Changes  PageRank  Login

xmpfilter 0.3.1: RSpec support, emacs love, win32 compatibility

xmpfilter is a small tool that can be used to

  • generate Test::Unit assertions and RSpec expectations semi-automatically
  • annotate source code with intermediate results (a bit like irb --simple-prompt but only for the lines explicitly marked with # =>). Very useful for example code (such as postings to ruby-talk).

As of 0.3.1, xmpfilter can generate RSpec expectations in addition to Test::Unit assertions, as shown in this animation: rspec.gif

xmpfilter can be used conveniently from any decent editor (see README.vim and README.emacs for examples). xmpfilter 0.3.1 works on win32 and solves a couple minor bugs in 0.3.0.


Get xmpfilter here.

Patch for xmpfilter 0.3.1 - eao197 (2006-12-29 (Fri) 03:14:40)

There is a small bug in xmpfilter.rb 0.3.1: command-line argument '-l' does not handled properly. This is a patch:

--- D:\usr\xmpfilter-0.3.1\xmpfilter.rb	2006-10-17 18:21:47.000000000 +0400
+++ xmpfilter.rb	2006-12-02 20:00:30.404125000 +0300
@@ -301,7 +301,7 @@
     opts.on("-S FILE", "--interpreter FILE", "Use interpreter FILE.") do |interpreter|
       options.interpreter = interpreter
-    opts.on("-l N", "--min-line-length N", Integer, "Align markers to N spaces.") do |interpreter|
+    opts.on("-l N", "--min-line-length N", Integer, "Align markers to N spaces.") do |min_codeline_size|
       options.min_codeline_size = min_codeline_size
     opts.on("--[no]-delimiters", "Put delimiters around code.",

Thank for a very useful tool -- xmplfilter!

mfp 2006-12-29 (Fri) 04:30:42

thx, applied it to the new version (included in rcodetools) that is being released later today :-)

Windows? - Anonymous (2006-10-17 (Tue) 18:26:21)

Does it work in windows? I had trouble getting it going.

Anonymous 2006-10-17 (Tue) 19:18:03

Scratch that. Works under windows ok but I'm just having trouble getting it to work with Rails unit tests. No error is coming up. It just doesn't fill in the annotations.

mfp 2006-10-18 (Wed) 03:49:02

Rails' tests are special in that they have lots of dependencies and they do some nasty tricks to configure the environment (such as the infamous require(File.dirname(__FILE__)+"../../foo/bar/baz.rb")). If the script being filtered doesn't execute correctly, xmpfilter will not be able to add any annotations.

Passing some -rsomelib options to xmpfilter might help, but it might not be enough. I'm looking into this.

Anonymous 2006-10-18 (Wed) 19:41:36

I noticed that the code writes out temporary files in the default temp direction. I suspect this is the cause of the issue because of the File.dirname(__FILE__) trick you mentioned. I suspect generating the temp files into the same directory might help (as long as they got deleted after!).

mfp 2006-10-19 (Thr) 03:15:58

Yes, that's part of the problem. I've pushed a couple patches to:

  • create the temporary files in the current WD
  • specify the WD (--cd dir)

Another problem with Rails' unit tests is that you normally need to run rake db:test:prepare at least once before the tests can be executed.

I'm probably adding a --rails option which will set the WD and change a few other things.

mfp 2006-10-20 (Fri) 04:38:06

Alright, I've implemented --rails, which:

  • sets --poetry (no parentheses)
  • disables warnings (--no-warnings)
  • generates Test::Unit assertions (-u)
  • tries to change to the correct working dir

You can find a version with all these changes (and some more) in the darcs repository at http://eigenclass.org/repos/xmpfilter/

Anonymous 2006-10-23 (Mon) 19:14:45

Hi. I tried out the new rails version (from darcs) under windows at it seems there are some additional issues. Line 84:

at_exit { File.unlink fname }

comes back with a permission denied error (presumably the file is still open when it tried to delete it).

if you comment this out you run across another problem on line 49.

output = stderr.readlines

`readlines': not opened for reading (IOError)

screencast - technomancy (2006-10-17 (Tue) 11:10:10)

How'd you generate that gif? It looks great.

mfp 2006-10-17 (Tue) 17:36:52

It's just x11rec (which happens to be written in Ruby) recording a vim session inside urxvt.

Last modified:2006/10/17 09:27:08
Keyword(s):[blog] [ruby] [frontpage] [xmpfilter] [0.3.1] [release]