rspec-bash 0.1.1 → 0.2.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/.rubocop.yml +8 -0
- data/Gemfile +1 -0
- data/README.md +23 -0
- data/Rakefile +15 -4
- data/bin/bash_stub.sh +92 -0
- data/bin/bash_wrapper.sh.erb +12 -0
- data/bin/ruby_stub.rb +33 -0
- data/lib/rspec/bash.rb +5 -4
- data/lib/rspec/bash/command.rb +5 -0
- data/lib/rspec/bash/command/call_configuration.rb +76 -0
- data/lib/rspec/bash/command/call_configuration_manager.rb +24 -0
- data/lib/rspec/bash/command/call_log.rb +48 -0
- data/lib/rspec/bash/command/call_log_manager.rb +38 -0
- data/lib/rspec/bash/command/stubbed_command.rb +64 -0
- data/lib/rspec/bash/server.rb +3 -0
- data/lib/rspec/bash/server/bash_stub_marshaller.rb +19 -0
- data/lib/rspec/bash/server/ruby_stub_marshaller.rb +13 -0
- data/lib/rspec/bash/server/stub_server.rb +47 -0
- data/lib/rspec/bash/stubbed_env.rb +75 -54
- data/lib/rspec/bash/util/call_conf_argument_list_matcher.rb +5 -5
- data/lib/rspec/bash/util/call_log_argument_list_matcher.rb +1 -1
- data/lib/rspec/bash/wrapper.rb +4 -0
- data/lib/rspec/bash/wrapper/bash_stub_script.rb +15 -0
- data/lib/rspec/bash/wrapper/bash_wrapper.rb +54 -0
- data/lib/rspec/bash/wrapper/ruby_stub_script.rb +15 -0
- data/lib/rspec/bash/wrapper/stub_function.rb +36 -0
- data/rspec-bash.gemspec +2 -1
- data/spec/classes/command/call_configuration_manager_spec.rb +68 -0
- data/spec/classes/{call_configuration_spec.rb → command/call_configuration_spec.rb} +51 -114
- data/spec/classes/command/call_log_manager_spec.rb +83 -0
- data/spec/classes/{call_log_spec.rb → command/call_log_spec.rb} +23 -82
- data/spec/classes/command/stubbed_command_spec.rb +118 -0
- data/spec/classes/server/bash_stub_marshaller_spec.rb +38 -0
- data/spec/classes/server/ruby_stub_marshaller_spec.rb +31 -0
- data/spec/classes/server/stub_server_spec.rb +121 -0
- data/spec/classes/stubbed_env_spec.rb +141 -280
- data/spec/classes/util/call_conf_argument_list_matcher_spec.rb +17 -17
- data/spec/classes/util/call_log_argument_list_matcher_spec.rb +24 -18
- data/spec/classes/wrapper/bash_wrapper_spec.rb +37 -0
- data/spec/classes/wrapper/ruby_stub_script_spec.rb +204 -0
- data/spec/helper/string_file_io.rb +1 -1
- data/spec/integration/call_log/called_with_args_spec.rb +8 -4
- data/spec/integration/call_log/called_with_no_args_spec.rb +1 -1
- data/spec/integration/call_log/stdin_spec.rb +10 -4
- data/spec/integration/edge_cases_spec.rb +34 -0
- data/spec/integration/matchers/be_called_with_arguments_spec.rb +12 -13
- data/spec/integration/matchers/be_called_with_no_arguments_spec.rb +6 -7
- data/spec/integration/stubbed_command/outputs_spec.rb +111 -91
- data/spec/integration/stubbed_command/returns_exitstatus_spec.rb +46 -37
- data/spec/integration/stubbed_env/execute_with_env_vars_spec.rb +3 -4
- data/spec/integration/stubbed_env/execute_with_path_spec.rb +6 -7
- data/spec/integration/stubbed_env/execute_with_stub_wrapper_spec.rb +4 -12
- data/spec/integration/stubbed_env/override_spec.rb +354 -0
- data/spec/integration/wrapper/bash_stub_script_spec.rb +383 -0
- data/spec/integration/wrapper/bash_wrapper_spec.rb +48 -0
- data/spec/scripts/function_library.sh +9 -1
- data/spec/spec_helper.rb +2 -0
- metadata +65 -21
- data/bin/function_override.sh.erb +0 -7
- data/bin/function_override_wrapper.sh.erb +0 -19
- data/bin/stub.rb.erb +0 -56
- data/lib/rspec/bash/call_configuration.rb +0 -62
- data/lib/rspec/bash/call_log.rb +0 -71
- data/lib/rspec/bash/stubbed_command.rb +0 -88
- data/spec/classes/stub_spec.rb +0 -510
- data/spec/classes/stubbed_command_spec.rb +0 -134
- data/spec/integration/assert_called_spec.rb +0 -0
@@ -1,98 +1,107 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
include Rspec::Bash
|
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
|
2
15
|
|
3
16
|
describe 'StubbedCommand' do
|
4
|
-
include Rspec::Bash
|
5
17
|
let(:stubbed_env) { create_stubbed_env }
|
6
|
-
let!(:
|
18
|
+
let!(:command) { stubbed_env.stub_command('stubbed_command') }
|
7
19
|
|
8
20
|
context '#returns_exitstatus' do
|
9
21
|
context 'when given no exit status to return' do
|
10
|
-
|
11
|
-
_, _, status = stubbed_env.execute_inline('command1 first_argument second_argument')
|
12
|
-
status.exitstatus
|
13
|
-
end
|
22
|
+
execute_script('stubbed_command first_argument second_argument')
|
14
23
|
|
15
24
|
it 'exits with the appropriate exit code' do
|
16
|
-
expect(
|
25
|
+
expect(exitcode).to be 0
|
17
26
|
end
|
18
27
|
end
|
19
28
|
|
20
29
|
context 'when given no args to match' do
|
21
|
-
|
22
|
-
|
30
|
+
before do
|
31
|
+
command
|
23
32
|
.returns_exitstatus(100)
|
24
|
-
_, _, status = stubbed_env.execute_inline('command1 first_argument second_argument')
|
25
|
-
status.exitstatus
|
26
33
|
end
|
27
34
|
|
35
|
+
execute_script('stubbed_command first_argument second_argument')
|
36
|
+
|
28
37
|
it 'exits with the appropriate exit code' do
|
29
|
-
expect(
|
38
|
+
expect(exitcode).to be 100
|
30
39
|
end
|
31
40
|
end
|
32
41
|
|
33
42
|
context 'when given an exact argument match' do
|
34
|
-
|
35
|
-
|
43
|
+
before do
|
44
|
+
command
|
36
45
|
.with_args('first_argument', 'second_argument')
|
37
46
|
.returns_exitstatus(101)
|
38
|
-
_, _, status = stubbed_env.execute_inline('command1 first_argument second_argument')
|
39
|
-
status.exitstatus
|
40
47
|
end
|
41
48
|
|
49
|
+
execute_script('stubbed_command first_argument second_argument')
|
50
|
+
|
42
51
|
it 'exits with the appropriate exit code' do
|
43
|
-
expect(
|
52
|
+
expect(exitcode).to be 101
|
44
53
|
end
|
45
54
|
end
|
46
55
|
context 'when given an anything argument match' do
|
47
|
-
|
48
|
-
|
56
|
+
before do
|
57
|
+
command
|
49
58
|
.with_args('first_argument', anything)
|
50
59
|
.returns_exitstatus(102)
|
51
|
-
_, _, status = stubbed_env.execute_inline('command1 first_argument second_argument')
|
52
|
-
status.exitstatus
|
53
60
|
end
|
54
61
|
|
62
|
+
execute_script('stubbed_command first_argument second_argument')
|
63
|
+
|
55
64
|
it 'exits with the appropriate exit code' do
|
56
|
-
expect(
|
65
|
+
expect(exitcode).to be 102
|
57
66
|
end
|
58
67
|
end
|
59
68
|
context 'when given any_args argument match' do
|
60
|
-
|
61
|
-
|
69
|
+
before do
|
70
|
+
command
|
62
71
|
.with_args(any_args)
|
63
72
|
.returns_exitstatus(103)
|
64
|
-
_, _, status = stubbed_env.execute_inline('command1 poglet piglet')
|
65
|
-
status.exitstatus
|
66
73
|
end
|
67
74
|
|
75
|
+
execute_script('stubbed_command poglet piglet')
|
76
|
+
|
68
77
|
it 'exits with the appropriate exit code' do
|
69
|
-
expect(
|
78
|
+
expect(exitcode).to be 103
|
70
79
|
end
|
71
80
|
end
|
72
81
|
context 'when given other types of RSpec::Mock::ArgumentMatcher argument match' do
|
73
|
-
|
74
|
-
|
82
|
+
before do
|
83
|
+
command
|
75
84
|
.with_args(instance_of(String), instance_of(String))
|
76
85
|
.returns_exitstatus(104)
|
77
|
-
_, _, status = stubbed_env.execute_inline('command1 poglet 1')
|
78
|
-
status.exitstatus
|
79
86
|
end
|
80
87
|
|
88
|
+
execute_script('stubbed_command poglet 1')
|
89
|
+
|
81
90
|
it 'exits with the appropriate exit code' do
|
82
|
-
expect(
|
91
|
+
expect(exitcode).to be 104
|
83
92
|
end
|
84
93
|
end
|
85
94
|
context 'when given regex argument match' do
|
86
|
-
|
87
|
-
|
95
|
+
before do
|
96
|
+
command
|
88
97
|
.with_args(/p.glet/, /p.glet/)
|
89
98
|
.returns_exitstatus(105)
|
90
|
-
_, _, status = stubbed_env.execute_inline('command1 poglet piglet')
|
91
|
-
status.exitstatus
|
92
99
|
end
|
93
100
|
|
101
|
+
execute_script('stubbed_command poglet piglet')
|
102
|
+
|
94
103
|
it 'exits with the appropriate exit code' do
|
95
|
-
expect(
|
104
|
+
expect(exitcode).to be 105
|
96
105
|
end
|
97
106
|
end
|
98
107
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
include Rspec::Bash
|
2
3
|
|
3
4
|
describe 'StubbedEnv' do
|
4
|
-
|
5
|
+
subject { create_stubbed_env }
|
5
6
|
|
6
7
|
context '#execute(..., ENV => VARIABLES)' do
|
7
|
-
let(:stubbed_env) { create_stubbed_env }
|
8
|
-
|
9
8
|
it 'exits with an error' do
|
10
|
-
stdout, =
|
9
|
+
stdout, = subject.execute_inline(
|
11
10
|
'echo $SOME_ENV_VAR',
|
12
11
|
'SOME_ENV_VAR' => 'SekretCredential'
|
13
12
|
)
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
include Rspec::Bash
|
2
3
|
|
3
4
|
describe 'StubbedEnv' do
|
4
|
-
|
5
|
+
subject { create_stubbed_env }
|
5
6
|
|
6
7
|
context '#execute(path, ...)' do
|
7
8
|
describe 'running a file with non-existing commands' do
|
@@ -11,21 +12,19 @@ describe 'StubbedEnv' do
|
|
11
12
|
end
|
12
13
|
|
13
14
|
context 'with stubbed environment' do
|
14
|
-
let(:stubbed_env) { create_stubbed_env }
|
15
|
-
|
16
15
|
it 'exits with an error' do
|
17
|
-
|
16
|
+
subject.execute_inline 'command1 "foo bar" 2>&1'
|
18
17
|
expect($CHILD_STATUS.exitstatus).not_to eq 0
|
19
18
|
end
|
20
19
|
|
21
20
|
context 'with a stubbed command' do
|
22
21
|
before do
|
23
|
-
|
22
|
+
subject.stub_command('command1')
|
24
23
|
end
|
25
24
|
|
26
25
|
it 'exits with status code 0' do
|
27
|
-
_, _,
|
28
|
-
expect(
|
26
|
+
_, _, exitcode = subject.execute_inline 'command1 "foo bar" 2>&1'
|
27
|
+
expect(exitcode.exitstatus).to eq 0
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
@@ -1,23 +1,15 @@
|
|
1
|
-
require 'English'
|
2
1
|
require 'rspec/bash'
|
2
|
+
include Rspec::Bash
|
3
3
|
|
4
4
|
describe 'StubbedEnv' do
|
5
|
-
|
6
|
-
let(:
|
7
|
-
let!(:grep_mock) { stubbed_env.stub_command('grep') }
|
8
|
-
let!(:ls_mock) { stubbed_env.stub_command('ls') }
|
5
|
+
subject { create_stubbed_env }
|
6
|
+
let!(:grep_mock) { subject.stub_command('grep') }
|
9
7
|
|
10
8
|
context '#execute(<commands that are in stub wrapper>, ...)' do
|
11
9
|
it 'does not call the grep command' do
|
12
|
-
|
10
|
+
subject.execute_inline('exit 0')
|
13
11
|
|
14
12
|
expect(grep_mock).to_not be_called
|
15
13
|
end
|
16
|
-
|
17
|
-
it 'does not call the ls command' do
|
18
|
-
stubbed_env.execute_inline('exit 0')
|
19
|
-
|
20
|
-
expect(ls_mock).to_not be_called
|
21
|
-
end
|
22
14
|
end
|
23
15
|
end
|
@@ -0,0 +1,354 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Rspec::Bash
|
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
|
+
describe('StubbedEnv override tests') do
|
30
|
+
subject { create_stubbed_env }
|
31
|
+
let(:stubbed_env) { subject }
|
32
|
+
|
33
|
+
let!(:command) do
|
34
|
+
command = subject.stub_command('overridden_command')
|
35
|
+
command.outputs('i was overridden')
|
36
|
+
command.outputs('standard error output', to: :stderr)
|
37
|
+
command
|
38
|
+
end
|
39
|
+
let!(:function) do
|
40
|
+
function = subject.stub_command('overridden_function')
|
41
|
+
function.outputs('i was overridden')
|
42
|
+
function.outputs('standard error output', to: :stderr)
|
43
|
+
function
|
44
|
+
end
|
45
|
+
|
46
|
+
context '#execute_inline' do
|
47
|
+
context 'with a stubbed function' do
|
48
|
+
context 'and no arguments' do
|
49
|
+
execute_script(
|
50
|
+
<<-multiline_script
|
51
|
+
#!/usr/bin/env bash
|
52
|
+
function overridden_function {
|
53
|
+
echo 'i was not overridden'
|
54
|
+
}
|
55
|
+
overridden_function
|
56
|
+
|
57
|
+
echo 'standard error output' 1>&2
|
58
|
+
multiline_script
|
59
|
+
)
|
60
|
+
|
61
|
+
it 'calls the stubbed function' do
|
62
|
+
expect(function).to be_called
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'prints the overridden output' do
|
66
|
+
expect(stdout).to eql('i was overridden')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'prints provided stderr output to standard error' do
|
70
|
+
expect(stderr.chomp).to eql('standard error outputstandard error output')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'and simple arguments' do
|
75
|
+
execute_script(
|
76
|
+
<<-multiline_script
|
77
|
+
#!/usr/bin/env bash
|
78
|
+
function overridden_function {
|
79
|
+
echo 'i was not overridden'
|
80
|
+
}
|
81
|
+
overridden_function argument_one argument_two
|
82
|
+
|
83
|
+
echo 'standard error output' 1>&2
|
84
|
+
multiline_script
|
85
|
+
)
|
86
|
+
|
87
|
+
it 'calls the stubbed function' do
|
88
|
+
expect(function).to be_called_with_arguments('argument_one', 'argument_two')
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'prints the overridden output' do
|
92
|
+
expect(stdout).to eql('i was overridden')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'and complex arguments (spaces, etc.)' do
|
97
|
+
execute_script(
|
98
|
+
<<-multiline_script
|
99
|
+
#!/usr/bin/env bash
|
100
|
+
function overridden_function {
|
101
|
+
echo 'i was not overridden'
|
102
|
+
}
|
103
|
+
overridden_function "argument one" "argument two"
|
104
|
+
|
105
|
+
echo 'standard error output' 1>&2
|
106
|
+
multiline_script
|
107
|
+
)
|
108
|
+
|
109
|
+
it 'calls the stubbed function' do
|
110
|
+
expect(function).to be_called_with_arguments('argument one', 'argument two')
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'prints the overridden output' do
|
114
|
+
expect(stdout).to eql('i was overridden')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
context 'with a stubbed command' do
|
119
|
+
context 'and no arguments' do
|
120
|
+
execute_script(
|
121
|
+
<<-multiline_script
|
122
|
+
#!/usr/bin/env bash
|
123
|
+
overridden_command
|
124
|
+
multiline_script
|
125
|
+
)
|
126
|
+
|
127
|
+
it 'calls the stubbed command' do
|
128
|
+
expect(command).to be_called
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'prints the overridden output' do
|
132
|
+
expect(stdout).to eql('i was overridden')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'and simple arguments' do
|
137
|
+
execute_script(
|
138
|
+
<<-multiline_script
|
139
|
+
#!/usr/bin/env bash
|
140
|
+
overridden_command argument_one argument_two
|
141
|
+
multiline_script
|
142
|
+
)
|
143
|
+
|
144
|
+
it 'calls the stubbed command' do
|
145
|
+
expect(command).to be_called_with_arguments('argument_one', 'argument_two')
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'prints the overridden output' do
|
149
|
+
expect(stdout).to eql('i was overridden')
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'and complex arguments (spaces, etc.)' do
|
154
|
+
execute_script(
|
155
|
+
<<-multiline_script
|
156
|
+
#!/usr/bin/env bash
|
157
|
+
overridden_command "argument one" "argument two"
|
158
|
+
multiline_script
|
159
|
+
)
|
160
|
+
|
161
|
+
it 'calls the stubbed command' do
|
162
|
+
expect(command).to be_called_with_arguments('argument one', 'argument two')
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'prints the overridden output' do
|
166
|
+
expect(stdout).to eql('i was overridden')
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'and a path' do
|
171
|
+
context 'relative path' do
|
172
|
+
let!(:path_command) do
|
173
|
+
path_command = subject.stub_command('relative/path/to/overridden_path_command')
|
174
|
+
path_command.outputs('i was overridden in a path')
|
175
|
+
end
|
176
|
+
|
177
|
+
execute_script(
|
178
|
+
'relative/path/to/overridden_path_command'
|
179
|
+
)
|
180
|
+
|
181
|
+
it 'calls the relative path stubbed command' do
|
182
|
+
expect(path_command).to be_called
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'prints the relative path overridden output' do
|
186
|
+
expect(stdout).to eql('i was overridden in a path')
|
187
|
+
end
|
188
|
+
end
|
189
|
+
context 'absolute path' do
|
190
|
+
let!(:path_command) do
|
191
|
+
path_command = subject.stub_command('/absolute/path/to/overridden_path_command')
|
192
|
+
path_command.outputs('i was overridden in a path')
|
193
|
+
end
|
194
|
+
|
195
|
+
execute_script(
|
196
|
+
'/absolute/path/to/overridden_path_command'
|
197
|
+
)
|
198
|
+
|
199
|
+
it 'calls the stubbed command' do
|
200
|
+
expect(path_command).to be_called
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'prints the overridden output' do
|
204
|
+
expect(stdout).to eql('i was overridden in a path')
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context '#execute_function' do
|
212
|
+
context 'with a stubbed function' do
|
213
|
+
context 'and no arguments' do
|
214
|
+
execute_function(
|
215
|
+
'./spec/scripts/function_library.sh',
|
216
|
+
'overridden_function'
|
217
|
+
)
|
218
|
+
|
219
|
+
it 'calls the stubbed function' do
|
220
|
+
expect(function).to be_called
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'prints the overridden output' do
|
224
|
+
expect(stdout).to eql('i was overridden')
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'prints provided stderr output to standard error' do
|
228
|
+
expect(stderr).to eql("standard error output\n")
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context 'and simple arguments' do
|
233
|
+
execute_function(
|
234
|
+
'./spec/scripts/function_library.sh',
|
235
|
+
'overridden_function argument_one argument_two'
|
236
|
+
)
|
237
|
+
|
238
|
+
it 'calls the stubbed function' do
|
239
|
+
expect(function).to be_called_with_arguments('argument_one', 'argument_two')
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'prints the overridden output' do
|
243
|
+
expect(stdout).to eql('i was overridden')
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'and complex arguments (spaces, etc.)' do
|
248
|
+
execute_function(
|
249
|
+
'./spec/scripts/function_library.sh',
|
250
|
+
'overridden_function "argument one" "argument two"'
|
251
|
+
)
|
252
|
+
|
253
|
+
it 'calls the stubbed function' do
|
254
|
+
expect(function).to be_called_with_arguments('argument one', 'argument two')
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'prints the overridden output' do
|
258
|
+
expect(stdout).to eql('i was overridden')
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'and a path' do
|
263
|
+
context 'relative path' do
|
264
|
+
let!(:path_function) do
|
265
|
+
path_function = subject.stub_command('relative/path/to/overridden_path_functions')
|
266
|
+
path_function.outputs('i was overridden in a path')
|
267
|
+
end
|
268
|
+
|
269
|
+
execute_function(
|
270
|
+
'./spec/scripts/function_library.sh',
|
271
|
+
'relative/path/to/overridden_path_functions'
|
272
|
+
)
|
273
|
+
|
274
|
+
it 'calls the relative path stubbed function' do
|
275
|
+
expect(path_function).to be_called
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'prints the relative path overridden output' do
|
279
|
+
expect(stdout).to eql('i was overridden in a path')
|
280
|
+
end
|
281
|
+
end
|
282
|
+
context 'absolute path' do
|
283
|
+
let!(:path_function) do
|
284
|
+
path_function = subject.stub_command('/absolute/path/to/overridden_path_functions')
|
285
|
+
path_function.outputs('i was overridden in a path')
|
286
|
+
end
|
287
|
+
|
288
|
+
execute_function(
|
289
|
+
'./spec/scripts/function_library.sh',
|
290
|
+
'/absolute/path/to/overridden_path_functions'
|
291
|
+
)
|
292
|
+
|
293
|
+
it 'calls the stubbed function' do
|
294
|
+
expect(path_function).to be_called
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'prints the overridden output' do
|
298
|
+
expect(stdout).to eql('i was overridden in a path')
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
context 'with a stubbed command' do
|
304
|
+
context 'and no arguments' do
|
305
|
+
execute_function(
|
306
|
+
'./spec/scripts/function_library.sh',
|
307
|
+
'overridden_command_function'
|
308
|
+
)
|
309
|
+
|
310
|
+
it 'calls the stubbed command' do
|
311
|
+
expect(command).to be_called
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'prints the overridden output' do
|
315
|
+
expect(stdout).to eql('i was overridden')
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'prints provided stderr output to standard error' do
|
319
|
+
expect(stderr.chomp).to eql('standard error outputstandard error output')
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
context 'and simple arguments' do
|
324
|
+
execute_function(
|
325
|
+
'./spec/scripts/function_library.sh',
|
326
|
+
'overridden_command_function argument_one argument_two'
|
327
|
+
)
|
328
|
+
|
329
|
+
it 'calls the stubbed command' do
|
330
|
+
expect(command).to be_called_with_arguments('argument_one', 'argument_two')
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'prints the overridden output' do
|
334
|
+
expect(stdout).to eql('i was overridden')
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
context 'and complex arguments (spaces, etc.)' do
|
339
|
+
execute_function(
|
340
|
+
'./spec/scripts/function_library.sh',
|
341
|
+
'overridden_command_function "argument one" "argument two"'
|
342
|
+
)
|
343
|
+
|
344
|
+
it 'calls the stubbed command' do
|
345
|
+
expect(command).to be_called_with_arguments('argument one', 'argument two')
|
346
|
+
end
|
347
|
+
|
348
|
+
it 'prints the overridden output' do
|
349
|
+
expect(stdout).to eql('i was overridden')
|
350
|
+
end
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|