shell_mock 0.7.0 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 147a2390f3f6299b3da3a3e548347c97b6915d6d
4
- data.tar.gz: 85433c788c0479b762fe5542030d729ddf0922e8
3
+ metadata.gz: 9cfb3f3cd0005a629a39cbd9dff20630b9688668
4
+ data.tar.gz: 7276898279f5a813f7b7678ec2e6fee5d783f1e5
5
5
  SHA512:
6
- metadata.gz: 86cfdd6bb159d3731cba1759484c677269e5fd1beb3d48813451712847f90b328cb875eb104d4778811b283a164b96b84f30542fb6abadf049b9252ddb4b7c13
7
- data.tar.gz: 3a6807143e3a613d86444b9cecca1c7636ba2246f80e6b64d736a1be514983f2ecbb2b9dc12180f781deb9d7c1a4d5fbf4c253e2a1290124eaee2d100bdfda7a
6
+ metadata.gz: 504995cd6616c844be4281b875fab4fe40c5b94e9e9b47e0ee9e2d7dc561d37cb1a6d499c12c77ea4800871b020e38daff921c59c091f60c3ca0301b06035d86
7
+ data.tar.gz: a3cd02b088b51cb9c72ecd6d7d28c112c47be614cc02d2403a083b83af1612d2d1d9337d61cf0ede8558e1ce8553dcac57c3cdc118b24b27a4399290231243df
@@ -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(env, command = nil, **options)
12
- env, command = {}, env if command.nil?
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, **options)
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(env, command = nil, **options)
12
- env, command = {}, env if command.nil?
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, **options)
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, **options)
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(env, command = nil, **options)
12
- env, command = {}, env if command.nil?
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, **options)
25
+ __un_shell_mocked_system(env, command, options)
27
26
  else
28
27
  raise NoStubSpecified.new(env, command, options)
29
28
  end
@@ -1,3 +1,3 @@
1
1
  module ShellMock
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  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.7.0
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-08 00:00:00.000000000 Z
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