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 17, 2020
1 parent 8116530 commit 0b2c7aa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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][])
Expand Down
6 changes: 6 additions & 0 deletions config/rubocop-rspec.yml
@@ -0,0 +1,6 @@
RSpec:
Language:
Helpers:
- let_it_be
Hooks:
- before_all
10 changes: 10 additions & 0 deletions docs/README.md
Expand Up @@ -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)
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[config/rubocop-rspec.yml]

spec.require_paths = ["lib"]

Expand Down

0 comments on commit 0b2c7aa

Please sign in to comment.