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
About the Author