brew/Library/Homebrew/test/lock_file_spec.rb

37 lines
797 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-05-22 03:23:50 +02:00
require "lock_file"
2017-02-20 22:43:09 +01:00
RSpec.describe LockFile do
subject(:lock_file) { described_class.new("foo") }
2017-02-20 22:43:09 +01:00
describe "#lock" do
it "does not raise an error when already locked" do
lock_file.lock
2017-02-20 22:43:09 +01:00
expect { lock_file.lock }.not_to raise_error
2017-02-20 22:43:09 +01:00
end
it "raises an error if a lock already exists" do
lock_file.lock
2017-02-20 22:43:09 +01:00
expect do
2017-02-20 22:43:09 +01:00
described_class.new("foo").lock
end.to raise_error(OperationInProgressError)
2017-02-20 22:43:09 +01:00
end
end
describe "#unlock" do
it "does not raise an error when already unlocked" do
expect { lock_file.unlock }.not_to raise_error
2017-02-20 22:43:09 +01:00
end
2017-05-22 03:23:50 +02:00
it "unlocks when locked" do
lock_file.lock
lock_file.unlock
2017-02-20 22:43:09 +01:00
expect { described_class.new("foo").lock }.not_to raise_error
end
end
end