Also, you can use it on your RSpec 2 project even if you’re not going to upgrade it to RSpec 3 for now.
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.
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.
$ gem install transpec
Normally you don’t need to add
transpec to your
*.gemspec since this isn’t a tool to be used daily.
Before converting your specs:
rspec gem dependency 2.14 or later. If not, change your
*.gemspec to do so.
rspec and check if all the specs pass.
transpec in the project root directory:
$ cd some-project $ transpec
This will run the specs, convert them, and overwrite all spec files in the
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!