script_utils 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +37 -0
- data/README.md +1 -0
- data/lib/script_utils.rb +10 -0
- data/script_utils.gemspec +15 -0
- data/spec/script_utils/script_utils_spec.rb +62 -0
- data/spec/spec_helper.rb +2 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8a8dcd51b813639dd0a4d24f850451f140ea2d0a
|
4
|
+
data.tar.gz: 57cd04f77442459795ed059cd77dc128e324872d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ece639d474e02af3830bcf2357a70e32663a25d304e4a40edc6f115d55dfcc12edcc35af671f362b0e4081b4b535498dd5d9a30ed761d5ad0de3911c80b593e
|
7
|
+
data.tar.gz: f9cd4c3261f806d8379a2bc044760cdb1eda2f135f77ccd9118b07313bf1f31cdb8483dae0906faf5b482568440f1f53e25ac2db2dafa0f54a43c310e96504ad
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
script_utils (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.0)
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
method_source (0.8.2)
|
12
|
+
pry (0.9.12.6)
|
13
|
+
coderay (~> 1.0)
|
14
|
+
method_source (~> 0.8)
|
15
|
+
slop (~> 3.4)
|
16
|
+
rspec (3.2.0)
|
17
|
+
rspec-core (~> 3.2.0)
|
18
|
+
rspec-expectations (~> 3.2.0)
|
19
|
+
rspec-mocks (~> 3.2.0)
|
20
|
+
rspec-core (3.2.3)
|
21
|
+
rspec-support (~> 3.2.0)
|
22
|
+
rspec-expectations (3.2.1)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.2.0)
|
25
|
+
rspec-mocks (3.2.1)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.2.0)
|
28
|
+
rspec-support (3.2.2)
|
29
|
+
slop (3.5.0)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
pry
|
36
|
+
rspec (= 3.2.0)
|
37
|
+
script_utils!
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# script-utils
|
data/lib/script_utils.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
module ScriptUtils
|
2
|
+
module_function
|
3
|
+
|
4
|
+
def run(cmd, output: false, bundle_exec: false, ensure_success: true, working_dir: false)
|
5
|
+
cmd = "bundle exec #{cmd}" if bundle_exec
|
6
|
+
cmd = "cd #{working_dir}; #{cmd}" if working_dir
|
7
|
+
output ? system(cmd) : `#{cmd}`
|
8
|
+
raise if ensure_success && !$?.success?
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = 'script_utils'
|
3
|
+
gem.version = '0.0.1'
|
4
|
+
gem.summary = 'script helpers'
|
5
|
+
gem.author = 'Lihan Li'
|
6
|
+
gem.email = 'frankieteardrop@gmail.com'
|
7
|
+
gem.homepage = 'https://github.com/lihanli/script-utils'
|
8
|
+
|
9
|
+
gem.add_development_dependency('rspec', '3.2.0')
|
10
|
+
gem.add_development_dependency('pry')
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ScriptUtils do
|
4
|
+
describe '#run' do
|
5
|
+
def run(*args)
|
6
|
+
ScriptUtils.run(*args)
|
7
|
+
end
|
8
|
+
|
9
|
+
def expect_command(cmd, output: false)
|
10
|
+
expect(ScriptUtils).to receive(:"#{output ? 'system' : '`'}").once.with(cmd)
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when ensure_success is false' do
|
14
|
+
it 'should not raise on nonzero exit code' do
|
15
|
+
run('false', ensure_success: false)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when ensure_success is true' do
|
20
|
+
context 'when bundle exec is false' do
|
21
|
+
context 'when output is true' do
|
22
|
+
it 'should run the system cmd' do
|
23
|
+
expect_command('ls', output: true)
|
24
|
+
run('ls', output: true)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when output is false' do
|
29
|
+
it 'should raise on nonzero exit code' do
|
30
|
+
expect { run('false') }.to raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should run backticks' do
|
34
|
+
expect_command('ls')
|
35
|
+
run('ls', output: false)
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when working dir is set' do
|
39
|
+
it 'should cd to the working dir' do
|
40
|
+
expect_command('cd lib; ls')
|
41
|
+
run('ls', working_dir: 'lib')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when bundle_exec is true' do
|
48
|
+
context 'when working dir is set' do
|
49
|
+
it 'should cd to the working dir' do
|
50
|
+
expect_command('cd lib; bundle exec ls')
|
51
|
+
run('ls', working_dir: 'lib', bundle_exec: true)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should add bundle exec to the cmd' do
|
56
|
+
expect_command('bundle exec ls')
|
57
|
+
run('ls', bundle_exec: true)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: script_utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lihan Li
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email: frankieteardrop@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- README.md
|
50
|
+
- lib/script_utils.rb
|
51
|
+
- script_utils.gemspec
|
52
|
+
- spec/script_utils/script_utils_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: https://github.com/lihanli/script-utils
|
55
|
+
licenses: []
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.4.5
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: script helpers
|
77
|
+
test_files:
|
78
|
+
- spec/script_utils/script_utils_spec.rb
|
79
|
+
- spec/spec_helper.rb
|