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

Address rubocop offences #99

Merged
merged 1 commit into from
Oct 18, 2024
Merged

Conversation

yuki24
Copy link
Contributor

@yuki24 yuki24 commented Oct 12, 2024

The Rubocop checks are failing with the latest Rubocop version (e.g. build#74):

Running RuboCop...
RuboCop failed!
Inspecting 63 files
....W..........................................................

Offenses:

features/step_definitions/flatware_steps.rb:34:14: W: [Correctable] Lint/Void: Operator - used in void context.
    Time.now - started_at
             ^

63 files inspected, 1 offense detected, 1 offense autocorrectable

However, when I run bundle exec rubocop -a to auto-fix them, the code ends up with an incorrect fix:

diff --git a/features/step_definitions/flatware_steps.rb b/features/step_definitions/flatware_steps.rb
index 1728508..6899b1f 100644
--- a/features/step_definitions/flatware_steps.rb
+++ b/features/step_definitions/flatware_steps.rb
@@ -28,10 +28,10 @@ module Support
   end

   def duration(&_block)
-    started_at = Time.now
+    Time.now
     yield
   ensure
-    Time.now - started_at
+    Time.now
   end
 end
 World(Support)

I believe that what we want to do with this method is to just measure how long the given block takes to execute, and we should be able to do that with the Benchmark module, which should be more appropriate:

Benchmark.realtime { slow_method }
# => returns the time taken to execute the #slow_method, in float.

@briandunn briandunn merged commit 54aa19b into briandunn:master Oct 18, 2024
24 checks passed
@yuki24 yuki24 deleted the yuki24/chore/rubocop branch October 18, 2024 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants