rspec-bash 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/Gemfile +1 -0
  4. data/README.md +23 -0
  5. data/Rakefile +15 -4
  6. data/bin/bash_stub.sh +92 -0
  7. data/bin/bash_wrapper.sh.erb +12 -0
  8. data/bin/ruby_stub.rb +33 -0
  9. data/lib/rspec/bash.rb +5 -4
  10. data/lib/rspec/bash/command.rb +5 -0
  11. data/lib/rspec/bash/command/call_configuration.rb +76 -0
  12. data/lib/rspec/bash/command/call_configuration_manager.rb +24 -0
  13. data/lib/rspec/bash/command/call_log.rb +48 -0
  14. data/lib/rspec/bash/command/call_log_manager.rb +38 -0
  15. data/lib/rspec/bash/command/stubbed_command.rb +64 -0
  16. data/lib/rspec/bash/server.rb +3 -0
  17. data/lib/rspec/bash/server/bash_stub_marshaller.rb +19 -0
  18. data/lib/rspec/bash/server/ruby_stub_marshaller.rb +13 -0
  19. data/lib/rspec/bash/server/stub_server.rb +47 -0
  20. data/lib/rspec/bash/stubbed_env.rb +75 -54
  21. data/lib/rspec/bash/util/call_conf_argument_list_matcher.rb +5 -5
  22. data/lib/rspec/bash/util/call_log_argument_list_matcher.rb +1 -1
  23. data/lib/rspec/bash/wrapper.rb +4 -0
  24. data/lib/rspec/bash/wrapper/bash_stub_script.rb +15 -0
  25. data/lib/rspec/bash/wrapper/bash_wrapper.rb +54 -0
  26. data/lib/rspec/bash/wrapper/ruby_stub_script.rb +15 -0
  27. data/lib/rspec/bash/wrapper/stub_function.rb +36 -0
  28. data/rspec-bash.gemspec +2 -1
  29. data/spec/classes/command/call_configuration_manager_spec.rb +68 -0
  30. data/spec/classes/{call_configuration_spec.rb → command/call_configuration_spec.rb} +51 -114
  31. data/spec/classes/command/call_log_manager_spec.rb +83 -0
  32. data/spec/classes/{call_log_spec.rb → command/call_log_spec.rb} +23 -82
  33. data/spec/classes/command/stubbed_command_spec.rb +118 -0
  34. data/spec/classes/server/bash_stub_marshaller_spec.rb +38 -0
  35. data/spec/classes/server/ruby_stub_marshaller_spec.rb +31 -0
  36. data/spec/classes/server/stub_server_spec.rb +121 -0
  37. data/spec/classes/stubbed_env_spec.rb +141 -280
  38. data/spec/classes/util/call_conf_argument_list_matcher_spec.rb +17 -17
  39. data/spec/classes/util/call_log_argument_list_matcher_spec.rb +24 -18
  40. data/spec/classes/wrapper/bash_wrapper_spec.rb +37 -0
  41. data/spec/classes/wrapper/ruby_stub_script_spec.rb +204 -0
  42. data/spec/helper/string_file_io.rb +1 -1
  43. data/spec/integration/call_log/called_with_args_spec.rb +8 -4
  44. data/spec/integration/call_log/called_with_no_args_spec.rb +1 -1
  45. data/spec/integration/call_log/stdin_spec.rb +10 -4
  46. data/spec/integration/edge_cases_spec.rb +34 -0
  47. data/spec/integration/matchers/be_called_with_arguments_spec.rb +12 -13
  48. data/spec/integration/matchers/be_called_with_no_arguments_spec.rb +6 -7
  49. data/spec/integration/stubbed_command/outputs_spec.rb +111 -91
  50. data/spec/integration/stubbed_command/returns_exitstatus_spec.rb +46 -37
  51. data/spec/integration/stubbed_env/execute_with_env_vars_spec.rb +3 -4
  52. data/spec/integration/stubbed_env/execute_with_path_spec.rb +6 -7
  53. data/spec/integration/stubbed_env/execute_with_stub_wrapper_spec.rb +4 -12
  54. data/spec/integration/stubbed_env/override_spec.rb +354 -0
  55. data/spec/integration/wrapper/bash_stub_script_spec.rb +383 -0
  56. data/spec/integration/wrapper/bash_wrapper_spec.rb +48 -0
  57. data/spec/scripts/function_library.sh +9 -1
  58. data/spec/spec_helper.rb +2 -0
  59. metadata +65 -21
  60. data/bin/function_override.sh.erb +0 -7
  61. data/bin/function_override_wrapper.sh.erb +0 -19
  62. data/bin/stub.rb.erb +0 -56
  63. data/lib/rspec/bash/call_configuration.rb +0 -62
  64. data/lib/rspec/bash/call_log.rb +0 -71
  65. data/lib/rspec/bash/stubbed_command.rb +0 -88
  66. data/spec/classes/stub_spec.rb +0 -510
  67. data/spec/classes/stubbed_command_spec.rb +0 -134
  68. data/spec/integration/assert_called_spec.rb +0 -0
