rubocop / rubocop-rspec

Code style checking for RSpec files.
https://docs.rubocop.org/rubocop-rspec
MIT License
809 stars 276 forks source link

Non-Blocking-Bug: RSpec/MessageSpies #820

Closed luke-hill closed 4 years ago

luke-hill commented 5 years ago

Set the following config

RSpec/MessageSpies:
  SupportedStyles: receive

Run rubocop

Observe failures

The full error is very long but looks like it's trying to do something against the type safety

An error occurred while RSpec/MessageSpies cop was inspecting /home/luke/Code/site_prism/spec/site_prism_spec.rb:15:6.
undefined method `map' for "receive":String
Did you mean?  tap
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/mixin/configurable_enforced_style.rb:89:in `supported_styles'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/mixin/configurable_enforced_style.rb:66:in `style'

This was ran against the SitePrism repo, whilst trying to fix these issues - https://github.com/site-prism/site_prism/blob/master/.rubocop_todo.yml#L53

Mention the following information in the issue report:
0.73.0 (using Parser 2.6.3.0, running on ruby 2.3.8 x86_64-linux)
Finished in 1.6680358289995638 seconds

This didn't stop the rubocop tool from working, and it did report the results correctly, just with a shedload of red warnings.

pirj commented 5 years ago

@luke-hill Can you please provide more detailed backtrace? I can't reproduce on site_prism master branch with Ruby 2.5.5.

luke-hill commented 5 years ago
An error occurred while RSpec/MessageSpies cop was inspecting /home/luke/Code/site_prism/spec/site_prism_spec.rb:17:6.
undefined method `map' for "receive":String
Did you mean?  tap
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/mixin/configurable_enforced_style.rb:89:in `supported_styles'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/mixin/configurable_enforced_style.rb:66:in `style'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-rspec-1.33.0/lib/rubocop/cop/rspec/message_spies.rb:67:in `preferred_style?'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-rspec-1.33.0/lib/rubocop/cop/rspec/message_spies.rb:48:in `block in on_send'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-rspec-1.33.0/lib/rubocop/cop/rspec/message_spies.rb:63:in `block in receive_message_matcher'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-rspec-1.33.0/lib/rubocop/cop/rspec/message_spies.rb:51:in `block in receive_message'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/node.rb:564:in `block in visit_descendants'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/node.rb:193:in `block in each_child_node'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/node.rb:190:in `each'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/node.rb:190:in `each_child_node'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/node.rb:563:in `visit_descendants'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/node.rb:268:in `each_node'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-rspec-1.33.0/lib/rubocop/cop/rspec/message_spies.rb:44:in `receive_message'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-rspec-1.33.0/lib/rubocop/cop/rspec/message_spies.rb:63:in `receive_message_matcher'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-rspec-1.33.0/lib/rubocop/cop/rspec/message_spies.rb:47:in `on_send'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:57:in `block (2 levels) in trigger_responding_cops'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:128:in `with_cop_error_handling'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:56:in `block in trigger_responding_cops'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:55:in `each'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:55:in `trigger_responding_cops'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:32:in `block (2 levels) in <class:Commissioner>'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:50:in `each'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:50:in `on_begin'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:164:in `on_block'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:50:in `each'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:50:in `on_begin'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:164:in `on_block'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:50:in `each'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:50:in `on_begin'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:164:in `on_block'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:33:in `block (2 levels) in <class:Commissioner>'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/ast/traversal.rb:13:in `walk'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/commissioner.rb:44:in `investigate'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/team.rb:119:in `investigate'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/team.rb:107:in `offenses'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cop/team.rb:44:in `inspect_file'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:277:in `inspect_file'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:225:in `block in do_inspection_loop'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:257:in `block in iterate_until_no_changes'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:250:in `loop'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:250:in `iterate_until_no_changes'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:221:in `do_inspection_loop'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:124:in `block in file_offenses'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:142:in `file_offense_cache'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:122:in `file_offenses'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:110:in `process_file'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:87:in `block in each_inspected_file'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:86:in `each'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:86:in `reduce'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:86:in `each_inspected_file'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:73:in `inspect_files'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/runner.rb:39:in `run'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cli.rb:210:in `execute_runner'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cli.rb:80:in `execute_runners'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/lib/rubocop/cli.rb:51:in `run'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/exe/rubocop:13:in `block in <top (required)>'
/usr/share/rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
/home/luke/.rvm/gems/ruby-2.3.8/gems/rubocop-0.73.0/exe/rubocop:12:in `<top (required)>'
/home/luke/.rvm/gems/ruby-2.3.8/bin/rubocop:23:in `load'
/home/luke/.rvm/gems/ruby-2.3.8/bin/rubocop:23:in `<main>'
/home/luke/.rvm/gems/ruby-2.3.8/bin/ruby_executable_hooks:24:in `eval'
/home/luke/.rvm/gems/ruby-2.3.8/bin/ruby_executable_hooks:24:in `<main>'
.Scanning /home/luke/Code/site_prism/spec/spec_helper.rb
luke-hill commented 5 years ago

https://travis-ci.com/site-prism/site_prism/jobs/231773214 is a CI job runnign with it

pirj commented 5 years ago

Thanks for the quick update 👍

@luke-hill This is where the problem originates from. The fix is trivial:

RSpec/MessageSpies:
-  SupportedStyles: receive
+  EnforcedStyle: receive

@bquorning @Darhazer Do you think this misconfiguration possibility is something that needs Core RuboCop attention? I think of restricting SupportedStyles and maybe some other core options to be only defined in config/default.yml, not user-defined .rubocop*.ymls.

bquorning commented 5 years ago

I’m not sure rubocop has any distinction between “official” configuration files and user-defined configurations. Of course we want to still be able to use SupportedStyles in rubocop-rspec’s configuration file ;-)

bquorning commented 5 years ago

I just want to add, I have also configured SupportedStyles in my rubocop configuration file. More than once. 🤦‍♂

pirj commented 5 years ago

I just want to add, I have also configured SupportedStyles in my rubocop configuration file

It's not a big deal if it's a list ¯_(ツ)_/¯

pirj commented 5 years ago

Did the fix work for you, @luke-hill ? Do you mind to close the issue, or do you think anything still needs to be addressed in the scope of this ticket?

luke-hill commented 5 years ago

I think something still needs fixing. Because you should never get a massive stacktrace. Something needs fixing, even if it's just

"Please ensure SupportedStyles is an Array"

bquorning commented 5 years ago

@luke-hill I think that would be an issue for rubocop-hq/rubocop. Could you open an issue there, please? (I could probably also transfer this issue)

pirj commented 4 years ago

@luke-hill Just in case, have you notified rubocop team about this? @bquorning I believe this issue can be closed.

luke-hill commented 4 years ago

I didn't notify the original team no sorry @pirj

pirj commented 4 years ago

@bbatsov @koic Is validating proper user-defined configuration (.rubocop.yml vs config/default.yml) something you'd like to add you the roadmap?