私は FactoryGirl を使用して、ユニット (RSpec) テストと統合 (Cucumber) テストの両方でモデルをモックしています。ファクトリを作成するときNews
、ランダムな画像 URL を作成しますが、これは明らかにプロジェクト内には存在しません。Selenium テストを実行すると、これは 404 として取得されます。
FactoryGirl.define do
factory :news do
title { Faker::Lorem.sentence }
image { Faker::Internet.relative_url ".jpg" }
body { Faker::Lorem.paragraphs.join "\r\n\r\n" }
before :create do
Timecop.freeze Faker::Date.time
end
after :create do
Timecop.return
end
after :build do |article|
# Somehow mock a 200 response for #{article.image}
end
factory :published_news do
published true
end
end
end
画像の応答をモックする最良の方法は何ですか?