问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/18202261/include-actiondispatchtestprocess-prevents-guard-from-reloading-properly