pidlock 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/pidlock.rb +6 -0
  2. data/spec/lib/pidlock_spec.rb +13 -0
  3. metadata +1 -1
data/lib/pidlock.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'logger'
2
+ require 'fileutils'
2
3
 
3
4
  class Pidlock
4
5
 
@@ -36,4 +37,9 @@ class Pidlock
36
37
  end
37
38
  end
38
39
 
40
+ def unlock
41
+ @file.close
42
+ FileUtils.rm_f(@filename)
43
+ end
44
+
39
45
  end
@@ -86,5 +86,18 @@ describe Pidlock do
86
86
  pidlock.logger = logger2
87
87
  pidlock.lock
88
88
  end
89
+ it "should close and remove the file if unlocked" do
90
+ @file.should_receive(:gets).and_return('667')
91
+ ps = stub("ProcTableStruct", :comm => 'test')
92
+ ::Sys::ProcTable.should_receive(:ps).with(667).and_return(nil)
93
+ logger.should_receive(:warn).with('WARNING: resetting stale lockfile')
94
+ @file.should_receive(:rewind)
95
+ @file.should_receive(:write).with(666)
96
+ lock = Pidlock.new('my.pid')
97
+ lock.lock
98
+ FileUtils.should_receive(:rm_f).with("/var/run/my.pid").and_return(true)
99
+ @file.should_receive(:close)
100
+ lock.unlock
101
+ end
89
102
  end
90
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pidlock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: