Search code examples
ruby-on-railstddpapercliptemporary-fileswercker

Wercker test fails to open tempfiles


In my code I have the following block

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

This code works fine locally and on production... the problem is that I have set up Wercker app to automate testing and deploying but the block mentioned above fails on wercker and return the following error

Errno::ENOENT:
No such file or directory @ rb_sysopen - /pipeline/build/tmp/539e01d4776572049647010020140615-1174-ajp5tf.txt
# ./lib/some_lib.rb:63:in `some_method'

any ideas how to solve this so that the build on wercker pass ?


Solution

  • I guess the tmp folder is ignored (.gitignore) in your repository and so it won't be created when you do a clean repository clone.

    I might be wrong but Tempfile.open([model.id.to_s, '.txt'], Rails.root.join('tmp')) doesn't create the tmp folder, it expects it to already exist.

    I had similar problems with ignored folders - you can test it with a clean git clone then executing this test as it would run on a CI/CD server.