The right way to use #fixture_file_upload in request specs

10 views
Skip to first unread message

belgoros

unread,
Apr 24, 2019, 11:18:53 AM4/24/19
to rspec
I still can't figure out the right way to use fixture_file_upload method in a request spec.
I looked through several issues: 1554 and 1943, but still no success.

I put an image rails.jpeg in spec/fixtures folder.
Here is an example that fails:

describe 'PATCH /shops/:shop_identifer' do
    let
(:photo) {fixture_file_upload('files/rails.jpeg') }
    let
(:valid_params) do
      ams_json
(
       
Shop,
        category
: shop.category,
        country
: shop.country,
        identifier
: shop.identifier,
        modified_by
: shop.modified_by,
        name
: 'new name',
        photo
: photo,
        status
: shop.status
     
)
   
end


    before
{ patch "/shops/#{shop.identifier}", params: valid_params, headers: headers }
...
    it
'creates a blob ' do
      expect
(shop.photo.attached?).to be true
   
end


It fails with:

RuntimeError:

 files
/rails.jpeg file does not exist


What am I missing?

RSpec version: 3.8.1
Rails version: 5.2.0


belgoros

unread,
Apr 24, 2019, 11:42:17 AM4/24/19
to rspec
I found it in RSpec docs.
SO, instead of fixture_file_upload, I had to use file_fixture.
Hope this helps.
You can customize files location.

Jon Rowe

unread,
Apr 27, 2019, 4:31:38 AM4/27/19
to rs...@googlegroups.com
I believe it depends on your Rails version, as Rails 5 has the file_fixture method.

Jon Rowe
---------------------------
Reply all
Reply to author
Forward
0 new messages