I'm working on a Ruby on Trailblazer API and I keep getting this error when I run my Rspec test suite:
FrozenError: can't modify frozen #<Class:NotificationCenter>: NotificationCenter
I can't seem to determine where or how the class is being frozen. Find the file and stacktrace below for context:
sftp.rb File:
# frozen_string_literal: true
require 'grape'
require 'concepts'
class NotificationCenter < NotificationCenter.superclass
module API ### <- failure occurs on this line ###
class Notifications < Grape::API
class Reports < Grape::API
class Failed < Grape::API
class Sftp < Grape::API
resource :sftp do
route_param :email do
desc 'send notification to a specific user when report has failed to upload to sftp'
params do
optional :test, type: Boolean, default: true
requires :email, type: String, coerce_with: Base64.method(:urlsafe_decode64)
requires :report_name, type: String
end
post do
result = run! Notification::Report::User, {}, 'email.cell' => Notification::Cell::Report::Failed::Sftp
handle! result
end
end
end
end
end
end
end
end
end
Stack trace:
An error occurred while loading ./spec/resources/notifications/statements/failed_spec.rb.
Failure/Error: module API
FrozenError:
can't modify frozen #<Class:NotificationCenter>: NotificationCenter
# ./app/resources/notifications/reports/failed/sftp.rb:7:in `<class:NotificationCenter>'
# ./app/resources/notifications/reports/failed/sftp.rb:6:in `<top (required)>'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
# ./app/resources/notifications/reports/failed.rb:7:in `glob'
# ./app/resources/notifications/reports/failed.rb:7:in `<top (required)>'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
# ./app/resources/notifications/reports.rb:7:in `glob'
# ./app/resources/notifications/reports.rb:7:in `<top (required)>'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
# ./app/resources/notifications.rb:7:in `glob'
# ./app/resources/notifications.rb:7:in `<top (required)>'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
# ./app/resources.rb:4:in `glob'
# ./app/resources.rb:4:in `<top (required)>'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
# ./app.rb:9:in `<top (required)>'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/zeitwerk-2.6.6/lib/zeitwerk/kernel.rb:38:in `require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `block in require'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:291:in `require'
# ./spec/resources/notifications/statements/failed_spec.rb:3:in `<top (required)>'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:285:in `load'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:285:in `block in load'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:257:in `load_dependency'
# /usr/local/bundle/gems/activesupport-5.2.8.1/lib/active_support/dependencies.rb:285:in `load'
As I said earlier, I can't seem to determine where or how the class is being frozen. I traversed the stack trace to try and determine where the NotificationCenter class had been defined the very first time. As far as I can tell, the sftp.rb file above, where the error is occuring, is the first time the class is being defined. I put a binding.pry just below class NotificationCenter < NotificationCenter.superclass, and ran NotificationCenter.frozen?, which returned true.
This is strange to me because as the class is being defined, the very first time it even comes into existence (as far as I can tell), it is already frozen. Additionally, there is not a single .freeze in the entire repository. So the class is seemingly being frozen by some other means.
Does anyone have any idea why this might occur?