shell_mock 0.5.0 → 0.6.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 +12 -0
- data/README.adoc +142 -0
- data/lib/shell_mock/backtick_monkey_patch.rb +1 -1
- data/lib/shell_mock/command_stub.rb +30 -26
- data/lib/shell_mock/exec_monkey_patch.rb +1 -1
- data/lib/shell_mock/rspec/matchers.rb +5 -3
- data/lib/shell_mock/rspec.rb +0 -2
- data/lib/shell_mock/{call_verifier.rb → run_verifier.rb} +6 -6
- data/lib/shell_mock/spawn_monkey_patch.rb +1 -1
- data/lib/shell_mock/system_monkey_patch.rb +1 -1
- data/lib/shell_mock/version.rb +1 -1
- data/lib/shell_mock.rb +3 -1
- data/shell_mock.gemspec +1 -0
- metadata +18 -4
- data/README.md +0 -107
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c6fffa51532c59b133e8176343ab0fb1d6ca8b5
|
4
|
+
data.tar.gz: 71450c650b0e65096422bb2a7f467516bf810846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92aae540345018da0abd3b68d0704f56f0e8e9aa1bdf8ecabae9cc051fb1606a7874c6dc007ac0c368ef971974997550593feb42e03e5bd25bdbd51711187a31
|
7
|
+
data.tar.gz: 2d2d7ac3b2c6a3542ab48e16d16e3b9a36d7e6ddcfc35c369c26e61b984bf1e652ec29f98cebb3ff4df4594653e8aff1fa97bff4c61a549346a05ec6d51450db
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
## ROADMAP 1.0.0
|
2
2
|
|
3
|
+
* `IOPopenMonkeyPatch`
|
4
|
+
* `PTYSpawnMonkeyPatch`
|
5
|
+
* `OpenMonkeyPatch`
|
6
|
+
* should `SpawnMonkeyPatch` be 2 patches (`KernelSpawnMonkeyPatch` and `ProcessSpawnMonkeyPatch`)?
|
3
7
|
* convert `CommandStub#and_exit` to `CommandStub#will_exit`
|
4
8
|
* convert `CommandStub#and_output` to `CommandStub#will_output`
|
5
9
|
* convert `CommandStub#and_return` to `CommandStub#will_return`
|
6
10
|
* add `CommandStub#will_cause(&blk)` for specifying desired side effects
|
7
11
|
* add `CommandStub#will_stdout(str)` & `CommandStub#will_stderr(str)`. these will work differently for backtick than it will for system & exec.
|
12
|
+
* ADD YARD DOCUMENTATION TO METHODS
|
8
13
|
* maybe add `CommandStub#with_stdin(str)` for `spawn`?
|
14
|
+
* 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
|
+
|
16
|
+
## RELEASE 0.6.0
|
17
|
+
|
18
|
+
* FEATURE: use `#and_succeed` to set an invocation's exit status to 0
|
19
|
+
* FEATURE: use `#and_fail` to set an invocation's exit status to 1
|
20
|
+
* FIX: `ShellMock.disable` now resets the `let_commands_run` flag, preventing that from carrying between tests
|
9
21
|
|
10
22
|
## RELEASE 0.5.0
|
11
23
|
|
data/README.adoc
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
= ShellMock
|
2
|
+
:ext-relative: .adoc
|
3
|
+
:source-highlighter: coderay
|
4
|
+
:sectanchors:
|
5
|
+
:linkattrs:
|
6
|
+
:icons: font
|
7
|
+
:toc: macro
|
8
|
+
:toc-title:
|
9
|
+
:toclevels: 3
|
10
|
+
ifdef::env-github[]
|
11
|
+
:tip-caption: :bulb:
|
12
|
+
:note-caption: :information_source:
|
13
|
+
:important-caption: :heavy_exclamation_mark:
|
14
|
+
:caution-caption: :fire:
|
15
|
+
:warning-caption: :warning:
|
16
|
+
endif::[]
|
17
|
+
|
18
|
+
http://badge.fury.io/rb/shell_mock[image:https://badge.fury.io/rb/shell_mock.png[Gem Version]]
|
19
|
+
http://travis-ci.org/yarmiganosca/shell_mock[image:https://secure.travis-ci.org/yarmiganosca/shell_mock.png[Build Status]]
|
20
|
+
|
21
|
+
toc::[]
|
22
|
+
|
23
|
+
== What is ShellMock?
|
24
|
+
|
25
|
+
It's http://github.com/bblimke/webmock[webmock, target="_blank"] for shell commands. It's pretty simple. You can do things like this:
|
26
|
+
|
27
|
+
[source,ruby]
|
28
|
+
----
|
29
|
+
require 'shell_mock/rspec'
|
30
|
+
|
31
|
+
RSpec.describe "shelling out to run 'ls'" do
|
32
|
+
before { ShellMock.enable } # <1>
|
33
|
+
after { ShellMock.disable }
|
34
|
+
|
35
|
+
let(:stub) { ShellMock.stub_command('ls') } # <2>
|
36
|
+
|
37
|
+
it "works"
|
38
|
+
system('ls') # <3>
|
39
|
+
|
40
|
+
expect(stub).to have_been_called # <4>
|
41
|
+
end
|
42
|
+
end
|
43
|
+
----
|
44
|
+
<1> enables ShellMock's monkey patches during the test
|
45
|
+
<2> creates a command stub that will match the command `"ls"` (by default it will exit `0` and have no output)
|
46
|
+
<3> shells out to run `"ls"` (in this case using `Kernel#system`)
|
47
|
+
<4> correctly expects that our command stub for `"ls"` will have recorded an invocation
|
48
|
+
|
49
|
+
== Using ShellMock
|
50
|
+
|
51
|
+
=== You can narrow what invocations are matched to your command stub:
|
52
|
+
|
53
|
+
Match env vars as well as the command: `ShellMock.stub_command('ls').with_env({'FOO' => 'bar'})`
|
54
|
+
|
55
|
+
Provide a more complete invocation: `ShellMock.stub_command('ls $HOME')`
|
56
|
+
|
57
|
+
Shelling out to run `"ls"` won't match this command stub, but shelling out to run `"ls $HOME"` will.
|
58
|
+
|
59
|
+
NOTE: ShellMock always matches as strictly as possible, so if you stubbed both `"ls"` and `"ls $HOME"`, invocations of `"ls $HOME'` will only ever match against the `"ls $HOME"` stub and never the `"ls"` stub.
|
60
|
+
|
61
|
+
=== Setting the behavior of the command invocation:
|
62
|
+
|
63
|
+
Have the mock command invocation write to stdout: `ShellMock.stub_command('ls').and_output("\n")`
|
64
|
+
|
65
|
+
Set the mock command invocation's exit status: `ShellMock.stub_command('ls').and_exit(2)`
|
66
|
+
|
67
|
+
Set the mock command invocation's exit status to `0`: `ShellMock.stub_command('ls').and_succeed`
|
68
|
+
|
69
|
+
Set the mock command invocation's exit status to `1`: `ShellMock.stub_command('ls').and_fail`
|
70
|
+
|
71
|
+
If you want to both write to stdout and set the exit code (a common pair), `ShellMock.stub_command('ls').and_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
|
+
=== Specifying the expected number of command invocations:
|
74
|
+
|
75
|
+
Called exactly once: `expect(stub).to have_been_called.once`
|
76
|
+
|
77
|
+
Not called: `expect(stub).to have_been_called.never`
|
78
|
+
|
79
|
+
Not called (using RSpec expectation negation): `expect(stub).to_not have_been_called`
|
80
|
+
|
81
|
+
Called exactly `n` times: `expect(stub).to have_been_called.times(n)`
|
82
|
+
|
83
|
+
Called more than `n` times: `expect(stub).to have_been_called.more_than(n)`
|
84
|
+
|
85
|
+
Called fewer than `n` times: `expect(stub).to have_been_called.fewer_than(n)`
|
86
|
+
|
87
|
+
`less_than` can be used as an alias for `fewer_than`
|
88
|
+
|
89
|
+
== Limitations
|
90
|
+
|
91
|
+
Currently, only exact string matches of the stubbed command string are supported. Basic regex support or more complex matching for arguments and flags may be added later.
|
92
|
+
|
93
|
+
ShellMock supports stubbing these ways of shelling out in Ruby:
|
94
|
+
|
95
|
+
* https://ruby-doc.org/core/Kernel.html#method-i-60[`Kernel#``, window="_blank"] (aka "backticks")
|
96
|
+
* https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#command[`%x` command literal, window="_blank"] (which delegates to backticks)
|
97
|
+
* https://ruby-doc.org/core/Kernel.html#method-i-system[`Kernel#system`, window="_blank"]
|
98
|
+
* https://ruby-doc.org/core/Kernel.html#method-i-exec[`Kernel#exec`, window="_blank"]
|
99
|
+
* https://ruby-doc.org/core/Kernel.html#method-i-spawn[`Kernel#spawn`, window="_blank"]
|
100
|
+
* https://ruby-doc.org/core/Process.html#method-c-spawn[`Process.spawn`, window="_blank"]
|
101
|
+
* https://ruby-doc.org/stdlib/libdoc/open3/rdoc/Open3.html[the `Open3` module, window="_blank"] (since all its methods use `spawn`)
|
102
|
+
|
103
|
+
ShellMock currently *DOES NOT* support stubbing these ways of shelling out in Ruby (but will):
|
104
|
+
|
105
|
+
* https://ruby-doc.org/core/IO.html#method-c-popen[`IO.popen`, window="_blank"]
|
106
|
+
* https://ruby-doc.org/stdlib/libdoc/pty/rdoc/PTY.html#method-c-spawn[`PTY.spawn`, window="_blank"]
|
107
|
+
* https://devver.wordpress.com/2009/07/13/a-dozen-or-so-ways-to-start-sub-processes-in-ruby-part-2/[passing a string that starts with `"|"`, window="_blank"] to https://ruby-doc.org/core/Kernel.html#method-i-open[`Kernel#open`, window="_blank"]
|
108
|
+
|
109
|
+
== Installation
|
110
|
+
|
111
|
+
Add this line to your application's Gemfile:
|
112
|
+
|
113
|
+
[source,ruby]
|
114
|
+
----
|
115
|
+
gem 'shell_mock'
|
116
|
+
----
|
117
|
+
|
118
|
+
And then execute:
|
119
|
+
|
120
|
+
....
|
121
|
+
$ bundle
|
122
|
+
....
|
123
|
+
|
124
|
+
Or install it yourself as:
|
125
|
+
|
126
|
+
....
|
127
|
+
$ gem install shell_mock
|
128
|
+
....
|
129
|
+
|
130
|
+
== Development
|
131
|
+
|
132
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
133
|
+
|
134
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to https://rubygems.org[rubygems.org].
|
135
|
+
|
136
|
+
== Contributing
|
137
|
+
|
138
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yarmiganosca/shell_mock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the http://contributor-covenant.org[Contributor Covenant] code of conduct.
|
139
|
+
|
140
|
+
== License
|
141
|
+
|
142
|
+
The gem is available as open source under the terms of the http://opensource.org/licenses/MIT[MIT License].
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'shell_mock/call_verifier'
|
2
1
|
require 'shell_mock/stub_registry'
|
3
2
|
|
4
3
|
module ShellMock
|
@@ -7,12 +6,14 @@ module ShellMock
|
|
7
6
|
|
8
7
|
def initialize(command)
|
9
8
|
@command = command
|
10
|
-
@env = {}
|
11
|
-
@options = {}
|
12
9
|
@side_effect = proc {}
|
13
|
-
@exitstatus = 0
|
14
10
|
|
15
11
|
@reader, @writer = IO.pipe
|
12
|
+
|
13
|
+
with_env({})
|
14
|
+
with_options({})
|
15
|
+
and_output(nil)
|
16
|
+
and_succeed
|
16
17
|
end
|
17
18
|
|
18
19
|
def with_env(env)
|
@@ -45,40 +46,43 @@ module ShellMock
|
|
45
46
|
self
|
46
47
|
end
|
47
48
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
marshaled_signatures.each do |marshaled_signature|
|
52
|
-
@calls += 1
|
53
|
-
end
|
54
|
-
|
55
|
-
@calls
|
49
|
+
def and_succeed
|
50
|
+
and_exit(0)
|
56
51
|
end
|
57
52
|
|
58
|
-
def
|
59
|
-
|
53
|
+
def and_fail
|
54
|
+
and_exit(1)
|
60
55
|
end
|
61
56
|
|
62
|
-
def
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
attr_reader :reader, :writer
|
69
|
-
|
70
|
-
def marshaled_signatures
|
71
|
-
messages = ""
|
57
|
+
def runs
|
58
|
+
@runs ||= 0
|
72
59
|
|
73
60
|
loop do
|
74
61
|
begin
|
75
|
-
|
62
|
+
reader.read_nonblock(1)
|
63
|
+
@runs += 1
|
76
64
|
rescue IO::WaitReadable
|
77
65
|
break
|
78
66
|
end
|
79
67
|
end
|
80
68
|
|
81
|
-
|
69
|
+
@runs
|
82
70
|
end
|
71
|
+
|
72
|
+
def ran
|
73
|
+
writer.write("R")
|
74
|
+
end
|
75
|
+
|
76
|
+
def to_oneliner
|
77
|
+
if output
|
78
|
+
"echo '#{output}' && exit #{exitstatus}"
|
79
|
+
else
|
80
|
+
"exit #{exitstatus}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
attr_reader :reader, :writer
|
83
87
|
end
|
84
88
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
require 'shell_mock/
|
1
|
+
require 'shell_mock/run_verifier'
|
2
2
|
|
3
3
|
module ShellMock
|
4
4
|
module Matchers
|
5
|
-
def
|
6
|
-
ShellMock::
|
5
|
+
def have_run
|
6
|
+
ShellMock::RunVerifier.new
|
7
7
|
end
|
8
|
+
alias have_been_called have_run
|
9
|
+
alias have_ran have_run
|
8
10
|
end
|
9
11
|
end
|
data/lib/shell_mock/rspec.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
module ShellMock
|
2
|
-
class
|
2
|
+
class RunVerifier
|
3
3
|
def initialize
|
4
4
|
more_than(0)
|
5
5
|
end
|
6
6
|
|
7
7
|
def times(n)
|
8
|
-
|
8
|
+
match_runs_when { |runs| runs == n }
|
9
9
|
|
10
10
|
self
|
11
11
|
end
|
12
12
|
|
13
13
|
def fewer_than(n)
|
14
|
-
|
14
|
+
match_runs_when { |runs| runs < n }
|
15
15
|
|
16
16
|
self
|
17
17
|
end
|
18
18
|
alias less_than fewer_than
|
19
19
|
|
20
20
|
def more_than(n)
|
21
|
-
|
21
|
+
match_runs_when { |runs| runs > n }
|
22
22
|
|
23
23
|
self
|
24
24
|
end
|
@@ -34,7 +34,7 @@ module ShellMock
|
|
34
34
|
def matches?(command_stub)
|
35
35
|
@command_stub = command_stub
|
36
36
|
|
37
|
-
condition.call(command_stub.
|
37
|
+
condition.call(command_stub.runs)
|
38
38
|
end
|
39
39
|
|
40
40
|
def failure_message
|
@@ -49,7 +49,7 @@ module ShellMock
|
|
49
49
|
|
50
50
|
attr_reader :command_stub, :condition
|
51
51
|
|
52
|
-
def
|
52
|
+
def match_runs_when(&blk)
|
53
53
|
@condition = blk
|
54
54
|
end
|
55
55
|
end
|
data/lib/shell_mock/version.rb
CHANGED
data/lib/shell_mock.rb
CHANGED
@@ -3,6 +3,7 @@ require 'shell_mock/stub_registry'
|
|
3
3
|
require 'shell_mock/command_stub'
|
4
4
|
require 'shell_mock/monkey_patches'
|
5
5
|
require 'shell_mock/core_ext/module'
|
6
|
+
require 'shell_mock/rspec'
|
6
7
|
|
7
8
|
module ShellMock
|
8
9
|
def self.stub_command(command)
|
@@ -42,7 +43,8 @@ module ShellMock
|
|
42
43
|
|
43
44
|
StubRegistry.clear
|
44
45
|
|
45
|
-
@enabled
|
46
|
+
@enabled = false
|
47
|
+
@let_commands_run = nil
|
46
48
|
|
47
49
|
true
|
48
50
|
end
|
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.6.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-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: asciidoctor
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: WebMock for shell commands
|
98
112
|
email:
|
99
113
|
- yarmiganosca@gmail.com
|
@@ -109,13 +123,12 @@ files:
|
|
109
123
|
- CODE_OF_CONDUCT.md
|
110
124
|
- Gemfile
|
111
125
|
- LICENSE.txt
|
112
|
-
- README.
|
126
|
+
- README.adoc
|
113
127
|
- Rakefile
|
114
128
|
- bin/console
|
115
129
|
- bin/setup
|
116
130
|
- lib/shell_mock.rb
|
117
131
|
- lib/shell_mock/backtick_monkey_patch.rb
|
118
|
-
- lib/shell_mock/call_verifier.rb
|
119
132
|
- lib/shell_mock/command_stub.rb
|
120
133
|
- lib/shell_mock/core_ext/module.rb
|
121
134
|
- lib/shell_mock/exec_monkey_patch.rb
|
@@ -124,6 +137,7 @@ files:
|
|
124
137
|
- lib/shell_mock/no_stub_specified.rb
|
125
138
|
- lib/shell_mock/rspec.rb
|
126
139
|
- lib/shell_mock/rspec/matchers.rb
|
140
|
+
- lib/shell_mock/run_verifier.rb
|
127
141
|
- lib/shell_mock/spawn_monkey_patch.rb
|
128
142
|
- lib/shell_mock/stub_registry.rb
|
129
143
|
- lib/shell_mock/system_monkey_patch.rb
|
data/README.md
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
# ShellMock
|
2
|
-
[](http://badge.fury.io/rb/shell_mock)
|
3
|
-
[](http://travis-ci.org/yarmiganosca/shell_mock)
|
4
|
-
|
5
|
-
It's [webmock](http://github.com/bblimke/webmock) for shell commands. It's pretty simple. You can do things like this:
|
6
|
-
|
7
|
-
```ruby
|
8
|
-
require 'shell_mock/rspec'
|
9
|
-
|
10
|
-
RSpec.describe "shelling out to run 'ls'" do
|
11
|
-
before { ShellMock.enable }
|
12
|
-
after { ShellMock.disable }
|
13
|
-
|
14
|
-
let(:stub) { ShellMock.stub_command('ls') }
|
15
|
-
|
16
|
-
it "works"
|
17
|
-
expect(system('ls')).to eq true
|
18
|
-
|
19
|
-
expect(stub).to have_been_called
|
20
|
-
end
|
21
|
-
end
|
22
|
-
```
|
23
|
-
|
24
|
-
This:
|
25
|
-
1. enables ShellMock's monkey patches during the test
|
26
|
-
2. creates a command stub that will match the command `"ls"` (by default it will exit `0` and have no output)
|
27
|
-
3. shells out to run `"ls"` (in this case using `Kernel#system`)
|
28
|
-
4. correctly expects that our command stub for `"ls"` will have recorded an invocation
|
29
|
-
|
30
|
-
### You can narrow what invocations are matched to your command stub:
|
31
|
-
|
32
|
-
**Match env vars as well as the command:** `ShellMock.stub_command('ls').with_env({'FOO' => 'bar'})`
|
33
|
-
|
34
|
-
**Provide a more complete invocation:** `ShellMock.stub_command('ls $HOME')`
|
35
|
-
|
36
|
-
Shelling out to run `"ls"` won't match this command stub, but shelling out to run `"ls $HOME"` will. ShellMock always matches as strictly as possible, so if you stubbed `"ls"` and `"ls $HOME"`, invocations of `"ls $HOME'` would only ever match against the latter.
|
37
|
-
|
38
|
-
### Setting the behavior of the command invocation:
|
39
|
-
|
40
|
-
**Have the mock command invocation write to stdout:** `ShellMock.stub_command('ls').and_output("\n")`
|
41
|
-
|
42
|
-
**Set the mock command invocation's exit status:** `ShellMock.stub_command('ls').and_exit(2)`
|
43
|
-
|
44
|
-
If you want to both write to stdout and set the exit code (a common pair), `ShellMock.stub_command('ls').and_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`.
|
45
|
-
|
46
|
-
### Specifying the expected number of command invocations:
|
47
|
-
|
48
|
-
**Called exactly once:** `expect(stub).to have_been_called.once`
|
49
|
-
|
50
|
-
**Not called:** `expect(stub).to have_been_called.never`
|
51
|
-
|
52
|
-
**Not called (using RSpec expectation negation):** `expect(stub).to_not have_been_called`
|
53
|
-
|
54
|
-
**Called exactly `n` times:** `expect(stub).to have_been_called.times(n)`
|
55
|
-
|
56
|
-
**Called more than `n` times:** `expect(stub).to have_been_called.more_than(n)`
|
57
|
-
|
58
|
-
**Called fewer than `n` times:** `expect(stub).to have_been_called.fewer_than(n)`
|
59
|
-
|
60
|
-
`less_than` can be used as an alias for `fewer_than`
|
61
|
-
## Limitations
|
62
|
-
|
63
|
-
Currently, only exact string matches of the stubbed command string are supported. Basic regex support or more complex matching for arguments and flags may be added later.
|
64
|
-
|
65
|
-
ShellMock supports stubbing these ways of shelling out in Ruby:
|
66
|
-
* [`` Kernel#` ``](https://ruby-doc.org/core/Kernel.html#method-i-60) (aka "backticks")
|
67
|
-
* [`%x` command literal](https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#command) (which delegates to backticks)
|
68
|
-
* [`Kernel#system`](https://ruby-doc.org/core/Kernel.html#method-i-system)
|
69
|
-
* [`Kernel#exec`](https://ruby-doc.org/core/Kernel.html#method-i-exec)
|
70
|
-
* [`Kernel#spawn`](https://ruby-doc.org/core/Kernel.html#method-i-spawn)
|
71
|
-
* [`Process.spawn`](https://ruby-doc.org/core/Process.html#method-c-spawn)
|
72
|
-
* [the `Open3` module](https://ruby-doc.org/stdlib/libdoc/open3/rdoc/Open3.html) (since all its methods use `spawn`)
|
73
|
-
|
74
|
-
ShellMock currently DOES NOT support stubbing these ways of shelling out in Ruby (but will):
|
75
|
-
* [`IO.popen`](https://ruby-doc.org/core/IO.html#method-c-popen)
|
76
|
-
* [`PTY.spawn`](https://ruby-doc.org/stdlib/libdoc/pty/rdoc/PTY.html#method-c-spawn)
|
77
|
-
* [passing a string that starts with `"|"`](https://devver.wordpress.com/2009/07/13/a-dozen-or-so-ways-to-start-sub-processes-in-ruby-part-2/) to [`Kernel#open`](https://ruby-doc.org/core/Kernel.html#method-i-open)
|
78
|
-
|
79
|
-
## Installation
|
80
|
-
|
81
|
-
Add this line to your application's Gemfile:
|
82
|
-
|
83
|
-
```ruby
|
84
|
-
gem 'shell_mock'
|
85
|
-
```
|
86
|
-
|
87
|
-
And then execute:
|
88
|
-
|
89
|
-
$ bundle
|
90
|
-
|
91
|
-
Or install it yourself as:
|
92
|
-
|
93
|
-
$ gem install shell_mock
|
94
|
-
|
95
|
-
## Development
|
96
|
-
|
97
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
98
|
-
|
99
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
100
|
-
|
101
|
-
## Contributing
|
102
|
-
|
103
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/yarmiganosca/shell_mock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
104
|
-
|
105
|
-
## License
|
106
|
-
|
107
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|