shell_mock 0.6.0 → 0.7.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 +13 -3
- data/Gemfile +2 -0
- data/README.adoc +15 -14
- data/lib/shell_mock/command_stub.rb +22 -11
- data/lib/shell_mock/core_ext/module.rb +10 -0
- data/lib/shell_mock/version.rb +1 -1
- metadata +2 -3
- data/.env +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 147a2390f3f6299b3da3a3e548347c97b6915d6d
|
4
|
+
data.tar.gz: 85433c788c0479b762fe5542030d729ddf0922e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86cfdd6bb159d3731cba1759484c677269e5fd1beb3d48813451712847f90b328cb875eb104d4778811b283a164b96b84f30542fb6abadf049b9252ddb4b7c13
|
7
|
+
data.tar.gz: 3a6807143e3a613d86444b9cecca1c7636ba2246f80e6b64d736a1be514983f2ecbb2b9dc12180f781deb9d7c1a4d5fbf4c253e2a1290124eaee2d100bdfda7a
|
data/CHANGELOG.md
CHANGED
@@ -4,15 +4,25 @@
|
|
4
4
|
* `PTYSpawnMonkeyPatch`
|
5
5
|
* `OpenMonkeyPatch`
|
6
6
|
* should `SpawnMonkeyPatch` be 2 patches (`KernelSpawnMonkeyPatch` and `ProcessSpawnMonkeyPatch`)?
|
7
|
-
* convert `CommandStub#and_exit` to `CommandStub#will_exit`
|
8
|
-
* convert `CommandStub#and_output` to `CommandStub#will_output`
|
9
|
-
* convert `CommandStub#and_return` to `CommandStub#will_return`
|
10
7
|
* add `CommandStub#will_cause(&blk)` for specifying desired side effects
|
11
8
|
* add `CommandStub#will_stdout(str)` & `CommandStub#will_stderr(str)`. these will work differently for backtick than it will for system & exec.
|
12
9
|
* ADD YARD DOCUMENTATION TO METHODS
|
13
10
|
* maybe add `CommandStub#with_stdin(str)` for `spawn`?
|
14
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.
|
15
12
|
|
13
|
+
## RELEASE 0.7.0
|
14
|
+
|
15
|
+
* FEATURE: `#to_output` is an alias of `#and_output`
|
16
|
+
* FEATURE: `#to_return` is an alias of `#and_return`
|
17
|
+
* FEATURE: `#to_exit` is an alias of `#and_exit`
|
18
|
+
* FEATURE: `#to_succeed` is an alias of `#and_succeed`
|
19
|
+
* FEATURE: `#to_fail` is an alias of `#and_fail`
|
20
|
+
* DEPRECATION: `#and_output` is deprecated and will be removed in 1.0.0. Use `#to_output` instead.
|
21
|
+
* DEPRECATION: `#and_return` is deprecated and will be removed in 1.0.0. Use `#to_return` instead.
|
22
|
+
* DEPRECATION: `#and_exit` is deprecated and will be removed in 1.0.0. Use `#to_exit` instead.
|
23
|
+
* DEPRECATION: `#and_succeed` is deprecated and will be removed in 1.0.0. Use `#to_succeed` instead.
|
24
|
+
* DEPRECATION: `#and_fail` is deprecated and will be removed in 1.0.0. Use `#to_fail` instead.
|
25
|
+
|
16
26
|
## RELEASE 0.6.0
|
17
27
|
|
18
28
|
* FEATURE: use `#and_succeed` to set an invocation's exit status to 0
|
data/Gemfile
CHANGED
data/README.adoc
CHANGED
@@ -15,8 +15,9 @@ ifdef::env-github[]
|
|
15
15
|
:warning-caption: :warning:
|
16
16
|
endif::[]
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
image:https://badge.fury.io/rb/shell_mock.svg["Gem Version", link="https://badge.fury.io/rb/shell_mock"]
|
19
|
+
image:https://travis-ci.org/yarmiganosca/shell_mock.svg?branch=master["Build Status", link="https://travis-ci.org/yarmiganosca/shell_mock"]
|
20
|
+
image:https://coveralls.io/repos/github/yarmiganosca/shell_mock/badge.svg?branch=master["Test Coverage", link="https://coveralls.io/github/yarmiganosca/shell_mock?branch=master"]
|
20
21
|
|
21
22
|
toc::[]
|
22
23
|
|
@@ -37,7 +38,7 @@ RSpec.describe "shelling out to run 'ls'" do
|
|
37
38
|
it "works"
|
38
39
|
system('ls') # <3>
|
39
40
|
|
40
|
-
expect(stub).to
|
41
|
+
expect(stub).to have_run # <4>
|
41
42
|
end
|
42
43
|
end
|
43
44
|
----
|
@@ -60,29 +61,29 @@ NOTE: ShellMock always matches as strictly as possible, so if you stubbed both `
|
|
60
61
|
|
61
62
|
=== Setting the behavior of the command invocation:
|
62
63
|
|
63
|
-
Have the mock command invocation write to stdout: `ShellMock.stub_command('ls').
|
64
|
+
Have the mock command invocation write to stdout: `ShellMock.stub_command('ls').to_output("\n")`
|
64
65
|
|
65
|
-
Set the mock command invocation's exit status: `ShellMock.stub_command('ls').
|
66
|
+
Set the mock command invocation's exit status: `ShellMock.stub_command('ls').to_exit(2)`
|
66
67
|
|
67
|
-
Set the mock command invocation's exit status to `0`: `ShellMock.stub_command('ls').
|
68
|
+
Set the mock command invocation's exit status to `0`: `ShellMock.stub_command('ls').to_succeed`
|
68
69
|
|
69
|
-
Set the mock command invocation's exit status to `1`: `ShellMock.stub_command('ls').
|
70
|
+
Set the mock command invocation's exit status to `1`: `ShellMock.stub_command('ls').to_fail`
|
70
71
|
|
71
|
-
If you want to both write to stdout and set the exit code (a common pair), `ShellMock.stub_command('ls').
|
72
|
+
If you want to both write to stdout and set the exit code (a common pair), `ShellMock.stub_command('ls').to_return("\n")` will both have the command invocation write the passed string to stdout, and will set the mock command invocation's exit status to `0`.
|
72
73
|
|
73
74
|
=== Specifying the expected number of command invocations:
|
74
75
|
|
75
|
-
Called exactly once: `expect(stub).to
|
76
|
+
Called exactly once: `expect(stub).to have_run.once`
|
76
77
|
|
77
|
-
Not called: `expect(stub).to
|
78
|
+
Not called: `expect(stub).to have_run.never`
|
78
79
|
|
79
|
-
Not called (using RSpec expectation negation): `expect(stub).to_not
|
80
|
+
Not called (using RSpec expectation negation): `expect(stub).to_not have_run`
|
80
81
|
|
81
|
-
Called exactly `n` times: `expect(stub).to
|
82
|
+
Called exactly `n` times: `expect(stub).to have_run.times(n)`
|
82
83
|
|
83
|
-
Called more than `n` times: `expect(stub).to
|
84
|
+
Called more than `n` times: `expect(stub).to have_run.more_than(n)`
|
84
85
|
|
85
|
-
Called fewer than `n` times: `expect(stub).to
|
86
|
+
Called fewer than `n` times: `expect(stub).to have_run.fewer_than(n)`
|
86
87
|
|
87
88
|
`less_than` can be used as an alias for `fewer_than`
|
88
89
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'shell_mock/stub_registry'
|
2
|
+
require 'shell_mock/core_ext/module'
|
2
3
|
|
3
4
|
module ShellMock
|
4
5
|
class CommandStub
|
@@ -12,8 +13,8 @@ module ShellMock
|
|
12
13
|
|
13
14
|
with_env({})
|
14
15
|
with_options({})
|
15
|
-
|
16
|
-
|
16
|
+
to_output(nil)
|
17
|
+
to_succeed
|
17
18
|
end
|
18
19
|
|
19
20
|
def with_env(env)
|
@@ -28,31 +29,41 @@ module ShellMock
|
|
28
29
|
self
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
+
def to_output(output)
|
32
33
|
@output = output
|
33
34
|
|
34
35
|
self
|
35
36
|
end
|
37
|
+
alias and_output to_output
|
38
|
+
deprecate :and_output, :to_output, "1.0.0"
|
36
39
|
|
37
|
-
def
|
40
|
+
def to_return(output)
|
38
41
|
self.
|
39
|
-
|
40
|
-
|
42
|
+
to_output(output).
|
43
|
+
to_exit(0)
|
41
44
|
end
|
45
|
+
alias and_return to_return
|
46
|
+
deprecate :and_return, :to_return, "1.0.0"
|
42
47
|
|
43
|
-
def
|
48
|
+
def to_exit(exitstatus)
|
44
49
|
@exitstatus = exitstatus
|
45
50
|
|
46
51
|
self
|
47
52
|
end
|
53
|
+
alias and_exit to_exit
|
54
|
+
deprecate :and_exit, :to_exit, "1.0.0"
|
48
55
|
|
49
|
-
def
|
50
|
-
|
56
|
+
def to_succeed
|
57
|
+
to_exit(0)
|
51
58
|
end
|
59
|
+
alias and_succeed to_succeed
|
60
|
+
deprecate :and_succeed, :to_succeed, "1.0.0"
|
52
61
|
|
53
|
-
def
|
54
|
-
|
62
|
+
def to_fail
|
63
|
+
to_exit(1)
|
55
64
|
end
|
65
|
+
alias and_fail to_fail
|
66
|
+
deprecate :and_fail, :to_fail, "1.0.0"
|
56
67
|
|
57
68
|
def runs
|
58
69
|
@runs ||= 0
|
@@ -2,4 +2,14 @@ Module.class_exec do
|
|
2
2
|
def eigenclass
|
3
3
|
@eigenclass ||= class << self; self; end
|
4
4
|
end
|
5
|
+
|
6
|
+
def deprecate(name, replacement, version)
|
7
|
+
old_name = :"#{name}_without_deprecation"
|
8
|
+
alias_method old_name, name
|
9
|
+
|
10
|
+
define_method(name) do |*args, &blk|
|
11
|
+
warn "ShellMock: ##{name} is deprecated and will be removed by #{version}. Please use #{replacement} instead."
|
12
|
+
send old_name, *args, &blk
|
13
|
+
end
|
14
|
+
end
|
5
15
|
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.
|
4
|
+
version: 0.7.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: 2018-
|
11
|
+
date: 2018-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,7 +115,6 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
- ".env"
|
119
118
|
- ".gitignore"
|
120
119
|
- ".rspec"
|
121
120
|
- ".travis.yml"
|