Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Using Search and Replace Regular Expressions to Convert from Test::Unit to Rspec

Chad Woolley
Saturday, June 2, 2007

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
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

2 Comments

  1. Gen Du says:

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

    January 16, 2008 at 2:22 am

  2. Chad Woolley says:

    Variety is the spice of life ;)

    January 18, 2008 at 1:35 am

Add New Comment Cancel reply

Your email address will not be published.

Chad Woolley

Chad Woolley
Denver

Recent Posts

  • Automating Bundler In Your Deploy
  • [ANN] GemInstaller 0.5.3 Released
  • The Great Ruby IDE Smackdown of '09
Subscribe to Chad's Feed

Author Topics

bundler (1)
geminstaller (2)
open source (5)
rubygems (4)
ide (1)
ruby on rails (5)
gogaruco (19)
government (1)
agile (18)
pivotaltracker (1)
testing (2)
mac (2)
remote (1)
rant (1)
mtnwestrubyconf (1)
dependency injection (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >