Search code examples
rspecrubocop

RSpec & Rubocop / Ruby Style Guide


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.

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

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.)

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?

A work around is running

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!


Solution

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