3

I've got a model :

FactoryGirl.define do
  factory :model do
    mini_image { fixture_file_upload(Rails.root.join('spec', 'photos', 'rails.png'), 'image/png') }
    name "Test model"
  end
end

When a run rake spec, I received this error:

NoMethodError:
   undefined method `fixture_file_upload'

I already add to my spec_helper this

config.include ActionDispatch::TestProcess

The only way I find to made my Factory working is to add this line at the beginning of my models.rb file, but it's not very clean :

include ActionDispatch::TestProcess

Anyone have another solution ?

Thanks

Supernini
  • 591
  • 5
  • 8
  • I'm not sure what's going on here with your error, but using `Rack::Test::UploadedFile.new(...)` as an alternate approach is discussed in http://stackoverflow.com/questions/3966263/attachment-fu-testing-in-rails-3 – Peter Alfvin Sep 12 '13 at 14:07

1 Answers1

12

Try to add this in your spec_helper.rb, outside of RSpec.configure block.

FactoryGirl::SyntaxRunner.class_eval do
  include ActionDispatch::TestProcess
end
abookyun
  • 457
  • 5
  • 13
  • 1
    Or to test_helper.rb if you're not using RSpec. – Shadwell Jan 16 '15 at 12:38
  • I first thought this was the solution for my set-up as well (Rails 4.2.5, RSpec 3.1.0, FactoryGirl 4.4.0). However, somehow after quitting Guard (which was sitting in the background) and running rspec on the command line, it crashed on these lines in my `spec_helper.rb` file. A very straightforward solution was to simply put `include ActionDispatch::TestProcess` in the factory file where I'd used `fixture_file_upload` (luckily just one factory). – bovender Jan 25 '16 at 20:40