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

Sibling pull requests:
 - palkan/action_policy#138
  • Loading branch information
pirj committed Nov 9, 2020
1 parent 8116530 commit 11795f6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .rubocop-rspec-aliases.yml
@@ -0,0 +1,6 @@
RSpec:
Language:
Helpers:
- let_it_be
Hooks:
- before_all
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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][])
Expand Down
11 changes: 11 additions & 0 deletions docs/README.md
Expand Up @@ -88,6 +88,17 @@ 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)
Expand Down
2 changes: 1 addition & 1 deletion test-prof.gemspec
Expand Up @@ -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"]

Expand Down

0 comments on commit 11795f6

Please sign in to comment.