rspec-bash 0.0.3 → 0.1.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 +30 -0
- data/.travis.yml +1 -0
- data/Gemfile +4 -4
- data/README.md +87 -77
- data/Rakefile +1 -1
- data/bin/function_override_wrapper.sh.erb +6 -3
- data/bin/stub.rb.erb +56 -0
- data/lib/rspec/bash.rb +1 -0
- data/lib/rspec/bash/call_configuration.rb +39 -14
- data/lib/rspec/bash/call_log.rb +33 -43
- data/lib/rspec/bash/matchers/called_with_arguments.rb +7 -2
- data/lib/rspec/bash/stubbed_command.rb +22 -14
- data/lib/rspec/bash/stubbed_env.rb +15 -16
- data/lib/rspec/bash/util.rb +2 -0
- data/lib/rspec/bash/util/call_conf_argument_list_matcher.rb +47 -0
- data/lib/rspec/bash/util/call_log_argument_list_matcher.rb +33 -0
- data/return_exitstatus_spec.rb +14 -0
- data/rspec-bash.gemspec +2 -3
- data/spec/classes/call_configuration_spec.rb +296 -8
- data/spec/classes/call_log_spec.rb +168 -272
- data/spec/classes/stub_spec.rb +510 -0
- data/spec/classes/stubbed_command_spec.rb +26 -26
- data/spec/classes/stubbed_env_spec.rb +58 -64
- data/spec/classes/util/call_conf_argument_list_matcher_spec.rb +579 -0
- data/spec/classes/util/call_log_argument_list_matcher_spec.rb +211 -0
- data/spec/helper/shared_tmpdir.rb +6 -0
- data/spec/helper/string_file_io.rb +9 -0
- data/spec/integration/call_log/called_with_args_spec.rb +48 -0
- data/spec/integration/call_log/called_with_no_args_spec.rb +21 -0
- data/spec/integration/call_log/stdin_spec.rb +53 -0
- data/spec/integration/matchers/be_called_with_arguments_spec.rb +60 -0
- data/spec/integration/matchers/be_called_with_no_arguments_spec.rb +35 -0
- data/spec/integration/stubbed_command/outputs_spec.rb +262 -0
- data/spec/integration/stubbed_command/returns_exitstatus_spec.rb +99 -0
- data/spec/integration/stubbed_env/execute_with_env_vars_spec.rb +17 -0
- data/spec/integration/stubbed_env/execute_with_path_spec.rb +34 -0
- data/spec/integration/stubbed_env/execute_with_stub_wrapper_spec.rb +23 -0
- data/spec/spec_helper.rb +10 -0
- metadata +42 -24
- data/bin/stub +0 -62
- data/spec/integration/assert_called_spec.rb +0 -48
- data/spec/integration/assert_stdin_spec.rb +0 -39
- data/spec/integration/chain_args_spec.rb +0 -65
- data/spec/integration/change_exitstatus_spec.rb +0 -53
- data/spec/integration/provide_env_vars_spec.rb +0 -31
- data/spec/integration/replace_shell_commands_spec.rb +0 -48
- data/spec/integration/stub_output_spec.rb +0 -110
- data/spec/matchers/be_called_with_arguments_spec.rb +0 -55
- data/spec/matchers/be_called_with_no_arguments_spec.rb +0 -32
@@ -1,9 +1,9 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
include Rspec::Bash
|
3
3
|
|
4
4
|
describe 'StubbedCommand' do
|
5
|
-
|
6
|
-
|
5
|
+
include_examples 'manage a :temp_directory'
|
6
|
+
|
7
7
|
before(:each) do
|
8
8
|
allow(FileUtils).to receive(:cp)
|
9
9
|
end
|
@@ -12,11 +12,13 @@ describe 'StubbedCommand' do
|
|
12
12
|
before(:each) do
|
13
13
|
@call_log = double(Rspec::Bash::CallLog)
|
14
14
|
allow(Rspec::Bash::CallLog).to receive(:new).and_return(@call_log)
|
15
|
-
@subject = Rspec::Bash::StubbedCommand.new('command',
|
15
|
+
@subject = Rspec::Bash::StubbedCommand.new('command', temp_directory)
|
16
16
|
end
|
17
17
|
context 'with only a series of arguments' do
|
18
18
|
it 'passes the check to its CallLog\'s #called_with_args? method' do
|
19
|
-
expect(@call_log).to receive(:called_with_args?)
|
19
|
+
expect(@call_log).to receive(:called_with_args?)
|
20
|
+
.with('first_argument', 'second_argument')
|
21
|
+
.and_return(true)
|
20
22
|
@subject.called_with_args?('first_argument', 'second_argument')
|
21
23
|
end
|
22
24
|
end
|
@@ -24,7 +26,7 @@ describe 'StubbedCommand' do
|
|
24
26
|
|
25
27
|
context '#with_args' do
|
26
28
|
before(:each) do
|
27
|
-
@subject = Rspec::Bash::StubbedCommand.new('command',
|
29
|
+
@subject = Rspec::Bash::StubbedCommand.new('command', temp_directory)
|
28
30
|
@subject.with_args('argument_one', 'argument_two')
|
29
31
|
end
|
30
32
|
it 'sets the arguments array on the StubbedCommand to the arguments that were passed in' do
|
@@ -36,19 +38,22 @@ describe 'StubbedCommand' do
|
|
36
38
|
before(:each) do
|
37
39
|
@call_log = double(Rspec::Bash::CallLog)
|
38
40
|
allow(Rspec::Bash::CallLog).to receive(:new).and_return(@call_log)
|
39
|
-
@subject = Rspec::Bash::StubbedCommand.new('command',
|
41
|
+
@subject = Rspec::Bash::StubbedCommand.new('command', temp_directory)
|
40
42
|
end
|
41
43
|
it 'returns value returned from call_log argument count when there are no arguments' do
|
42
44
|
expect(@call_log).to receive(:call_count).with([]).and_return('arbitrary return value')
|
43
45
|
expect(@subject.call_count([])).to eql 'arbitrary return value'
|
44
46
|
end
|
45
47
|
it 'returns value returned from call_log argument count when there is only one argument' do
|
46
|
-
expect(@call_log).to receive(:call_count)
|
47
|
-
|
48
|
+
expect(@call_log).to receive(:call_count)
|
49
|
+
.with(['only arg'])
|
50
|
+
.and_return('arbitrary return value')
|
51
|
+
expect(@subject.call_count(['only arg'])).to eql 'arbitrary return value'
|
48
52
|
end
|
49
53
|
it 'returns value returned from call_log argument count when there are multiple arguments' do
|
50
|
-
expect(@call_log).to receive(:call_count).with(['first arg', 'second arg'])
|
51
|
-
|
54
|
+
expect(@call_log).to receive(:call_count).with(['first arg', 'second arg'])
|
55
|
+
.and_return('arbitrary return value')
|
56
|
+
expect(@subject.call_count(['first arg', 'second arg'])).to eql 'arbitrary return value'
|
52
57
|
end
|
53
58
|
end
|
54
59
|
|
@@ -56,7 +61,7 @@ describe 'StubbedCommand' do
|
|
56
61
|
before(:each) do
|
57
62
|
@call_log = double(Rspec::Bash::CallLog)
|
58
63
|
allow(Rspec::Bash::CallLog).to receive(:new).and_return(@call_log)
|
59
|
-
@subject = Rspec::Bash::StubbedCommand.new('command',
|
64
|
+
@subject = Rspec::Bash::StubbedCommand.new('command', temp_directory)
|
60
65
|
end
|
61
66
|
it 'returns false when there is no call_log' do
|
62
67
|
expect(@call_log).to receive(:exist?).and_return(false)
|
@@ -73,12 +78,12 @@ describe 'StubbedCommand' do
|
|
73
78
|
expect(@subject.called?).to be_truthy
|
74
79
|
end
|
75
80
|
end
|
76
|
-
|
81
|
+
|
77
82
|
context '#stdin' do
|
78
83
|
before(:each) do
|
79
84
|
@call_log = double(Rspec::Bash::CallLog)
|
80
85
|
allow(Rspec::Bash::CallLog).to receive(:new).and_return(@call_log)
|
81
|
-
@subject = Rspec::Bash::StubbedCommand.new('command',
|
86
|
+
@subject = Rspec::Bash::StubbedCommand.new('command', temp_directory)
|
82
87
|
end
|
83
88
|
it 'returns nil when there is no call_log' do
|
84
89
|
expect(@call_log).to receive(:exist?).and_return(false)
|
@@ -95,39 +100,34 @@ describe 'StubbedCommand' do
|
|
95
100
|
before(:each) do
|
96
101
|
@call_configuration = double(Rspec::Bash::CallConfiguration)
|
97
102
|
allow(Rspec::Bash::CallConfiguration).to receive(:new).and_return(@call_configuration)
|
98
|
-
@subject = Rspec::Bash::StubbedCommand.new('command',
|
103
|
+
@subject = Rspec::Bash::StubbedCommand.new('command', temp_directory)
|
99
104
|
end
|
100
105
|
it 'sets the exitcode on call_configuration' do
|
101
106
|
expect(@call_configuration).to receive(:set_exitcode).with('exit code', anything)
|
102
|
-
expect(@call_configuration).to receive(:write)
|
103
107
|
@subject.returns_exitstatus 'exit code'
|
104
108
|
end
|
105
109
|
it 'returns itself' do
|
106
110
|
expect(@call_configuration).to receive(:set_exitcode)
|
107
|
-
expect(@call_configuration).to receive(:write)
|
108
111
|
expect(@subject.returns_exitstatus(anything)).to eql @subject
|
109
112
|
end
|
110
113
|
end
|
111
|
-
|
114
|
+
|
112
115
|
context '#outputs' do
|
113
116
|
before(:each) do
|
114
117
|
@call_configuration = double(Rspec::Bash::CallConfiguration)
|
115
118
|
allow(Rspec::Bash::CallConfiguration).to receive(:new).and_return(@call_configuration)
|
116
|
-
@subject = Rspec::Bash::StubbedCommand.new('command',
|
119
|
+
@subject = Rspec::Bash::StubbedCommand.new('command', temp_directory)
|
117
120
|
end
|
118
121
|
it 'sets the output on the call_configuration' do
|
119
|
-
expect(@call_configuration).to receive(:
|
120
|
-
expect(@call_configuration).to receive(:write)
|
122
|
+
expect(@call_configuration).to receive(:add_output).with('contents', 'stderr', anything)
|
121
123
|
@subject.outputs('contents', to: 'stderr')
|
122
124
|
end
|
123
125
|
it 'sets the "to" value for the output to stdout by default' do
|
124
|
-
expect(@call_configuration).to receive(:
|
125
|
-
expect(@call_configuration).to receive(:write)
|
126
|
+
expect(@call_configuration).to receive(:add_output).with('contents', :stdout, anything)
|
126
127
|
@subject.outputs('contents')
|
127
128
|
end
|
128
129
|
it 'returns itself' do
|
129
|
-
expect(@call_configuration).to receive(:
|
130
|
-
expect(@call_configuration).to receive(:write)
|
130
|
+
expect(@call_configuration).to receive(:add_output)
|
131
131
|
expect(@subject.outputs(anything)).to eql @subject
|
132
132
|
end
|
133
133
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'rspec/bash'
|
1
|
+
require 'spec_helper'
|
3
2
|
|
4
3
|
describe 'StubbedEnv' do
|
5
4
|
include Rspec::Bash
|
@@ -15,15 +14,16 @@ describe 'StubbedEnv' do
|
|
15
14
|
|
16
15
|
context 'and no arguments' do
|
17
16
|
before(:each) do
|
18
|
-
@stdout, @stderr, @status = subject.execute_inline(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
@stdout, @stderr, @status = subject.execute_inline(
|
18
|
+
<<-multiline_script
|
19
|
+
#!/usr/bin/env bash
|
20
|
+
function overridden_function {
|
21
|
+
echo 'i was not overridden'
|
22
|
+
}
|
23
|
+
overridden_function
|
24
|
+
|
25
|
+
echo 'standard error output' 1>&2
|
26
|
+
multiline_script
|
27
27
|
)
|
28
28
|
end
|
29
29
|
|
@@ -42,15 +42,16 @@ describe 'StubbedEnv' do
|
|
42
42
|
|
43
43
|
context 'and simple arguments' do
|
44
44
|
before(:each) do
|
45
|
-
@stdout, @stderr, @status = subject.execute_inline(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
@stdout, @stderr, @status = subject.execute_inline(
|
46
|
+
<<-multiline_script
|
47
|
+
#!/usr/bin/env bash
|
48
|
+
function overridden_function {
|
49
|
+
echo 'i was not overridden'
|
50
|
+
}
|
51
|
+
overridden_function argument_one argument_two
|
52
|
+
|
53
|
+
echo 'standard error output' 1>&2
|
54
|
+
multiline_script
|
54
55
|
)
|
55
56
|
end
|
56
57
|
|
@@ -65,15 +66,16 @@ describe 'StubbedEnv' do
|
|
65
66
|
|
66
67
|
context 'and complex arguments (spaces, etc.)' do
|
67
68
|
before(:each) do
|
68
|
-
@stdout, @stderr, @status = subject.execute_inline(
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
69
|
+
@stdout, @stderr, @status = subject.execute_inline(
|
70
|
+
<<-multiline_script
|
71
|
+
#!/usr/bin/env bash
|
72
|
+
function overridden_function {
|
73
|
+
echo 'i was not overridden'
|
74
|
+
}
|
75
|
+
overridden_function "argument one" "argument two"
|
76
|
+
|
77
|
+
echo 'standard error output' 1>&2
|
78
|
+
multiline_script
|
77
79
|
)
|
78
80
|
end
|
79
81
|
|
@@ -95,10 +97,11 @@ describe 'StubbedEnv' do
|
|
95
97
|
|
96
98
|
context 'and no arguments' do
|
97
99
|
before(:each) do
|
98
|
-
@stdout, @stderr, @status = subject.execute_inline(
|
99
|
-
|
100
|
-
|
101
|
-
|
100
|
+
@stdout, @stderr, @status = subject.execute_inline(
|
101
|
+
<<-multiline_script
|
102
|
+
#!/usr/bin/env bash
|
103
|
+
overridden_command
|
104
|
+
multiline_script
|
102
105
|
)
|
103
106
|
end
|
104
107
|
|
@@ -113,10 +116,11 @@ describe 'StubbedEnv' do
|
|
113
116
|
|
114
117
|
context 'and simple arguments' do
|
115
118
|
before(:each) do
|
116
|
-
@stdout, @stderr, @status = subject.execute_inline(
|
117
|
-
|
118
|
-
|
119
|
-
|
119
|
+
@stdout, @stderr, @status = subject.execute_inline(
|
120
|
+
<<-multiline_script
|
121
|
+
#!/usr/bin/env bash
|
122
|
+
overridden_command argument_one argument_two
|
123
|
+
multiline_script
|
120
124
|
)
|
121
125
|
end
|
122
126
|
|
@@ -131,10 +135,11 @@ describe 'StubbedEnv' do
|
|
131
135
|
|
132
136
|
context 'and complex arguments (spaces, etc.)' do
|
133
137
|
before(:each) do
|
134
|
-
@stdout, @stderr, @status = subject.execute_inline(
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
+
@stdout, @stderr, @status = subject.execute_inline(
|
139
|
+
<<-multiline_script
|
140
|
+
#!/usr/bin/env bash
|
141
|
+
overridden_command "argument one" "argument two"
|
142
|
+
multiline_script
|
138
143
|
)
|
139
144
|
end
|
140
145
|
|
@@ -161,8 +166,8 @@ describe 'StubbedEnv' do
|
|
161
166
|
context 'and no arguments' do
|
162
167
|
before(:each) do
|
163
168
|
@stdout, @stderr, @status = subject.execute_function(
|
164
|
-
|
165
|
-
|
169
|
+
'./spec/scripts/function_library.sh',
|
170
|
+
'overridden_function'
|
166
171
|
)
|
167
172
|
end
|
168
173
|
|
@@ -182,8 +187,8 @@ describe 'StubbedEnv' do
|
|
182
187
|
context 'and simple arguments' do
|
183
188
|
before(:each) do
|
184
189
|
@stdout, @stderr, @status = subject.execute_function(
|
185
|
-
|
186
|
-
|
190
|
+
'./spec/scripts/function_library.sh',
|
191
|
+
'overridden_function argument_one argument_two'
|
187
192
|
)
|
188
193
|
end
|
189
194
|
|
@@ -199,8 +204,8 @@ describe 'StubbedEnv' do
|
|
199
204
|
context 'and complex arguments (spaces, etc.)' do
|
200
205
|
before(:each) do
|
201
206
|
@stdout, @stderr, @status = subject.execute_function(
|
202
|
-
|
203
|
-
|
207
|
+
'./spec/scripts/function_library.sh',
|
208
|
+
'overridden_function "argument one" "argument two"'
|
204
209
|
)
|
205
210
|
end
|
206
211
|
|
@@ -223,8 +228,8 @@ describe 'StubbedEnv' do
|
|
223
228
|
context 'and no arguments' do
|
224
229
|
before(:each) do
|
225
230
|
@stdout, @stderr, @status = subject.execute_function(
|
226
|
-
|
227
|
-
|
231
|
+
'./spec/scripts/function_library.sh',
|
232
|
+
'overridden_command_function'
|
228
233
|
)
|
229
234
|
end
|
230
235
|
|
@@ -244,8 +249,8 @@ describe 'StubbedEnv' do
|
|
244
249
|
context 'and simple arguments' do
|
245
250
|
before(:each) do
|
246
251
|
@stdout, @stderr, @status = subject.execute_function(
|
247
|
-
|
248
|
-
|
252
|
+
'./spec/scripts/function_library.sh',
|
253
|
+
'overridden_command_function argument_one argument_two'
|
249
254
|
)
|
250
255
|
end
|
251
256
|
|
@@ -261,8 +266,8 @@ describe 'StubbedEnv' do
|
|
261
266
|
context 'and complex arguments (spaces, etc.)' do
|
262
267
|
before(:each) do
|
263
268
|
@stdout, @stderr, @status = subject.execute_function(
|
264
|
-
|
265
|
-
|
269
|
+
'./spec/scripts/function_library.sh',
|
270
|
+
'overridden_command_function "argument one" "argument two"'
|
266
271
|
)
|
267
272
|
end
|
268
273
|
|
@@ -278,10 +283,6 @@ describe 'StubbedEnv' do
|
|
278
283
|
end
|
279
284
|
|
280
285
|
describe 'creating a stubbed env' do
|
281
|
-
it 'extends the PATH with the stubbed folder first' do
|
282
|
-
expect { create_stubbed_env }.to change { ENV['PATH'] }
|
283
|
-
end
|
284
|
-
|
285
286
|
it 'creates a folder to place the stubbed commands in' do
|
286
287
|
env = create_stubbed_env
|
287
288
|
expect(Pathname.new(env.dir)).to exist
|
@@ -290,13 +291,6 @@ describe 'StubbedEnv' do
|
|
290
291
|
end
|
291
292
|
|
292
293
|
describe '#cleanup' do
|
293
|
-
it 'restores the environment variable PATH' do
|
294
|
-
original_path = ENV['PATH']
|
295
|
-
env = create_stubbed_env
|
296
|
-
|
297
|
-
expect { env.cleanup }.to change { ENV['PATH'] }.to original_path
|
298
|
-
end
|
299
|
-
|
300
294
|
it 'removes the folder with stubbed commands' do
|
301
295
|
env = create_stubbed_env
|
302
296
|
env.cleanup
|
@@ -0,0 +1,579 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Rspec::Bash::Util
|
3
|
+
|
4
|
+
describe 'CallConfArgumentListMatcher' do
|
5
|
+
context '#get_best_call_conf' do
|
6
|
+
context 'given a call conf list with a with multiple sets of args, output and exitcodes' do
|
7
|
+
let(:call_conf_list) do
|
8
|
+
[
|
9
|
+
{
|
10
|
+
args: [],
|
11
|
+
exitcode: 6,
|
12
|
+
outputs: [
|
13
|
+
{
|
14
|
+
target: :stdout,
|
15
|
+
content: 'seventh_content'
|
16
|
+
}
|
17
|
+
]
|
18
|
+
},
|
19
|
+
{
|
20
|
+
args: %w(first_argument second_argument third_argument),
|
21
|
+
exitcode: 1,
|
22
|
+
outputs: [
|
23
|
+
{
|
24
|
+
target: :stdout,
|
25
|
+
content: 'second_content'
|
26
|
+
}
|
27
|
+
]
|
28
|
+
},
|
29
|
+
{
|
30
|
+
args: ['first_argument', anything, anything],
|
31
|
+
exitcode: 3,
|
32
|
+
outputs: [
|
33
|
+
{
|
34
|
+
target: :stdout,
|
35
|
+
content: 'fourth_content'
|
36
|
+
}
|
37
|
+
]
|
38
|
+
},
|
39
|
+
{
|
40
|
+
args: [anything, 'second_argument'],
|
41
|
+
exitcode: 4,
|
42
|
+
outputs: [
|
43
|
+
{
|
44
|
+
target: :stdout,
|
45
|
+
content: 'fifth_content'
|
46
|
+
}
|
47
|
+
]
|
48
|
+
},
|
49
|
+
{
|
50
|
+
args: %w(first_argument second_argument),
|
51
|
+
exitcode: 0,
|
52
|
+
outputs: [
|
53
|
+
{
|
54
|
+
target: :stdout,
|
55
|
+
content: 'first_content'
|
56
|
+
}
|
57
|
+
]
|
58
|
+
},
|
59
|
+
{
|
60
|
+
args: %w(first_argument second_argument),
|
61
|
+
exitcode: 2,
|
62
|
+
outputs: [
|
63
|
+
{
|
64
|
+
target: :stdout,
|
65
|
+
content: 'third_content'
|
66
|
+
}
|
67
|
+
]
|
68
|
+
},
|
69
|
+
{
|
70
|
+
args: [anything, anything, anything, anything],
|
71
|
+
exitcode: 5,
|
72
|
+
outputs: [
|
73
|
+
{
|
74
|
+
target: :stdout,
|
75
|
+
content: 'sixth_content'
|
76
|
+
}
|
77
|
+
]
|
78
|
+
},
|
79
|
+
{
|
80
|
+
args: [anything, anything, 'third_argument', anything, anything],
|
81
|
+
exitcode: 7,
|
82
|
+
outputs: [
|
83
|
+
{
|
84
|
+
target: :stdout,
|
85
|
+
content: 'eighth_content'
|
86
|
+
}
|
87
|
+
]
|
88
|
+
},
|
89
|
+
{
|
90
|
+
args: [anything, anything, anything, anything, anything],
|
91
|
+
exitcode: 8,
|
92
|
+
outputs: [
|
93
|
+
{
|
94
|
+
target: :stdout,
|
95
|
+
content: 'ninth_content'
|
96
|
+
}
|
97
|
+
]
|
98
|
+
},
|
99
|
+
{
|
100
|
+
args: [anything],
|
101
|
+
exitcode: 9,
|
102
|
+
outputs: [
|
103
|
+
{
|
104
|
+
target: :stdout,
|
105
|
+
content: 'tenth_content'
|
106
|
+
}
|
107
|
+
]
|
108
|
+
},
|
109
|
+
{
|
110
|
+
args: [anything],
|
111
|
+
exitcode: 10,
|
112
|
+
outputs: [
|
113
|
+
{
|
114
|
+
target: :stdout,
|
115
|
+
content: 'eleventh_content'
|
116
|
+
}
|
117
|
+
]
|
118
|
+
}
|
119
|
+
]
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'returns the longest conf match' do
|
123
|
+
argument_list_from_call = %w(first_argument second_argument third_argument)
|
124
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
125
|
+
call_conf_match = subject.get_best_call_conf(*argument_list_from_call)
|
126
|
+
expect(call_conf_match).to eql call_conf_list.at(2)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'returns the last longest conf match for multiple exact matches' do
|
130
|
+
argument_list_from_call = %w(first_argument second_argument)
|
131
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
132
|
+
call_conf_match = subject.get_best_call_conf(*argument_list_from_call)
|
133
|
+
expect(call_conf_match).to eql call_conf_list.at(5)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'returns the longest conf match for any_arg v. anything matches' do
|
137
|
+
argument_list_from_call = %w(first_argument second_argument third_argument fourth_argument)
|
138
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
139
|
+
call_conf_match = subject.get_best_call_conf(*argument_list_from_call)
|
140
|
+
expect(call_conf_match).to eql call_conf_list.at(6)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'returns the last longest conf match for matches with some anythings' do
|
144
|
+
argument_list_from_call = %w(
|
145
|
+
first_argument second_argument third_argument
|
146
|
+
fourth_argument fifth_argument
|
147
|
+
)
|
148
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
149
|
+
call_conf_match = subject.get_best_call_conf(*argument_list_from_call)
|
150
|
+
expect(call_conf_match).to eql call_conf_list.at(8)
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'returns the last anything match for multiple, all anything matches' do
|
154
|
+
argument_list_from_call = %w(first_argument)
|
155
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
156
|
+
call_conf_match = subject.get_best_call_conf(*argument_list_from_call)
|
157
|
+
expect(call_conf_match).to eql call_conf_list.at(10)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
context 'given a call conf list with a with no all matchers' do
|
161
|
+
let(:call_conf_list) do
|
162
|
+
[
|
163
|
+
{
|
164
|
+
args: %w(first_argument second_argument),
|
165
|
+
exitcode: 0,
|
166
|
+
outputs: [
|
167
|
+
{
|
168
|
+
target: :stdout,
|
169
|
+
content: 'first_content'
|
170
|
+
}
|
171
|
+
]
|
172
|
+
},
|
173
|
+
{
|
174
|
+
args: %w(first_argument second_argument third_argument),
|
175
|
+
exitcode: 1,
|
176
|
+
outputs: [
|
177
|
+
{
|
178
|
+
target: :stdout,
|
179
|
+
content: 'second_content'
|
180
|
+
}
|
181
|
+
]
|
182
|
+
},
|
183
|
+
{
|
184
|
+
args: %w(first_argument second_argument),
|
185
|
+
exitcode: 2,
|
186
|
+
outputs: [
|
187
|
+
{
|
188
|
+
target: :stdout,
|
189
|
+
content: 'third_content'
|
190
|
+
}
|
191
|
+
]
|
192
|
+
},
|
193
|
+
{
|
194
|
+
args: ['first_argument', anything, 'third_argument'],
|
195
|
+
exitcode: 3,
|
196
|
+
outputs: [
|
197
|
+
{
|
198
|
+
target: :stdout,
|
199
|
+
content: 'fourth_content'
|
200
|
+
}
|
201
|
+
]
|
202
|
+
},
|
203
|
+
{
|
204
|
+
args: [anything, 'second_argument'],
|
205
|
+
exitcode: 4,
|
206
|
+
outputs: [
|
207
|
+
{
|
208
|
+
target: :stdout,
|
209
|
+
content: 'fifth_content'
|
210
|
+
}
|
211
|
+
]
|
212
|
+
},
|
213
|
+
{
|
214
|
+
args: [anything, anything, anything, anything],
|
215
|
+
exitcode: 5,
|
216
|
+
outputs: [
|
217
|
+
{
|
218
|
+
target: :stdout,
|
219
|
+
content: 'sixth_content'
|
220
|
+
}
|
221
|
+
]
|
222
|
+
}
|
223
|
+
]
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'returns an empty conf for no matches' do
|
227
|
+
argument_list_from_call =
|
228
|
+
%w(first_argument second_argument third_argument fourth_argument fifth_argument)
|
229
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
230
|
+
call_conf_match = subject.get_best_call_conf(*argument_list_from_call)
|
231
|
+
expect(call_conf_match).to be_empty
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
context '#get_call_conf_matches' do
|
236
|
+
context 'given a call conf list with a with multiple sets of args, output and exitcodes' do
|
237
|
+
let(:call_conf_list) do
|
238
|
+
[
|
239
|
+
{
|
240
|
+
args: %w(first_argument second_argument),
|
241
|
+
exitcode: 0,
|
242
|
+
outputs: [
|
243
|
+
{
|
244
|
+
target: :stdout,
|
245
|
+
content: 'first_content'
|
246
|
+
}
|
247
|
+
]
|
248
|
+
},
|
249
|
+
{
|
250
|
+
args: %w(first_argument second_argument third_argument),
|
251
|
+
exitcode: 1,
|
252
|
+
outputs: [
|
253
|
+
{
|
254
|
+
target: :stdout,
|
255
|
+
content: 'second_content'
|
256
|
+
}
|
257
|
+
]
|
258
|
+
},
|
259
|
+
{
|
260
|
+
args: %w(first_argument second_argument),
|
261
|
+
exitcode: 2,
|
262
|
+
outputs: [
|
263
|
+
{
|
264
|
+
target: :stdout,
|
265
|
+
content: 'third_content'
|
266
|
+
}
|
267
|
+
]
|
268
|
+
},
|
269
|
+
{
|
270
|
+
args: ['first_argument', YAML.load(YAML.dump(anything)), 'third_argument'],
|
271
|
+
exitcode: 3,
|
272
|
+
outputs: [
|
273
|
+
{
|
274
|
+
target: :stdout,
|
275
|
+
content: 'fourth_content'
|
276
|
+
}
|
277
|
+
]
|
278
|
+
},
|
279
|
+
{
|
280
|
+
args: [anything, 'second_argument'],
|
281
|
+
exitcode: 4,
|
282
|
+
outputs: [
|
283
|
+
{
|
284
|
+
target: :stdout,
|
285
|
+
content: 'fifth_content'
|
286
|
+
}
|
287
|
+
]
|
288
|
+
},
|
289
|
+
{
|
290
|
+
args: [anything, anything, anything, anything],
|
291
|
+
exitcode: 5,
|
292
|
+
outputs: [
|
293
|
+
{
|
294
|
+
target: :stdout,
|
295
|
+
content: 'sixth_content'
|
296
|
+
}
|
297
|
+
]
|
298
|
+
},
|
299
|
+
{
|
300
|
+
args: [],
|
301
|
+
exitcode: 6,
|
302
|
+
outputs: [
|
303
|
+
{
|
304
|
+
target: :stdout,
|
305
|
+
content: 'seventh_content'
|
306
|
+
}
|
307
|
+
]
|
308
|
+
},
|
309
|
+
{
|
310
|
+
args: [
|
311
|
+
'first_argument', 'second_argument',
|
312
|
+
'third_argument', 'fourth_argument', any_args
|
313
|
+
],
|
314
|
+
exitcode: 6,
|
315
|
+
outputs: [
|
316
|
+
{
|
317
|
+
target: :stdout,
|
318
|
+
content: 'seventh_content'
|
319
|
+
}
|
320
|
+
]
|
321
|
+
},
|
322
|
+
{
|
323
|
+
args: [
|
324
|
+
'first_argument', 'second_argument',
|
325
|
+
'third_argument', 'fourth_argument', YAML.load(YAML.dump(any_args))
|
326
|
+
],
|
327
|
+
exitcode: 6,
|
328
|
+
outputs: [
|
329
|
+
{
|
330
|
+
target: :stdout,
|
331
|
+
content: 'seventh_content'
|
332
|
+
}
|
333
|
+
]
|
334
|
+
}
|
335
|
+
]
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'returns the correct confs for a single exact/anything argument match' do
|
339
|
+
argument_list_from_call = %w(first_argument second_argument third_argument)
|
340
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
341
|
+
call_conf_match_list = subject.get_call_conf_matches(*argument_list_from_call)
|
342
|
+
expect(call_conf_match_list).to eql call_conf_list.values_at(1, 3, 6)
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'returns the correct confs for multiple exact/anything argument matches' do
|
346
|
+
argument_list_from_call = %w(first_argument second_argument)
|
347
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
348
|
+
call_conf_match_list = subject.get_call_conf_matches(*argument_list_from_call)
|
349
|
+
expect(call_conf_match_list).to eql call_conf_list.values_at(0, 2, 4, 6)
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'returns the correct confs for the all argument match' do
|
353
|
+
argument_list_from_call = %w(first_argument)
|
354
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
355
|
+
call_conf_match_list = subject.get_call_conf_matches(*argument_list_from_call)
|
356
|
+
expect(call_conf_match_list).to eql call_conf_list.values_at(6)
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'returns the correct confs for an any_args match' do
|
360
|
+
argument_list_from_call = %w(
|
361
|
+
first_argument second_argument
|
362
|
+
third_argument fourth_argument fifth_argument
|
363
|
+
)
|
364
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
365
|
+
actual_args_match = subject.get_call_conf_matches(*argument_list_from_call)
|
366
|
+
expect(actual_args_match).to eql call_conf_list.values_at(6, 7, 8)
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
context '#args_match?' do
|
371
|
+
context 'given a call conf list with a with multiple sets of args, output and exitcodes' do
|
372
|
+
let(:call_conf_list) do
|
373
|
+
[
|
374
|
+
{
|
375
|
+
args: %w(first_argument second_argument),
|
376
|
+
exitcode: 0,
|
377
|
+
outputs: [
|
378
|
+
{
|
379
|
+
target: :stdout,
|
380
|
+
content: 'first_content'
|
381
|
+
}
|
382
|
+
]
|
383
|
+
},
|
384
|
+
{
|
385
|
+
args: %w(first_argument second_argument third_argument),
|
386
|
+
exitcode: 1,
|
387
|
+
outputs: [
|
388
|
+
{
|
389
|
+
target: :stdout,
|
390
|
+
content: 'second_content'
|
391
|
+
}
|
392
|
+
]
|
393
|
+
},
|
394
|
+
{
|
395
|
+
args: %w(first_argument second_argument),
|
396
|
+
exitcode: 2,
|
397
|
+
outputs: [
|
398
|
+
{
|
399
|
+
target: :stdout,
|
400
|
+
content: 'third_content'
|
401
|
+
}
|
402
|
+
]
|
403
|
+
},
|
404
|
+
{
|
405
|
+
args: ['first_argument', anything, 'third_argument'],
|
406
|
+
exitcode: 3,
|
407
|
+
outputs: [
|
408
|
+
{
|
409
|
+
target: :stdout,
|
410
|
+
content: 'fourth_content'
|
411
|
+
}
|
412
|
+
]
|
413
|
+
},
|
414
|
+
{
|
415
|
+
args: [anything, 'second_argument'],
|
416
|
+
exitcode: 4,
|
417
|
+
outputs: [
|
418
|
+
{
|
419
|
+
target: :stdout,
|
420
|
+
content: 'fifth_content'
|
421
|
+
}
|
422
|
+
]
|
423
|
+
},
|
424
|
+
{
|
425
|
+
args: [anything, anything, anything, anything],
|
426
|
+
exitcode: 5,
|
427
|
+
outputs: [
|
428
|
+
{
|
429
|
+
target: :stdout,
|
430
|
+
content: 'sixth_content'
|
431
|
+
}
|
432
|
+
]
|
433
|
+
},
|
434
|
+
{
|
435
|
+
args: [],
|
436
|
+
exitcode: 7,
|
437
|
+
outputs: [
|
438
|
+
{
|
439
|
+
target: :stdout,
|
440
|
+
content: 'eighth_content'
|
441
|
+
}
|
442
|
+
]
|
443
|
+
}
|
444
|
+
]
|
445
|
+
end
|
446
|
+
|
447
|
+
it 'returns the correct confs for a single exact/anything argument match' do
|
448
|
+
argument_list_from_call = %w(first_argument second_argument third_argument)
|
449
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
450
|
+
actual_args_match = subject.args_match?(*argument_list_from_call)
|
451
|
+
expect(actual_args_match).to be true
|
452
|
+
end
|
453
|
+
|
454
|
+
it 'returns the correct confs for multiple exact/anything argument matches' do
|
455
|
+
argument_list_from_call = %w(first_argument second_argument)
|
456
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
457
|
+
actual_args_match = subject.args_match?(*argument_list_from_call)
|
458
|
+
expect(actual_args_match).to be true
|
459
|
+
end
|
460
|
+
|
461
|
+
it 'returns the correct confs for the all argument match' do
|
462
|
+
argument_list_from_call = %w(first_argument)
|
463
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
464
|
+
actual_args_match = subject.args_match?(*argument_list_from_call)
|
465
|
+
expect(actual_args_match).to be true
|
466
|
+
end
|
467
|
+
end
|
468
|
+
context 'given a call conf list with a with no all matchers' do
|
469
|
+
let(:call_conf_list) do
|
470
|
+
[
|
471
|
+
{
|
472
|
+
args: %w(first_argument second_argument),
|
473
|
+
exitcode: 0,
|
474
|
+
outputs: [
|
475
|
+
{
|
476
|
+
target: :stdout,
|
477
|
+
content: 'first_content'
|
478
|
+
}
|
479
|
+
]
|
480
|
+
},
|
481
|
+
{
|
482
|
+
args: %w(first_argument second_argument third_argument),
|
483
|
+
exitcode: 1,
|
484
|
+
outputs: [
|
485
|
+
{
|
486
|
+
target: :stdout,
|
487
|
+
content: 'second_content'
|
488
|
+
}
|
489
|
+
]
|
490
|
+
},
|
491
|
+
{
|
492
|
+
args: %w(first_argument second_argument),
|
493
|
+
exitcode: 2,
|
494
|
+
outputs: [
|
495
|
+
{
|
496
|
+
target: :stdout,
|
497
|
+
content: 'third_content'
|
498
|
+
}
|
499
|
+
]
|
500
|
+
},
|
501
|
+
{
|
502
|
+
args: ['first_argument', anything, 'third_argument'],
|
503
|
+
exitcode: 3,
|
504
|
+
outputs: [
|
505
|
+
{
|
506
|
+
target: :stdout,
|
507
|
+
content: 'fourth_content'
|
508
|
+
}
|
509
|
+
]
|
510
|
+
},
|
511
|
+
{
|
512
|
+
args: [anything, 'second_argument'],
|
513
|
+
exitcode: 4,
|
514
|
+
outputs: [
|
515
|
+
{
|
516
|
+
target: :stdout,
|
517
|
+
content: 'fifth_content'
|
518
|
+
}
|
519
|
+
]
|
520
|
+
},
|
521
|
+
{
|
522
|
+
args: [anything, anything, anything, anything],
|
523
|
+
exitcode: 5,
|
524
|
+
outputs: [
|
525
|
+
{
|
526
|
+
target: :stdout,
|
527
|
+
content: 'sixth_content'
|
528
|
+
}
|
529
|
+
]
|
530
|
+
},
|
531
|
+
{
|
532
|
+
args: [
|
533
|
+
'first_argument', 'second_argument',
|
534
|
+
'third_argument', 'fourth_argument', any_args
|
535
|
+
],
|
536
|
+
exitcode: 6,
|
537
|
+
outputs: [
|
538
|
+
{
|
539
|
+
target: :stdout,
|
540
|
+
content: 'seventh_content'
|
541
|
+
}
|
542
|
+
]
|
543
|
+
}
|
544
|
+
]
|
545
|
+
end
|
546
|
+
|
547
|
+
it 'returns the correct confs for a single exact/anything argument match' do
|
548
|
+
argument_list_from_call = %w(first_argument second_argument third_argument)
|
549
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
550
|
+
actual_args_match = subject.args_match?(*argument_list_from_call)
|
551
|
+
expect(actual_args_match).to be true
|
552
|
+
end
|
553
|
+
|
554
|
+
it 'returns the correct confs for multiple exact/anything argument matches' do
|
555
|
+
argument_list_from_call = %w(first_argument second_argument)
|
556
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
557
|
+
actual_args_match = subject.args_match?(*argument_list_from_call)
|
558
|
+
expect(actual_args_match).to be true
|
559
|
+
end
|
560
|
+
|
561
|
+
it 'returns the correct confs for the all argument match' do
|
562
|
+
argument_list_from_call = %w(first_argument)
|
563
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
564
|
+
actual_args_match = subject.args_match?(*argument_list_from_call)
|
565
|
+
expect(actual_args_match).to be false
|
566
|
+
end
|
567
|
+
|
568
|
+
it 'returns the correct confs for an any_args match' do
|
569
|
+
argument_list_from_call = %w(
|
570
|
+
first_argument second_argument
|
571
|
+
third_argument fourth_argument fifth_argument
|
572
|
+
)
|
573
|
+
subject = CallConfArgumentListMatcher.new(call_conf_list)
|
574
|
+
actual_args_match = subject.args_match?(*argument_list_from_call)
|
575
|
+
expect(actual_args_match).to be true
|
576
|
+
end
|
577
|
+
end
|
578
|
+
end
|
579
|
+
end
|