回形针和功能测试问题(导轨)

时间:2010-07-28 15:24:33

标签: ruby-on-rails unit-testing paperclip

我的功能测试涉及回形针和附件存在问题。我正在使用fixture_file_upload方法伪造附件上传。

我的测试间歇性地给出了下面的错误(或类似的错误),由factory_girl调用生成包含附件的对象,该错误在我的设置块中。

@asset = Factory(:asset, :item => fixture_file_upload('test.png','image/png'))

但是,即使在最终的每个测试中都运行了设置块,也不会为每个测试生成此错误。在文件中运行单个测试(调用设置块和上面的方法)运行正常。只有多次测试才能得到错误(并且根据运行的测试数量而定并不一样。)因此,对fixture_file_upload的多次调用存在某种冲突。

任何人对如何解决这个问题都有任何想法?谢谢。

Errno::ENOENT: No such file or directory - /var/folders/cm/cmC3aPSEE7i3lzQGMwM2Kk+++TI/-Tmp-/stream,17938,0,17938,0
    /Users/francis/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/fileutils.rb:1407:in `stat'
    /Users/francis/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/fileutils.rb:1407:in `block in fu_each_src_dest'
    /Users/francis/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/fileutils.rb:1423:in `fu_each_src_dest0'
    /Users/francis/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/fileutils.rb:1405:in `fu_each_src_dest'
    /Users/francis/.rvm/rubies/ruby-1.9.2-preview3/lib/ruby/1.9.1/fileutils.rb:504:in `mv'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/paperclip-2.3.3/lib/paperclip/storage.rb:42:in `block in flush_writes'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/paperclip-2.3.3/lib/paperclip/storage.rb:38:in `each'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/paperclip-2.3.3/lib/paperclip/storage.rb:38:in `flush_writes'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/paperclip-2.3.3/lib/paperclip/attachment.rb:144:in `save'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/paperclip-2.3.3/lib/paperclip.rb:384:in `block in save_attached_files'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/paperclip-2.3.3/lib/paperclip.rb:377:in `block in each_attachment'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/paperclip-2.3.3/lib/paperclip.rb:376:in `each'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/paperclip-2.3.3/lib/paperclip.rb:376:in `each_attachment'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/paperclip-2.3.3/lib/paperclip.rb:383:in `save_attached_files'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activerecord-3.0.0.beta4/lib/active_record/callbacks.rb:290:in `create_or_update'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activerecord-3.0.0.beta4/lib/active_record/persistence.rb:53:in `save!'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activerecord-3.0.0.beta4/lib/active_record/validations.rb:46:in `save!'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activerecord-3.0.0.beta4/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:240:in `block in save!'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:287:in `block in with_transaction_returning_status'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activerecord-3.0.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:202:in `transaction'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:285:in `with_transaction_returning_status'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activerecord-3.0.0.beta4/lib/active_record/transactions.rb:240:in `save!'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/factory_girl-1.3.1/lib/factory_girl/proxy/create.rb:6:in `result'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/factory_girl-1.3.1/lib/factory_girl/factory.rb:326:in `run'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/factory_girl-1.3.1/lib/factory_girl/factory.rb:270:in `create'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/factory_girl-1.3.1/lib/factory_girl/factory.rb:301:in `default_strategy'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/factory_girl-1.3.1/lib/factory_girl.rb:20:in `Factory'
    /Users/francis/dev/r3/works/test/functional/assets_controller_test.rb:13:in `block in <class:AssetsControllerTest>'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:433:in `_run_setup_callbacks'
    /Users/francis/.rvm/gems/ruby-1.9.2-preview3/gems/activesupport-3.0.0.beta4/lib/active_support/testing/setup_and_teardown.rb:34:in `run'

1 个答案:

答案 0 :(得分:0)

看起来像这个问题:https://github.com/thoughtbot/paperclip/issues/270。本文中有一种可能的解决方法。