我正在我的应用程序上测试一个显示视频的页面。我试图通过绕过视频上传过程或其他方式来加快测试速度??
也许我在上传文件时错误地使用了FactoryGirl。
使用FactoryGirl,我正在创建视频
FactoryGirl.define do
factory :video do
user_id 1
type "Live"
title "FooBar"
description "Foo bar is the description"
video { fixture_file_upload(Rails.root.join('spec', 'files', 'concert.mov'), 'video/mp4') }
end
end
在请求的规范中,我将视频描述为:
describe "videos page" do
let(:user) { FactoryGirl.create(:user) }
let!(:video1) { FactoryGirl.create(:video) }
before { visit user_video_path(user) }
it { should have_title(user.name) }
it { should have_content(user.name) }
describe "videos" do
it { should have_content(video1.description) }
end
end
现在,每次我对这个页面运行测试时,它都会经过文件上传过程,这需要更多的时间。我也在使用FFmpeg
**video.rb (video model)**
validates :video, presence: true
has_attached_file :video, :styles => {
:medium => { :geometry => "640x480", :format => 'mp4' },
:thumb => { :geometry => "470x290#", :format => 'jpg', :time => 10 }
},
:processors => [:ffmpeg]
当我测试页面时,它的作用是CLI完成视频上传过程,就像您上传视频并观看本地服务器时一样。
发布于 2014-03-01 01:23:56
使用某些值覆盖video属性,这些值通过了使用工厂创建对象时测试所需的所有验证和要求。对于具体类型,您可以使用double。试试这样的东西
file = double('file', :size => 0.2.megabytes, :content_type => 'mp4', :original_filename => 'rails')
let!(:video1) { FactoryGirl.create(:video, video => file) }
https://stackoverflow.com/questions/22108853
复制