How to create a Mock in Ruby On Rails (Carrierwave) to simulate sending an image to a S3 (Cloudinary)

Asked

Viewed 125 times

2

I created a project creation system with image. My images are uploaded to Cloudinary + Carrierwave.

Before the Test did not break because I sent to the server, but when I integrated in Cloudinary the code broke.

I think I know what it can be, but I don’t know how to fix it. When it inserts it into the Cloudinary database it returns a random value, as I do to

   **within(".asset_project") do
      expect(page).to have_css("img[src*='project.png']")
   end**

the TDD is correct, because I think this is it.

Follows the image of errors and code: https://lh6.googleusercontent.com/-dasTkpspvKI/VHNl-7pfVRI/AAAAAAAAEt4/L-fNHEwV0ek/s1600/creating_projects_spec.png

https://lh5.googleusercontent.com/-Ra4_Fe5ufAw/VHNl0g3_THI/AAAAAAAAEto/Gk3nE3lM2RQ/s1600/BDD.png

  • if it puts a random value, you cannot access the model and compare if the one in the view is the same as the model’s?

  • If I understand the question, you need to "mock" a call to an external API. Is that? If yes, using the Gem Webmock does not solve?

  • solved to Gem! Thank you very much!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.