Skip to content

Commit 784f127

Browse files
committedAug 18, 2024·
Make test case stricter
1 parent 1346215 commit 784f127

14 files changed

+97
-52
lines changed
 

‎spec/binary_file_match_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
context 'when input is from stdin' do
55
let(:input) { content }
66
let(:args) { '_' }
7-
let(:expect_output) { 'Binary file matches.' }
7+
let(:expect_output) { "Binary file matches.\n" }
88

99
it_behaves_like 'a successful exec'
1010
end
1111

1212
context 'when input is from file' do
1313
let(:file) { 'binary_file' }
1414
let(:args) { "_ #{file}" }
15-
let(:expect_output) { 'Binary file matches.' }
15+
let(:expect_output) { "Binary file matches.\n" }
1616

1717
before do
1818
write_file(file, content)
@@ -24,7 +24,7 @@
2424
describe 'non-binary file' do
2525
let(:input) { "hello\tworld\n" }
2626
let(:args) { '_' }
27-
let(:expect_output) { "hello\tworld" }
27+
let(:expect_output) { "hello\tworld\n" }
2828

2929
it_behaves_like 'a successful exec'
3030
end

‎spec/container/instance_methods_spec.rb

+46-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe 'Container internal methods' do
22
using RSpec::Parameterized::TableSyntax
33

4-
where(:method, :expect_output) do
4+
where(:method, :output) do
55
'gsub' | %w[barbar foofoo].join("\n")
66
'gsub!' | %w[barbar barbar].join("\n")
77
'sub' | %w[barfoo foofoo].join("\n")
@@ -11,23 +11,25 @@
1111
with_them do
1212
let(:input) { 'foofoo' }
1313
let(:args) { %('puts #{method}(/foo/, "bar"); _') }
14+
let(:expect_output) { "#{output}\n" }
1415

1516
it_behaves_like 'a successful exec'
1617
end
1718

18-
where(:method, :expect_output) do
19+
where(:method, :output) do
1920
'tr' | %w[FOOFOO foofoo].join("\n")
2021
'tr!' | %w[FOOFOO FOOFOO].join("\n")
2122
end
2223

2324
with_them do
2425
let(:input) { 'foofoo' }
2526
let(:args) { %('puts #{method}("a-z", "A-Z"); _') }
27+
let(:expect_output) { "#{output}\n" }
2628

2729
it_behaves_like 'a successful exec'
2830
end
2931

30-
where(:command, :expect_output) do
32+
where(:command, :output) do
3133
'grep(/foo/)' | 'foo'
3234
'grep_v(/bar/)' | 'foo baz'
3335
'grep(/foo/){|i| i + "hoge" }' | 'foohoge'
@@ -37,6 +39,7 @@
3739
with_them do
3840
let(:input) { %w[foo bar baz].join("\n") }
3941
let(:args) { %(-s '#{command}') }
42+
let(:expect_output) { "#{output}\n" }
4043

4144
it_behaves_like 'a successful exec'
4245
end
@@ -48,8 +51,8 @@
4851
'String' => {
4952
condition: '"2 foo baz"',
5053
output: {
51-
without_block: '2 foo baz',
52-
with_block: '2'
54+
without_block: "2 foo baz\n",
55+
with_block: "2\n"
5356
}
5457
},
5558
'Regexp' => {
@@ -60,14 +63,14 @@
6063
2 foo baz
6164
3 foo qux
6265
OUTPUT
63-
with_block: %w[1 2 3].join("\n")
66+
with_block: "1\n2\n3\n"
6467
}
6568
},
6669
'TrueClass' => {
6770
condition: '_1 == "3"',
6871
output: {
69-
without_block: '3 foo qux',
70-
with_block: '3'
72+
without_block: "3 foo qux\n",
73+
with_block: "3\n"
7174
}
7275
},
7376
'FalseClass' => {
@@ -85,7 +88,7 @@
8588
2 foo baz
8689
3 foo qux
8790
OUTPUT
88-
with_block: %w[1 2 3].join("\n")
91+
with_block: "1\n2\n3\n"
8992
}
9093
},
9194
'NilClass' => {
@@ -131,9 +134,13 @@
131134
'String' => {
132135
condition: '"2 foo baz"',
133136
output: {
134-
without_block: '2 foo baz',
135-
with_block: '2 foo baz',
136-
return_value: %w[false true false].join("\n")
137+
without_block: "2 foo baz\n",
138+
with_block: "2 foo baz\n",
139+
return_value: <<~VALUE
140+
false
141+
true
142+
false
143+
VALUE
137144
}
138145
},
139146
'Regexp' => {
@@ -149,23 +156,35 @@
149156
2 foo baz
150157
3 foo qux
151158
OUTPUT
152-
return_value: %w[true true true].join("\n")
159+
return_value: <<~VALUE
160+
true
161+
true
162+
true
163+
VALUE
153164
}
154165
},
155166
'TrueClass' => {
156167
condition: '_1 == "3"',
157168
output: {
158-
without_block: '3 foo qux',
159-
with_block: '3 foo qux',
160-
return_value: %w[false false true].join("\n")
169+
without_block: "3 foo qux\n",
170+
with_block: "3 foo qux\n",
171+
return_value: <<~VALUE
172+
false
173+
false
174+
true
175+
VALUE
161176
}
162177
},
163178
'FalseClass' => {
164179
condition: '_1 == "4"',
165180
output: {
166181
without_block: '',
167182
with_block: '',
168-
return_value: %w[false false false].join("\n")
183+
return_value: <<~VALUE
184+
false
185+
false
186+
false
187+
VALUE
169188
}
170189
},
171190
'Integer' => {
@@ -181,15 +200,23 @@
181200
2 foo baz
182201
3 foo qux
183202
OUTPUT
184-
return_value: %w[true true true].join("\n")
203+
return_value: <<~VALUE
204+
true
205+
true
206+
true
207+
VALUE
185208
}
186209
},
187210
'NilClass' => {
188211
condition: '_2 =~ /hoge/',
189212
output: {
190213
without_block: '',
191214
with_block: '',
192-
return_value: %w[false false false].join("\n")
215+
return_value: <<~VALUE
216+
false
217+
false
218+
false
219+
VALUE
193220
}
194221
}
195222
}

‎spec/container/special_variables_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
with_them do
88
let(:input) { 'foo' }
99
let(:args) { "-q 'puts #{name}'" }
10-
let(:expect_output) { input }
10+
let(:expect_output) { "#{input}\n" }
1111

1212
it_behaves_like 'a successful exec'
1313
end

‎spec/error_message_spec.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe 'Show error message' do
22
using RSpec::Parameterized::TableSyntax
33

4-
where(:args, :expect_output) do
4+
where(:args, :output) do
55
'--invalid-option' | 'Error: invalid option: --invalid-option'
66
'-t test' | 'Error: "test" is invalid type. possible values: text,json,yaml'
77
'-t' | 'Error: missing argument: -t'
@@ -17,13 +17,14 @@
1717

1818
with_them do
1919
let(:input) { "test\n" }
20+
let(:expect_output) { "#{output}\n" }
2021
it_behaves_like 'a failed exec'
2122
end
2223

2324
context 'when permission denied' do
2425
let(:file) { 'permission_denied_file' }
2526
let(:args) { "_ #{file}" }
26-
let(:expect_output) { "Error: #{file}: permission denied" }
27+
let(:expect_output) { "Error: #{file}: permission denied\n" }
2728

2829
before do
2930
touch(file)

‎spec/feature/array_size_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
end
77

88
let(:args) { '-s _.size' }
9-
let(:expect_output) { '140000' }
9+
let(:expect_output) { "140000\n" }
1010

1111
it_behaves_like 'a successful exec'
1212
end

‎spec/feature/hash_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
{
44
'key is exist' => {
55
args: '-j _.foo',
6-
expect_output: 'bar'
6+
expect_output: "\"bar\"\n"
77
},
88
'key is not exist' => {
99
args: '-j _.piyo.class.to_s',
10-
expect_output: 'NilClass'
10+
expect_output: "\"NilClass\"\n"
1111
}
1212
}
1313
end

‎spec/feature/integaer_float_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[
1010
"##{mark} with String argument",
1111
%('#{statement}'),
12-
answer.to_s
12+
"#{answer}\n"
1313
]
1414
end
1515
end
@@ -30,7 +30,7 @@
3030
[
3131
"##{mark} with String argument",
3232
%(-q 'p #{statement}'),
33-
answer.to_s
33+
"#{answer}\n"
3434
]
3535
end
3636
end

‎spec/feature/nil_class_spec.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
describe '#+' do
55
where(:input, :expect_output) do
6-
%w[1 2 3].join("\n") | '6'
7-
%w[1.1 2.2 3.3].join("\n") | '6.6'
8-
%w[foo bar baz].join("\n") | 'foobarbaz'
6+
%w[1 2 3].join("\n") | "6\n"
7+
%w[1.1 2.2 3.3].join("\n") | "6.6\n"
8+
%w[foo bar baz].join("\n") | "foobarbaz\n"
99
end
1010

1111
with_them do
@@ -20,9 +20,13 @@
2020
describe '#<<' do
2121
let(:input) { %w[foo bar baz].join("\n") }
2222
let(:args) do
23-
%w[-q 's<<=_1; at_exit { puts s }']
23+
%w[-q 's<<=_1; at_exit { p s }']
24+
end
25+
let(:expect_output) do
26+
<<~OUTPUT
27+
["foo", "bar", "baz"]
28+
OUTPUT
2429
end
25-
let(:expect_output) { '["foo", "bar", "baz"]' }
2630

2731
it_behaves_like 'a successful exec'
2832
end

‎spec/feature/string_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[
1111
"##{mark} with #{klass} argument",
1212
%(-q 'p #{statement}'),
13-
answer.to_s
13+
"#{answer}\n"
1414
]
1515
end
1616
end

