Skip to content

Commit

Permalink
RSpec -> RSpecRails
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Mar 27, 2024
1 parent 73411e4 commit 38a9ed7
Show file tree
Hide file tree
Showing 38 changed files with 981 additions and 3,577 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,26 @@ jobs:
- uses: actions/checkout@v4
- name: Use latest RuboCop from `master`
run: |
echo "gem 'rubocop', github: 'rubocop/rubocop'" > Gemfile.local
echo "gem 'rubocop', github: 'rubocop-hq/rubocop'" > Gemfile.local
- uses: ruby/setup-ruby@v1

This comment has been minimized.

Copy link
@pirj

pirj Mar 27, 2024

Member

Why rubocop-hq?

This comment has been minimized.

Copy link
@ydah

ydah Mar 27, 2024

Author Member

Ah, Because the following PR was cut from the branch before merging. I updated it.
rubocop/rubocop-rspec#1836

with:
ruby-version: "3.3"
bundler-cache: true
- run: NO_COVERAGE=true bundle exec rake ${{ matrix.task }}

edge-rubocop-rspec:
runs-on: ubuntu-latest
strategy:
matrix:
task:
- internal_investigation
- spec
name: "Edge RuboCop RSpec: ${{ matrix.task }}"
steps:
- uses: actions/checkout@v4
- name: Use latest RuboCop RSpec from `master`
run: |
echo "gem 'rubocop-rspec', github: 'rubocop/rubocop-rspec'" > Gemfile.local
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
Expand Down
14 changes: 3 additions & 11 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ Lint/RedundantCopDisableDirective:

Metrics/BlockLength:
Exclude:
- rubocop-rspec.gemspec
- rubocop-rspec_rails.gemspec
- Rakefile
- '**/*.rake'

Naming/FileName:
Exclude:
- lib/rubocop-rspec.rb
- lib/rubocop-rspec_rails.rb

Naming/InclusiveLanguage:
Enabled: true
Expand Down Expand Up @@ -85,9 +85,6 @@ Naming/InclusiveLanguage:
violation:
Suggestions:
- offense
'register no offense':
Suggestions:
- registers no offense

RSpec:
Language:
Expand Down Expand Up @@ -118,11 +115,6 @@ Style/FormatStringToken:
Style/RequireOrder:
Enabled: true

RSpec/SpecFilePathFormat:
Enabled: true
Exclude:
- spec/rubocop/cop/rspec/mixin/**/*.rb

# Enable some of RuboCop's pending cops.

Layout/LineContinuationSpacing:
Expand All @@ -142,7 +134,7 @@ Style/RedundantStringEscape:
Style/ReturnNilInPredicateMethodDefinition:
Enabled: true

# Enable our own pending cops.
# Enable pending rubocop-rspec cops.

RSpec/BeEmpty:
Enabled: true
Expand Down
2 changes: 1 addition & 1 deletion .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

SimpleCov.start do
enable_coverage :branch
minimum_coverage line: 99.60, branch: 94.77
minimum_coverage line: 95.17, branch: 85.13
add_filter '/spec/'
add_filter '/vendor/bundle/'
end
911 changes: 2 additions & 909 deletions CHANGELOG.md

Large diffs are not rendered by default.

44 changes: 18 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,79 @@
# RuboCop RSpec
# RuboCop RSpec Rails

