process_helper 0.0.1

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.
@@ -0,0 +1,69 @@
1
+ require_relative '../spec_helper'
2
+
3
+ RSpec.describe 'options validation raises InvalidOptionError' do
4
+ attr_reader :clazz
5
+
6
+ before do
7
+ @clazz = Clazz.new
8
+ end
9
+
10
+ it 'on single invalid option' do
11
+ expect do
12
+ clazz.process('echo', invalid_option: false)
13
+ end.to raise_error(
14
+ ProcessHelper::InvalidOptionsError,
15
+ /Invalid option\(s\) 'invalid_option' given.*Valid options are.*puts_output/)
16
+ end
17
+
18
+ it 'on multiple invalid options' do
19
+ expect do
20
+ clazz.process('echo', invalid_option: false, invalid_option2: true)
21
+ end.to raise_error(
22
+ ProcessHelper::InvalidOptionsError,
23
+ /Invalid option\(s\) 'invalid_option, invalid_option2' given/)
24
+ end
25
+
26
+ it 'when both long and short form of option is given' do
27
+ expect do
28
+ clazz.process('echo', puts_output: :always, out: :always)
29
+ end.to raise_error(
30
+ ProcessHelper::InvalidOptionsError,
31
+ "Cannot specify both 'puts_output' and 'out'")
32
+ end
33
+
34
+ it 'when expected_exit_status param is passed non-integer or array without all integers' do
35
+ expect do
36
+ clazz.process('echo', expected_exit_status: '0')
37
+ end.to raise_error(
38
+ ProcessHelper::InvalidOptionsError,
39
+ "'expected_exit_status','exp_st' options must be an Integer or an array of Integers")
40
+ end
41
+
42
+ it 'when boolean param is passed non-boolean' do
43
+ expect do
44
+ clazz.process('echo', include_output_in_exception: '0')
45
+ end.to raise_error(
46
+ ProcessHelper::InvalidOptionsError,
47
+ "'include_output_in_exception','out_ex' options must be a boolean")
48
+ end
49
+
50
+ it 'when puts_output param is passed invalid value' do
51
+ expect do
52
+ clazz.process('echo', puts_output: :invalid)
53
+ end.to raise_error(
54
+ ProcessHelper::InvalidOptionsError,
55
+ "'puts_output','out' options must be one of the following: :always, :error, :never")
56
+ end
57
+
58
+ it 'when input_lines is passed invalid value'
59
+
60
+ it 'when timeout is passed non-float'
61
+
62
+ it 'when passed a short option' do
63
+ expect do
64
+ clazz.process('echo', exp_st: '0')
65
+ end.to raise_error(
66
+ ProcessHelper::InvalidOptionsError,
67
+ "'expected_exit_status','exp_st' options must be an Integer or an array of Integers")
68
+ end
69
+ end
@@ -0,0 +1,61 @@
1
+ require_relative 'spec_helper'
2
+
3
+ RSpec.describe 'output handling' do
4
+ attr_reader :clazz
5
+
6
+ before do
7
+ @clazz = Clazz.new
8
+ end
9
+
10
+ it 'captures stdout only' do
11
+ expect do
12
+ clazz.process(
13
+ 'echo stdout > /dev/stdout && echo stderr > /dev/null',
14
+ puts_output: :always)
15
+ end.to output("stdout\n").to_stdout
16
+ .and(not_output.to_stderr)
17
+ end
18
+
19
+ it 'captures stderr only' do
20
+ expect do
21
+ clazz.process(
22
+ 'echo stdout > /dev/null && echo stderr > /dev/stderr',
23
+ puts_output: :always)
24
+ end.to output("stderr\n").to_stdout
25
+ .and(not_output.to_stderr)
26
+ end
27
+
28
+ it 'captures stdout and stderr' do
29
+ expect do
30
+ clazz.process(
31
+ 'echo stdout > /dev/stdout && echo stderr > /dev/stderr',
32
+ puts_output: :always)
33
+ end.to output("stdout\nstderr\n").to_stdout
34
+ .and(not_output.to_stderr)
35
+ end
36
+
37
+ describe 'when :puts_output == :never' do
38
+ describe 'when include_output_in_exception is false' do
39
+ it 'show warning' do
40
+ expect do
41
+ clazz.process(
42
+ 'echo stdout > /dev/stdout',
43
+ puts_output: :never,
44
+ include_output_in_exception: false)
45
+ end.to output(/all error output will be suppressed if process fails/).to_stderr
46
+ .and(not_output.to_stdout)
47
+ end
48
+ end
49
+
50
+ describe 'when include_output_in_exception == true' do
51
+ it 'do not show warning' do
52
+ expect do
53
+ clazz.process(
54
+ 'echo stdout > /dev/stdout',
55
+ puts_output: :never)
56
+ end.to output(/unless process fails with an exit code other than \[0\]/).to_stderr
57
+ .and(not_output.to_stdout)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,24 @@
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ end
5
+
6
+ require 'rspec'
7
+ require_relative '../lib/process_helper'
8
+
9
+ RSpec::Matchers.define_negated_matcher :not_output, :output
10
+ RSpec::Matchers.define_negated_matcher :not_raise_error, :raise_error
11
+
12
+ # RSpec config
13
+ # RSpec.configure do |c|
14
+ # end
15
+
16
+ # RSpec helper methods
17
+ # module SpecHelper
18
+ # end
19
+ # include SpecHelper
20
+
21
+ # Dummy fixture class
22
+ class Clazz
23
+ include ProcessHelper
24
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe 'static analysis checks' do
4
+ include ProcessHelper
5
+
6
+ it 'ruby-lint' do
7
+ process(
8
+ "ruby-lint #{File.expand_path('../../spec', __FILE__)}",
9
+ puts_output: :error
10
+ )
11
+ end
12
+
13
+ it 'rubocop' do
14
+ process(
15
+ "rubocop -c #{File.expand_path('../../.rubocop.yml', __FILE__)}",
16
+ puts_output: :error)
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'spec_helper'
2
+
3
+ RSpec.describe 'version' do
4
+ it 'is semantic' do
5
+ expect(::ProcessHelper::VERSION).to match(/^\d\.\d\.\d\.*\w*$/)
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: process_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Glenn Oppegard
8
+ - Chad Woolley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-04-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.6'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.6'
28
+ - !ruby/object:Gem::Dependency
29
+ name: codeclimate-test-reporter
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.1'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.1'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubocop
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '='
75
+ - !ruby/object:Gem::Version
76
+ version: 0.29.1
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '='
82
+ - !ruby/object:Gem::Version
83
+ version: 0.29.1
84
+ - !ruby/object:Gem::Dependency
85
+ name: ruby-lint
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '='
89
+ - !ruby/object:Gem::Version
90
+ version: 2.0.2
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '='
96
+ - !ruby/object:Gem::Version
97
+ version: 2.0.2
98
+ description: Wrapper around Open3#popen2e with other useful options.
99
+ email:
100
+ - oppegard@gmail.com
101
+ - thewoolleyman@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rubocop.yml"
108
+ - ".ruby-version"
109
+ - ".travis.yml"
110
+ - Gemfile
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - lib/process_helper.rb
115
+ - lib/process_helper/empty_command_error.rb
116
+ - lib/process_helper/invalid_options_error.rb
117
+ - lib/process_helper/unexpected_exit_status_error.rb
118
+ - lib/process_helper/unprocessed_input_error.rb
119
+ - lib/process_helper/version.rb
120
+ - process_helper.gemspec
121
+ - ruby-lint.yml
122
+ - spec/error_handling_spec.rb
123
+ - spec/input_handling_spec.rb
124
+ - spec/options/expected_exit_status_spec.rb
125
+ - spec/options/include_output_in_exception_spec.rb
126
+ - spec/options/puts_output_spec.rb
127
+ - spec/options/validation_spec.rb
128
+ - spec/output_handling_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/static_analysis_spec.rb
131
+ - spec/version_spec.rb
132
+ homepage: https://github.com/thewoolleyman/process_helper
133
+ licenses:
134
+ - Unlicense
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 1.9.2
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.4.3
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Makes it easier to spawn ruby sub-processes with proper capturing / of stdout
156
+ and stderr streams.
157
+ test_files:
158
+ - spec/error_handling_spec.rb
159
+ - spec/input_handling_spec.rb
160
+ - spec/options/expected_exit_status_spec.rb
161
+ - spec/options/include_output_in_exception_spec.rb
162
+ - spec/options/puts_output_spec.rb
163
+ - spec/options/validation_spec.rb
164
+ - spec/output_handling_spec.rb
165
+ - spec/spec_helper.rb
166
+ - spec/static_analysis_spec.rb
167
+ - spec/version_spec.rb