2

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 ?

a14m
  • 7,808
  • 8
  • 50
  • 67
  • I guess Wercker doesn't allow you to create files. In general you want to test the behavior rather than the actual disk I/O. There's a nice gem that helps with that: https://github.com/defunkt/fakefs – Tal Jun 16 '14 at 06:18

2 Answers2

3

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.

Viktor Benei
  • 3,447
  • 2
  • 28
  • 37
1

The problem was that wercker doesn't create the tmp, and to solve this just add the following step to your wercker.yml ( before running the specs )

    - 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

and make sure that ls -l $WERCKER_ROOT include something like following

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

one other way solve this issue is to create tmp/.gitkeep and commit it to your repo... this will solve the issue as well ( which is a cleaner solution )

a14m
  • 7,808
  • 8
  • 50
  • 67