RSpec tests failing only on shared runners

Hello,

I recently wrote tests for one of my models that uses Rails’ ActiveStorage, and I configured it to store files on disk. My tests are passing locally, and the functionality works as expected, but when the tests run on GitLab’s shared runners, they fail. I’m having a lot of trouble trying to debug this issue. My app is not dockerized, but the docker image that GitLab’s CI creates automatically has worked perfectly until now. Are the docker images not configured to store files on disk? How can I debug the issue?

Thanks,

Alex

Hi!

Could you please share some more info about the issue/error you’ve getting?

Sure! Here is the output from my three failing tests:

1) User is valid with a profile image returns true
     Failure/Error: user.profile_image.attach(io: File.open(profile_image_path), filename: profile_image_file_name)

     TypeError:
       no implicit conversion of nil into String
     # (erb):11:in `<main>'
     # ./spec/models/user_spec.rb:28:in `block (4 levels) in <main>'

  2) User is valid with a profile image with a file size that is too large returns false
     Failure/Error: user.profile_image.attach(io: File.open(profile_image_path), filename: profile_image_file_name)

     NoMethodError:
       undefined method `upload' for nil:NilClass
     # ./spec/models/user_spec.rb:36:in `block (5 levels) in <main>'

  3) User is valid with a profile image with a file that is not an image returns false
     Failure/Error: user.profile_image.attach(io: File.open(profile_image_path), filename: profile_image_file_name)

     NoMethodError:
       undefined method `upload' for nil:NilClass
     # ./spec/models/user_spec.rb:45:in `block (5 levels) in <main>'

For the first error message (no implicit conversion of nil into String), this seems to be occurring because the profile_image_path could not be found. The file is a fixture and is located in my application’s directory. I’m assuming the other errors are occurring because the file cannot be found for some reason.

As I mentioned in my first post, these tests pass without any issues on my local development environment.

Hello,

I’m now getting a different error only on my shared runners. This is a very annoying issue and has led to several release delays. Is there any way I can debug what’s going on in the shared runners to find out how to resolve the issue?

159) ContactMessagesController POST #create logged in user increments the number of ContactMessages by 1

Failure/Error: email_domain = ::Mail::Address.new(email).domain.try(:downcase)
NameError:         uninitialized constant Mail

This is now complaining about the mail gem not being installed, but that is installed with Rails, and the logs when the Docker image is spinning up show that the mail gem is indeed installed. Like before, all of my tests pass without issue when I run them locally, and my production environment is working fine. I have a pretty lightweight app and am highly cognizant of making sure my tests are set up properly and not flaky.

Any help would be greatly appreciated.