Home>

I'm checking the code on rubycop while creating a portfolio on rails,
Espec/requests/users_requests_spec.rb: 97: 1: E: Lint/Syntax: unexpected token kEND
(Using Ruby 2.6 parser;configure using TargetRubyVersion parameter, under AllCops)
end
^^^
Error was coming out.

I'll sort out what I doubt or don't understand.
1. Possibility of syntax error
2. Misconfiguration of rubycop.yml and ruby-version
3. I don't know how to ensure that the specified version is adopted
(I can't verbalize well when I look it up on the net)

#frozen_string_literal: true
require'rails_helper'
RSpec.describe'UsersRequests', type :: request do
  before do
    get signup_path
  end
  describe'GET #index'
  describe'GET #show' do
    before {get users_path, params: {user: create (: user)}}
    subject {response}
    it'responds successfully' do
      is_expected.to be_successful
    end
    it'returns a 200 response' do
      is_expected.to have_http_status (200)
    end
  end
  describe'GET #new' do
    before {get new_user_path}
    subject {response}
    it'responds successfully' do
      is_expected.to be_successful
    end
    it'returns a 200 response' do
      is_expected.to have_http_status (200)
    end
  end
  describe'POST #create' do
    describe'valid request' do
      describe'check users count' do
        it'add a user' do
          expect do
            post signup_path, params: {user: attributes_for (: user)}
          end.to change (User,: count) .by (1)
        end
      end
      describe'check response' do
        before {post users_path, params: {user: attributes_for (: user)}}
        subject {response}
        it'rediorect to show' do
          is_expected.to redirect_to user_path (User.last)
        end
        it'returns a 302 response' do
          is_expected.to have_http_status (302)
        end
      end
    end
    describe'invalid request' do
      describe'check user count' doit'does not add a user' do
          expect do
            post signup_path, params: {user: attributes_for (: invalid_user)}
          end.to change (User,: count) .by (0)
        end
      end
        describe'check response' do
          before {post signup_path, params: {user: attributes_for (: invalid_user)}}
          subject {response}
          it'render new' do
            is_expected.to render_template ('new')
          end
          it'responds successfully' do
            is_expected.to be_successful
          end
          it'returns a 200 response' do
            is_expected.to have_http_status (200)
          end
        end
      end
    end
  end
  describe'GET #edit' do end
  describe'PUT #update' do end
  describe'DELETE #destroy' do end
end

It doesn't look syntactically wrong,
The terget ruby ​​version of .rubocop.yml is also matched with the ruby ​​version.
The .ruby-version also matches the ruby ​​version i am using.

% ruby ​​-v
ruby 2.6.3p62
2.6.3
inherit_from: .rubocop_todo.yml
AllCops:
  Exclude:
    --'db/**/*'
    --'tmp/**/*'
    --'vendor/**/*'
    --'lib/geohash.rb'
    --'lib/manager/geo.rb'
    --'bin/spring'
    --'Gemfile'
    --'spec /*.rb'
    --'config/puma.rb'
    --'. Pryrc'
  TargetRubyVersion: 2.6.3

# Offense count: 326
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
  Exclude:
    --'Rakefile'
    -'**/*/.rake'
    --'spec /**/*.rb'
  Max: 275
Naming/PredicateName:
  ForbiddenPrefixes:
    --has_
Style/Mixin Usage:Include:
    --app /**/*.rb
Naming/MethodParameterName:
  MinNameLength: 1
Naming/AccessorMethodName:
  Enabled: false
Style/Documentation:
  Enabled: false
Style/Ascii Comments:
  Enabled: false
# Offense count: 7
Metrics/Perceived Complexity:
  Max: 18
# Offense count: 45
# Configuration parameters: CountComments.
# Metrics/MethodLength:
  #Max: 106
# Offense count: 45
# Configuration parameters: CountComments.
# Metrics/MethodLength:
  #Max: 109
# Offense count: 1
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
  Max: 7
# Offense count: 7
Metrics/Cyclomatic Complexity:
  Max: 15
# Offense count: 4
# Configuration parameters: CountComments.
Metrics/ClassLength:
  Max: 140
# Offense count: 1
# Configuration parameters: CountBlocks.
Metrics/Block Nesting:
  Max: 4
# Offense count: 40
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
  Max: 111
# Offense count: 53
Metrics/AbcSize:
  Max: 109
# Offense count: 1
Lint/SuppressedException:
  Exclude:
    --'config/unicorn.rb'

In .rubocop.yml, rspec is set to be excluded.
However, for some reason only the request spec is warned.

I thought that parser was related from the error statement, so in the gemfile
gem'parser', '2.7.1.5'
Even if I run bundle update parser with, the error is not resolved, ...
Execute the following command after update

$bundle list | grep parser
  * parser (2.7.2.0)
  * regexp_parser (1.8.1)

Is 2.7.2.0 adopted for parser?

It doesn't matter what the trivial matter is, so please let us know.
Also, if you need other necessary data, I will upload it.

  • Answer # 1

    do endCannot be written continuously.do;endPlease put a semicolon or write in empty curly braces.It's really a syntax error.

  • Answer # 2

    #frozen_string_literal: true
    require'rails_helper'
    RSpec.describe'UsersRequests', type :: request do
      before do
        get signup_path
      end
      #describe'GET #index' do;end
      describe'GET #show' do
        before {get users_path, params: {user: create (: user)}}
        subject {response}
        it'responds successfully' do
          is_expected.to be_successful
        end
        it'returns a 200 response' do
          is_expected.to have_http_status (200)
        end
      end
      describe'GET #new' do
        before {get new_user_path}
        subject {response}
        it'responds successfully' do
          is_expected.to be_successful
        end
        it'returns a 200 response' do
          is_expected.to have_http_status (200)
        end
      end
      describe'POST #create' do
        describe'valid request' do
          describe'check users count' do
            it'add a user' do
              expect do
                post signup_path, params: {user: attributes_for (: user)}
              end.to change (User,: count) .by (1)
            end
          end
          describe'check response' do
            before {post users_path, params: {user: attributes_for (: user)}}
            subject {response}
            it'rediorect to show' do
              is_expected.to redirect_to user_path (User.last)
            end
            it'returns a 302 response' do
              is_expected.to have_http_status (302)
            end
          end
        end
        describe'invalid request' do
          describe'check user count' do
            it'does not add a user' do
              expect do
                post signup_path, params: {user: attributes_for (: invalid_user)}
              end.to change (User,: count) .by (0)
            end
          end
          describe'check response' do
            before {post signup_path, params: {user: attributes_for (: invalid_user)}}
            subject {response}
            it'render new' do
              is_expected.to render_template ('new')
            end
            it'responds successfully' do
              is_expected.to be_successful
            end
            it'returns a 200 response' do
              is_expected.to have_http_status (200)
            end
          end
        end
      end
    end
    #describe'GET #edit' do;end
    #describe'PUT #update' do;end
    #describe'DELETE #destroy' do;end
    # end

    As a result of executing the rubocop -a command with the test code not written and the end of the last line commented out, the above result was obtained and the error disappeared.