Skip to content

Commit

Permalink
Add RuboCop RSpec support
Browse files Browse the repository at this point in the history
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/rubocop-rspec#1077
 - rubocop/rubocop-rspec#956
 - #103
  • Loading branch information
pirj committed Nov 17, 2020
1 parent 3927a67 commit fad3b5b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

## master

- Add support for RSpec aliases detection when linting policy specs with `rubocop-rspec` 2.0 ([@pirj][])

## 0.5.0 (2020-09-29)

- Move `deny!` / `allow!` to core. ([@palkan][])
Expand Down Expand Up @@ -429,3 +431,4 @@ This value is now stored in a cache (if any) instead of just the call result (`t
[@nicolas-brousse]: https://github.com/nicolas-brousse
[@somenugget]: https://github.com/somenugget
[@Be-ngt-oH]: https://github.com/Be-ngt-oH
[@pirj]: https://github.com/pirj
2 changes: 1 addition & 1 deletion action_policy.gemspec
Expand Up @@ -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[config/rubocop-rspec.yml]

spec.metadata = {
"bug_tracker_uri" => "http://github.com/palkan/action_policy/issues",
Expand Down
17 changes: 17 additions & 0 deletions config/rubocop-rspec.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
10 changes: 10 additions & 0 deletions docs/testing.md
Expand Up @@ -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: config/rubocop-rspec.yml
```

0 comments on commit fad3b5b

Please sign in to comment.