我正在编写一个文件下载测试,在此期间我使用的是 original_filename。我能够使用fixture_file_upload
. 但是如何存根/模拟 original_filename 调用。
def import_for_photo(picture_url, user)
remote_photo = open(picture_url)
remote_photo.original_filename = "#{user.id}.jpg"
user.update_attributes({:picture => remote_photo})
end
考试
def test_import_for_photo
fixture_file = fixture_file_upload(File.join('files', 'test.jpg'), 'image/jpeg')
OpenURI.expects(:open_uri).returns(fixture_file)
import_for_photo("http://dummy_url.com/dummy.jpg", users(:one))
assert_equal "1.jpg", users(:one).reload.picture_file_name
end
测试输出,
NoMethodError: undefined method `original_filename=' for #<File:/tmp/test.jpg20120512-4253-x673nc-0>
我知道为什么这个测试失败了,但是如何解决呢?