From 0b2c7aa2e7755cd60a74ed06799787b57045f1d5 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Mon, 9 Nov 2020 12:15:34 +0300 Subject: [PATCH] Add RuboCop RSpec support Previously, RuboCop RSpec failed to detect RSpec aliases. A number of cops were failing false offences, and some cops were unable to lint, as they were skipping locally defined RSpec aliases taking them for arbitrary blocks and method calls. See: - rubocop-hq/rubocop-rspec#1077 - rubocop-hq/rubocop-rspec#956 Sibling pull requests: - https://github.com/palkan/action_policy/pull/138 --- CHANGELOG.md | 2 ++ config/rubocop-rspec.yml | 6 ++++++ docs/README.md | 10 ++++++++++ test-prof.gemspec | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 config/rubocop-rspec.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 23043c32..3d44ea18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master (unrealeased) +- Add support for RSpec aliases detection when linting specs using `let_it_be`/`before_all` with `rubocop-rspec` 2.0 ([@pirj][]) + ## 0.12.2 (2020-09-03) - Execute Minitest `before_all` in the context of the current test object. ([@palkan][]) diff --git a/config/rubocop-rspec.yml b/config/rubocop-rspec.yml new file mode 100644 index 00000000..f054f16d --- /dev/null +++ b/config/rubocop-rspec.yml @@ -0,0 +1,6 @@ +RSpec: + Language: + Helpers: + - let_it_be + Hooks: + - before_all diff --git a/docs/README.md b/docs/README.md index c9f51a3d..2d546f3a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -88,6 +88,16 @@ Supported Ruby versions: Supported RSpec version (for RSpec features only): >= 3.5.0 (for older RSpec version use TestProf < 0.8.0). +### Linting with RuboCop RSpec + +When you lint your RSpec spec files with `rubocop-rspec`, it will fail to properly detect RSpec constructs that TestProf defines, `let_it_be` and `before_all`. +Make sure to use `rubocop-rspec` 2.0 or newer and add the following to your `.rubocop.yml`: + +```yaml +inherit_gem: + test-prof: config/rubocop-rspec.yml +``` + ## Profilers - [RubyProf Integration](./profilers/ruby_prof.md) diff --git a/test-prof.gemspec b/test-prof.gemspec index b751f152..d711e1f5 100644 --- a/test-prof.gemspec +++ b/test-prof.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |spec| "source_code_uri" => "http://github.com/test-prof/test-prof" } - spec.files = Dir.glob("lib/**/*") + Dir.glob("config/**/*") + Dir.glob("assets/**/*") + %w[README.md LICENSE.txt CHANGELOG.md] + spec.files = Dir.glob("lib/**/*") + Dir.glob("config/**/*") + Dir.glob("assets/**/*") + %w[README.md LICENSE.txt CHANGELOG.md] + %w[config/rubocop-rspec.yml] spec.require_paths = ["lib"]