A magical tool for converting your specs to the latest RSpec syntax.

View on GitHub

RSpec 3 ready

Transpec lets you upgrade your RSpec 2 specs to RSpec 3 in no time. It supports conversions for almost all of the RSpec 3 changes, and it’s officially recommended by the RSpec team.

Also, you can use it on your RSpec 2 project even if you’re not going to upgrade it to RSpec 3 for now.

Robust conversion

Transpec is not an error-prone regexp-ish thing. It parses your Ruby code and performs static code analysis. This means, for example, it can recognize whether a mock is a method invocation or a local variable.

Furthermore, with dynamic code analysis, it inspects whether a mock is a RSpec method or another method with the same name.

Sane code style

You don’t want to rewrite your specs by hand nor do you want a quick-and-dirty job by poorly written software.

Transpec converts your specs while honoring your code style such as line breaks, indentations and parentheses as much as possible. Also the conversion behavior can be customized with command line options.


Simply install transpec with gem command:

$ gem install transpec

Normally you don’t need to add transpec to your Gemfile or *.gemspec since this isn’t a tool to be used daily.

Basic Usage

Before converting your specs:

Then, run transpec in the project root directory:

$ cd some-project
$ transpec

This will run the specs, convert them, and overwrite all spec files in the spec directory.

After the conversion, run rspec again and check whether everything is still green:

$ bundle exec rspec

If it’s green, commit the changes with an auto-generated message that describes the conversion summary and helps your team members to understand the new syntax:

$ git commit -aeF .git/COMMIT_EDITMSG

And you are done!

Who’s used it?