How to mute clip file paths in Capybara / Rspec

For some applications, I use Paperclip to download files (actually dm-paperclip flavor) and Factory Girl, Rspec, Capybara for testing. I have a very simple Factory model for the Picture model, in which I correct my file properties as suggested in this post :

FactoryGirl.define do
  factory :picture do
    title "My Picasso"
    description "It like looking in a mirror."
    picture_file_file_name { 'spec/resources/img_1.jpg' }
    picture_file_content_type { 'image/jpg' }
    picture_file_file_size { 1024 }
  end
end

In various property tests with Capybara, I visit pages where templates have thumbnails of Picture instances:

feature "List of Pictures", :js => true  do
  scenario "displays appropriately the index page of the pictures with pagination" do
    FactoryGirl.create_list(:picture, 21)
    visit '/pictures'
    # And more testing...
  end
end

An example of partial use in one of the templates:

=  content_tag_for(:li, picture, :class => 'listed_picture') do
  = link_to picture_path(picture) do
    - if picture.picture_file?
      = image_tag picture.picture_file.url(:thumb)

The problem that I am facing now is when I run the specifications, the test fails because there is no suitable route for sketching the sketch:

No route matches [GET] "/system/picture_files/1/thumb/img_1.jpg"

Is there a way to drown out the auxiliary clip methods to pass the test?

Thanks in advance for your help!

+4
1

. .

, URL- , , . :

#picture.rb

class Picture
...
  def picture_file_url(size = nil)
    picture_file.url(size)
  end
...
end

URL- :

describe "List of Pictures", :js => true  do
  it "displays appropriately the index page of the pictures with pagination" do
    let(:picture) { create(:picture) }
    allow(Picture).to receive(:picture_file_url) { "url" }
    visit '/pictures'
    # And more testing...
  end
end

, -.

+1

Source: https://habr.com/ru/post/1541977/


All Articles