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

TravelAround cop does not detect around block when the block is passed as a proc using #49

Open
aki77 opened this issue Sep 3, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@aki77
Copy link

aki77 commented Sep 3, 2024

The RuboCop::Cop::RSpecRails::TravelAround cop does not detect the following pattern:

around do |example|
  freeze_time(&example)
end

Expected behavior

The cop should detect and flag this pattern as it involves freezing time within the around block.

Actual behavior

The cop does not detect this pattern, leading to a potential inconsistency in time-travel-related detection.

@r7kamura
Copy link
Contributor

r7kamura commented Sep 5, 2024

I didn't know about this proc style usage until now, but it is certainly mentioned in the rspec-core comments, and it seems to be a legitimate usecase.

@r7kamura
Copy link
Contributor

r7kamura commented Sep 5, 2024

It seems like it could be handled just by changing this part, but it would be a bit more tedious to try to verify the exact correspondence of the example variable.

# @!method extract_run_in_travel(node)
def_node_matcher :extract_run_in_travel, <<~PATTERN
(block
$(send nil? TRAVEL_METHOD_NAMES ...)
(args ...)
(send _ :run)
)
PATTERN

@r7kamura
Copy link
Contributor

r7kamura commented Sep 5, 2024

around do |example|
  freeze_time(&example)
end

Since the above code is interpreted as follows,

(block
  (send nil :around)
  (args
    (procarg0
      (arg :example)))
  (send nil :freeze_time
    (block-pass
      (lvar :example))))

It would be good to change the (send _ :run) part to also support (block-pass (lvar _))?

@ydah ydah added the bug Something isn't working label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants