From 4e5743386b0d2599a08eedec63ee934449e8c768 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sun, 8 Nov 2020 19:09:27 +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: - https://github.com/rubocop-hq/rubocop-rspec/issues/1077 - https://github.com/rubocop-hq/rubocop-rspec/pull/956 - https://github.com/palkan/action_policy/issues/103 --- .rubocop-rspec-aliases.yml | 17 +++++++++++++++++ action_policy.gemspec | 2 +- docs/testing.md | 10 ++++++++++ 3 files changed, 28 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..c3f664fa --- /dev/null +++ b/.rubocop-rspec-aliases.yml @@ -0,0 +1,17 @@ +RSpec: + Language: + ExampleGroups: + Regular: + - describe_rule + Focused: + - fdescribe_rule + Skipped: + - xdescribe_rule + Includes: + Examples: + - succeed + - failed + - fsucceed + - ffailed + - xsucceed + - xfailed diff --git a/action_policy.gemspec b/action_policy.gemspec index 2ad703b9..685a0361 100644 --- a/action_policy.gemspec +++ b/action_policy.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/palkan/action_policy" spec.license = "MIT" - spec.files = Dir.glob("lib/**/*") + Dir.glob("lib/.rbnext/**/*") + %w[README.md LICENSE.txt CHANGELOG.md] + spec.files = Dir.glob("lib/**/*") + Dir.glob("lib/.rbnext/**/*") + %w[README.md LICENSE.txt CHANGELOG.md] + %w[rubocop-rspec-aliases.yml] spec.metadata = { "bug_tracker_uri" => "http://github.com/palkan/action_policy/issues", diff --git a/docs/testing.md b/docs/testing.md index bc27c156..7aab7188 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -388,3 +388,13 @@ describe "users/index.html.slim" do end end ``` + +## Linting with RuboCop RSpec + +When you lint your RSpec spec files with `rubocop-rspec`, it will fail to detect RSpec aliases that Action Policy defines. +Make sure to use `rubocop-rspec` 2.0 or newer and add the following to your `.rubocop.yml`: + +```yaml +inherit_gem: + action_policy: .rubocop-rspec-aliases.yml +```