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

v2.26.0 regression: undefined method 'sym_type?' for nil:NilClass #1765

Closed
jtannas opened this issue Jan 5, 2024 · 3 comments · Fixed by #1768 or #1771
Closed

v2.26.0 regression: undefined method 'sym_type?' for nil:NilClass #1765

jtannas opened this issue Jan 5, 2024 · 3 comments · Fixed by #1768 or #1771
Labels

Comments

@jtannas
Copy link
Contributor

jtannas commented Jan 5, 2024

On the newly release v2.26.0 version, rubocop-rspec encounters an error whenever inspecting the command run_test! in my code

        context 'when the user does not agree to the terms of use' do
          let(:body) { valid_body.merge(tosAcceptedAt: false) }

          run_test!
        end

Environment information: 1.59.0 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 3.1.2) [x86_64-linux]

Stack Trace

An error occurred while RSpec/SharedExamples cop was inspecting /home/jtannas/foo-project/backend/spec/requests/api/v1/users/url_spec.rb:87:10.
undefined method `sym_type?' for nil:NilClass

            ast_node.sym_type?
                    ^^^^^^^^^^
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-rspec-2.26.0/lib/rubocop/cop/rspec/shared_examples.rb:72:in `offense?'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-rspec-2.26.0/lib/rubocop/cop/rspec/shared_examples.rb:57:in `block in on_send'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-rspec-2.26.0/lib/rubocop/cop/rspec/shared_examples.rb:59:in `shared_examples'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-rspec-2.26.0/lib/rubocop/cop/rspec/shared_examples.rb:55:in `on_send'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:107:in `public_send'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:105:in `each'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:69:in `on_send'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:158:in `on_block'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:158:in `on_block'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:158:in `on_block'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:158:in `on_block'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:158:in `on_block'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `each'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/commissioner.rb:87:in `investigate'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/team.rb:156:in `investigate_partial'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cop/team.rb:98:in `investigate'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:345:in `block in inspect_file'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `each'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `flat_map'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:344:in `inspect_file'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:287:in `block in do_inspection_loop'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:321:in `block in iterate_until_no_changes'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `loop'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:314:in `iterate_until_no_changes'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:283:in `do_inspection_loop'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:164:in `block in file_offenses'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:189:in `file_offense_cache'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:163:in `file_offenses'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:154:in `process_file'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:135:in `block in each_inspected_file'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `each'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `reduce'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:134:in `each_inspected_file'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:120:in `inspect_files'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/runner.rb:73:in `run'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cli/command.rb:11:in `run'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cli/environment.rb:18:in `run'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:118:in `run_command'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:125:in `execute_runners'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:51:in `block in run'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:77:in `profile_if_needed'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/lib/rubocop/cli.rb:43:in `run'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/exe/rubocop:19:in `block in <top (required)>'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/3.1.0/benchmark.rb:311:in `realtime'
/home/jtannas/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/rubocop-1.59.0/exe/rubocop:19:in `<top (required)>'
/home/jtannas/.rbenv/versions/3.1.2/bin/rubocop:25:in `load'
/home/jtannas/.rbenv/versions/3.1.2/bin/rubocop:25:in `<main>'

@jtannas jtannas changed the title v2.26.0 regression: undefined method sym_type?' for nil:NilClass` v2.26.0 regression: undefined method 'sym_type?' for nil:NilClass Jan 5, 2024
@bquorning
Copy link
Collaborator

@jtannas I cannot reproduce the issue from the 5-line snippet you shared.

Would you try reducing your spec/requests/api/v1/users/url_spec.rb to the smallest possible where the error still occurs?

@Tabby
Copy link

Tabby commented Jan 5, 2024

I'm seeing the same issue and it's only affecting specs that make use of RSwag, which is where run_test! comes from

FWIW, we also have the following block in .rubocop.yml to ensure specs that use RSwag are not incorrectly parsed as lacking examples:

RSpec:
  Language:
    ExampleGroups:
      Regular:
        - path
        - post
        - put
        - get
        - delete
        - response
    Includes:
      Examples:
        - run_test!

@bquorning
Copy link
Collaborator

Thank you for reporting this bug. It should be fixed by v2.26.1.

ydah added a commit to rubocop/rubocop-rspec_rails that referenced this issue Mar 27, 2024
ydah added a commit to rubocop/rubocop-rspec_rails that referenced this issue Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants