rspec-bash 0.2.1 → 0.3.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/bin/bash_stub.sh +14 -6
- data/bin/bash_wrapper.sh.erb +2 -2
- data/bin/ruby_stub.rb +4 -4
- data/lib/rspec/bash/command/call_configuration.rb +24 -7
- data/lib/rspec/bash/stubbed_env.rb +3 -3
- data/lib/rspec/bash/wrapper/stub_function.rb +1 -1
- data/rspec-bash.gemspec +1 -1
- data/spec/classes/command/call_configuration_spec.rb +104 -35
- data/spec/classes/stubbed_env_spec.rb +4 -4
- data/spec/classes/util/call_conf_argument_list_matcher_spec.rb +154 -154
- data/spec/classes/wrapper/ruby_stub_script_spec.rb +5 -5
- data/spec/integration/edge_cases/stub_internals_spec.rb +101 -0
- data/spec/integration/stubbed_command/outputs_spec.rb +46 -13
- data/spec/integration/stubbed_command/returns_exitstatus_spec.rb +0 -12
- data/spec/integration/stubbed_env/override_spec.rb +0 -25
- data/spec/integration/wrapper/bash_stub_script_spec.rb +49 -23
- data/spec/spec_helper.rb +25 -0
- metadata +4 -2
@@ -133,20 +133,20 @@ describe 'RubyStubFunction' do
|
|
133
133
|
before do
|
134
134
|
stdout_configuration = {
|
135
135
|
args: [],
|
136
|
-
outputs:
|
137
|
-
{
|
136
|
+
outputs: {
|
137
|
+
stderr: {
|
138
138
|
target: :stderr,
|
139
139
|
content: "stderr\n"
|
140
140
|
},
|
141
|
-
{
|
141
|
+
stdout: {
|
142
142
|
target: :stdout,
|
143
143
|
content: "stdout\n"
|
144
144
|
},
|
145
|
-
{
|
145
|
+
'tofile' => {
|
146
146
|
target: 'tofile',
|
147
147
|
content: "tofile\n"
|
148
148
|
}
|
149
|
-
|
149
|
+
},
|
150
150
|
exitcode: 8
|
151
151
|
}
|
152
152
|
allow(stub_socket).to receive(:read).and_return(Marshal.dump(stdout_configuration))
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Rspec::Bash
|
3
|
+
|
4
|
+
# rubocop:disable Metrics/AbcSize
|
5
|
+
# rubocop:disable Metrics/MethodLength
|
6
|
+
def expect_normal_operation
|
7
|
+
it 'should not blow up the test framework' do
|
8
|
+
expect(first_command).to be_called_with_arguments('hello')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should return given stdout' do
|
12
|
+
expect(stdout).to eql 'stdout'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return given stderr' do
|
16
|
+
expect(stderr.chomp).to eql 'stderr'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return the given exit code' do
|
20
|
+
expect(exitcode).to eql 1
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'treat calls like any other stub' do
|
24
|
+
expect(second_command).to be_called_with_no_arguments
|
25
|
+
end
|
26
|
+
end
|
27
|
+
# rubocop:enable Metrics/AbcSize
|
28
|
+
# rubocop:enable Metrics/AbcSize
|
29
|
+
|
30
|
+
describe 'integration for overrides of key stub internals' do
|
31
|
+
let(:stubbed_env) { create_stubbed_env }
|
32
|
+
let!(:first_command) do
|
33
|
+
stubbed_env.stub_command('first_command')
|
34
|
+
.outputs('stdout', to: :stdout)
|
35
|
+
.outputs('stderr', to: :stderr)
|
36
|
+
.returns_exitstatus(1)
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'bash' do
|
40
|
+
let!(:second_command) { stubbed_env.stub_command('bash') }
|
41
|
+
|
42
|
+
execute_script 'bash; first_command hello'
|
43
|
+
|
44
|
+
expect_normal_operation
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'ruby' do
|
48
|
+
let!(:second_command) { stubbed_env.stub_command('ruby') }
|
49
|
+
|
50
|
+
execute_script 'ruby; first_command hello'
|
51
|
+
|
52
|
+
expect_normal_operation
|
53
|
+
end
|
54
|
+
|
55
|
+
context '/usr/bin/env' do
|
56
|
+
let!(:second_command) { stubbed_env.stub_command('/usr/bin/env') }
|
57
|
+
|
58
|
+
execute_script '/usr/bin/env; first_command hello'
|
59
|
+
|
60
|
+
expect_normal_operation
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'source' do
|
64
|
+
let!(:second_command) { stubbed_env.stub_command('source') }
|
65
|
+
|
66
|
+
execute_script 'source; first_command hello'
|
67
|
+
|
68
|
+
expect_normal_operation
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'grep' do
|
72
|
+
let!(:second_command) { stubbed_env.stub_command('grep') }
|
73
|
+
|
74
|
+
execute_script 'grep; first_command hello'
|
75
|
+
|
76
|
+
expect_normal_operation
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'exit' do
|
80
|
+
let!(:second_command) { stubbed_env.stub_command('exit') }
|
81
|
+
|
82
|
+
execute_script 'exit; first_command hello'
|
83
|
+
|
84
|
+
expect_normal_operation
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'readonly' do
|
88
|
+
let!(:second_command) { stubbed_env.stub_command('readonly') }
|
89
|
+
|
90
|
+
execute_script <<-multiline_script
|
91
|
+
function first_command {
|
92
|
+
echo 'overridden'
|
93
|
+
}
|
94
|
+
|
95
|
+
readonly
|
96
|
+
first_command hello
|
97
|
+
multiline_script
|
98
|
+
|
99
|
+
expect_normal_operation
|
100
|
+
end
|
101
|
+
end
|
@@ -1,18 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
include Rspec::Bash
|
3
3
|
|
4
|
-
def execute_script(script)
|
5
|
-
let!(:execute_results) do
|
6
|
-
stdout, stderr, status = stubbed_env.execute_inline(
|
7
|
-
script
|
8
|
-
)
|
9
|
-
[stdout, stderr, status]
|
10
|
-
end
|
11
|
-
let(:stdout) { execute_results[0] }
|
12
|
-
let(:stderr) { execute_results[1] }
|
13
|
-
let(:exitcode) { execute_results[2].exitstatus }
|
14
|
-
end
|
15
|
-
|
16
4
|
describe 'StubbedCommand' do
|
17
5
|
let(:stubbed_env) { create_stubbed_env }
|
18
6
|
let!(:command) { stubbed_env.stub_command('stubbed_command') }
|
@@ -179,7 +167,7 @@ describe 'StubbedCommand' do
|
|
179
167
|
end
|
180
168
|
|
181
169
|
describe 'target file path' do
|
182
|
-
let(:temp_file) { Tempfile.new('for
|
170
|
+
let(:temp_file) { Tempfile.new('for testing') }
|
183
171
|
|
184
172
|
context 'when given no arguments to match' do
|
185
173
|
before do
|
@@ -277,6 +265,51 @@ describe 'StubbedCommand' do
|
|
277
265
|
FileUtils.remove_entry_secure dynamic_file
|
278
266
|
end
|
279
267
|
end
|
268
|
+
|
269
|
+
describe 'when given a filename that matches the stdout target' do
|
270
|
+
let(:stdout_file) { Pathname.new('stdout') }
|
271
|
+
|
272
|
+
before do
|
273
|
+
command
|
274
|
+
.outputs('i am supposed to go to a file', to: 'stdout')
|
275
|
+
end
|
276
|
+
|
277
|
+
execute_script('stubbed_command poglet piglet')
|
278
|
+
|
279
|
+
it 'outputs the expected content to the file' do
|
280
|
+
expect(stdout_file.read).to eql 'i am supposed to go to a file'
|
281
|
+
end
|
282
|
+
|
283
|
+
after(:each) do
|
284
|
+
FileUtils.remove_entry_secure stdout_file
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
describe 'any target' do
|
290
|
+
context 'when given a non-string output' do
|
291
|
+
before do
|
292
|
+
command.outputs(['an array'], to: :stdout)
|
293
|
+
end
|
294
|
+
|
295
|
+
execute_script('stubbed_command first_argument second_argument')
|
296
|
+
|
297
|
+
it 'outputs the expected output to stdout' do
|
298
|
+
expect(stdout).to eql '["an array"]'
|
299
|
+
end
|
300
|
+
end
|
301
|
+
context 'when given multiple outputs settings' do
|
302
|
+
before do
|
303
|
+
command.outputs('first output', to: :stdout)
|
304
|
+
command.outputs('second output', to: :stdout)
|
305
|
+
end
|
306
|
+
|
307
|
+
execute_script('stubbed_command first_argument second_argument')
|
308
|
+
|
309
|
+
it 'outputs only the results from the second call to outputs' do
|
310
|
+
expect(stdout).to eql 'second output'
|
311
|
+
end
|
312
|
+
end
|
280
313
|
end
|
281
314
|
end
|
282
315
|
end
|
@@ -1,18 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
include Rspec::Bash
|
3
3
|
|
4
|
-
def execute_script(script)
|
5
|
-
let!(:execute_results) do
|
6
|
-
stdout, stderr, status = stubbed_env.execute_inline(
|
7
|
-
script
|
8
|
-
)
|
9
|
-
[stdout, stderr, status]
|
10
|
-
end
|
11
|
-
let(:stdout) { execute_results[0] }
|
12
|
-
let(:stderr) { execute_results[1] }
|
13
|
-
let(:exitcode) { execute_results[2].exitstatus }
|
14
|
-
end
|
15
|
-
|
16
4
|
describe 'StubbedCommand' do
|
17
5
|
let(:stubbed_env) { create_stubbed_env }
|
18
6
|
let!(:command) { stubbed_env.stub_command('stubbed_command') }
|
@@ -1,31 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
include Rspec::Bash
|
3
3
|
|
4
|
-
def execute_script(script)
|
5
|
-
let!(:execute_results) do
|
6
|
-
stdout, stderr, status = stubbed_env.execute_inline(
|
7
|
-
script
|
8
|
-
)
|
9
|
-
[stdout, stderr, status]
|
10
|
-
end
|
11
|
-
let(:stdout) { execute_results[0] }
|
12
|
-
let(:stderr) { execute_results[1] }
|
13
|
-
let(:exitcode) { execute_results[2].exitstatus }
|
14
|
-
end
|
15
|
-
|
16
|
-
def execute_function(script, function)
|
17
|
-
let!(:execute_results) do
|
18
|
-
stdout, stderr, status = stubbed_env.execute_function(
|
19
|
-
script,
|
20
|
-
function
|
21
|
-
)
|
22
|
-
[stdout, stderr, status]
|
23
|
-
end
|
24
|
-
let(:stdout) { execute_results[0] }
|
25
|
-
let(:stderr) { execute_results[1] }
|
26
|
-
let(:exitcode) { execute_results[2].exitstatus }
|
27
|
-
end
|
28
|
-
|
29
4
|
describe('StubbedEnv override tests') do
|
30
5
|
subject { create_stubbed_env }
|
31
6
|
let(:stubbed_env) { subject }
|
@@ -2,23 +2,27 @@ require 'spec_helper'
|
|
2
2
|
include Rspec::Bash
|
3
3
|
|
4
4
|
def execute_script(script)
|
5
|
-
let(:temp_file) { Tempfile.new('for
|
5
|
+
let(:temp_file) { Tempfile.new('for testing') }
|
6
6
|
|
7
|
-
|
7
|
+
capture_execute_results script
|
8
8
|
|
9
9
|
after do
|
10
10
|
FileUtils.remove_entry_secure temp_file if script.include? '<temp file>'
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def capture_execute_results(script)
|
15
15
|
let!(:execute_results) do
|
16
16
|
script.gsub!(/<temp file>/, temp_file.path) if script.include? '<temp file>'
|
17
17
|
stubbed_env.execute_function(BashStubScript.path, script)
|
18
18
|
end
|
19
|
+
capture_standard_streams
|
20
|
+
end
|
19
21
|
|
22
|
+
def capture_standard_streams
|
20
23
|
let(:stdout) { execute_results[0] }
|
21
24
|
let(:stderr) { execute_results[1] }
|
25
|
+
let(:exit_code) { execute_results[2].exitstatus }
|
22
26
|
end
|
23
27
|
|
24
28
|
describe 'BashStub' do
|
@@ -166,24 +170,20 @@ describe 'BashStub' do
|
|
166
170
|
Sparsify.sparse(
|
167
171
|
{
|
168
172
|
exitcode: 10_000,
|
169
|
-
outputs:
|
170
|
-
{
|
171
|
-
target:
|
173
|
+
outputs: {
|
174
|
+
stdout: {
|
175
|
+
target: :stdout,
|
172
176
|
content: "stdout\nstdout,stdout"
|
173
177
|
},
|
174
|
-
{
|
175
|
-
target:
|
176
|
-
content: 1
|
177
|
-
},
|
178
|
-
{
|
179
|
-
target: 'stderr',
|
178
|
+
stderr: {
|
179
|
+
target: :stderr,
|
180
180
|
content: "stderr\" stderr\nstderr"
|
181
181
|
},
|
182
|
-
{
|
182
|
+
'tofile' => {
|
183
183
|
target: 'tofile',
|
184
184
|
content: "tofile\ntofile:\", tofile"
|
185
185
|
}
|
186
|
-
|
186
|
+
}
|
187
187
|
}, sparse_array: true
|
188
188
|
), indent: '', space: ''
|
189
189
|
)
|
@@ -205,12 +205,20 @@ describe 'BashStub' do
|
|
205
205
|
expect(stdout.chomp).to eql "stdout\\nstdout,stdout\nstderr\\\" stderr\\nstderr" \
|
206
206
|
"\ntofile\\ntofile:\\\", tofile"
|
207
207
|
end
|
208
|
+
|
209
|
+
it 'extracts a multiple value field with a dynamic key' do
|
210
|
+
stdout, _stderr = stubbed_env.execute_function(
|
211
|
+
BashStubScript.path,
|
212
|
+
"extract-string-properties '#{call_conf}' 'outputs\\..*\\.target'"
|
213
|
+
)
|
214
|
+
expect(stdout.chomp).to eql "stdout\nstderr\ntofile"
|
215
|
+
end
|
208
216
|
end
|
209
217
|
end
|
210
218
|
|
211
219
|
context '.print-output' do
|
212
|
-
context 'given a stdout target and its associated content' do
|
213
|
-
execute_script("print-output 'stdout' '\\nstdout \\\\nstdout\nstdout\\n'")
|
220
|
+
context 'given a stdout type and target and its associated content' do
|
221
|
+
execute_script("print-output 'stdout' 'stdout' '\\nstdout \\\\nstdout\nstdout\\n'")
|
214
222
|
|
215
223
|
it 'prints the output to stdout' do
|
216
224
|
expect(stdout).to eql "\nstdout \\nstdout\nstdout\n"
|
@@ -221,8 +229,8 @@ describe 'BashStub' do
|
|
221
229
|
end
|
222
230
|
end
|
223
231
|
|
224
|
-
context 'given a stderr target and its associated content' do
|
225
|
-
execute_script("print-output 'stderr' '\\nstderr \\\\nstderr\nstderr\\n'")
|
232
|
+
context 'given a stderr type and target and its associated content' do
|
233
|
+
execute_script("print-output 'stderr' 'stderr' '\\nstderr \\\\nstderr\nstderr\\n'")
|
226
234
|
|
227
235
|
it 'prints the output to stderr' do
|
228
236
|
expect(stderr).to eql "\nstderr \\nstderr\nstderr\n"
|
@@ -233,8 +241,8 @@ describe 'BashStub' do
|
|
233
241
|
end
|
234
242
|
end
|
235
243
|
|
236
|
-
context 'given a file target (anything but stderr or stdout)' do
|
237
|
-
execute_script("print-output '<temp file>' '\\ntofile \\\\ntofile\ntofile\\n'")
|
244
|
+
context 'given a file type and target (anything but stderr or stdout)' do
|
245
|
+
execute_script("print-output 'file' '<temp file>' '\\ntofile \\\\ntofile\ntofile\\n'")
|
238
246
|
|
239
247
|
it 'prints the output to the file' do
|
240
248
|
expect(temp_file.read).to eql "\ntofile \\ntofile\ntofile\n"
|
@@ -244,6 +252,21 @@ describe 'BashStub' do
|
|
244
252
|
expect(stderr.chomp).to eql ''
|
245
253
|
end
|
246
254
|
|
255
|
+
it 'does not print the output to stdout' do
|
256
|
+
expect(stdout.chomp).to eql ''
|
257
|
+
end
|
258
|
+
end
|
259
|
+
context 'given a file type and target that is an empty string' do
|
260
|
+
execute_script("print-output 'file' '' '\\ntofile \\\\ntofile\ntofile\\n'")
|
261
|
+
|
262
|
+
it 'does not exit with a non-zero exit code' do
|
263
|
+
expect(exit_code).to eql 0
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'does not print the output to stderr' do
|
267
|
+
expect(stderr.chomp).to eql ''
|
268
|
+
end
|
269
|
+
|
247
270
|
it 'does not print the output to stdout' do
|
248
271
|
expect(stdout.chomp).to eql ''
|
249
272
|
end
|
@@ -332,6 +355,9 @@ describe 'BashStub' do
|
|
332
355
|
@extract_string_properties
|
333
356
|
.with_args('call conf', 'outputs\..*\.target')
|
334
357
|
.outputs("stdout\nstderr\ntofile\n")
|
358
|
+
@extract_string_properties
|
359
|
+
.with_args('call conf', 'outputs\..*\.type')
|
360
|
+
.outputs("stdout\nstderr\nfile\n")
|
335
361
|
@extract_string_properties
|
336
362
|
.with_args('call conf', 'outputs\..*\.content')
|
337
363
|
.outputs("\\nstd out\\n\n\\nstd err\\n\n\\nto file\\n\n")
|
@@ -371,13 +397,13 @@ describe 'BashStub' do
|
|
371
397
|
end
|
372
398
|
it 'prints the extracted outputs (with newlines still escaped)' do
|
373
399
|
expect(@print_output).to be_called_with_arguments(
|
374
|
-
'stdout', '\nstd out\n'
|
400
|
+
'stdout', 'stdout', '\nstd out\n'
|
375
401
|
)
|
376
402
|
expect(@print_output).to be_called_with_arguments(
|
377
|
-
'stderr', '\nstd err\n'
|
403
|
+
'stderr', 'stderr', '\nstd err\n'
|
378
404
|
)
|
379
405
|
expect(@print_output).to be_called_with_arguments(
|
380
|
-
'tofile', '\nto file\n'
|
406
|
+
'file', 'tofile', '\nto file\n'
|
381
407
|
)
|
382
408
|
end
|
383
409
|
it 'exits with the extracted exit code' do
|
data/spec/spec_helper.rb
CHANGED
@@ -14,3 +14,28 @@ require 'helper/shared_tmpdir'
|
|
14
14
|
RSpec.configure do |c|
|
15
15
|
c.include Rspec::Bash
|
16
16
|
end
|
17
|
+
|
18
|
+
def execute_script(script)
|
19
|
+
let!(:execute_results) do
|
20
|
+
stdout, stderr, status = stubbed_env.execute_inline(
|
21
|
+
script
|
22
|
+
)
|
23
|
+
[stdout, stderr, status]
|
24
|
+
end
|
25
|
+
let(:stdout) { execute_results[0] }
|
26
|
+
let(:stderr) { execute_results[1] }
|
27
|
+
let(:exitcode) { execute_results[2].exitstatus }
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute_function(script, function)
|
31
|
+
let!(:execute_results) do
|
32
|
+
stdout, stderr, status = stubbed_env.execute_function(
|
33
|
+
script,
|
34
|
+
function
|
35
|
+
)
|
36
|
+
[stdout, stderr, status]
|
37
|
+
end
|
38
|
+
let(:stdout) { execute_results[0] }
|
39
|
+
let(:stderr) { execute_results[1] }
|
40
|
+
let(:exitcode) { execute_results[2].exitstatus }
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-bash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Brewer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2018-01-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sparsify
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- spec/integration/call_log/called_with_no_args_spec.rb
|
123
123
|
- spec/integration/call_log/stdin_spec.rb
|
124
124
|
- spec/integration/edge_cases/long_command_spec.rb
|
125
|
+
- spec/integration/edge_cases/stub_internals_spec.rb
|
125
126
|
- spec/integration/matchers/be_called_with_arguments_spec.rb
|
126
127
|
- spec/integration/matchers/be_called_with_no_arguments_spec.rb
|
127
128
|
- spec/integration/stubbed_command/outputs_spec.rb
|
@@ -178,6 +179,7 @@ test_files:
|
|
178
179
|
- spec/integration/call_log/called_with_no_args_spec.rb
|
179
180
|
- spec/integration/call_log/stdin_spec.rb
|
180
181
|
- spec/integration/edge_cases/long_command_spec.rb
|
182
|
+
- spec/integration/edge_cases/stub_internals_spec.rb
|
181
183
|
- spec/integration/matchers/be_called_with_arguments_spec.rb
|
182
184
|
- spec/integration/matchers/be_called_with_no_arguments_spec.rb
|
183
185
|
- spec/integration/stubbed_command/outputs_spec.rb
|