I'm trying to test a file upload using RSpec 3.7 in a Rails 5.2 app, and the simplest recommendation I've seen (several places, including this SO post) is to use fixture_file_upload
- which looks great, except that it doesn't seem to be available in my app, and I don't know why.
The only thing I can think of is that our app is not using ActiveRecord, it's using MongoID. But ActiveRecord shouldn't be required to use these methods... they're totally unrelated. Is there another new "ActiveSomething" library in Rails 5 that I'm missing? (this app was upgraded from a Rails 4 app...)
To explain my problem more concretely, I've tried putting:
let(:file) { fixture_file_upload('invalid_csv.csv') }
in one of my contexts, and it raises an exception:
undefined local variable or method 'fixture_path' for #<RSpec::ExampleGroups::...>
I tried defining config.file_fixture_path
as outlined here, and that raises it's own exception:
undefined method `file_fixture_path=' for #<RSpec::Core::Configuration::...>
Does this work at all? Clearly I'm missing something...
config.fixture_path = "#{Rails.root}/xxx/xxx"
in RSpec.configure? – Browderfixture_path=
for <RSpec::Core::Configuration...>" – Stamfordfixture_file_upload
helper that was justRack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/#{path}"), mime, true)
. Seems like a ridiculous thing to do but it works in Rails6 and lets me get on with the upgrade so... – HensleyRack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/#{path}"), mime, true)
as mentioned above has worked around the problem to me. – Centuplicate