Ruby on rails Wercker测试无法打开临时文件

Ruby on rails Wercker测试无法打开临时文件,ruby-on-rails,tdd,paperclip,temporary-files,wercker,Ruby On Rails,Tdd,Paperclip,Temporary Files,Wercker,在我的代码中,我有以下代码块 Tempfile.open([model.id.to_s, '.txt'], Rails.root.join('tmp')) do |file| begin file << somedata_i_have_before model.file = file # using paperclip gem attached file ensure # close and delete file file.close

在我的代码中,我有以下代码块

Tempfile.open([model.id.to_s, '.txt'], Rails.root.join('tmp')) do |file|
  begin
    file << somedata_i_have_before
    model.file = file # using paperclip gem attached file
  ensure
    # close and delete file
    file.close
    file.unlink
  end
end

有没有办法解决这个问题,让基于wercker的构建通过?

我想tmp文件夹被忽略了。gitignore在你的存储库中,所以当你进行一个干净的存储库克隆时,它不会被创建

我可能错了,但是Tempfile.open[model.id.to_',.txt',Rails.root.join'tmp'没有创建tmp文件夹,它希望它已经存在


我对忽略的文件夹也有类似的问题-您可以使用干净的git克隆对其进行测试,然后像在CI/CD服务器上运行一样执行此测试。

我猜tmp文件夹被忽略了。gitignore位于存储库中,因此在执行干净的存储库克隆时不会创建它

我可能错了,但是Tempfile.open[model.id.to_',.txt',Rails.root.join'tmp'没有创建tmp文件夹,它希望它已经存在


我对被忽略的文件夹也有类似的问题-你可以用一个干净的git克隆来测试它,然后像在CI/CD服务器上运行一样执行这个测试。

问题是wercker没有创建tmp,要解决这个问题,只需在运行规范之前向wercker.yml添加以下步骤

    - script:
        name: create and grant writing permission to /tmp directory
        code: |
            mkdir $WERCKER_ROOT/tmp
            chmod -R 755 $WERCKER_ROOT/tmp
            echo "$(ls -l $WERCKER_ROOT)"

    # A step that executes `rspec` command
    - script:
        name: rspec
        code: bundle exec rspec
并确保ls-l$WERCKER_ROOT包含以下内容

drwxr-xr-x  2 ubuntu ubuntu 4096 Jun 15 22:39 tmp

解决此问题的另一种方法是创建tmp/.gitcept并将其提交到您的repo。。。这也将解决这个问题,这是一个更干净的解决方案。问题是wercker没有创建tmp,要解决这个问题,只需在运行规范之前向wercker.yml添加以下步骤

    - script:
        name: create and grant writing permission to /tmp directory
        code: |
            mkdir $WERCKER_ROOT/tmp
            chmod -R 755 $WERCKER_ROOT/tmp
            echo "$(ls -l $WERCKER_ROOT)"

    # A step that executes `rspec` command
    - script:
        name: rspec
        code: bundle exec rspec
并确保ls-l$WERCKER_ROOT包含以下内容

drwxr-xr-x  2 ubuntu ubuntu 4096 Jun 15 22:39 tmp

解决此问题的另一种方法是创建tmp/.gitcept并将其提交到您的repo。。。这也将解决这个问题,这是一个更干净的解决方案

我想Wercker不允许您创建文件。通常,您希望测试行为,而不是实际的磁盘I/O。有一个很好的gem可以帮助您做到这一点:我想Wercker不允许您创建文件。通常,您希望测试行为,而不是实际的磁盘I/O。有一个很好的gem可以帮助您做到这一点:。gitkeep还可以解决此问题-除非您的一个脚本删除tmp文件夹,但这是不太可能的。gitkeep还可以解决此问题-除非您的一个脚本删除tmp文件夹,但这是不太可能的: