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,309 +1,205 @@
|
|
1
|
-
require '
|
2
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
include Rspec::Bash
|
3
|
+
include Rspec::Bash::Util
|
3
4
|
|
4
5
|
describe 'CallLog' do
|
5
6
|
let(:stubbed_env) { create_stubbed_env }
|
6
|
-
|
7
|
+
let(:mock_log_file) { StringFileIO.new }
|
8
|
+
let(:mock_log_pathname) { instance_double(Pathname) }
|
9
|
+
let(:mock_call_log_matcher) { instance_double(CallLogArgumentListMatcher) }
|
10
|
+
before(:each) do
|
11
|
+
allow(mock_call_log_matcher).to receive(:get_call_log_matches).and_return(
|
12
|
+
[
|
13
|
+
{
|
14
|
+
args: %w(first_argument second_argument),
|
15
|
+
stdin: 'first_stdin'
|
16
|
+
},
|
17
|
+
{
|
18
|
+
args: %w(first_argument second_argument),
|
19
|
+
stdin: 'second_stdin'
|
20
|
+
},
|
21
|
+
{
|
22
|
+
args: %w(first_argument second_argument),
|
23
|
+
stdin: 'third_stdin'
|
24
|
+
}
|
25
|
+
]
|
26
|
+
)
|
27
|
+
allow(mock_call_log_matcher).to receive(:get_call_count).and_return(3)
|
28
|
+
allow(mock_call_log_matcher).to receive(:args_match?).and_return(true)
|
29
|
+
allow(CallLogArgumentListMatcher).to receive(:new).with(any_args)
|
30
|
+
.and_return(mock_call_log_matcher)
|
31
|
+
allow(mock_log_pathname).to receive(:open).with('r').and_yield(mock_log_file)
|
32
|
+
allow(mock_log_pathname).to receive(:open).with('w').and_yield(mock_log_file)
|
33
|
+
end
|
7
34
|
|
8
|
-
|
9
|
-
it 'returns nil when no YAML file is used for call log' do
|
10
|
-
@subject = Rspec::Bash::CallLog.new(anything)
|
11
|
-
allow(YAML).to receive(:load_file).and_return([])
|
35
|
+
subject { CallLog.new(mock_log_pathname) }
|
12
36
|
|
13
|
-
|
37
|
+
context '#stdin_for_args' do
|
38
|
+
it 'returns the first matching stdin via the specialized matcher' do
|
39
|
+
expect(mock_call_log_matcher).to receive(:get_call_log_matches)
|
40
|
+
.with(any_args)
|
41
|
+
expect(subject.stdin_for_args('first_argument', 'second_argument')).to eql 'first_stdin'
|
14
42
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@subject = Rspec::Bash::CallLog.new(anything)
|
22
|
-
allow(YAML).to receive(:load_file).and_return(actual_call_log_list)
|
23
|
-
|
24
|
-
expect(@subject.stdin_for_args('arbitrary argument').first).to eql 'correct value'
|
43
|
+
end
|
44
|
+
context '#call_count?' do
|
45
|
+
it 'returns the expected call count via the specialized matcher' do
|
46
|
+
expect(mock_call_log_matcher).to receive(:get_call_count)
|
47
|
+
.with(any_args)
|
48
|
+
expect(subject.call_count('first_argument', 'second_argument')).to eql 3
|
25
49
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@subject = Rspec::Bash::CallLog.new(anything)
|
33
|
-
allow(YAML).to receive(:load_file).and_return(actual_call_log_list)
|
34
|
-
|
35
|
-
expect(@subject.stdin_for_args('arbitrary argument').sort).to eql ['first value', 'second value'].sort
|
50
|
+
end
|
51
|
+
context '#called_with_args' do
|
52
|
+
it 'returns the expected value via the specialized matcher' do
|
53
|
+
expect(mock_call_log_matcher).to receive(:args_match?)
|
54
|
+
.with(any_args)
|
55
|
+
expect(subject.called_with_args?('first_argument', 'second_argument')).to eql true
|
36
56
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
}]
|
43
|
-
@subject = Rspec::Bash::CallLog.new(anything)
|
44
|
-
allow(YAML).to receive(:load_file).and_return(actual_call_log_list)
|
57
|
+
end
|
58
|
+
context '#called_with_no_args?' do
|
59
|
+
it 'returns false if no call log is found' do
|
60
|
+
@subject = Rspec::Bash::CallLog.new(mock_log_pathname)
|
61
|
+
@subject.call_log = []
|
45
62
|
|
46
|
-
expect(@subject.
|
63
|
+
expect(@subject.called_with_no_args?).to be_falsey
|
64
|
+
end
|
65
|
+
it 'returns true if no arguments are in call log' do
|
66
|
+
actual_call_log = [{
|
67
|
+
args: nil,
|
68
|
+
stdin: []
|
69
|
+
}]
|
70
|
+
@subject = Rspec::Bash::CallLog.new(mock_log_pathname)
|
71
|
+
@subject.call_log = actual_call_log
|
72
|
+
|
73
|
+
expect(@subject.called_with_no_args?).to be_truthy
|
74
|
+
end
|
75
|
+
it 'returns fails if a single argument is in call log' do
|
76
|
+
actual_call_log = [{
|
77
|
+
args: ['I am an argument'],
|
78
|
+
stdin: []
|
79
|
+
}]
|
80
|
+
@subject = Rspec::Bash::CallLog.new(mock_log_pathname)
|
81
|
+
@subject.call_log = actual_call_log
|
82
|
+
|
83
|
+
expect(@subject.called_with_no_args?).to be_falsey
|
84
|
+
end
|
85
|
+
it 'returns fails if multiple arguments is in call log' do
|
86
|
+
actual_call_log = [{
|
87
|
+
args: ['I am an argument', 'as am I'],
|
88
|
+
stdin: []
|
89
|
+
}]
|
90
|
+
@subject = Rspec::Bash::CallLog.new(mock_log_pathname)
|
91
|
+
@subject.call_log = actual_call_log
|
92
|
+
|
93
|
+
expect(@subject.called_with_no_args?).to be_falsey
|
47
94
|
end
|
48
95
|
end
|
49
96
|
|
50
|
-
context '#
|
51
|
-
context 'with
|
52
|
-
|
53
|
-
@subject = Rspec::Bash::CallLog.new('command_with_no_call_log_file')
|
54
|
-
allow(YAML).to receive(:load_file).and_raise(Errno::ENOENT)
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'does not find an un-passed argument anywhere in the series' do
|
58
|
-
expect(@subject.call_count('not_an_argument')).to eql 0
|
59
|
-
end
|
60
|
-
end
|
61
|
-
context 'with only an series of arguments provided' do
|
62
|
-
context 'and a command log with only one argument' do
|
63
|
-
before(:each) do
|
64
|
-
actual_call_log_list =
|
65
|
-
[{
|
66
|
-
'args' => ['first_argument'],
|
67
|
-
'stdin' => [],
|
68
|
-
}]
|
69
|
-
@subject = Rspec::Bash::CallLog.new('command_with_one_argument_log')
|
70
|
-
allow(@subject).to receive(:load_call_log_list).and_return(actual_call_log_list)
|
71
|
-
end
|
97
|
+
context '#add_log' do
|
98
|
+
context 'with any setup' do
|
99
|
+
subject { Rspec::Bash::CallLog.new(mock_log_pathname) }
|
72
100
|
|
73
|
-
|
74
|
-
|
101
|
+
context 'with no existing configuration' do
|
102
|
+
let(:expected_log) do
|
103
|
+
[
|
104
|
+
{
|
105
|
+
args: %w(first_argument second_argument),
|
106
|
+
stdin: 'first_stdin'
|
107
|
+
}
|
108
|
+
]
|
75
109
|
end
|
76
|
-
|
77
|
-
|
78
|
-
expect(
|
110
|
+
it 'adds a call log for the arguments passed in' do
|
111
|
+
subject.add_log('first_stdin', %w(first_argument second_argument))
|
112
|
+
expect(subject.call_log).to eql expected_log
|
79
113
|
end
|
80
114
|
|
81
|
-
it '
|
82
|
-
expect(
|
115
|
+
it 'writes that log to its log file' do
|
116
|
+
expect(mock_log_file).to receive(:write).with(expected_log.to_yaml)
|
117
|
+
subject.add_log('first_stdin', %w(first_argument second_argument))
|
83
118
|
end
|
84
119
|
end
|
85
|
-
context '
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
expect(@subject.call_count('first_argument')).to eql 0
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'finds the first argument anywhere in the series exactly once' do
|
101
|
-
expect(@subject.call_count('first_argument', anything)).to eql 1
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'does not find the second argument when first argument is not provided' do
|
105
|
-
expect(@subject.call_count('second_argument')).to eql 0
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'finds the second argument anywhere in the series exactly once' do
|
109
|
-
expect(@subject.call_count(anything, 'second_argument')).to eql 1
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'finds two contiguous arguments in the series exactly once' do
|
113
|
-
expect(@subject.call_count('first_argument', 'second_argument')).to eql 1
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'does not find an un-passed argument anywhere in the series' do
|
117
|
-
expect(@subject.call_count('not_an_argument')).to eql 0
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'does not find a wildcard argument when other argument is not provided' do
|
121
|
-
expect(@subject.call_count(anything)).to eql 0
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'finds when both arguments are wildcards exactly once' do
|
125
|
-
expect(@subject.call_count(anything, anything)).to eql 1
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'finds when only the first argument is a wildcard exactly once' do
|
129
|
-
expect(@subject.call_count(anything, 'second_argument')).to eql 1
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'finds when only the second argument is a wildcard exactly once' do
|
133
|
-
expect(@subject.call_count('first_argument', anything)).to eql 1
|
120
|
+
context 'with an existing log' do
|
121
|
+
let(:expected_log) do
|
122
|
+
[
|
123
|
+
{
|
124
|
+
args: %w(first_argument second_argument),
|
125
|
+
stdin: 'first_stdin'
|
126
|
+
},
|
127
|
+
{
|
128
|
+
args: %w(first_argument),
|
129
|
+
stdin: 'second_stdin'
|
130
|
+
}
|
131
|
+
]
|
134
132
|
end
|
135
|
-
|
136
|
-
it 'does not find when wildcard is in wrong position' do
|
137
|
-
expect(@subject.call_count('first_argument', anything, 'second_argument')).to eql 0
|
138
|
-
end
|
139
|
-
end
|
140
|
-
context 'and a command called with three arguments' do
|
141
133
|
before(:each) do
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
allow(@subject).to receive(:load_call_log_list).and_return(actual_call_log_list)
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'does not find first argument when other arguments are not provided' do
|
152
|
-
expect(@subject.call_count('first_argument')).to eql 0
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'finds the first argument anywhere in the series exactly once' do
|
156
|
-
expect(@subject.call_count('first_argument', anything, anything)).to eql 1
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'does not find second argument when other arguments are not provided' do
|
160
|
-
expect(@subject.call_count('second_argument')).to eql 0
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'finds the second argument anywhere in the series exactly once' do
|
164
|
-
expect(@subject.call_count(anything, 'second_argument', anything)).to eql 1
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'does not find third argument when other arguments are not provided' do
|
168
|
-
expect(@subject.call_count('third_argument')).to eql 0
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'finds the third argument anywhere in the series exactly once' do
|
172
|
-
expect(@subject.call_count(anything, anything, 'third_argument')).to eql 1
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'finds three contiguous arguments in the series exactly once' do
|
176
|
-
expect(@subject.call_count('first_argument', 'second_argument', 'third_argument')).to eql 1
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'does not find two non-contiguous arguments in the series exactly once' do
|
180
|
-
expect(@subject.call_count('first_argument', 'third_argument')).to eql 0
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'does not find an un-passed argument anywhere in the series' do
|
184
|
-
expect(@subject.call_count('not_an_argument')).to eql 0
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'finds when only the first argument is a wildcard' do
|
188
|
-
expect(@subject.call_count(anything, 'second_argument', 'third_argument')).to eql 1
|
134
|
+
subject.call_log = [
|
135
|
+
{
|
136
|
+
args: %w(first_argument second_argument),
|
137
|
+
stdin: 'first_stdin'
|
138
|
+
}
|
139
|
+
]
|
189
140
|
end
|
190
|
-
|
191
|
-
|
192
|
-
expect(
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'finds when only the third argument is a wildcard' do
|
196
|
-
expect(@subject.call_count('first_argument', 'second_argument', anything)).to eql 1
|
197
|
-
end
|
198
|
-
|
199
|
-
it 'finds when both the first and second arguments are wildcards' do
|
200
|
-
expect(@subject.call_count(anything, anything, 'third_argument')).to eql 1
|
201
|
-
end
|
202
|
-
|
203
|
-
it 'finds when both the first and third arguments are wildcards' do
|
204
|
-
expect(@subject.call_count(anything, 'second_argument', anything)).to eql 1
|
141
|
+
it 'adds a call log for the arguments passed in' do
|
142
|
+
subject.add_log('second_stdin', %w(first_argument))
|
143
|
+
expect(subject.call_log).to eql expected_log
|
205
144
|
end
|
206
145
|
|
207
|
-
it '
|
208
|
-
expect(
|
209
|
-
|
210
|
-
|
211
|
-
it 'does not find when wildcard is in wrong position' do
|
212
|
-
expect(@subject.call_count('first_argument', anything, 'second_argument', 'third_argument')).to eql 0
|
146
|
+
it 'writes that log to its log file' do
|
147
|
+
expect(mock_log_file).to receive(:write).with(expected_log.to_yaml)
|
148
|
+
subject.add_log('second_stdin', %w(first_argument))
|
213
149
|
end
|
214
150
|
end
|
215
|
-
context 'with an argument called multiple times' do
|
216
|
-
before(:each) do
|
217
|
-
actual_call_log_list =
|
218
|
-
[{
|
219
|
-
'args' => ['twice_called_arg'],
|
220
|
-
'stdin' => []
|
221
|
-
},
|
222
|
-
{
|
223
|
-
'args' => ['twice_called_arg'],
|
224
|
-
'stdin' => []
|
225
|
-
}]
|
226
|
-
@subject = Rspec::Bash::CallLog.new(anything)
|
227
|
-
allow(@subject).to receive(:load_call_log_list).and_return(actual_call_log_list)
|
228
|
-
end
|
229
|
-
it 'returns 2 when argument is called 2 times' do
|
230
|
-
expect(@subject.call_count('twice_called_arg')).to eql 2
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
context '#called_with_args' do
|
237
|
-
before(:each) do
|
238
|
-
actual_call_log_list =
|
239
|
-
[{
|
240
|
-
'args' => ['once_called_arg'],
|
241
|
-
'stdin' => []
|
242
|
-
},
|
243
|
-
{
|
244
|
-
'args' => ['twice_called_arg'],
|
245
|
-
'stdin' => []
|
246
|
-
},
|
247
|
-
{
|
248
|
-
'args' => ['twice_called_arg'],
|
249
|
-
'stdin' => []
|
250
|
-
}]
|
251
|
-
@subject = Rspec::Bash::CallLog.new(anything)
|
252
|
-
allow(@subject).to receive(:load_call_log_list).and_return(actual_call_log_list)
|
253
|
-
end
|
254
|
-
|
255
|
-
it 'returns false when there are no matching args' do
|
256
|
-
expect(@subject.called_with_args?('no-match')).to be_falsey
|
257
|
-
end
|
258
|
-
|
259
|
-
it 'returns true when there is a single matching arg' do
|
260
|
-
expect(@subject.called_with_args?('once_called_arg', anything)).to be_truthy
|
261
151
|
end
|
262
|
-
|
263
|
-
|
264
|
-
|
152
|
+
context 'with no config_path' do
|
153
|
+
subject { Rspec::Bash::CallConfiguration.new(nil, anything) }
|
154
|
+
it 'raises an error' do
|
155
|
+
expect do
|
156
|
+
subject.add_output('new_content', :stderr, %w(first_argument second_argument))
|
157
|
+
end.to raise_exception(NoMethodError)
|
158
|
+
end
|
265
159
|
end
|
266
160
|
end
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
expect(@subject.called_with_no_args?).to be_falsey
|
161
|
+
context '#call_log' do
|
162
|
+
context 'when there is no call_log_path' do
|
163
|
+
subject { Rspec::Bash::CallLog.new(nil) }
|
164
|
+
it 'returns an empty array' do
|
165
|
+
expect(subject.call_log).to eql []
|
166
|
+
end
|
274
167
|
end
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
expect(@subject.called_with_no_args?).to be_truthy
|
168
|
+
context 'when the call log exists but is empty' do
|
169
|
+
subject { Rspec::Bash::CallLog.new(mock_log_pathname) }
|
170
|
+
before(:each) do
|
171
|
+
allow(mock_log_file).to receive(:read).and_return('')
|
172
|
+
end
|
173
|
+
it 'returns an empty array' do
|
174
|
+
expect(subject.call_log).to eql []
|
175
|
+
end
|
285
176
|
end
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
expect(@subject.called_with_no_args?).to be_falsey
|
177
|
+
context 'when the call log file open throws a file not found exception' do
|
178
|
+
subject { Rspec::Bash::CallLog.new(mock_log_pathname) }
|
179
|
+
before(:each) do
|
180
|
+
allow(mock_log_pathname).to receive(:open).with('r').and_raise(Errno::ENOENT)
|
181
|
+
end
|
182
|
+
it 'returns an empty array' do
|
183
|
+
expect(subject.call_log).to eql []
|
184
|
+
end
|
296
185
|
end
|
297
|
-
|
298
|
-
|
186
|
+
context 'when setup is valid' do
|
187
|
+
subject { Rspec::Bash::CallLog.new(mock_log_pathname) }
|
188
|
+
let(:log) do
|
299
189
|
[{
|
300
|
-
|
301
|
-
|
190
|
+
args: %w(first_argument second_argument),
|
191
|
+
stdin: 'first_stdin'
|
302
192
|
}]
|
303
|
-
|
304
|
-
|
193
|
+
end
|
194
|
+
context 'and a call log exists' do
|
195
|
+
before(:each) do
|
196
|
+
allow(mock_log_file).to receive(:read).and_return(log.to_yaml)
|
197
|
+
end
|
305
198
|
|
306
|
-
|
199
|
+
it 'reads out what was in its configuration file' do
|
200
|
+
expect(subject.call_log).to eql log
|
201
|
+
end
|
202
|
+
end
|
307
203
|
end
|
308
204
|
end
|
309
205
|
end
|