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

Add rubocop alias config file #632

Merged
merged 2 commits into from
May 2, 2023

Conversation

toydestroyer
Copy link
Contributor

Problem

As previously discussed in issue #138, rubocop-rspec flags a violation of RSpec/EmptyExampleGroup when using rswag-only syntax without it, specify, etc.

Screenshot 2023-04-29 at 3 38 56 PM

Solution

Since the original issue was opened and closed in 2018, rubocop-rspec has released version 2.0, which now supports syntax extension in third-party gems. Details: https://docs.rubocop.org/rubocop-rspec/third_party_rspec_syntax_extensions.html

To resolve this issue, rswag-specs should come with the rubocop rspec alias config. And the README should contain instructions for users on how to enable it.

inherit_gem:
  rswag-specs: .rubocop_rspec_alias_config.yml

Examples:

Related Issues

#138

Checklist

  • Added tests
  • Changelog updated
  • Added documentation to README.md

Steps to Test or Reproduce

The problem can be reproduced by running rubocop-rspec against the code example from the README:

# spec/requests/blogs_spec.rb
require 'swagger_helper'

describe 'Blogs API' do

  path '/blogs' do

    post 'Creates a blog' do
      tags 'Blogs'
      consumes 'application/json'
      parameter name: :blog, in: :body, schema: {
        type: :object,
        properties: {
          title: { type: :string },
          content: { type: :string }
        },
        required: [ 'title', 'content' ]
      }

      response '201', 'blog created' do
        let(:blog) { { title: 'foo', content: 'bar' } }
        run_test!
      end

      response '422', 'invalid request' do
        let(:blog) { { title: 'foo' } }
        run_test!
      end
    end
  end

@toydestroyer toydestroyer marked this pull request as ready for review April 29, 2023 08:06
Copy link
Member

@romanblanco romanblanco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Thank you for the PR, @toydestroyer!

@romanblanco romanblanco merged commit 17273d9 into rswag:master May 2, 2023
@toydestroyer toydestroyer deleted the rubocop-rspec-aliases branch May 3, 2023 01:43
@romanblanco romanblanco added this to the Gem 2.10.0 milestone May 8, 2023
@romanblanco romanblanco removed this from the Gem 2.11.0 milestone Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants