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
-
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.
Related articles
- ruby - [rails] about the error that occurs when deleting likes (routing error)
- ruby on rails - about the error when trying to implement jquery with rails ($is not defined;please fix or add/* global * /)
- ruby on rails 6 - about rails error "wrong number of arguments (given 1, expected 0)"
- ruby on rails 5 - error about rails where method
- ruby - about the delete function in rails
- ruby on rails - i want to download a file with rails, s3 and carrierwave, but i get an error
- ruby on rails - rails routing error
- ruby on rails - about switching screen display on multiple models
- ruby on rails 5 - i want to get an error message when i enter the user id in full-width in url
- ruby on rails - error when vagrant up
- ruby on rails - i get a template is missing error in render
- ruby - about syntax error when running the calendar program
- ruby on rails - about request spec of rspec about test code at login
- ruby on rails - uncaught reference error: $is not defined cannot be resolved
- ruby on rails 6 - [error] nomethoderror in communitiescontroller # create undefined method `published?'for # <community: 0x0
- ruby on rails 6 - [error] nomethoderror in followscontroller # destroy undefined method `destroy'for nil: nilclass
- ruby on rails - [rails] about the problem that screen transition is not possible (error does not occur)
- ruby on rails - about the matter that does not transition to the detail page
- ruby on rails - about the description in applicationjs
- ruby - i get an error with the rails new command
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
do end
Cannot be written continuously.do;end
Please put a semicolon or write in empty curly braces.It's really a syntax error.