I'm installing an app with Pundit authorization and when I try to run RSpec tests I get:
undefined method `permissions'
for RSpec::ExampleGroups::UserPolicy:Class
(NoMethodError)
I'm installing an app with Pundit authorization and when I try to run RSpec tests I get:
undefined method `permissions'
for RSpec::ExampleGroups::UserPolicy:Class
(NoMethodError)
Found out what the problem was...
Following line in rails_helper.rb
was commented out:
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
Activating it made the tests work correctly :)
Also remember to add this your rails_helper
require 'pundit/rspec'
Found out what the problem was...
Following line in rails_helper.rb
was commented out:
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
Activating it made the tests work correctly :)
I had require 'pundit/rspec'
but I had misspelt "policies" in the spec directory structure:
spec/polices/my_policy_spec.rb
My mistake also returned the permission error message.
You can fix it by spelling policies correctly, alternatively, set the type of the test file to policy.
RSpec.describe MyPolicy, type: :policy do
...
...
end
© 2022 - 2024 — McMap. All rights reserved.
parallel_tests
. Thisrequire
onrails_helper
solved my problem. – Elvinaelvira