shell_mock 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Rakefile +1 -0
- data/lib/shell_mock.rb +20 -10
- data/lib/shell_mock/core_ext/kernel.rb +26 -0
- data/lib/shell_mock/version.rb +1 -1
- data/shell_mock.gemspec +1 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b82fb0b1848c54881355c530fcf8fa4f22d292a4
|
4
|
+
data.tar.gz: cf94368b1e001a8f7ecc80a10ff1b0ff94655cc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1e789a08c56339d8356d97d585bf405754582ad03a4c574f10873a05eb63951bd6ba867e725bb795a034cb096b19a6fd467d70cf9a760062462295c3dc1eb63
|
7
|
+
data.tar.gz: 07bc5c7aa946c4a34d932c61812d970da5cfb31cfea5bf35aca899b965011290a2e13a2fce010677354bf89cb51a2bc98241b2362ab4f70341af5aff2695140b
|
data/CHANGELOG.md
ADDED
data/Rakefile
CHANGED
data/lib/shell_mock.rb
CHANGED
@@ -29,24 +29,34 @@ module ShellMock
|
|
29
29
|
|
30
30
|
def self.enable
|
31
31
|
Kernel.module_exec do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if Kernel.respond_to?(:__shell_mocked_backtick)
|
38
|
-
define_method(:__un_shell_mocked_backtick, &method(:`).to_proc)
|
39
|
-
define_method(:`, &method(:__shell_mocked_backtick).to_proc)
|
32
|
+
ShellMock.alias_specifications.each do |spec|
|
33
|
+
if respond_to?(spec.replacement)
|
34
|
+
define_method(spec.alias_for_original, &method(spec.original).to_proc)
|
35
|
+
define_method(spec.original, &method(spec.replacement).to_proc)
|
36
|
+
end
|
40
37
|
end
|
41
38
|
end
|
42
39
|
end
|
43
40
|
|
44
41
|
def self.disable
|
45
42
|
Kernel.module_exec do
|
46
|
-
|
47
|
-
|
43
|
+
ShellMock.alias_specifications.each do |spec|
|
44
|
+
if respond_to?(spec.alias_for_original)
|
45
|
+
define_method(spec.original, &method(spec.alias_for_original).to_proc)
|
46
|
+
end
|
47
|
+
end
|
48
48
|
end
|
49
49
|
|
50
50
|
StubRegistry.clear
|
51
51
|
end
|
52
|
+
|
53
|
+
AliasSpecification = Struct.new(:original, :alias_for_original, :replacement)
|
54
|
+
|
55
|
+
def self.alias_specifications
|
56
|
+
[
|
57
|
+
AliasSpecification.new(:system, :__un_shell_mocked_system, :__shell_mocked_system),
|
58
|
+
AliasSpecification.new(:exec, :__un_shell_mocked_exec, :__shell_mocked_exec),
|
59
|
+
AliasSpecification.new(:`, :__un_shell_mocked_backtick, :__shell_mocked_backtick),
|
60
|
+
]
|
61
|
+
end
|
52
62
|
end
|
@@ -23,6 +23,32 @@ module Kernel
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
# This feels very boilerplatey because Kernel::system and Kernel::exec
|
27
|
+
# have very similar if not identical method signatures. I'm not sure
|
28
|
+
# whether extracting the commonalities would be worth it or just
|
29
|
+
# confuse.
|
30
|
+
def __shell_mocked_exec(env, command = nil, **options)
|
31
|
+
env, command = {}, env if command.nil?
|
32
|
+
|
33
|
+
# other arg manipulation
|
34
|
+
|
35
|
+
stub = ShellMock::StubRegistry.stub_matching(env, command, options)
|
36
|
+
|
37
|
+
if stub
|
38
|
+
stub.side_effect.call
|
39
|
+
`exit #{stub.exitstatus}`
|
40
|
+
stub.called_with(env, command, options)
|
41
|
+
|
42
|
+
return stub.exitstatus == 0
|
43
|
+
else
|
44
|
+
if ShellMock.let_commands_run?
|
45
|
+
__un_shell_mocked_exec(env, command, **options)
|
46
|
+
else
|
47
|
+
raise ShellMock::NoStubSpecified.new(env, command, options)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
26
52
|
def __shell_mocked_backtick(command)
|
27
53
|
stub = ShellMock::StubRegistry.stub_matching({}, command, {})
|
28
54
|
|
data/lib/shell_mock/version.rb
CHANGED
data/shell_mock.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shell_mock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hoffman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: structured_changelog
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
83
97
|
description: WebMock for shell commands
|
84
98
|
email:
|
85
99
|
- yarmiganosca@gmail.com
|
@@ -91,6 +105,7 @@ files:
|
|
91
105
|
- ".gitignore"
|
92
106
|
- ".rspec"
|
93
107
|
- ".travis.yml"
|
108
|
+
- CHANGELOG.md
|
94
109
|
- CODE_OF_CONDUCT.md
|
95
110
|
- Gemfile
|
96
111
|
- LICENSE.txt
|
@@ -128,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
143
|
version: '0'
|
129
144
|
requirements: []
|
130
145
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
146
|
+
rubygems_version: 2.6.3
|
132
147
|
signing_key:
|
133
148
|
specification_version: 4
|
134
149
|
summary: WebMock for shell commands
|