百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rails5-spec-converter

> 编程语言
开源

一个用于将 Rails 4 样式的规范升级为 Rails 5 样式的工具

177 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个用于将 Rails 4 样式的规范升级为 Rails 5 样式的工具

Rails5 Spec Converter

A script that fixes the syntax of your tests so Rails 5 will like them better. Inspired by transpec, the RSpec 2 -> 3 syntax conversion tool.

If you write a test like this:

get :users, search: 'bayleef', format: :json
expect(response).to be_success

Rails 5 will issue a hearty deprecation warning, persuading you to write this instead:

get :users, params: { search: 'bayleef' }, format: :json
expect(response).to be_success

This is great! That syntax is great. However, if you have a thousand tests lying around, it will probably be very time consuming to find all the places where you need to fix that.

Installation

Install the gem standalone like so:

$ gem install rails5-spec-converter

Usage

Make sure you've committed everything to Git first, then

$ cd some-project
$ rails5-spec-converter

This will update all the files in that directory matching the globs spec/**/*_spec.rb or test/**/*_test.rb.

If you want to specify a specific set of files instead, you can run rails5-spec-converter path_to_my_files.

By default it will make some noise, run with rails5-spec-converter --quiet if you want it not to.

Whitespace

Indentation

The tool will attempt to indent the newly-added "params" hash in situations when the arguments are on newlines, e.g.:

  get :index
      search: 'bayleef',
      format: :json

becomes

  get :index
      params: {
        search: 'bayleef'
      },
      format: :json

Since the extra spaces in front of 'params' are brand-new whitespace, you may want to configure them (default is 2 spaces).

rails5-spec-converter --indent ' '

rails5-spec-converter --indent '\t'

Hash Spacing

By default, for single-line hashes, a single space will be added after the opening curly brace and before the ending curly brace. The space will be omitted if the new params hash will contain any hash literals that do not have surrounding whitespace, ex:

post :users, user: {name: 'bayleef'}

becomes

post :users, params: {user: {name: 'bayleef'}}
  • --no-hash-spacing will force hashes to be written without extra whitespace in all files regardless of context.

  • --hash-spacing will force hashes to be written with extra whitespace in all files regardless of context.

Compatibility

It should work for both RSpec and MiniTest, but who really knows?

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rspec spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tjgrathwell/rails5-spec-converter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Contact

If this Gem helped you out at all, or it didn't help because you wanted it to do something different or it broke all your computer code, please let me know on twitter @tjgrathwell

License

The gem is available as open source under the terms of the MIT License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言