Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users should be able to globally configure example group and includes language #333

Closed
backus opened this issue Feb 26, 2017 · 9 comments
Closed

Comments

@backus
Copy link
Collaborator

backus commented Feb 26, 2017

As described in #321, if a user has some custom DSL in their specs then a handful of cops produce false positives. For example

RSpec.describe Authentication do
  role :user do
    it 'accepts the request' do
      expect(request).to be_accepted
    end
  end

  role :admin do
    it 'accepts the request' do
      expect(request).to be_accepted
    end
  end
end

In RSpec you can do something like this

RSpec.configure do |c|
  c.alias_example_group_to :detail, :detailed => true
end

and of course since it is plain old ruby you can do something like this (not sure if this would specifically work)

module AuthenticationSpecs
  def role(type)
    context "when user is a #{type}" do
      let(:user) { create(type) }

      yield
    end
  end
end

RSpec.configure do |config|
  config.extend(AuthenticationSpecs)
end

To handle stuff like this properly, we should support something like this

AllCops:
  RSpec:
    CustomExampleGroups:
    - detail
    - role

which all cops would respect.

@Ana06
Copy link

Ana06 commented Sep 19, 2018

It also happen with permissions. For example:

  permissions :create?, :can_create_package_in?, :unlock? do
    it { expect(subject).to permit(user, project) }
  end

  permissions :local_project_and_allowed_to_create_package_in? do
    it { expect(subject).to permit(user, project) }
  end

Just seen it in Rubocop 0.58.2

@bquorning
Copy link
Collaborator

permissions is from the Pundit gem’s RSpec DSL: https://www.rubydoc.info/gems/pundit/Pundit%2FRSpec%2FDSL:permissions

As @backus mentioned above, we’d have to make a configurable list of DSL aliases, and stick to using that list of aliases throughout our cops.

@pirj
Copy link
Member

pirj commented Aug 17, 2019

Additionally, I imagine a cop that would specifically watch over alias_example_group_to/alias_example_to/alias_object_eq_to occurrences in spec_helper.rb to make sure all of them are added AllCops/RSpec configuration, or explicitly ignored in it.

Not sure how to deal with aliases defined in specs directly, does Language have to track that dynamically?

@denys-husiev
Copy link

Have the same issue with pundit. Is it going to be released?

@pirj
Copy link
Member

pirj commented May 10, 2020

@denys-husiev There's nothing to release yet. A proof-of-concept is WIP now #894, you may jump in if you'd love to help. And after we would still need to make the rest parts of the Language module to be configurable. Any help on this front is much appreciated.

@sl4vr
Copy link
Contributor

sl4vr commented Jun 8, 2020

I made some POCs here: #921 (comment).
I would like to go ahead, but review and agreement on implementation are needed from @rubocop-hq maintainers.

@pirj
Copy link
Member

pirj commented Jun 8, 2020

@sl4vr Thanks a lot!
Really sorry for the huge delay. Moved the review of this to the top of my list.

@pirj
Copy link
Member

pirj commented Jun 11, 2020

Yet another case that could be improved https://github.com/rubocop-hq/rubocop-rspec/pull/858/files#r365795088

@pirj
Copy link
Member

pirj commented Nov 6, 2020

RSpec DSL alias configuration has been implemented in #956, and released in 2.0.

A reference implementation on how to allow third-party gems to configure their RSpec DSL configuration for RuboCop RSpec is tracked in #1077

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants