Permission denied - /var/tmp/ruby-uuid

Back | rails, ruby, testing | 9/1/2011 |

I’ve been fighting a trivial RoR controller test failure on a new build machine. The spec is rather trivial.

  1.   def mock_widget(stubs={})
  2.     @mock_widget ||= mock_model(Widget, stubs).as_null_object
  3.   end
  4.  
  5. it "assigns a newly created widget as @widget" do
  6.     Widget.stub(:new) { mock_widget }
  7.     post :create, :widget => {'these' => 'params'}
  8.     assigns(:widget).should be(mock_widget)
  9. end

Exceptions in Rails controllers are eaten in RSpec tests. So whenever I have a controller spec failure, I add a begin/rescue block in it. This is hacky, but gets the job done.

  1. def create
  2.   begin
  3.     ...
  4.   rescue Exception => e
  5.     puts e.message
  6.     puts e.backtrace
  7.     raise e
  8.   end
  9. end

Today’s spec failure was rather curious.

  1. Permission denied - /var/tmp/ruby-uuid                         | ETA:  00:00:02
  2. /home/jenkins/.rvm/gems/ruby-1.9.2-p290/gems/uuid-2.3.2/lib/uuid.rb:354:in `initialize'
  3. /home/jenkins/.rvm/gems/ruby-1.9.2-p290/gems/uuid-2.3.2/lib/uuid.rb:354:in `open'
  4. /home/jenkins/.rvm/gems/ruby-1.9.2-p290/gems/uuid-2.3.2/lib/uuid.rb:354:in `open_lock'
  5. /home/jenkins/.rvm/gems/ruby-1.9.2-p290/gems/uuid-2.3.2/lib/uuid.rb:322:in `next_sequence'
  6. /home/jenkins/.rvm/gems/ruby-1.9.2-p290/gems/uuid-2.3.2/lib/uuid.rb:256:in `initialize'
  7. /var/lib/jenkins/jobs/gravity-master/workspace/app/controllers/admin/widgets_controller.rb:35:in `new'
  8. /var/lib/jenkins/jobs/gravity-master/workspace/app/controllers/admin/widgets_controller.rb:35:in `widget_hash'
  9. /var/lib/jenkins/jobs/gravity-master/workspace/app/controllers/admin/widgets_controller.rb:12:in `create'

The culprit was ruby-uuid, an old library that creates a temporary file with a fixed name. If you run tests under different user accounts, the second run will yield a permission denied. Time to switch the UUID library, to maybe this one.