Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stubbing Paperclip S3 requests in specs

I am using Paperclip and S3 for image uploads and am trying to stub out calls to S3 from my test suite. I found the thoughtbot post which mentions doing

  a.cover       { a.paperclip_fixture('album', 'cover', 'png') }

but that gives me a "wrong number of arguments (4 for 2)" error. I tried switching the arguments above to an array, which removes the original error, but gives an error saying "Attribute already defined: paperclip_fixture".

Has anyone been able to get this working? Also, I'd ideally like to use the local filesystem for the development environment. Is there an easy way to do this?

like image 363
Eric M. Avatar asked Feb 09 '11 05:02

Eric M.


1 Answers

Okay, I've got the basic issue figured out. This is (I believe) as Eliza said, because I'm not using shoulda (I'm using rspec 2.6.0 and factory_girl 2.1.2).

Here's what worked for me (where Profile is the class that has attachements):

  Profile.any_instance.stub(:save_attached_files).and_return(true)
  @profile = Factory(:profile)

At the moment I just have this right in my before method of my rspec example. There's probably a better place to put it.

like image 124
denishaskin Avatar answered Sep 19 '22 13:09

denishaskin