Sha256: 2b5e78c097aed75b595e698b86362351caa66be3a01b3a2bc84e2b97a04ff82d

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'fileutils'

describe Mutagem::Mutex do

  before(:each) do
    # remove tmp/aruba
    FileUtils.rm_rf(current_dir)
  end

  it "should create a mutex, yield, and clean up" do
    in_current_dir do
      mutex = Mutagem::Mutex.new
      result = mutex.execute do
        File.should be_file('mutagem.lck')
        mutex.should be_locked
      end
      result.should be_true
      mutex.should_not be_locked
      File.should_not be_file('mutagem.lck')
    end
  end

  it "should prevent recursion but not block" do
    in_current_dir do
      Mutagem::Mutex.new.execute do
        File.should be_file('mutagem.lck')

        mutex = Mutagem::Mutex.new
        result = mutex.execute do
          # This block is protected, should not be here
          true.should be(false)
        end
        result.should be_false
        mutex.should be_locked
      end
      File.should_not be_file('mutagem.lck')
    end
  end

  it "should raise ArgumentError unless a block is given" do
    in_current_dir do
      mutex = Mutagem::Mutex.new
      lambda {result = mutex.execute}.should raise_error(ArgumentError, 'missing block')
    end
  end

end


Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mutagem-0.2.4 spec/mutagem/mutex_spec.rb
mutagem-0.2.3 spec/mutagem/mutex_spec.rb
mutagem-0.2.2 spec/mutagem/mutex_spec.rb
mutagem-0.2.1 spec/mutagem/mutex_spec.rb