I implemented a notification function in my personally developed app, then pushed it to Git and checked the CircleCI test results, but suddenly a lot of tests failed and I was a little troubled, so I will share the solution here.
Failure/Error: -if unchecked_notifications.any?
ActionView::Template::Error:
undefined local variable or method `unchecked_notifications' for #<#<Class:0x0000555732134140>:0x00005557326f7f78>
I have defined a helper method called unchecked_notifications
to change the view displayed when notifications are coming and when notifications are not coming. However, when RSpec is executed, this helper method is not loaded and it seems that the test failed with an error.
notifications_helper.rb
module NotificationsHelper
def unchecked_notifications
@notifications = current_user.passive_notifications.where(checked: false)
end
end
The solution is simple. Include the module in the file where you want to run the test and it should work. ↓ Example
post_spec.rb
require 'rails_helper'
#Include helper methods
include NotificationsHelper
RSpec.describe 'Posting function', type: :system do
#Test process
end
I output what I learned every day! If you have any suggestions, I would appreciate it if you could comment!
Recommended Posts