trick_bag 0.35.0 → 0.36.0

Sign up to get free protection for your applications and to get access to all the features.
data/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.36.0
2
+
3
+ * Add System module w/lsof and command_available? methods.
4
+
5
+
1
6
  ## v0.35.0
2
7
 
3
8
  * Added start_pos and max_count accessors to FileLineReader.
@@ -0,0 +1,27 @@
1
+ require 'os'
2
+
3
+ module TrickBag
4
+
5
+ # Convenience methods for dealing with Posix-compliant systems.
6
+ module System
7
+
8
+ module_function
9
+
10
+ # Calls lsof to return information about all files *open by this process*.
11
+ # Output returned is lsof's output, but after calling split("\n") to create
12
+ # an array of the result strings.
13
+ #@param options additional options to the lsof command line, if any, defaults to ''
14
+ def lsof(options = '')
15
+ raise "Cannot be called on a non-Posix operating system." unless OS.posix?
16
+ raise "lsof command not found" unless command_available?('lsof')
17
+ `lsof #{options} -p #{Process.pid}`.split("\n")
18
+ end
19
+
20
+
21
+ def command_available?(command)
22
+ raise "Cannot be called on a non-Posix operating system." unless OS.posix?
23
+ system("which #{command} > /dev/null")
24
+ end
25
+
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module TrickBag
2
- VERSION = "0.35.0"
2
+ VERSION = "0.36.0"
3
3
  end
@@ -3,6 +3,7 @@ require 'tempfile'
3
3
 
4
4
  require_relative '../../spec_helper'
5
5
  require 'trick_bag/enumerables/file_line_reader'
6
+ require 'trick_bag/system'
6
7
 
7
8
  module TrickBag
8
9
  module Enumerables
@@ -31,7 +32,7 @@ nbc.com
31
32
  @tempfile.unlink
32
33
  end
33
34
 
34
- let(:can_run_lsof?) { OS.posix? && system('which lsof > /dev/null') }
35
+ let(:can_run_lsof?) { OS.posix? && System.command_available?('lsof') }
35
36
 
36
37
  subject { FileLineReader.new(@tempfile.path) }
37
38
 
@@ -96,13 +97,10 @@ nbc.com
96
97
  pending "This test can only be run on a Posix-based OS having the 'lsof' command."
97
98
  end
98
99
 
99
- get_lsof_lines = -> do
100
- output = `lsof -p #{Process.pid} | grep file_domain_reader_spec`
101
- output.split("\n")
102
- end
100
+ get_lsof_lines = -> { System.lsof.grep(/file_domain_reader_spec/) }
103
101
 
104
102
  reader = FileLineReader.new(@tempfile.path, 0, 1)
105
- reader.each do |line|
103
+ reader.each do |_| # using _ as an identifier signifies that the value is not used
106
104
  expect(get_lsof_lines.().size).to eq(1)
107
105
  end
108
106
  expect(get_lsof_lines.().size).to eq(0)
@@ -121,7 +119,6 @@ nbc.com
121
119
  specify "max_count returns the value passed to the constructor" do
122
120
  expect(FileLineReader.new(@tempfile.path, 10, 200).max_count).to eq(200)
123
121
  end
124
-
125
122
  end
126
123
  end
127
124
  end
@@ -0,0 +1,35 @@
1
+ require_relative '../spec_helper'
2
+
3
+ require 'trick_bag/system'
4
+
5
+ module TrickBag
6
+ module System
7
+
8
+ posix_only_test = -> do
9
+ describe 'System' do
10
+
11
+ context "#command_available" do
12
+ specify 'which ls returns true' do
13
+ expect(System.command_available?('ls')).to be_true
14
+ end
15
+
16
+ specify 'which fsdfiuowqpfeqpxumwfuqiufqpiufpqwmiurqpruiiqwmxrqupruxmqowiruqmpmu returns false' do
17
+ expect(System.command_available?('fsdfiuowqpfeqpxumwfuqiufqpiufpqwmiurqpruiiqwmxrqupruxmqowiruqmpmu')).to be_false
18
+ end
19
+ end
20
+
21
+
22
+ context ".lsof" do
23
+ specify "returns ruby lines" do
24
+ lines = System.lsof
25
+ has_ruby_line = lines.any? { |line| /ruby/ === line }
26
+ expect(has_ruby_line).to be_true
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ posix_only_test.() if OS.posix?
33
+
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trick_bag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.35.0
4
+ version: 0.36.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-19 00:00:00.000000000 Z
12
+ date: 2014-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -136,6 +136,7 @@ files:
136
136
  - lib/trick_bag/numeric/start_and_max.rb
137
137
  - lib/trick_bag/numeric/totals.rb
138
138
  - lib/trick_bag/operators/operators.rb
139
+ - lib/trick_bag/system.rb
139
140
  - lib/trick_bag/timing/timing.rb
140
141
  - lib/trick_bag/validations/hash_validations.rb
141
142
  - lib/trick_bag/validations/object_validations.rb
@@ -155,6 +156,7 @@ files:
155
156
  - spec/trick_bag/numeric/start_and_max_spec.rb
156
157
  - spec/trick_bag/numeric/totals_spec.rb
157
158
  - spec/trick_bag/operators/operators_spec.rb
159
+ - spec/trick_bag/system_spec.rb
158
160
  - spec/trick_bag/timing/timing_spec.rb
159
161
  - spec/trick_bag/validations/hashes_validations_spec.rb
160
162
  - spec/trick_bag/validations/object_validations_spec.rb
@@ -200,6 +202,7 @@ test_files:
200
202
  - spec/trick_bag/numeric/start_and_max_spec.rb
201
203
  - spec/trick_bag/numeric/totals_spec.rb
202
204
  - spec/trick_bag/operators/operators_spec.rb
205
+ - spec/trick_bag/system_spec.rb
203
206
  - spec/trick_bag/timing/timing_spec.rb
204
207
  - spec/trick_bag/validations/hashes_validations_spec.rb
205
208
  - spec/trick_bag/validations/object_validations_spec.rb