I was just converting some Test::Unit tests to Rspec, and these regexps were handy. In one file, they handled 51 out of 53 lines, saving my fingers a lot of work. Tests can take an infinite variety of formats, so these obviously won't apply to everything, but they do illustrate how to use regexp substitution. This is using TextMate, your regexp implementation may vary...

from -> to
search string
replace string

def test_foo -> it "test_foo" do
def (test_[a-z_]*)
it "$1" do

assert !foo -> foo.should_not be_true
assert !(.*)$
$1.should_not be_true

assert foo -> foo.should be_true
assert (.*)$
$1.should be_true

assert_equal foo, bar -> bar.should == foo
assert_equal (.*), (.*)$
$2.should == $1

Comments

  1. Gen Du Gen Du on January 16, 2008 at 02:22AM

    Test::Unit to RSpec... so depressing :) .

  2. Chad Woolley Chad Woolley on January 18, 2008 at 01:35AM

    Variety is the spice of life ;)

Add a Comment (MarkDown available)