Recently we upgraded ruby to 3.2. We started getting the following error:
/Users/deepak/.rvm/gems/ruby-3.2.2@my-project/gems/pundit-2.3.0/lib/generators/rspec/templates/policy_spec.rb:1:in `template': undefined method `exists?' for File:Class (NoMethodError) Did you mean? exist?
This is how we traced it and fixed it:
Updated on 20th July 2023
and updating to the new version should solve this issue.
# Gemfile # https://github.com/varvet/pundit gem 'pundit', '~> 2.3.1'
You can just update pundit using
bundle update pundit
We found that the error was raised from pundit gem from this location:
Turned out that
File.exists? was first deprecated and later removed in Ruby 3.2 -
We also found that it has been fixed in this pull request varvet/pundit#754 but at the time of writing this article this change is not yet released
How we fixed it in our project:
# Gemfile # https://github.com/varvet/pundit gem 'pundit', git: 'https://github.com/varvet/pundit.git', ref: '5b22078'
ref is optional but it is recommended to add it.
ref avoids getting unstable changes from the main branch.