- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Description
The other day I was having no problems running fixture_file_upload in my factory. Previously I just used a basic Factory.define but I wanted to get rid of the deprecated warnings.
So today I went to run my tests and I am getting the following errors:
undefined method 'fixture_file_upload' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007fe6822f6e10>
undefined method `fixture_file_upload' for #<FactoryGirl::SyntaxRunner:0x007fe6827c2188>
The code looks like this
FactoryGirl.define do
factory :mongo_document do
original_filename "test.jpg"
file {fixture_file_upload(Rails.root.to_s + '/spec/fixtures/files/test.jpg', 'img/jpeg')}
end
end
I have even tried putting in
spec_helper / test_helper
include ActionController::TestProcess
No luck. What am I missing?
Activity
jferris commentedon May 22, 2012
Where is
fixture_file_upload
defined? Can you tryKernel.fixture_file_upload
?davidpatrick commentedon May 23, 2012
Okay so it looks like my project isn't loading the test_helper.rb because when I change the code to the following it will work
zerodie commentedon Jun 7, 2012
Thank you @batreyud, it works for me adding "include ActionDispatch::TestProcess".
ferdinandrosario commentedon Apr 9, 2014
Thanks for solution.It helps me also for "fixture_file_upload" in Rspec model.
sqbell commentedon Jun 4, 2014
Be careful, I've had some rather obscure, session related problems when I included the module. See: http://stackoverflow.com/questions/18202261/include-actiondispatchtestprocess-prevents-guard-from-reloading-properly.
Fix failing tests by adding corresponding module for fixture_file_upload
pjg commentedon Nov 15, 2018
Don't include ActionDispatch::TestProcess. It has some nasty consequences.
Proper solution is to use
Rack::Test::UploadedFile
directly in the factory (whatfixture_file_upload
essentially does anyway):josephbhunt commentedon Feb 13, 2019
@pjg I've been trying to use
Rack::Test::UploadedFile
, but I get an errorREXML::UndefinedNamespaceException: Undefined prefix Rack::Test: found
. Do I need to require a file or include a module to make this work?pjg commentedon Feb 14, 2019
@josephbhunt Judging by the
REXML::UndefinedNamespaceException
exception it looks like you're in the wrong context when you execute thisfile
helper (do you have it in the factory definition?). As a workaround you might try to prefixRack
with::
so that it references top-level namespace and becomes::Rack::Test::UploadedFile
.specs: use `fixture_file_upload` rather than `Rack::Test::UploadedFile`
fixture_file_upload
rather thanRack::Test::UploadedFile
demarches-simplifiees/demarches-simplifiees.fr#5318Merge #5318