shell_mock 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cfb3f3cd0005a629a39cbd9dff20630b9688668
|
4
|
+
data.tar.gz: 7276898279f5a813f7b7678ec2e6fee5d783f1e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 504995cd6616c844be4281b875fab4fe40c5b94e9e9b47e0ee9e2d7dc561d37cb1a6d499c12c77ea4800871b020e38daff921c59c091f60c3ca0301b06035d86
|
7
|
+
data.tar.gz: a3cd02b088b51cb9c72ecd6d7d28c112c47be614cc02d2403a083b83af1612d2d1d9337d61cf0ede8558e1ce8553dcac57c3cdc118b24b27a4399290231243df
|
data/CHANGELOG.md
CHANGED
@@ -10,6 +10,10 @@
|
|
10
10
|
* maybe add `CommandStub#with_stdin(str)` for `spawn`?
|
11
11
|
* maybe adding the ability to specify the order in which commands output to stdout vs. stderr (like, a sequence of outputs) would be useful? would definitely be fun to build, not sure how useful it would be though.
|
12
12
|
|
13
|
+
## RELEASE 0.7.1
|
14
|
+
|
15
|
+
* FIX: fixed an issue with our `spawn` monkey-patch receiving optional key-value parameters from `Open3.popen2e`.
|
16
|
+
|
13
17
|
## RELEASE 0.7.0
|
14
18
|
|
15
19
|
* FEATURE: `#to_output` is an alias of `#and_output`
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'shell_mock/monkey_patch'
|
2
2
|
require 'shell_mock/stub_registry'
|
3
3
|
require 'shell_mock/no_stub_specified'
|
4
|
+
require 'shell_mock/spawn_arguments'
|
4
5
|
|
5
6
|
module ShellMock
|
6
7
|
class ExecMonkeyPatch < MonkeyPatch
|
@@ -8,10 +9,8 @@ module ShellMock
|
|
8
9
|
:exec
|
9
10
|
end
|
10
11
|
|
11
|
-
def override(
|
12
|
-
env, command
|
13
|
-
|
14
|
-
# other arg manipulation can go here if necessary
|
12
|
+
def override(*args)
|
13
|
+
env, command, options = SpawnArguments(*args)
|
15
14
|
|
16
15
|
stub = StubRegistry.stub_matching(env, command, options)
|
17
16
|
|
@@ -23,7 +22,7 @@ module ShellMock
|
|
23
22
|
__un_shell_mocked_exec(stub.to_oneliner)
|
24
23
|
else
|
25
24
|
if ShellMock.let_commands_run?
|
26
|
-
__un_shell_mocked_exec(env, command,
|
25
|
+
__un_shell_mocked_exec(env, command, options)
|
27
26
|
else
|
28
27
|
raise NoStubSpecified.new(env, command, options)
|
29
28
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# The method signatures for exec, system, & spawn are identical and complicated.
|
2
|
+
# This is a helper method that extracts the env vars hash, command, and options hash components.
|
3
|
+
# I've called it SpawnArguments even though it's the same signature for exec, spawn, and system
|
4
|
+
# because the Ruby docs for exec and system refer to the docs for spawn, indicating that Ruby
|
5
|
+
# considers spawn the "origin" of the signature.
|
6
|
+
def SpawnArguments(*args)
|
7
|
+
# the env vars hash is either the first argument, or empty
|
8
|
+
env = if args.first.is_a?(Hash)
|
9
|
+
args.shift
|
10
|
+
else
|
11
|
+
{}
|
12
|
+
end
|
13
|
+
|
14
|
+
# the options hash is either the last argument, or empty
|
15
|
+
options = if args.last.is_a?(Hash)
|
16
|
+
args.pop
|
17
|
+
else
|
18
|
+
{}
|
19
|
+
end
|
20
|
+
|
21
|
+
raise(ArgumentError, "You must provide a command to run.") if args.empty?
|
22
|
+
|
23
|
+
command = args.shift
|
24
|
+
|
25
|
+
raise(
|
26
|
+
ArgumentError,
|
27
|
+
"Unable to recognize first command component. Expected String or Array, got #{args.first.class}."
|
28
|
+
) unless command.is_a?(String) || command.is_a?(Array)
|
29
|
+
|
30
|
+
raise(
|
31
|
+
ArgumentError,
|
32
|
+
"Each command component after the first must be strings."
|
33
|
+
) unless args.all? { |arg| arg.is_a?(String) }
|
34
|
+
|
35
|
+
if args.empty?
|
36
|
+
if command.is_a?(String) # single commandline string
|
37
|
+
[env, command, options]
|
38
|
+
elsif command.is_a?(Array)
|
39
|
+
[env, [command], options] # [command, argv0] pair with no other command arguments
|
40
|
+
end
|
41
|
+
else
|
42
|
+
# this covers
|
43
|
+
# a command with multiple string arguments
|
44
|
+
# and
|
45
|
+
# a [command, argv0] pair with multiple string arguments
|
46
|
+
[env, [command, *args], options]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'shell_mock/monkey_patch'
|
2
2
|
require 'shell_mock/stub_registry'
|
3
3
|
require 'shell_mock/no_stub_specified'
|
4
|
+
require 'shell_mock/spawn_arguments'
|
4
5
|
|
5
6
|
module ShellMock
|
6
7
|
class SpawnMonkeyPatch < MonkeyPatch
|
@@ -8,10 +9,8 @@ module ShellMock
|
|
8
9
|
:spawn
|
9
10
|
end
|
10
11
|
|
11
|
-
def override(
|
12
|
-
env, command
|
13
|
-
|
14
|
-
# other arg manipulation can go here if necessary
|
12
|
+
def override(*args)
|
13
|
+
env, command, options = SpawnArguments(*args)
|
15
14
|
|
16
15
|
stub = StubRegistry.stub_matching(env, command, options)
|
17
16
|
|
@@ -20,10 +19,10 @@ module ShellMock
|
|
20
19
|
|
21
20
|
stub.side_effect.call
|
22
21
|
|
23
|
-
__un_shell_mocked_spawn(stub.to_oneliner,
|
22
|
+
__un_shell_mocked_spawn(stub.to_oneliner, options)
|
24
23
|
else
|
25
24
|
if ShellMock.let_commands_run?
|
26
|
-
__un_shell_mocked_spawn(env, command,
|
25
|
+
__un_shell_mocked_spawn(env, command, options)
|
27
26
|
else
|
28
27
|
raise NoStubSpecified.new(env, command, options)
|
29
28
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'shell_mock/monkey_patch'
|
2
2
|
require 'shell_mock/stub_registry'
|
3
3
|
require 'shell_mock/no_stub_specified'
|
4
|
+
require 'shell_mock/spawn_arguments'
|
4
5
|
|
5
6
|
module ShellMock
|
6
7
|
class SystemMonkeyPatch < MonkeyPatch
|
@@ -8,10 +9,8 @@ module ShellMock
|
|
8
9
|
:system
|
9
10
|
end
|
10
11
|
|
11
|
-
def override(
|
12
|
-
env, command
|
13
|
-
|
14
|
-
# other arg manipulation can go here if necessary
|
12
|
+
def override(*args)
|
13
|
+
env, command, options = SpawnArguments(*args)
|
15
14
|
|
16
15
|
stub = StubRegistry.stub_matching(env, command, options)
|
17
16
|
|
@@ -23,7 +22,7 @@ module ShellMock
|
|
23
22
|
__un_shell_mocked_system(stub.to_oneliner)
|
24
23
|
else
|
25
24
|
if ShellMock.let_commands_run?
|
26
|
-
__un_shell_mocked_system(env, command,
|
25
|
+
__un_shell_mocked_system(env, command, options)
|
27
26
|
else
|
28
27
|
raise NoStubSpecified.new(env, command, options)
|
29
28
|
end
|
data/lib/shell_mock/version.rb
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.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Hoffman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- lib/shell_mock/rspec.rb
|
138
138
|
- lib/shell_mock/rspec/matchers.rb
|
139
139
|
- lib/shell_mock/run_verifier.rb
|
140
|
+
- lib/shell_mock/spawn_arguments.rb
|
140
141
|
- lib/shell_mock/spawn_monkey_patch.rb
|
141
142
|
- lib/shell_mock/stub_registry.rb
|
142
143
|
- lib/shell_mock/system_monkey_patch.rb
|