rspec-rails: fixture_file_upload cannot find files in request specs
Steps to to reproduce (using rails 4.2.5.1):
rails new fixture_file_upload
cd fixture_file_upload
echo "gem 'rspec-rails', '~> 3.0'" >> Gemfile
bundle
rails generate rspec:install
mkdir -p spec/fixtures/files
touch spec/fixtures/files/test.jpg
mkdir spec/requests
Create spec/requests/test_spec.rb with the following contents:
require 'rails_helper'
describe 'test', type: :request do
it 'tests' do
fixture_file_upload('test.jpg')
end
end
rake
Failures:
1) test tests
Failure/Error: fixture_file_upload('test.jpg')
RuntimeError:
test.jpg file does not exist
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 2
- Comments: 19 (4 by maintainers)
Commits related to this issue
- created mini app as specified in https://github.com/rspec/rspec-rails/issues/1554#issue-134479615 — committed to Andy-Bell/fixture_file_upload by Andy-Bell 8 years ago
The
include ActionDispatch::TestProcesssection works for me using Rails 5.0.0.1 and RSpec rails - 3.5.2.Thanks!
For what it’s worth, in case this is blocking people, passing an absolute path does work:
Seems like
ActionDispatch::TestProcessdoesn’t have access tofixture_pathso it won’t be able to prepend it to the passed file path.Also, it’s probably obvious to everybody else, but you have to explicitly put it under the
paramskey, you can’t path it through the path (duh):Same problem here. I found out the following while poking around:
#fixture_file_uploadusesfixture_pathonly ifself.class.respond_to?(:fixture_path)returns true (see https://github.com/rails/rails/blob/4-2-stable/actionpack/lib/action_dispatch/testing/test_process.rb#L38)p self.class, self.class.respond_to?(:fixture_path)to my example it printsRSpec::ExampleGroups::FoobarExample, true. So far, so good.#fixture_file_uploadmethod it printsActionDispatch::Integration::Session, false.So somehow the context inside
fixture_file_uploadseems to be wrong?can be closed