‎spec/filter/json_spec.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
let(:input) { '"foobar"' }
5656
let(:args) { '-j -H --no-color true testfile' }
5757
let(:expect_output) do
58-
input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
58+
out = input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
59+
"#{out}\n"
5960
end
6061

6162
before do
@@ -288,7 +289,7 @@
288289

289290
let(:args) { '-j _' }
290291
let(:expect_output) do
291-
'Error: failed to parse JSON: unexpected end of data position: 14'
292+
"Error: failed to parse JSON: unexpected end of data position: 14\n"
292293
end
293294

294295
it_behaves_like 'a failed exec'

‎spec/filter/text_spec.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
context 'when use -H option' do
3737
let(:args) { '-H --no-color true testfile' }
3838
let(:expect_output) do
39-
input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
39+
out = input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
40+
"#{out}\n"
4041
end
4142

4243
before do
@@ -84,10 +85,11 @@
8485
context 'when multiple files' do
8586
let(:args) { '--no-color true testfile1 testfile2' }
8687
let(:expect_output) do
87-
[
88+
out = [
8889
input.split("\n").map { |line| "testfile1:#{line}" }.join("\n"),
8990
input.split("\n").map { |line| "testfile2:#{line}" }.join("\n")
9091
].join("\n")
92+
"#{out}\n"
9193
end
9294

9395
before do

‎spec/filter/yaml_spec.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
describe 'Output UTF-8 string' do
8080
let(:input) { 'あいうえお🍣' }
8181
let(:args) { '-y _' }
82-
let(:expect_output) { 'あいうえお🍣' }
82+
let(:expect_output) { "あいうえお🍣\n" }
8383

8484
it_behaves_like 'a successful exec'
8585
end
@@ -247,19 +247,19 @@
247247
{
248248
'TrueClass' => {
249249
command: 'true',
250-
expect_output: 'true'
250+
expect_output: "true\n"
251251
},
252252
'FalseClass' => {
253253
command: 'false',
254-
expect_output: 'false'
254+
expect_output: "false\n"
255255
},
256256
'NilClass' => {
257257
command: 'nil',
258-
expect_output: 'null'
258+
expect_output: "null\n"
259259
},
260260
'Hash with null value' => {
261261
command: '{foo: nil}',
262-
expect_output: ':foo: null'
262+
expect_output: ":foo: null\n"
263263
}
264264
}
265265
end
@@ -275,7 +275,8 @@
275275
let(:input) { 'foobar' }
276276
let(:args) { '-y -H --no-color true testfile' }
277277
let(:expect_output) do
278-
input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
278+
out = input.split("\n").map { |line| "testfile:#{line}" }.join("\n")
279+
"#{out}\n"
279280
end
280281

281282
before do

‎spec/global_options/help_spec.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,27 @@
1010
1111
global options:
1212
-H, --with-filename print filename with output lines
13+
--with-record-number print record number with output lines
1314
-R, --recursive read all files under each directory recursively
1415
--include-filename searches for files matching a regex pattern
1516
-f, --file=program_file executed the contents of program_file
1617
-g, --grep Interpret command as a regex pattern for searching (like grep)
1718
-i, --in-place[=SUFFIX] edit files in place (makes backup if SUFFIX supplied)
1819
-n, --quiet suppress automatic printing
1920
-s, --slurp read all reacords into an array
21+
--[no-]color [no] colorized output (default: --color in TTY)
2022
--help show this message
2123
--version show version
2224
2325
text options:
2426
-F, --filed-separator VAL set the field separator (allow regexp)
25-
--[no-]color [no] colorized output (default: --color in TTY)
2627
2728
json options:
2829
-r, --raw-string output raw strings
2930
--disable-boolean-mode consider true/false/null as json literal
31+
-m, --minify minify json output
3032
3133
yaml options:
32-
-r, --raw-string output raw strings
3334
--disable-boolean-mode consider true/false/null as yaml literal
3435
--[no-]doc [no] output document sperator (refers to ---) (default:--no-doc)
3536
TEXT

‎spec/support/shared_examples.rb

+12-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
end
1111

1212
describe 'output' do
13-
it 'is expected output' do
14-
expect(last_command_started.output).to match expect_output
13+
it 'is expected output' do # rubocop:disable RSpec/MultipleExpectations
14+
if expect_output.is_a?(Regexp)
15+
expect(last_command_started.output).to match expect_output
16+
else
17+
expect(last_command_started.output).to eq expect_output
18+
end
1519
end
1620
end
1721
end
@@ -28,8 +32,12 @@
2832
end
2933

3034
describe 'output' do
31-
it 'is expected output' do
32-
expect(last_command_started.output).to match expect_output
35+
it 'is expected output' do # rubocop:disable RSpec/MultipleExpectations
36+
if expect_output.is_a?(Regexp)
37+
expect(last_command_started.output).to match expect_output
38+
else
39+
expect(last_command_started.output).to eq expect_output
40+
end
3341
end
3442
end
3543
end

0 commit comments

Comments
 (0)
Please sign in to comment.