From c57dc904ed3208b4a59cea861fef119032abc82a 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 --- .rubocop-rspec-aliases.yml | 6 ++++++ CHANGELOG.md | 2 ++ docs/README.md | 10 ++++++++++ test-prof.gemspec | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .rubocop-rspec-aliases.yml diff --git a/.rubocop-rspec-aliases.yml b/.rubocop-rspec-aliases.yml new file mode 100644 index 00000000..f054f16d --- /dev/null +++ b/.rubocop-rspec-aliases.yml @@ -0,0 +1,6 @@ +RSpec: + Language: + Helpers: + - let_it_be + Hooks: + - before_all diff --git a/CHANGELOG.md b/CHANGELOG.md index 23043c32..ce35d094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master (unrealeased) +- Add support for RSpec aliases detection when linting policy specs 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/docs/README.md b/docs/README.md index c9f51a3d..87f3f556 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: .rubocop-rspec-aliases.yml +``` + ## Profilers - [RubyProf Integration](./profilers/ruby_prof.md) diff --git a/test-prof.gemspec b/test-prof.gemspec index b751f152..feb7b10c 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[.rubocop-rspec-aliases.yml] spec.require_paths = ["lib"]