English 中文(简体)
如何在铁路使用ub/磁 original原-身份法 测试:大学
原标题:How to stub/mock original_filename method in Rails using Test::Unit

我正在编写一份下载文件试验,在此期间,我使用了原名——档案名称。 我能够用<代码>固定装置_file_upload对文件上载进行模拟。 但是,如何阻止/打碎原始名称。

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>

我知道这一检验为什么失败了,但如何加以确定?

最佳回答

找到解决办法。 我不是试图打扰<条码>:原始_filename ,而是坚持<条码>:原始名称=。 我的问题已经解决!

这里是法典

def test_import_for_photo
  fixture_file = fixture_file_upload(File.join( files ,  test.jpg ),  image/jpeg )
  fixture_file.expects(:original_filename=)
  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
问题回答

你们应设法利用暴风雨来做tu,或者(我认为)更妥善地转向使用光谱铁路。 他们拥有巨大的 mo/tu浴设施,使你能够进行更好的测试,使用更清洁的yn子,并为你的测试档案结构提供更多的组织。

这些大街的每一部都有便于查阅的有关如何打字/穿透电话的文件。





相关问题
Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Best browser for testing under Safari Mobile on Linux?

I have an iPhone web app I m producing on a Linux machine. What s the best browser I can use to most closely mimic the feature-limited version of Safari present on the iPhone? (It s a "slimmed down" ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Is there any error checking web app cralwers out there?

Wondering if there was some sort of crawler we could use to test and re-test everything when changes are made to the web app so we know some new change didn t error out any existing pages. Or maybe a ...

热门标签