[![Join the chat at https://gitter.im/rubocop-rspec/Lobby](https://badges.gitter.im/rubocop-rspec/Lobby.svg)](https://gitter.im/rubocop-rspec/Lobby)
[![Gem Version](https://badge.fury.io/rb/rubocop-rspec.svg)](https://rubygems.org/gems/rubocop-rspec)
![CI](https://github.com/rubocop/rubocop-rspec/workflows/CI/badge.svg)
[![Gem Version](https://badge.fury.io/rb/rubocop-rspec_rails.svg)](https://rubygems.org/gems/rubocop-rspec_rails)
![CI](https://github.com/rubocop/rubocop-rspec_rails/workflows/CI/badge.svg)

[RSpec](https://rspec.info/)-specific analysis for your projects, as an extension to
[RSpec Rails](https://rspec.info/)-specific analysis for your projects, as an extension to
[RuboCop](https://github.com/rubocop/rubocop).

## Installation

Just install the `rubocop-rspec` gem
Just install the `rubocop-rspec_rails` gem

```bash
gem install rubocop-rspec
gem install rubocop-rspec_rails
```

or if you use bundler put this in your `Gemfile`

```ruby
gem 'rubocop-rspec', require: false
gem 'rubocop-rspec_rails', require: false
```

### Upgrading to RuboCop RSpec v2.x

Read all the details in our [Upgrade to Version 2.x](https://docs.rubocop.org/rubocop-rspec/2.0/upgrade_to_version_2.html) document.

## Usage

You need to tell RuboCop to load the RSpec extension. There are three
You need to tell RuboCop to load the RSpec Rails extension. There are three
ways to do this:

### RuboCop configuration file

Put this into your `.rubocop.yml`.

```yaml
require: rubocop-rspec
require: rubocop-rspec_rails
```
Alternatively, use the following array notation when specifying multiple extensions.
```yaml
require:
- rubocop-other-extension
- rubocop-rspec
- rubocop-rspec_rails
```
Now you can run `rubocop` and it will automatically load the RuboCop RSpec
Now you can run `rubocop` and it will automatically load the RuboCop RSpec Rails
cops together with the standard cops.

### Command line

```bash
rubocop --require rubocop-rspec
rubocop --require rubocop-rspec_rails
```

### Rake task

```ruby
RuboCop::RakeTask.new do |task|
task.requires << 'rubocop-rspec'
task.requires << 'rubocop-rspec_rails'
end
```

### Code Climate

rubocop-rspec is available on Code Climate as part of the rubocop engine. [Learn More](https://marketing.codeclimate.com/changelog/55a433bbe30ba00852000fac/).

## Documentation

You can read more about RuboCop RSpec in its [official manual](https://docs.rubocop.org/rubocop-rspec).
You can read more about RuboCop RSpec Rails in its [official manual](https://docs.rubocop.org/rubocop-rspec_rails).

## The Cops

All cops are located under
[`lib/rubocop/cop/rspec`](lib/rubocop/cop/rspec), and contain
[`lib/rubocop/cop/rspec_rails`](lib/rubocop/cop/rspec_rails), and contain
examples/documentation.

In your `.rubocop.yml`, you may treat the RSpec cops just like any other
In your `.rubocop.yml`, you may treat the RSpec Rails cops just like any other
cop. For example:

```yaml
RSpec/FilePath:
RSpecRails/AvoidSetupHook:
Exclude:
- spec/my_poorly_named_spec_file.rb
```
Expand All @@ -92,5 +84,5 @@ Checkout the [contribution guidelines](.github/CONTRIBUTING.md).

## License

`rubocop-rspec` is MIT licensed. [See the accompanying file](MIT-LICENSE.md) for
`rubocop-rspec_rails` is MIT licensed. [See the accompanying file](MIT-LICENSE.md) for
the full text.
31 changes: 15 additions & 16 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,18 @@ desc 'Build config/default.yml'
task :build_config do
require 'yard'

require 'rubocop-rspec'
require 'rubocop/rspec/config_formatter'
require 'rubocop/rspec/description_extractor'

glob = File.join('lib', 'rubocop', 'cop', 'rspec',
'{,capybara,factory_bot,rails}', '*.rb')
# Due to YARD's sensitivity to file require order (as of 0.9.25),
# we have to prepend the list with our base cop, RuboCop::Cop::RSpec::Base.
# Otherwise, cop's parent class for cops loaded before our base cop class
# are detected as RuboCop::Cop::Base, and that complicates the detection
# of their relation with RuboCop RSpec.
rspec_cop_path = File.join('lib', 'rubocop', 'cop', 'rspec', 'base.rb')
require 'rubocop-rspec_rails'
require 'rubocop/rspec_rails/config_formatter'
require 'rubocop/rspec_rails/description_extractor'

glob = File.join('lib', 'rubocop', 'cop', 'rspec_rails', '*.rb')
YARD::Tags::Library.define_tag('Cop Safety Information', :safety)
YARD.parse(Dir[glob].prepend(rspec_cop_path), [])
YARD.parse(Dir[glob], [])

descriptions =
RuboCop::RSpec::DescriptionExtractor.new(YARD::Registry.all(:class)).to_h
RuboCop::RSpecRails::DescriptionExtractor.new(
YARD::Registry.all(:class)
).to_h
current_config = if Psych::VERSION >= '4.0.0' # RUBY_VERSION >= '3.1.0'
YAML.unsafe_load_file('config/default.yml')
else
Expand All @@ -54,7 +49,9 @@ task :build_config do

File.write(
'config/default.yml',
RuboCop::RSpec::ConfigFormatter.new(current_config, descriptions).dump
RuboCop::RSpecRails::ConfigFormatter.new(
current_config, descriptions
).dump
)
end

Expand Down Expand Up @@ -100,7 +97,9 @@ task :new_cop, [:cop] do |_task, args|
generator = RuboCop::Cop::Generator.new(cop_name)
generator.write_source
generator.write_spec
generator.inject_require(root_file_path: 'lib/rubocop/cop/rspec_cops.rb')
generator.inject_require(
root_file_path: 'lib/rubocop/cop/rspec_rails_cops.rb'
)
generator.inject_config

puts generator.todo
Expand Down
Loading

0 comments on commit 38a9ed7

Please sign in to comment.