简体   繁体   中英

ruby-rubocop cannot load such file — rubocop/rspec/focused

I've installed ruby-rubocop for VSCode, and gem installed rubocop, but every time I save a file, this error is thrown:

    cannot load such file -- rubocop/rspec/focused
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/config_loader_resolver.rb:15:in `block in resolve_requires'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/config_loader_resolver.rb:11:in `each'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/config_loader_resolver.rb:11:in `resolve_requires'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/config_loader.rb:45:in `load_file'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/config_loader.rb:90:in `configuration_from_file'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/config_store.rb:54:in `for_dir'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/config_store.rb:44:in `for'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/target_finder.rb:180:in `block in process_explicit_path'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/target_finder.rb:179:in `reject'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/target_finder.rb:179:in `process_explicit_path'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/target_finder.rb:39:in `block in find'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/target_finder.rb:35:in `each'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/target_finder.rb:35:in `find'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/runner.rb:69:in `find_target_files'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/runner.rb:34:in `run'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/cli/command.rb:10:in `run'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/cli/environment.rb:17:in `run'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/cli.rb:65:in `run_command'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/cli.rb:72:in `execute_runners'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/lib/rubocop/cli.rb:41:in `run'
    /Library/Ruby/Gems/2.6.0/gems/rubocop-0.85.0/exe/rubocop:13:in `block in <top (required)>'

Please help, I've been trying to make this work, and scouring the internet for solutions. but haven't had any luck yet.

That cop is part of the rubocop-rspec plug-in, so you may also have to run gem install rubocop-rspec .

Found and fixed the issue.

As it turns out, the culprits are:

  1. rubocop -v 0.85.0
  2. rubocop-rspec

The fix was just to downgrade both since our organization is using the older versions. So now I installed:

  1. rubocop -v 0.75.1
  2. rubocop-rspec-focused

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM