shell_mock 0.3.3 → 0.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/lib/shell_mock/monkey_patch.rb +7 -70
- data/lib/shell_mock/monkey_patches.rb +91 -0
- data/lib/shell_mock/version.rb +1 -1
- data/lib/shell_mock.rb +7 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0774052a9e5d9c22ec4c25344e620d68cddc8604
|
4
|
+
data.tar.gz: 76f022bcb48ff0558e5f4e4564a9a0ff63ddc30c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ce25833d01a646e100d285ce32f9810e15f348d760db2dacd669c8f045c600a16475026429226d6e10b7086c79485bfe73b0c48e2217bc272960c8eea6c479b
|
7
|
+
data.tar.gz: 1f0547eb74bbfd0296a5ad37e07b66eb15ce5f516ff78ad2c2f1abb4acbe792d4fb51a3d3c5614b294a8d164cf0c7ca8066ce8a128ac10078c6fa1fba494bd46
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
## ROADMAP 1.0.0
|
2
2
|
|
3
|
-
* add `with_side_effect(&blk)` for specifying desired side effects
|
3
|
+
* add `CommandStub#with_side_effect(&blk)` for specifying desired side effects
|
4
|
+
* add `CommandStub#with_stdout(str)` & `CommandStub#with_stderr(str)`. these will work differently for backtick than it will for system & exec.
|
5
|
+
* maybe add `CommandStub#with_stdin(str)` for `spawn`?
|
6
|
+
|
7
|
+
## RELEASE 0.4.0
|
8
|
+
|
9
|
+
* FEATURE: `Kernel#spawn` and `Kernel.spawn` are now supported, which means all of Open3 is, as all of that library eventually results in a `spawn` call.
|
4
10
|
|
5
11
|
## RELEASE 0.3.3
|
6
12
|
|
@@ -4,10 +4,10 @@ module ShellMock
|
|
4
4
|
class MonkeyPatch
|
5
5
|
attr_reader :original, :alias_for_original
|
6
6
|
|
7
|
-
def initialize(original_name,
|
7
|
+
def initialize(original_name, interpolatable_name = original_name, &block)
|
8
8
|
@original = original_name
|
9
|
-
@alias_for_original = "__un_shell_mocked_#{
|
10
|
-
@replacement = "__shell_mocked_#{
|
9
|
+
@alias_for_original = "__un_shell_mocked_#{interpolatable_name}"
|
10
|
+
@replacement = "__shell_mocked_#{interpolatable_name}"
|
11
11
|
@block = block
|
12
12
|
end
|
13
13
|
|
@@ -19,7 +19,8 @@ module ShellMock
|
|
19
19
|
class_or_module.send(:alias_method, alias_for_original, original)
|
20
20
|
|
21
21
|
begin
|
22
|
-
|
22
|
+
# so we don't have to see method redefinition warnings
|
23
|
+
class_or_module.send(:remove_method, original)
|
23
24
|
rescue NameError
|
24
25
|
end
|
25
26
|
|
@@ -28,7 +29,8 @@ module ShellMock
|
|
28
29
|
|
29
30
|
def disable_for(class_or_module)
|
30
31
|
begin
|
31
|
-
|
32
|
+
# so we don't have to see method redefinition warnings
|
33
|
+
class_or_module.send(:remove_method, original)
|
32
34
|
rescue NameError
|
33
35
|
end
|
34
36
|
|
@@ -40,69 +42,4 @@ module ShellMock
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
43
|
-
|
44
|
-
SystemMonkeyPatch = MonkeyPatch.new(:system) do |env, command = nil, **options|
|
45
|
-
env, command = {}, env if command.nil?
|
46
|
-
|
47
|
-
# other arg manipulation
|
48
|
-
|
49
|
-
stub = ShellMock::StubRegistry.stub_matching(env, command, options)
|
50
|
-
|
51
|
-
if stub
|
52
|
-
stub.side_effect.call
|
53
|
-
stub.called_with(env, command, options)
|
54
|
-
__un_shell_mocked_backtick("exit #{stub.exitstatus}")
|
55
|
-
|
56
|
-
return stub.exitstatus == 0
|
57
|
-
else
|
58
|
-
if ShellMock.let_commands_run?
|
59
|
-
__un_shell_mocked_system(env, command, **options)
|
60
|
-
else
|
61
|
-
raise ShellMock::NoStubSpecified.new(env, command, options)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# This feels very boilerplatey because Kernel::system and Kernel::exec
|
67
|
-
# have very similar if not identical method signatures. I'm not sure
|
68
|
-
# whether extracting the commonalities would be worth it or just
|
69
|
-
# confuse.
|
70
|
-
ExecMonkeyPatch = MonkeyPatch.new(:exec) do |env, command = nil, **options|
|
71
|
-
env, command = {}, env if command.nil?
|
72
|
-
|
73
|
-
# other arg manipulation
|
74
|
-
|
75
|
-
stub = ShellMock::StubRegistry.stub_matching(env, command, options)
|
76
|
-
|
77
|
-
if stub
|
78
|
-
stub.side_effect.call
|
79
|
-
stub.called_with(env, command, options)
|
80
|
-
|
81
|
-
exit stub.exitstatus
|
82
|
-
else
|
83
|
-
if ShellMock.let_commands_run?
|
84
|
-
__un_shell_mocked_exec(env, command, **options)
|
85
|
-
else
|
86
|
-
raise ShellMock::NoStubSpecified.new(env, command, options)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
BacktickMonkeyPatch = MonkeyPatch.new(:`, :backtick) do |command|
|
92
|
-
stub = ShellMock::StubRegistry.stub_matching({}, command, {})
|
93
|
-
|
94
|
-
if stub
|
95
|
-
stub.side_effect.call
|
96
|
-
__un_shell_mocked_backtick("exit #{stub.exitstatus}")
|
97
|
-
stub.called_with({}, command, {})
|
98
|
-
|
99
|
-
return stub.expected_output
|
100
|
-
else
|
101
|
-
if ShellMock.let_commands_run?
|
102
|
-
__un_shell_mocked_backtick(command)
|
103
|
-
else
|
104
|
-
raise ShellMock::NoStubSpecified.new({}, command, {})
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
45
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'shell_mock/monkey_patch'
|
2
|
+
require 'shell_mock/stub_registry'
|
3
|
+
require 'shell_mock/no_stub_specified'
|
4
|
+
|
5
|
+
module ShellMock
|
6
|
+
SpawnMonkeyPatch = MonkeyPatch.new(:spawn) do |env, command = nil, **options|
|
7
|
+
env, command = {}, env if command.nil?
|
8
|
+
|
9
|
+
# other arg manipulation can go here if necessary
|
10
|
+
|
11
|
+
stub = StubRegistry.stub_matching(env, command, options)
|
12
|
+
|
13
|
+
if stub
|
14
|
+
stub.side_effect.call
|
15
|
+
stub.called_with(env, command, options)
|
16
|
+
|
17
|
+
__un_shell_mocked_spawn("exit #{stub.exitstatus}")
|
18
|
+
else
|
19
|
+
if ShellMock.let_commands_run?
|
20
|
+
__un_shell_mocked_spawn(env, command, **options)
|
21
|
+
else
|
22
|
+
raise NoStubSpecified.new(env, command, options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
SystemMonkeyPatch = MonkeyPatch.new(:system) do |env, command = nil, **options|
|
28
|
+
env, command = {}, env if command.nil?
|
29
|
+
|
30
|
+
# other arg manipulation can go here if necessary
|
31
|
+
|
32
|
+
stub = StubRegistry.stub_matching(env, command, options)
|
33
|
+
|
34
|
+
if stub
|
35
|
+
stub.side_effect.call
|
36
|
+
stub.called_with(env, command, options)
|
37
|
+
__un_shell_mocked_backtick("exit #{stub.exitstatus}")
|
38
|
+
|
39
|
+
return stub.exitstatus == 0
|
40
|
+
else
|
41
|
+
if ShellMock.let_commands_run?
|
42
|
+
__un_shell_mocked_system(env, command, **options)
|
43
|
+
else
|
44
|
+
raise NoStubSpecified.new(env, command, options)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# This feels very boilerplatey because Kernel::system and Kernel::exec
|
50
|
+
# have very similar if not identical method signatures. I'm not sure
|
51
|
+
# whether extracting the commonalities would be worth it or would just
|
52
|
+
# confuse.
|
53
|
+
ExecMonkeyPatch = MonkeyPatch.new(:exec) do |env, command = nil, **options|
|
54
|
+
env, command = {}, env if command.nil?
|
55
|
+
|
56
|
+
# other arg manipulation can go here if necessary
|
57
|
+
|
58
|
+
stub = StubRegistry.stub_matching(env, command, options)
|
59
|
+
|
60
|
+
if stub
|
61
|
+
stub.side_effect.call
|
62
|
+
stub.called_with(env, command, options)
|
63
|
+
|
64
|
+
exit stub.exitstatus
|
65
|
+
else
|
66
|
+
if ShellMock.let_commands_run?
|
67
|
+
__un_shell_mocked_exec(env, command, **options)
|
68
|
+
else
|
69
|
+
raise NoStubSpecified.new(env, command, options)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
BacktickMonkeyPatch = MonkeyPatch.new('`', :backtick) do |command|
|
75
|
+
stub = StubRegistry.stub_matching({}, command, {})
|
76
|
+
|
77
|
+
if stub
|
78
|
+
stub.side_effect.call
|
79
|
+
stub.called_with({}, command, {})
|
80
|
+
__un_shell_mocked_backtick("exit #{stub.exitstatus}")
|
81
|
+
|
82
|
+
return stub.expected_output
|
83
|
+
else
|
84
|
+
if ShellMock.let_commands_run?
|
85
|
+
__un_shell_mocked_backtick(command)
|
86
|
+
else
|
87
|
+
raise NoStubSpecified.new({}, command, {})
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/shell_mock/version.rb
CHANGED
data/lib/shell_mock.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "shell_mock/version"
|
2
2
|
require 'shell_mock/stub_registry'
|
3
3
|
require 'shell_mock/command_stub'
|
4
|
-
require 'shell_mock/
|
4
|
+
require 'shell_mock/monkey_patches'
|
5
5
|
require 'shell_mock/core_ext/module'
|
6
6
|
|
7
7
|
module ShellMock
|
@@ -45,6 +45,11 @@ module ShellMock
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def self.monkey_patches
|
48
|
-
[
|
48
|
+
[
|
49
|
+
SpawnMonkeyPatch,
|
50
|
+
SystemMonkeyPatch,
|
51
|
+
ExecMonkeyPatch,
|
52
|
+
BacktickMonkeyPatch
|
53
|
+
]
|
49
54
|
end
|
50
55
|
end
|
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.4.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: 2018-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/shell_mock/command_stub.rb
|
119
119
|
- lib/shell_mock/core_ext/module.rb
|
120
120
|
- lib/shell_mock/monkey_patch.rb
|
121
|
+
- lib/shell_mock/monkey_patches.rb
|
121
122
|
- lib/shell_mock/no_stub_specified.rb
|
122
123
|
- lib/shell_mock/rspec.rb
|
123
124
|
- lib/shell_mock/rspec/matchers.rb
|