include ActionDispatch::TestProcess prevents guard from reloading properly
Asked Answered
R

1

10

I'm using fixture_file_upload to test some file uploads in my rspecs

If I just put it in the spec I get an error for method not found.

To get it working I put include ActionDispatch::TestProcess in my spec but I have found since I did that, that guard is not correctly reloading spec files when I make changes, it keeps running the tests against the old version of the files.

I can work around this by stopping and restarting guard, but it kind of defeats the purpose.

How do I prevent this from happening? How should I reference fixture_file_upload or where should I put the include?

Rathenau answered 13/8, 2013 at 6:38 Comment(0)
P
21

I don't know the exact source of the problem, but I have had some strange issues caused by ActionDispatch::TestProcess myself. You can, however, use a workaround instead of fixture_file_upload, meaning you can remove the problematic include.

If you have something like this (e.g. in a factory):

include ActionDispatch::TestProcess

fixture_file_upload('spec/factories/test.png', 'image/png')

you can replace it with:

Rack::Test::UploadedFile.new('spec/factories/test.png', 'image/png')

If you look at the source of fixture_file_upload you'll see it essentially just calls the above code.

Protozoal answered 22/4, 2014 at 13:19 Comment(2)
Fwiw: including ActionDispatch::TestProcess globally (which is what happens in a factory file afaik) adds more than just the fixture_file_upload method, and what's worse, it adds it to Object. Some of the other methods it adds are #session and #cookies. Those methods will be overloaded with the ActionDispatch::TestProcess versions inside any classes which were previously defined at the time of include. This is bad news for a lot of reasons, and I suspect it causes a lot of hard-to-debug problems.Productive
Thanks Joshua, that sure shines some light on what might be causing the problem.Protozoal

© 2022 - 2024 — McMap. All rights reserved.