2012-10-20 95 views

回答

1

如果你已经使用回形针话,我可以帮你在这个..

写测试用例这样

def do_upload_file 
# write the request for the action as defined in your routes file 
# get :upload_file, :id => :user_id (id of the user) 
end 

before do 
# set the session variables and other parameters here.. 
end 

it "should upload the file correctly" do 
    @user.should_receive(:update_attributes).and_return(true) 
    do_upload_asset 
    response.should redirect_to(whatever_path) 
end 

对我的作品,并能为你希望工作太....

+1

如何上传测试特定的JPEG/PNG文件? –

1

你可以做到这一点使用:

obj.asset = fixture_file_upload('/dummy_file.png', 'image/png') 

在那里你可以在你的规范定义的固定路径助手为:

config.fixture_path = "#{Rails.root}/spec/fixtures" 

Official documentation

相关问题