@@ -1,510 +0,0 @@
1
- require 'spec_helper'
2
- include Rspec::Bash
3
-
4
- describe 'bin/stub' do
5
- include_examples 'manage a :temp_directory'
6
-
7
- let!(:subject_command) { StubbedCommand.new('stub', temp_directory) }
8
- let!(:subject_path) { subject_command.path }
9
- let!(:subject_file_name) { File.basename(subject_path) }
10
-
11
- let(:stub_call_conf) { instance_double(CallConfiguration) }
12
- let(:stub_call_pathname) { instance_double(Pathname) }
13
- let(:stub_directory_pathname) { instance_double(Pathname) }
14
- let(:stub_config_pathname) { instance_double(Pathname) }
15
- let(:stub_output_string_pathname) { instance_double(Pathname) }
16
- let(:stub_call_file) { StringFileIO.new }
17
- let(:stub_config_file) { StringIO.new }
18
- let(:stub_stderr_file) { StringIO.new }
19
- let(:stub_stdout_file) { StringIO.new }
20
- let(:stub_output_string_file) { StringIO.new }
21
- let(:exit_code_list) { [] }
22
-
23
- before(:each) do
24
- allow(stub_call_pathname).to receive(:open).with('w')
25
- .and_yield(stub_call_file)
26
- allow(stub_call_pathname).to receive(:open).with('r')
27
- .and_yield(stub_call_file)
28
- allow(stub_output_string_pathname).to receive(:open).with('w')
29
- .and_yield(stub_output_string_file)
30
- allow(stub_config_pathname).to receive(:exist?)
31
-
32
- allow(Pathname).to receive(:new).with('a unique file name')
33
- .and_return(stub_output_string_pathname)
34
- allow(Pathname).to receive(:new).with('first_argumentsecond_argumenta unique file name')
35
- .and_return(stub_output_string_pathname)
36
- allow(Pathname).to receive(:new).with(File.dirname(subject_path))
37
- .and_return(stub_directory_pathname)
38
-
39
- allow(stub_directory_pathname).to receive(:join).with("#{subject_file_name}_calls.yml")
40
- .and_return(stub_call_pathname)
41
- allow(stub_directory_pathname).to receive(:join).with("#{subject_file_name}_stub.yml")
42
- .and_return(stub_config_pathname)
43
-
44
- $stderr = stub_stderr_file
45
- $stdout = stub_stdout_file
46
- allow($stdin).to receive(:tty?).and_return(false)
47
-
48
- allow_any_instance_of(Kernel).to receive(:exit) do |_, exit_code|
49
- exit_code_list << exit_code
50
- raise SystemExit
51
- end
52
- end
53
-
54
- context 'with no configuration' do
55
- before(:each) do
56
- allow(stub_config_pathname).to receive(:exist?).and_return(false)
57
- end
58
- context 'and it is called with no arguments' do
59
- before(:each) do
60
- ARGV.replace []
61
- end
62
- context 'and no stdin' do
63
- let(:stub_call_log) do
64
- allow($stdin).to receive(:read).and_return('')
65
- load subject_path
66
-
67
- YAML.load(stub_call_file.string)
68
- end
69
-
70
- it 'logs a blank STDIN' do
71
- expect(stub_call_log[0][:stdin]).to be_empty
72
- end
73
-
74
- it 'logs no arguments' do
75
- expect(stub_call_log[0][:args]).to be_empty
76
- end
77
-
78
- it 'exits with appropriate code' do
79
- expect(exit_code_list[0]).to be_nil
80
- end
81
- end
82
- context 'and some stdin' do
83
- let(:stub_call_log) do
84
- allow($stdin).to receive(:read).and_return("dog\ncat\n")
85
- load subject_path
86
-
87
- YAML.load(stub_call_file.string)
88
- end
89
-
90
- it 'logs some STDIN' do
91
- expect(stub_call_log[0][:stdin]).to eql "dog\ncat\n"
92
- end
93
-
94
- it 'logs no arguments' do
95
- expect(stub_call_log[0][:args]).to be_empty
96
- end
97
-
98
- it 'exits with appropriate code' do
99
- expect(exit_code_list[0]).to be_nil
100
- end
101
- end
102
- end
103
- context 'and it is called with some arguments' do
104
- before(:each) do
105
- ARGV.replace %w(first_argument second_argument)
106
- end
107
- context 'and no stdin' do
108
- let(:stub_call_log) do
109
- allow($stdin).to receive(:read).and_return('')
110
- load subject_path
111
-
112
- YAML.load(stub_call_file.string)
113
- end
114
-
115
- it 'logs a blank STDIN' do
116
- expect(stub_call_log[0][:stdin]).to be_empty
117
- end
118
-
119
- it 'logs some arguments' do
120
- expect(stub_call_log[0][:args]).to eql %w(first_argument second_argument)
121
- end
122
-
123
- it 'exits with appropriate code' do
124
- expect(exit_code_list[0]).to be_nil
125
- end
126
- end
127
- context 'and some stdin' do
128
- let(:stub_call_log) do
129
- allow($stdin).to receive(:read).and_return("dog\ncat\n")
130
- load subject_path
131
-
132
- YAML.load(stub_call_file.string)
133
- end
134
-
135
- it 'logs some STDIN' do
136
- expect(stub_call_log[0][:stdin]).to eql "dog\ncat\n"
137
- end
138
-
139
- it 'logs some arguments' do
140
- expect(stub_call_log[0][:args]).to eql %w(first_argument second_argument)
141
- end
142
-
143
- it 'exits with appropriate code' do
144
- expect(exit_code_list[0]).to be_nil
145
- end
146
- end
147
- end
148
- context 'and it is called several times in a row' do
149
- let(:stub_call_log) do
150
- ARGV.replace []
151
- allow($stdin).to receive(:read).and_return('')
152
- load subject_path
153
-
154
- ARGV.replace []
155
- allow($stdin).to receive(:read).and_return("dog\ncat\n")
156
- load subject_path
157
-
158
- ARGV.replace %w(first_argument second_argument)
159
- allow($stdin).to receive(:read).and_return('')
160
- load subject_path
161
-
162
- ARGV.replace %w(first_argument second_argument)
163
- allow($stdin).to receive(:read).and_return("dog\ncat\n")
164
- load subject_path
165
-
166
- YAML.load(stub_call_file.string)
167
- end
168
-
169
- it 'logs a blank STDIN for the first call' do
170
- expect(stub_call_log[0][:stdin]).to be_empty
171
- end
172
-
173
- it 'logs no arguments for the first call' do
174
- expect(stub_call_log[0][:args]).to be_empty
175
- end
176
-
177
- it 'logs some STDIN for the second call' do
178
- expect(stub_call_log[1][:stdin]).to eql "dog\ncat\n"
179
- end
180
-
181
- it 'logs no arguments for the second call' do
182
- expect(stub_call_log[1][:args]).to be_empty
183
- end
184
-
185
- it 'logs a blank STDIN for the third call' do
186
- expect(stub_call_log[2][:stdin]).to be_empty
187
- end
188
-
189
- it 'logs some arguments for the third call' do
190
- expect(stub_call_log[2][:args]).to eql %w(first_argument second_argument)
191
- end
192
-
193
- it 'logs some STDIN for the fourth call' do
194
- expect(stub_call_log[3][:stdin]).to eql "dog\ncat\n"
195
- end
196
-
197
- it 'logs some arguments for the fourth call' do
198
- expect(stub_call_log[3][:args]).to eql %w(first_argument second_argument)
199
- end
200
-
201
- it 'exits with appropriate code for first call' do
202
- expect(exit_code_list[0]).to be_nil
203
- end
204
-
205
- it 'exits with appropriate code for second call' do
206
- expect(exit_code_list[1]).to be_nil
207
- end
208
-
209
- it 'exits with appropriate code for third call' do
210
- expect(exit_code_list[2]).to be_nil
211
- end
212
-
213
- it 'exits with appropriate code for fourth call' do
214
- expect(exit_code_list[3]).to be_nil
215
- end
216
- end
217
- end
218
- context 'with some configuration' do
219
- before(:each) do
220
- allow($stdin).to receive(:read).and_return('')
221
- allow(stub_config_pathname).to receive(:exist?).and_return(true)
222
- end
223
- context 'with configurations that does not end up matching calls' do
224
- before(:each) do
225
- stdout_configuration = [
226
- {
227
- args: ['super_special_argument'],
228
- outputs: [
229
- {
230
- target: :stderr,
231
- content: "no args content\n"
232
- }
233
- ],
234
- exitcode: 1
235
- }
236
- ]
237
- allow(stub_config_file).to receive(:read).and_return(stdout_configuration.to_yaml)
238
- allow(stub_config_pathname).to receive(:open).with('r').and_yield(stub_config_file)
239
- end
240
- context 'and it is called with no arguments' do
241
- before(:each) do
242
- ARGV.replace []
243
- begin
244
- load subject_path
245
- rescue SystemExit
246
- end
247
- end
248
-
249
- it 'exits with appropriate code' do
250
- expect(exit_code_list[0]).to eql 0
251
- end
252
-
253
- it 'outputs nothing to stdout' do
254
- expect(stub_stdout_file.string).to eql ''
255
- end
256
-
257
- it 'outputs nothing to stderr' do
258
- expect(stub_stderr_file.string).to eql ''
259
- end
260
- end
261
- context 'and it is called with some arguments' do
262
- before(:each) do
263
- ARGV.replace ['wrongo']
264
- begin
265
- load subject_path
266
- rescue SystemExit
267
- end
268
- end
269
-
270
- it 'exits with appropriate code' do
271
- expect(exit_code_list[0]).to eql 0
272
- end
273
-
274
- it 'outputs nothing to stdout' do
275
- expect(stub_stdout_file.string).to eql ''
276
- end
277
-
278
- it 'outputs nothing to stderr' do
279
- expect(stub_stderr_file.string).to eql ''
280
- end
281
- end
282
- context 'and it is called several times in a row' do
283
- before(:each) do
284
- ARGV.replace []
285
- begin
286
- load subject_path
287
- rescue SystemExit
288
- end
289
-
290
- ARGV.replace ['wrongo']
291
- begin
292
- load subject_path
293
- rescue SystemExit
294
- end
295
- end
296
-
297
- it 'exits with appropriate code for first call' do
298
- expect(exit_code_list[0]).to eql 0
299
- end
300
-
301
- it 'exits with appropriate code for second call' do
302
- expect(exit_code_list[1]).to eql 0
303
- end
304
-
305
- it 'outputs nothing to stdout' do
306
- expect(stub_stdout_file.string).to eql ''
307
- end
308
-
309
- it 'outputs nothing to stderr' do
310
- expect(stub_stderr_file.string).to eql ''
311
- end
312
- end
313
- end
314
- context 'with configurations for stdout, stderr and file behaviour' do
315
- before(:each) do
316
- stdout_configuration = [
317
- {
318
- args: [],
319
- outputs: [
320
- {
321
- target: :stderr,
322
- content: "no args content\n"
323
- },
324
- {
325
- target: :stderr,
326
- content: "more no args content\n"
327
- }
328
- ],
329
- exitcode: 1
330
- },
331
- {
332
- args: %w(first_argument second_argument),
333
- outputs: [
334
- {
335
- target: :stdout,
336
- content: "some args content\n"
337
- },
338
- {
339
- target: :stdout,
340
- content: "more some args content\n"
341
- }
342
- ],
343
- exitcode: 2
344
- },
345
- {
346
- args: %w(first_argument second_argument third_argument),
347
- outputs: [
348
- {
349
- target: 'a unique file name',
350
- content: "some args file content\n"
351
- },
352
- {
353
- target: 'a unique file name',
354
- content: "more some args file content\n"
355
- }
356
- ],
357
- exitcode: 3
358
- },
359
- {
360
- args: %w(first_argument second_argument third_argument fourth_argument),
361
- outputs: [
362
- {
363
- target: [:arg1, :arg2, 'a unique file name'],
364
- content: "some concatenated filename output\n"
365
- },
366
- {
367
- target: [:arg1, :arg2, 'a unique file name'],
368
- content: "more some concatenated filename output\n"
369
- }
370
- ],
371
- exitcode: 4
372
- }
373
- ]
374
- allow(stub_config_file).to receive(:read).and_return(stdout_configuration.to_yaml)
375
- allow(stub_config_pathname).to receive(:open).with('r').and_yield(stub_config_file)
376
- end
377
- context 'and it is called with no arguments' do
378
- before(:each) do
379
- ARGV.replace []
380
- begin
381
- load subject_path
382
- rescue SystemExit
383
- end
384
- end
385
-
386
- it 'matches the no argument configuration exactly and prints its stderr content' do
387
- expect(stub_stderr_file.string).to eql "no args content\nmore no args content\n"
388
- end
389
-
390
- it 'matches the no argument configuration exactly and exits with its exit code' do
391
- expect(exit_code_list[0]).to eql 1
392
- end
393
- end
394
- context 'and it is called with two arguments' do
395
- before(:each) do
396
- ARGV.replace %w(first_argument second_argument)
397
- begin
398
- load subject_path
399
- rescue SystemExit
400
- end
401
- end
402
-
403
- it 'matches the two argument configuration exactly and prints its stdout content' do
404
- expect(stub_stdout_file.string).to eql "some args content\nmore some args content\n"
405
- end
406
-
407
- it 'matches the two argument configuration exactly and exits with its exit code' do
408
- expect(exit_code_list[0]).to eql 2
409
- end
410
- end
411
- context 'and it is called with three arguments' do
412
- before(:each) do
413
- ARGV.replace %w(first_argument second_argument third_argument)
414
- begin
415
- load subject_path
416
- rescue SystemExit
417
- end
418
- end
419
-
420
- it 'matches the three argument configuration exactly and prints its file content' do
421
- expect(stub_output_string_file.string).to eql 'some args file content
422
- more some args file content
423
- '
424
- end
425
-
426
- it 'matches the three argument configuration exactly and exits with its exit code' do
427
- expect(exit_code_list[0]).to eql 3
428
- end
429
- end
430
- context 'and it is called with four arguments' do
431
- before(:each) do
432
- ARGV.replace %w(first_argument second_argument third_argument fourth_argument)
433
- begin
434
- load subject_path
435
- rescue SystemExit
436
- end
437
- end
438
-
439
- it 'matches the four argument configuration exactly and prints its named file content' do
440
- expect(stub_output_string_file.string).to eql 'some concatenated filename output
441
- more some concatenated filename output
442
- '
443
- end
444
-
445
- it 'matches the four argument configuration exactly and exits with its exit code' do
446
- expect(exit_code_list[0]).to eql 4
447
- end
448
- end
449
- context 'and it is called several times in a row' do
450
- before(:each) do
451
- ARGV.replace []
452
- begin
453
- load subject_path
454
- rescue SystemExit
455
- end
456
-
457
- ARGV.replace %w(first_argument second_argument)
458
- begin
459
- load subject_path
460
- rescue SystemExit
461
- end
462
-
463
- ARGV.replace %w(first_argument second_argument third_argument)
464
- begin
465
- load subject_path
466
- rescue SystemExit
467
- end
468
-
469
- ARGV.replace %w(first_argument second_argument third_argument fourth_argument)
470
- begin
471
- load subject_path
472
- rescue SystemExit
473
- end
474
- end
475
-
476
- it 'prints the expected output to stderr' do
477
- expect(stub_stderr_file.string).to eql "no args content\nmore no args content\n"
478
- end
479
-
480
- it 'prints the expected output to stdout' do
481
- expect(stub_stdout_file.string).to eql "some args content\nmore some args content\n"
482
- end
483
-
484
- it 'prints the expected output to the string named file' do
485
- expect(stub_output_string_file.string).to eql 'some args file content
486
- more some args file content
487
- some concatenated filename output
488
- more some concatenated filename output
489
- '
490
- end
491
-
492
- it 'exits with appropriate code for first call' do
493
- expect(exit_code_list[0]).to eql 1
494
- end
495
-
496
- it 'exits with appropriate code for second call' do
497
- expect(exit_code_list[1]).to eql 2
498
- end
499
-
500
- it 'exits with appropriate code for third call' do
501
- expect(exit_code_list[2]).to eql 3
502
- end
503
-
504
- it 'exits with appropriate code for fourth call' do
505
- expect(exit_code_list[3]).to eql 4
506
- end
507
- end
508
- end
509
- end
510
- end