规范Rubocop/Ruby风格指南 [英] RSpec & Rubocop / Ruby Style Guide

查看:86
本文介绍了规范Rubocop/Ruby风格指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当告诉Rails脚手架控制器生成rspec测试时,生成的文件不遵循 Ruby样式指南,因此 rubocop 会为此引发错误.

when telling the rails scaffold controller to generate rspec tests the generated files don't follow the Ruby Style Guide and thus rubocop throws errors on these.

只有几个警察"失败.样式/哈希语法,样式/字符串文字,样式/MethodCallParentheses,样式/SpaceInsideHashLiteral大括号,样式/块.

Only a couple of "cops" fail. Style/HashSyntax, Style/StringLiterals, Style/MethodCallParentheses, Style/SpaceInsideHashLiteralBraces, Style/Blocks.

我确实知道其中一些警察只是样式首选项,例如Style/StringLiterals(在不需要字符串插值或特殊符号的情况下,首选单引号的字符串.)

I do understand that some of these cops are just style preferences like for example Style/StringLiterals (Prefer single-quoted strings when you don't need string interpolation or special symbols.)

尽管如此,我还是希望我的测试符合rubocop.是否有人知道可以代替rspec-rails模板的宝石(例如

Nevertheless I'd like my tests to conform to rubocop. Is anyone aware of a gem that replaces the rspec-rails templates (e.g. controller_spec.rb) with ones that conform to the Ruby Style Guide / rubocops Cops? Or of any undocumented (or documented) rspec / rspec-rails feature that solves my problem?

解决方法正在运行

bundle exec rubocop spec --auto-correct

生成新的测试文件后,但我宁愿省略该步骤.

after generating new test files, but I'd prefer leaving out that step.

任何帮助或指针都将不胜感激!

Any help or pointers are greatly appreciated!

推荐答案

我建议向RSpec发出拉取请求,将其模板更改为与Rubocop兼容.

I would recommend making a pull request to RSpec changing their templates to be Rubocop-compliant.

这篇关于规范Rubocop/Ruby风格指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