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...
I've fixed this by including their module on the RSpec config block:
RSpec.configure do |config|
#...
config.include ActionDispatch::TestProcess::FixtureFile
#...
end
this worked for me
Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/doc.pdf"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With