-->

RSpec的和Rubocop / Ruby的风格指南(RSpec & Rubocop / Ruby

2019-09-28 14:24发布

告诉导轨支架控制器时生成rspec的测试生成的文件不遵循Ruby的风格指南 ,从而rubocop抛出这些错误。

只有一对夫妇的“警察”失败。 样式/ HashSyntax,款式/ StringLiterals,款式/ MethodCallParentheses,款式/ SpaceInsideHashLiteralBraces,款式/块。

我也明白,有些警察都像例如样式/ StringLiterals只是风格偏好(身高单引号字符串时,你不需要串插或特殊符号。)

不过,我想我的测试,以符合rubocop。 任何人是否知道宝石的,它取代了RSpec的护栏模板(如controller_spec.rb )与那些符合Ruby的风格指南/ rubocops警察? 或任何无证(或文件)的RSpec / RSpec的护栏的功能,解决了我的问题吗?

一个解决运行

bundle exec rubocop spec --auto-correct

产生新的测试文件后,但我宁愿离开了这一步。

任何帮助或指针是极大的赞赏!

Answer 1:

我会建议做一个拉请求RSpec的改变他们的模板是Rubocop兼容。



Answer 2:

我只是让rubocop自动更正类似的东西。 我通常有一个脚本, script/rubocop-autocorrect.rb什么的,我明确地列出所有应修正的警察。 我从未有过由它推出了一个错误; 那里至今只有一种情况rubocop未能纠正的东西(关于更换or通过||在一个非常怪异的情况下)。 它根本不算什么,它没有破坏代码。

完整的脚本看起来像(没什么特别的,只是我的喜好):

bundle exec rubocop -F -a --only \
Style/TrailingBlankLines,\
Style/TrailingWhitespace,\
Style/SymbolProc,\
Style/SpaceInsideHashLiteralBraces,\
Style/SpaceInsideBrackets,\
Style/SpaceInsideBlockBraces,\
Style/SpaceInsideParens,\
Style/SpaceAroundEqualsInParameterDefault,\
Style/Semicolon,\
Style/StringLiterals,\
Style/SpaceAfterComma,\
Style/SpaceAroundOperators,\
Style/AlignHash,\
Style/AlignParameters,\
Style/AndOr,\
Style/EmptyLines,\
Style/HashSyntax,\
Style/RedundantSelf,\
Style/ColonMethodCall,\
Style/IndentationWidth,\
Style/MultilineIfThen,\
Style/NegatedIf,\
Style/PercentLiteralDelimiters,\
Style/BarePercentLiterals,\
Style/BlockEndNewline,\
Style/CollectionMethods,\
Style/CommentIndentation,\
Style/IndentationConsistency,\
Style/ParenthesesAroundCondition,\
Style/CaseIndentation,\
Lint/EndAlignment,\
Style/LeadingCommentSpace,\
Style/MutableConstant,\
Style/NumericLiteralPrefix,\
Style/MultilineIfModifier,\
Style/TrailingCommaInLiteral,\
Style/IndentArray,\
Style/AlignArray,\
Style/MultilineArrayBraceLayout,\
Style/ElseAlignment,\
Lint/EndAlignment,\
Style/MultilineMethodCallBraceLayout,\
Style/ClosingParenthesisIndentation,\
Style/MultilineHashBraceLayout,\
Lint/BlockAlignment,\
Style/IndentHash,\
Style/LeadingCommentSpace,\
Style/SpaceBeforeComma,\
Style/SpaceBeforeSemicolon,\
Style/Tab,\
Style/MultilineMethodCallIndentation


文章来源: RSpec & Rubocop / Ruby Style Guide
标签: rspec rubocop