seeing_is_believing 2.1.3 → 2.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/Readme.md +1 -0
- data/features/flags.feature +2 -2
- data/features/regression.feature +95 -0
- data/features/support/env.rb +2 -2
- data/lib/seeing_is_believing.rb +6 -4
- data/lib/seeing_is_believing/binary/clean_body.rb +1 -1
- data/lib/seeing_is_believing/binary/comment_formatter.rb +8 -1
- data/lib/seeing_is_believing/binary/comment_lines.rb +1 -0
- data/lib/seeing_is_believing/binary/commentable_lines.rb +3 -0
- data/lib/seeing_is_believing/evaluate_by_moving_files.rb +2 -2
- data/lib/seeing_is_believing/has_exception.rb +17 -1
- data/lib/seeing_is_believing/line.rb +33 -0
- data/lib/seeing_is_believing/result.rb +31 -0
- data/lib/seeing_is_believing/the_matrix.rb +25 -9
- data/lib/seeing_is_believing/version.rb +1 -1
- data/lib/seeing_is_believing/wrap_expressions.rb +16 -8
- data/seeing_is_believing.gemspec +4 -2
- data/spec/binary/clean_body_spec.rb +45 -44
- data/spec/binary/comment_formatter_spec.rb +24 -23
- data/spec/binary/comment_lines_spec.rb +31 -30
- data/spec/binary/parse_args_spec.rb +130 -129
- data/spec/binary/rewrite_comments_spec.rb +10 -9
- data/spec/debugger_spec.rb +9 -8
- data/spec/evaluate_by_moving_files_spec.rb +26 -19
- data/spec/hard_core_ensure_spec.rb +32 -20
- data/spec/line_spec.rb +27 -26
- data/spec/seeing_is_believing_spec.rb +155 -132
- data/spec/spec_helper.rb +3 -0
- data/spec/wrap_expressions_spec.rb +376 -313
- metadata +37 -6
data/seeing_is_believing.gemspec
CHANGED
@@ -20,10 +20,12 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
22
|
s.add_dependency "parser", "~> 2.1.4"
|
23
|
+
s.add_dependency "psych", "~> 2.0"
|
23
24
|
|
24
|
-
s.add_development_dependency "
|
25
|
+
s.add_development_dependency "pry", "~> 0.10.0"
|
26
|
+
s.add_development_dependency "haiti", "~> 0.1.0"
|
25
27
|
s.add_development_dependency "rake", "~> 10.0.3"
|
26
|
-
s.add_development_dependency "rspec", "~>
|
28
|
+
s.add_development_dependency "rspec", "~> 3.0.0"
|
27
29
|
s.add_development_dependency "cucumber", "~> 1.2.1"
|
28
30
|
s.add_development_dependency "ichannel", "~> 5.1.1"
|
29
31
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'seeing_is_believing/binary/clean_body'
|
2
3
|
|
3
4
|
describe SeeingIsBelieving::Binary::CleanBody do
|
@@ -8,58 +9,58 @@ describe SeeingIsBelieving::Binary::CleanBody do
|
|
8
9
|
end
|
9
10
|
|
10
11
|
context 'when told to clean out value annotations' do
|
11
|
-
example { call
|
12
|
-
example { call
|
13
|
-
example { call
|
14
|
-
example { call
|
15
|
-
example { call
|
16
|
-
example { call
|
17
|
-
example { call
|
12
|
+
example { expect(call "1#=>1", true).to eq "1" }
|
13
|
+
example { expect(call "1 #=>1", true).to eq "1" }
|
14
|
+
example { expect(call "1 #=>1", true).to eq "1" }
|
15
|
+
example { expect(call "1 #=> 1", true).to eq "1" }
|
16
|
+
example { expect(call "1 #=> 1", true).to eq "1" }
|
17
|
+
example { expect(call "1 #=> 1", true).to eq "1" }
|
18
|
+
example { expect(call "\n1 # => 1", true).to eq "\n1" }
|
18
19
|
end
|
19
20
|
|
20
21
|
context 'when told not to clean out value annotations' do
|
21
|
-
example { call
|
22
|
-
example { call
|
23
|
-
example { call
|
24
|
-
example { call
|
25
|
-
example { call
|
26
|
-
example { call
|
27
|
-
example { call
|
22
|
+
example { expect(call "1#=>1", false).to eq "1#=>1" }
|
23
|
+
example { expect(call "1 #=>1", false).to eq "1 #=>1" }
|
24
|
+
example { expect(call "1 #=>1", false).to eq "1 #=>1" }
|
25
|
+
example { expect(call "1 #=> 1", false).to eq "1 #=> 1" }
|
26
|
+
example { expect(call "1 #=> 1", false).to eq "1 #=> 1" }
|
27
|
+
example { expect(call "1 #=> 1", false).to eq "1 #=> 1" }
|
28
|
+
example { expect(call "\n1 # => 1", false).to eq "\n1 # => 1" }
|
28
29
|
end
|
29
30
|
|
30
31
|
context 'cleaning inline exception annotations' do
|
31
|
-
example { call
|
32
|
-
example { call
|
33
|
-
example { call
|
34
|
-
example { call
|
35
|
-
example { call
|
36
|
-
example { call
|
37
|
-
example { call
|
38
|
-
|
39
|
-
example { call
|
40
|
-
example { call
|
32
|
+
example { expect(call "1#~>1" ).to eq "1" }
|
33
|
+
example { expect(call "1 #~>1" ).to eq "1" }
|
34
|
+
example { expect(call "1 #~>1" ).to eq "1" }
|
35
|
+
example { expect(call "1 #~> 1" ).to eq "1" }
|
36
|
+
example { expect(call "1 #~> 1" ).to eq "1" }
|
37
|
+
example { expect(call "1 #~> 1" ).to eq "1" }
|
38
|
+
example { expect(call "\n1 # ~> 1").to eq "\n1" }
|
39
|
+
|
40
|
+
example { expect(call "# >> 1").to eq "" }
|
41
|
+
example { expect(call "# !> 1").to eq "" }
|
41
42
|
end
|
42
43
|
|
43
44
|
context 'cleaning stdout annotations' do
|
44
|
-
example { call(<<-CODE).
|
45
|
+
example { expect(call(<<-CODE)).to eq "1" }
|
45
46
|
1
|
46
47
|
# >> 2
|
47
48
|
CODE
|
48
49
|
|
49
|
-
example { call(<<-CODE).
|
50
|
+
example { expect(call(<<-CODE)).to eq "1" }
|
50
51
|
1
|
51
52
|
|
52
53
|
# >> 2
|
53
54
|
CODE
|
54
55
|
|
55
|
-
example { call(<<-CODE).
|
56
|
+
example { expect(call(<<-CODE)).to eq "1\n" }
|
56
57
|
1
|
57
58
|
|
58
59
|
|
59
60
|
# >> 2
|
60
61
|
CODE
|
61
62
|
|
62
|
-
example { call(<<-CODE).
|
63
|
+
example { expect(call(<<-CODE)).to eq "1\n" }
|
63
64
|
1
|
64
65
|
|
65
66
|
|
@@ -69,7 +70,7 @@ describe SeeingIsBelieving::Binary::CleanBody do
|
|
69
70
|
CODE
|
70
71
|
|
71
72
|
|
72
|
-
example { call(<<-CODE).
|
73
|
+
example { expect(call(<<-CODE)).to eq "1\n" }
|
73
74
|
1
|
74
75
|
|
75
76
|
|
@@ -79,25 +80,25 @@ describe SeeingIsBelieving::Binary::CleanBody do
|
|
79
80
|
end
|
80
81
|
|
81
82
|
context 'cleaning stderr annotations' do
|
82
|
-
example { call(<<-CODE).
|
83
|
+
example { expect(call(<<-CODE)).to eq "1" }
|
83
84
|
1
|
84
85
|
# !> 2
|
85
86
|
CODE
|
86
87
|
|
87
|
-
example { call(<<-CODE).
|
88
|
+
example { expect(call(<<-CODE)).to eq "1" }
|
88
89
|
1
|
89
90
|
|
90
91
|
# !> 2
|
91
92
|
CODE
|
92
93
|
|
93
|
-
example { call(<<-CODE).
|
94
|
+
example { expect(call(<<-CODE)).to eq "1" }
|
94
95
|
1
|
95
96
|
|
96
97
|
# !> 2
|
97
98
|
# !> 3
|
98
99
|
CODE
|
99
100
|
|
100
|
-
example { call(<<-CODE).
|
101
|
+
example { expect(call(<<-CODE)).to eq "1\n" }
|
101
102
|
1
|
102
103
|
|
103
104
|
|
@@ -109,25 +110,25 @@ describe SeeingIsBelieving::Binary::CleanBody do
|
|
109
110
|
|
110
111
|
|
111
112
|
context 'cleaning end of file exception annotations' do
|
112
|
-
example { call(<<-CODE).
|
113
|
+
example { expect(call(<<-CODE)).to eq "1" }
|
113
114
|
1
|
114
115
|
# ~>2
|
115
116
|
CODE
|
116
117
|
|
117
|
-
example { call(<<-CODE).
|
118
|
+
example { expect(call(<<-CODE)).to eq "1" }
|
118
119
|
1
|
119
120
|
|
120
121
|
# ~> 2
|
121
122
|
CODE
|
122
123
|
|
123
|
-
example { call(<<-CODE).
|
124
|
+
example { expect(call(<<-CODE)).to eq "1" }
|
124
125
|
1
|
125
126
|
|
126
127
|
# ~> 2
|
127
128
|
# ~> 3
|
128
129
|
CODE
|
129
130
|
|
130
|
-
example { call(<<-CODE).
|
131
|
+
example { expect(call(<<-CODE)).to eq "1\n" }
|
131
132
|
1
|
132
133
|
|
133
134
|
|
@@ -136,7 +137,7 @@ describe SeeingIsBelieving::Binary::CleanBody do
|
|
136
137
|
# ~> 2
|
137
138
|
CODE
|
138
139
|
|
139
|
-
example { call(<<-CODE).
|
140
|
+
example { expect(call(<<-CODE)).to eq "1\n" }
|
140
141
|
1 # ~> error
|
141
142
|
|
142
143
|
|
@@ -145,7 +146,7 @@ describe SeeingIsBelieving::Binary::CleanBody do
|
|
145
146
|
end
|
146
147
|
|
147
148
|
context 'putting it all together' do
|
148
|
-
example { call(<<-CODE).
|
149
|
+
example { expect(call(<<-CODE)).to eq "1" }
|
149
150
|
1
|
150
151
|
|
151
152
|
# >> 1
|
@@ -158,7 +159,7 @@ describe SeeingIsBelieving::Binary::CleanBody do
|
|
158
159
|
# ~> 6
|
159
160
|
CODE
|
160
161
|
|
161
|
-
example { call(<<-CODE).
|
162
|
+
example { expect(call(<<-CODE)).to eq "1" }
|
162
163
|
1
|
163
164
|
|
164
165
|
# >> 1
|
@@ -174,7 +175,7 @@ describe SeeingIsBelieving::Binary::CleanBody do
|
|
174
175
|
# ~> 6
|
175
176
|
CODE
|
176
177
|
|
177
|
-
example { call(<<-CODE).
|
178
|
+
example { expect(call(<<-CODE)).to eq "1" }
|
178
179
|
1
|
179
180
|
|
180
181
|
# >> 1
|
@@ -185,7 +186,7 @@ describe SeeingIsBelieving::Binary::CleanBody do
|
|
185
186
|
# ~> 6
|
186
187
|
CODE
|
187
188
|
|
188
|
-
example { call(<<-CODE).
|
189
|
+
example { expect(call(<<-CODE)).to eq "1\n3" }
|
189
190
|
1
|
190
191
|
# >> 1
|
191
192
|
# >> 2
|
@@ -194,7 +195,7 @@ describe SeeingIsBelieving::Binary::CleanBody do
|
|
194
195
|
# !> 5
|
195
196
|
CODE
|
196
197
|
|
197
|
-
example { call(<<-CODE).
|
198
|
+
example { expect(call(<<-CODE)).to eq "1\n3\n6" }
|
198
199
|
1
|
199
200
|
# >> 1
|
200
201
|
# >> 2
|
@@ -206,7 +207,7 @@ describe SeeingIsBelieving::Binary::CleanBody do
|
|
206
207
|
# ~> 8
|
207
208
|
CODE
|
208
209
|
|
209
|
-
example { call(<<-CODE).
|
210
|
+
example { expect(call(<<-CODE)).to eq "1\n\nputs \"omg\"" }
|
210
211
|
1 # => 1
|
211
212
|
|
212
213
|
puts "omg" # ~> RuntimeError: omg
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'seeing_is_believing/binary/comment_formatter'
|
2
3
|
|
3
4
|
describe SeeingIsBelieving::Binary::CommentFormatter do
|
@@ -6,49 +7,49 @@ describe SeeingIsBelieving::Binary::CommentFormatter do
|
|
6
7
|
end
|
7
8
|
|
8
9
|
specify 'it returns the consolidated result if there are no truncations' do
|
9
|
-
result_for
|
10
|
+
expect(result_for 1, '=>', '12345').to eq '=>12345'
|
10
11
|
end
|
11
12
|
|
12
13
|
specify 'result_length truncates a result to the specified length, using elipses up to that length if appropriate' do
|
13
14
|
line_length = 1
|
14
15
|
separator = '=>'
|
15
16
|
result = '12345'
|
16
|
-
result_for
|
17
|
-
result_for
|
18
|
-
result_for
|
19
|
-
result_for
|
20
|
-
result_for
|
21
|
-
result_for
|
17
|
+
expect(result_for line_length, separator, result, max_result_length: Float::INFINITY).to eq '=>12345'
|
18
|
+
expect(result_for line_length, separator, result, max_result_length: 7 ).to eq '=>12345'
|
19
|
+
expect(result_for line_length, separator, result, max_result_length: 6 ).to eq '=>1...'
|
20
|
+
expect(result_for line_length, separator, result, max_result_length: 5 ).to eq '=>...'
|
21
|
+
expect(result_for line_length, separator, result, max_result_length: 4 ).to eq ''
|
22
|
+
expect(result_for line_length, separator, result, max_result_length: 0 ).to eq ''
|
22
23
|
end
|
23
24
|
|
24
25
|
specify 'line_length truncates a result to the specified length, minus the length of the line' do
|
25
26
|
line_length = 1
|
26
27
|
separator = '=>'
|
27
28
|
result = '12345'
|
28
|
-
result_for
|
29
|
-
result_for
|
30
|
-
result_for
|
31
|
-
result_for
|
32
|
-
result_for
|
33
|
-
result_for
|
34
|
-
result_for
|
29
|
+
expect(result_for line_length, separator, result ).to eq '=>12345'
|
30
|
+
expect(result_for line_length, separator, result, max_line_length: Float::INFINITY).to eq '=>12345'
|
31
|
+
expect(result_for line_length, separator, result, max_line_length: 8 ).to eq '=>12345'
|
32
|
+
expect(result_for line_length, separator, result, max_line_length: 7 ).to eq '=>1...'
|
33
|
+
expect(result_for line_length, separator, result, max_line_length: 6 ).to eq '=>...'
|
34
|
+
expect(result_for line_length, separator, result, max_line_length: 5 ).to eq ''
|
35
|
+
expect(result_for line_length, separator, result, max_line_length: 0 ).to eq ''
|
35
36
|
end
|
36
37
|
|
37
38
|
specify 'pad_to will pad the length that the line is displayed in' do
|
38
|
-
result_for
|
39
|
-
result_for
|
40
|
-
result_for
|
39
|
+
expect(result_for 1, '=>', '2', pad_to: 0).to eq '=>2'
|
40
|
+
expect(result_for 1, '=>', '2', pad_to: 1).to eq '=>2'
|
41
|
+
expect(result_for 1, '=>', '2', pad_to: 2).to eq ' =>2'
|
41
42
|
end
|
42
43
|
|
43
44
|
specify 'pad_to is ignored when separator/result will not be printed' do
|
44
|
-
result_for
|
45
|
-
result_for
|
45
|
+
expect(result_for 1, '=>', '12345', pad_to: 2, max_line_length: 2).to eq ''
|
46
|
+
expect(result_for 1, '=>', '12345', pad_to: 2, max_result_length: 2).to eq ''
|
46
47
|
end
|
47
48
|
|
48
49
|
specify 'they can all work together' do
|
49
|
-
result_for
|
50
|
-
result_for
|
51
|
-
result_for
|
52
|
-
result_for
|
50
|
+
expect(result_for 1, '=>', '12345', max_line_length: 100, max_result_length: 100, pad_to: 2).to eq ' =>12345'
|
51
|
+
expect(result_for 1, '=>', '12345', max_line_length: 8, max_result_length: 100, pad_to: 2).to eq ' =>1...'
|
52
|
+
expect(result_for 1, '=>', '12345', max_line_length: 100, max_result_length: 6, pad_to: 2).to eq ' =>1...'
|
53
|
+
expect(result_for 1, '=>', '12345', max_line_length: 100, max_result_length: 6, pad_to: 2).to eq ' =>1...'
|
53
54
|
end
|
54
55
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'seeing_is_believing/binary/comment_lines'
|
2
3
|
|
3
4
|
describe SeeingIsBelieving::Binary::CommentLines, 'passes in the each commentable line and the line number, and adds the returned text (whitespace+comment) to the end' do
|
@@ -6,17 +7,17 @@ describe SeeingIsBelieving::Binary::CommentLines, 'passes in the each commentabl
|
|
6
7
|
end
|
7
8
|
|
8
9
|
example 'just checking some edge cases' do
|
9
|
-
call("") { ';' }.
|
10
|
-
call("__END__\n1") { ';' }.
|
11
|
-
call("1\n__END__") { ';' }.
|
10
|
+
expect(call("") { ';' }).to eq ";"
|
11
|
+
expect(call("__END__\n1") { ';' }).to eq "__END__\n1"
|
12
|
+
expect(call("1\n__END__") { ';' }).to eq "1;\n__END__"
|
12
13
|
end
|
13
14
|
|
14
15
|
it "doesn't comment lines whose newline is escaped" do
|
15
|
-
call("1 +\\\n2") { |_, line_number| "--#{line_number}--" }.
|
16
|
+
expect(call("1 +\\\n2") { |_, line_number| "--#{line_number}--" }).to eq "1 +\\\n2--2--"
|
16
17
|
end
|
17
18
|
|
18
19
|
it "doesn't comment lines inside of strings" do
|
19
|
-
call(<<-INPUT) { |_, line_number| "--#{line_number}--" }.
|
20
|
+
expect(call(<<-INPUT) { |_, line_number| "--#{line_number}--" }).to eq <<-OUTPUT
|
20
21
|
"a\#{1+1
|
21
22
|
}"
|
22
23
|
"a
|
@@ -46,7 +47,7 @@ describe SeeingIsBelieving::Binary::CommentLines, 'passes in the each commentabl
|
|
46
47
|
end
|
47
48
|
|
48
49
|
it 'does comment the first line of a heredoc' do
|
49
|
-
call(<<-INPUT.gsub(/^ */, '')) { |_, line_number| "--#{line_number}--" }.
|
50
|
+
expect(call(<<-INPUT.gsub(/^ */, '')) { |_, line_number| "--#{line_number}--" }).to eq <<-OUTPUT.gsub(/^ */, '')
|
50
51
|
<<A
|
51
52
|
1
|
52
53
|
A
|
@@ -92,7 +93,7 @@ describe SeeingIsBelieving::Binary::CommentLines, 'passes in the each commentabl
|
|
92
93
|
end
|
93
94
|
|
94
95
|
it "doesn't comment lines inside of regexes" do
|
95
|
-
call(<<-INPUT) { |_, line_number| "--#{line_number}--" }.
|
96
|
+
expect(call(<<-INPUT) { |_, line_number| "--#{line_number}--" }).to eq <<-OUTPUT
|
96
97
|
/a\#{1+1
|
97
98
|
}/
|
98
99
|
/a
|
@@ -110,7 +111,7 @@ describe SeeingIsBelieving::Binary::CommentLines, 'passes in the each commentabl
|
|
110
111
|
end
|
111
112
|
|
112
113
|
it "doesn't comment lines inside of backticks/%x" do
|
113
|
-
call(<<-INPUT) { |_, line_number| "--#{line_number}--" }.
|
114
|
+
expect(call(<<-INPUT) { |_, line_number| "--#{line_number}--" }).to eq <<-OUTPUT
|
114
115
|
`a\#{1+1
|
115
116
|
}`
|
116
117
|
%x[\#{1+1
|
@@ -136,7 +137,7 @@ describe SeeingIsBelieving::Binary::CommentLines, 'passes in the each commentabl
|
|
136
137
|
end
|
137
138
|
|
138
139
|
it "doesn't comment lines inside of string arrays" do
|
139
|
-
call(<<-INPUT) { |_, line_number| "--#{line_number}--" }.
|
140
|
+
expect(call(<<-INPUT) { |_, line_number| "--#{line_number}--" }).to eq <<-OUTPUT
|
140
141
|
%w[
|
141
142
|
a
|
142
143
|
]
|
@@ -158,26 +159,26 @@ describe SeeingIsBelieving::Binary::CommentLines, 'passes in the each commentabl
|
|
158
159
|
"'4\n"\
|
159
160
|
"5'+\n"\
|
160
161
|
"%Q'\n"\
|
161
|
-
" \#{5+6} 7'\n")
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
lines.
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
result.
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
162
|
+
" \#{5+6} 7'\n") { |line, line_number|
|
163
|
+
lines << line
|
164
|
+
"--#{line_number}--"
|
165
|
+
}
|
166
|
+
|
167
|
+
expect(lines).to eq ["1 +",
|
168
|
+
" 2",
|
169
|
+
"",
|
170
|
+
"5'+",
|
171
|
+
" \#{5+6} 7'"]
|
172
|
+
|
173
|
+
expect(result).to eq "1 +--1--\n"\
|
174
|
+
" 2--2--\n"\
|
175
|
+
"--3--\n"\
|
176
|
+
"# just a comment\n"\
|
177
|
+
"3 # already has a comment\n"\
|
178
|
+
"'4\n"\
|
179
|
+
"5'+--7--\n"\
|
180
|
+
"%Q'\n"\
|
181
|
+
" \#{5+6} 7'--9--\n"
|
181
182
|
end
|
182
183
|
|
183
184
|
|
@@ -838,6 +839,6 @@ __END__
|
|
838
839
|
1
|
839
840
|
OUTPUT
|
840
841
|
|
841
|
-
call(input) { ';' }.
|
842
|
+
expect(call(input) { ';' }).to eq output
|
842
843
|
end
|
843
844
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
require 'seeing_is_believing/binary/parse_args'
|
2
3
|
|
3
4
|
describe SeeingIsBelieving::Binary::ParseArgs do
|
@@ -13,29 +14,29 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
+
failure_message do |options|
|
17
18
|
"#{error_assertion.inspect} should have matched one of the errors: #{options[:errors].inspect}"
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
+
failure_message_when_negated do |options|
|
21
22
|
"#{error_assertion.inspect} should NOT have matched any of the errors: #{options[:errors].inspect}"
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
26
|
def parse(args, outstream=nil)
|
26
|
-
|
27
|
+
SeeingIsBelieving::Binary::ParseArgs.call args, outstream
|
27
28
|
end
|
28
29
|
|
29
30
|
shared_examples 'it requires a positive int argument' do |flags|
|
30
31
|
it 'expects an integer argument' do
|
31
32
|
flags.each do |flag|
|
32
|
-
parse([flag, '1']).
|
33
|
-
parse([flag, '0']).
|
34
|
-
parse([flag, '-1']).
|
35
|
-
parse([flag, '1.0']).
|
36
|
-
parse([flag, 'a']).
|
37
|
-
parse([flag, '' ]).
|
38
|
-
parse([flag ]).
|
33
|
+
expect(parse([flag, '1'])).to_not have_error /#{flag}/
|
34
|
+
expect(parse([flag, '0'])).to have_error /#{flag}/
|
35
|
+
expect(parse([flag, '-1'])).to have_error /#{flag}/
|
36
|
+
expect(parse([flag, '1.0'])).to have_error /#{flag}/
|
37
|
+
expect(parse([flag, 'a'])).to have_error /#{flag}/
|
38
|
+
expect(parse([flag, '' ])).to have_error /#{flag}/
|
39
|
+
expect(parse([flag ])).to have_error /#{flag}/
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
@@ -43,60 +44,60 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
43
44
|
shared_examples 'it requires a non-negative float or int' do |flags|
|
44
45
|
it 'expects a non-negative float or int argument' do
|
45
46
|
flags.each do |flag|
|
46
|
-
parse([flag, '1']).
|
47
|
-
parse([flag, '0']).
|
48
|
-
parse([flag, '-1']).
|
49
|
-
parse([flag,'-1.0']).
|
50
|
-
parse([flag, '1.0']).
|
51
|
-
parse([flag, 'a']).
|
52
|
-
parse([flag, '' ]).
|
53
|
-
parse([flag ]).
|
47
|
+
expect(parse([flag, '1'])).to_not have_error /#{flag}/
|
48
|
+
expect(parse([flag, '0'])).to_not have_error /#{flag}/
|
49
|
+
expect(parse([flag, '-1'])).to have_error /#{flag}/
|
50
|
+
expect(parse([flag,'-1.0'])).to have_error /#{flag}/
|
51
|
+
expect(parse([flag, '1.0'])).to_not have_error /#{flag}/
|
52
|
+
expect(parse([flag, 'a'])).to have_error /#{flag}/
|
53
|
+
expect(parse([flag, '' ])).to have_error /#{flag}/
|
54
|
+
expect(parse([flag ])).to have_error /#{flag}/
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
59
|
specify 'unknown options set an error' do
|
59
|
-
parse(['--xyz']).
|
60
|
-
parse(['-y']).
|
61
|
-
parse(['-y', 'b']).
|
60
|
+
expect(parse(['--xyz'])).to have_error 'Unknown option: "--xyz"'
|
61
|
+
expect(parse(['-y'])).to have_error 'Unknown option: "-y"'
|
62
|
+
expect(parse(['-y', 'b'])).to have_error 'Unknown option: "-y"'
|
62
63
|
end
|
63
64
|
|
64
65
|
example 'example: multiple args' do
|
65
66
|
options = parse(%w[filename -l 12 -L 20 -h -r torequire])
|
66
|
-
options[:filename].
|
67
|
-
options[:start_line].
|
68
|
-
options[:end_line].
|
69
|
-
options[:require].
|
70
|
-
options[:help].
|
71
|
-
options[:errors].
|
67
|
+
expect(options[:filename]).to eq 'filename'
|
68
|
+
expect(options[:start_line]).to eq 12
|
69
|
+
expect(options[:end_line]).to eq 20
|
70
|
+
expect(options[:require]).to eq ['torequire']
|
71
|
+
expect(options[:help]).to be_a_kind_of String
|
72
|
+
expect(options[:errors]).to be_empty
|
72
73
|
end
|
73
74
|
|
74
75
|
describe ':filename' do
|
75
76
|
it 'defaults to nil' do
|
76
|
-
parse([])[:filename].
|
77
|
+
expect(parse([])[:filename]).to be_nil
|
77
78
|
end
|
78
79
|
|
79
80
|
it 'is the first non-flag' do
|
80
|
-
parse(['a'])[:filename].
|
81
|
-
parse(['-x', 'a'])[:filename].
|
82
|
-
parse(['a', '-x'])[:filename].
|
81
|
+
expect(parse(['a'])[:filename]).to eq 'a'
|
82
|
+
expect(parse(['-x', 'a'])[:filename]).to eq 'a'
|
83
|
+
expect(parse(['a', '-x'])[:filename]).to eq 'a'
|
83
84
|
end
|
84
85
|
|
85
86
|
it 'sets an error if given multiple filenames' do
|
86
|
-
parse([]).
|
87
|
-
parse(['a']).
|
88
|
-
parse(['a', 'b']).
|
87
|
+
expect(parse([])).to_not have_error /name/
|
88
|
+
expect(parse(['a'])).to_not have_error /Can only have one filename/
|
89
|
+
expect(parse(['a', 'b'])).to have_error 'Can only have one filename, but had: "a", "b"'
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
92
93
|
describe ':start_line' do
|
93
94
|
it 'defaults to 1' do
|
94
|
-
parse([])[:start_line].
|
95
|
+
expect(parse([])[:start_line]).to equal 1
|
95
96
|
end
|
96
97
|
|
97
98
|
it 'is set with -l and --start-line' do
|
98
|
-
parse(['-l', '1'])[:start_line].
|
99
|
-
parse(['--start-line', '12'])[:start_line].
|
99
|
+
expect(parse(['-l', '1'])[:start_line]).to eq 1
|
100
|
+
expect(parse(['--start-line', '12'])[:start_line]).to eq 12
|
100
101
|
end
|
101
102
|
|
102
103
|
it_behaves_like 'it requires a positive int argument', ['-l', '--start-line']
|
@@ -104,30 +105,30 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
104
105
|
|
105
106
|
describe ':end_line' do
|
106
107
|
it 'defaults to infinity' do
|
107
|
-
parse([])[:end_line].
|
108
|
+
expect(parse([])[:end_line]).to equal Float::INFINITY
|
108
109
|
end
|
109
110
|
|
110
111
|
it 'is set with -L and --end-line' do
|
111
|
-
parse(['-L', '1'])[:end_line].
|
112
|
-
parse(['--end-line', '12'])[:end_line].
|
112
|
+
expect(parse(['-L', '1'])[:end_line]).to eq 1
|
113
|
+
expect(parse(['--end-line', '12'])[:end_line]).to eq 12
|
113
114
|
end
|
114
115
|
|
115
116
|
it_behaves_like 'it requires a positive int argument', ['-L', '--end-line']
|
116
117
|
end
|
117
118
|
|
118
119
|
it 'swaps start and end line around if they are out of order' do
|
119
|
-
parse(%w[-l 2 -L 1])[:start_line].
|
120
|
-
parse(%w[-l 2 -L 1])[:end_line].
|
120
|
+
expect(parse(%w[-l 2 -L 1])[:start_line]).to eq 1
|
121
|
+
expect(parse(%w[-l 2 -L 1])[:end_line]).to eq 2
|
121
122
|
end
|
122
123
|
|
123
124
|
describe ':result_length' do
|
124
125
|
it 'defaults to infinity' do
|
125
|
-
parse([])[:max_result_length].
|
126
|
+
expect(parse([])[:max_result_length]).to eq Float::INFINITY
|
126
127
|
end
|
127
128
|
|
128
129
|
it 'is set with -D and --result-length' do
|
129
|
-
parse(['-D', '10'])[:max_result_length].
|
130
|
-
parse(['--result-length', '10'])[:max_result_length].
|
130
|
+
expect(parse(['-D', '10'])[:max_result_length]).to eq 10
|
131
|
+
expect(parse(['--result-length', '10'])[:max_result_length]).to eq 10
|
131
132
|
end
|
132
133
|
|
133
134
|
it_behaves_like 'it requires a positive int argument', ['-D', '--result-length']
|
@@ -135,12 +136,12 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
135
136
|
|
136
137
|
describe ':max_line_length' do
|
137
138
|
it 'defaults to infinity' do
|
138
|
-
parse([])[:max_line_length].
|
139
|
+
expect(parse([])[:max_line_length]).to eq Float::INFINITY
|
139
140
|
end
|
140
141
|
|
141
142
|
it 'is set with -d and --line-length' do
|
142
|
-
parse(['-d', '10'])[:max_line_length].
|
143
|
-
parse(['--line-length', '10'])[:max_line_length].
|
143
|
+
expect(parse(['-d', '10'])[:max_line_length]).to eq 10
|
144
|
+
expect(parse(['--line-length', '10'])[:max_line_length]).to eq 10
|
144
145
|
end
|
145
146
|
|
146
147
|
it_behaves_like 'it requires a positive int argument', ['-d', '--line-length']
|
@@ -148,148 +149,148 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
148
149
|
|
149
150
|
describe :require do
|
150
151
|
it 'defaults to an empty array' do
|
151
|
-
parse([])[:require].
|
152
|
+
expect(parse([])[:require]).to be_empty
|
152
153
|
end
|
153
154
|
|
154
155
|
it '-r and --require sets each required file into the result array' do
|
155
|
-
parse(%w[-r f1 --require f2])[:require].
|
156
|
+
expect(parse(%w[-r f1 --require f2])[:require]).to eq %w[f1 f2]
|
156
157
|
end
|
157
158
|
|
158
159
|
it 'sets an error if not provided with a filename' do
|
159
|
-
parse(['--require', 'f']).
|
160
|
-
parse(['-r']).
|
161
|
-
parse(['--require']).
|
160
|
+
expect(parse(['--require', 'f'])).to_not have_error /-r/
|
161
|
+
expect(parse(['-r'])).to have_error /-r\b/
|
162
|
+
expect(parse(['--require'])).to have_error /--require\b/
|
162
163
|
end
|
163
164
|
end
|
164
165
|
|
165
166
|
describe ':help' do
|
166
167
|
it 'defaults to nil' do
|
167
|
-
parse([])[:help].
|
168
|
+
expect(parse([])[:help]).to be_nil
|
168
169
|
end
|
169
170
|
|
170
171
|
it 'is set to the flag only help screen with -h and --help and -help' do
|
171
|
-
parse(['-h'])[:help].
|
172
|
-
parse(['--help'])[:help].
|
172
|
+
expect(parse(['-h'])[:help]).to include 'Usage:'
|
173
|
+
expect(parse(['--help'])[:help]).to include 'Usage:'
|
173
174
|
|
174
|
-
parse(['-h'])[:help].
|
175
|
-
parse(['--help'])[:help].
|
175
|
+
expect(parse(['-h'])[:help]).to_not include 'Examples:'
|
176
|
+
expect(parse(['--help'])[:help]).to_not include 'Examples:'
|
176
177
|
end
|
177
178
|
|
178
179
|
it 'is set to the flag with examples help screen with --help+ and -h+' do
|
179
|
-
parse(['-h+'])[:help].
|
180
|
-
parse(['--help+'])[:help].
|
180
|
+
expect(parse(['-h+'])[:help]).to include 'Usage:'
|
181
|
+
expect(parse(['--help+'])[:help]).to include 'Usage:'
|
181
182
|
|
182
|
-
parse(['-h+'])[:help].
|
183
|
-
parse(['--help+'])[:help].
|
183
|
+
expect(parse(['-h+'])[:help]).to include 'Examples:'
|
184
|
+
expect(parse(['--help+'])[:help]).to include 'Examples:'
|
184
185
|
end
|
185
186
|
end
|
186
187
|
|
187
188
|
describe ':program' do
|
188
189
|
it 'defaults to nil' do
|
189
|
-
parse([])[:program].
|
190
|
+
expect(parse([])[:program]).to be_nil
|
190
191
|
end
|
191
192
|
|
192
193
|
it 'is set with -e or --program, and takes the next arg' do
|
193
|
-
parse(['-e', '1'])[:program].
|
194
|
-
parse(['--program', '1'])[:program].
|
194
|
+
expect(parse(['-e', '1'])[:program]).to eq '1'
|
195
|
+
expect(parse(['--program', '1'])[:program]).to eq '1'
|
195
196
|
end
|
196
197
|
|
197
198
|
it 'sets an error if not given a program' do
|
198
|
-
parse([]).
|
199
|
-
parse([]).
|
200
|
-
parse(['-e']).
|
201
|
-
parse(['--program']).
|
199
|
+
expect(parse([])).to_not have_error /-e/
|
200
|
+
expect(parse([])).to_not have_error /--program/
|
201
|
+
expect(parse(['-e'])).to have_error /-e/
|
202
|
+
expect(parse(['--program'])).to have_error /--program/
|
202
203
|
end
|
203
204
|
|
204
205
|
it 'sets an error if a filename is also give' do
|
205
|
-
parse(['-e', '1']).
|
206
|
-
parse(['-e', '1', 'abc']).
|
206
|
+
expect(parse(['-e', '1'])).to_not have_error /-e/
|
207
|
+
expect(parse(['-e', '1', 'abc'])).to have_error /"abc"/
|
207
208
|
end
|
208
209
|
end
|
209
210
|
|
210
211
|
describe':load_path' do
|
211
212
|
it 'defaults to an empty array' do
|
212
|
-
parse([])[:load_path].
|
213
|
+
expect(parse([])[:load_path]).to be_empty
|
213
214
|
end
|
214
215
|
|
215
216
|
specify '-I and --load-path sets each required file into the result array' do
|
216
|
-
parse(%w[-I f1 --load-path f2])[:load_path].
|
217
|
+
expect(parse(%w[-I f1 --load-path f2])[:load_path]).to eq %w[f1 f2]
|
217
218
|
end
|
218
219
|
|
219
220
|
it 'sets an error if not provided with a dir' do
|
220
|
-
parse(['--load-path', 'f']).
|
221
|
-
parse(['-I']).
|
222
|
-
parse(['--load-path']).
|
221
|
+
expect(parse(['--load-path', 'f'])).to_not have_error /-I/
|
222
|
+
expect(parse(['-I'])).to have_error /-I\b/
|
223
|
+
expect(parse(['--load-path'])).to have_error /--load-path\b/
|
223
224
|
end
|
224
225
|
end
|
225
226
|
|
226
227
|
describe ':encoding' do
|
227
228
|
it 'defaults to nil' do
|
228
|
-
parse([])[:encoding].
|
229
|
+
expect(parse([])[:encoding]).to be_nil
|
229
230
|
end
|
230
231
|
|
231
232
|
specify '-K and --encoding sets the encoding to the next argument' do
|
232
|
-
parse(%w[-K u])[:encoding].
|
233
|
-
parse(%w[--encoding u])[:encoding].
|
233
|
+
expect(parse(%w[-K u])[:encoding]).to eq 'u'
|
234
|
+
expect(parse(%w[--encoding u])[:encoding]).to eq 'u'
|
234
235
|
end
|
235
236
|
|
236
237
|
specify 'with -K, the argument can be placed immediately after it (e.g. -Ku) because Ruby allows this' do
|
237
|
-
parse(['-Ku'])[:encoding].
|
238
|
-
parse(['-Ku']).
|
238
|
+
expect(parse(['-Ku'])[:encoding]).to eq 'u'
|
239
|
+
expect(parse(['-Ku'])).to_not have_error /-K/
|
239
240
|
end
|
240
241
|
|
241
242
|
it 'sets an error if not provided with an encoding' do
|
242
|
-
parse(['-Ku']).
|
243
|
-
parse(['-K u']).
|
244
|
-
parse(['--encoding', 'u']).
|
245
|
-
parse(['-K']).
|
246
|
-
parse(['--encoding']).
|
243
|
+
expect(parse(['-Ku'])).to_not have_error /-K/
|
244
|
+
expect(parse(['-K u'])).to_not have_error /-K/
|
245
|
+
expect(parse(['--encoding', 'u'])).to_not have_error /--encoding/
|
246
|
+
expect(parse(['-K'])).to have_error /-K/
|
247
|
+
expect(parse(['--encoding'])).to have_error /--encoding/
|
247
248
|
end
|
248
249
|
end
|
249
250
|
|
250
251
|
describe ':as' do
|
251
252
|
it 'defaults to nil' do
|
252
|
-
parse([])[:as].
|
253
|
+
expect(parse([])[:as]).to be_nil
|
253
254
|
end
|
254
255
|
|
255
256
|
it 'can be set with -a and --as' do
|
256
|
-
parse(%w[-a abc])[:as].
|
257
|
-
parse(%w[--as abc])[:as].
|
257
|
+
expect(parse(%w[-a abc])[:as]).to eq 'abc'
|
258
|
+
expect(parse(%w[--as abc])[:as]).to eq 'abc'
|
258
259
|
end
|
259
260
|
|
260
261
|
it 'sets an error if not provided with a filename' do
|
261
|
-
parse(%w[-a f]).
|
262
|
-
parse(%w[-as f]).
|
263
|
-
parse(%w[-a ]).
|
264
|
-
parse(%w[--as ]).
|
262
|
+
expect(parse(%w[-a f])).to_not have_error /-a/
|
263
|
+
expect(parse(%w[-as f])).to_not have_error /--as/
|
264
|
+
expect(parse(%w[-a ])).to have_error /-a/
|
265
|
+
expect(parse(%w[--as ])).to have_error /--as/
|
265
266
|
end
|
266
267
|
end
|
267
268
|
|
268
269
|
describe ':clean' do
|
269
270
|
it 'defaults to false' do
|
270
|
-
parse([])[:clean].
|
271
|
+
expect(parse([])[:clean]).to eq false
|
271
272
|
end
|
272
273
|
|
273
274
|
it 'can be set with -c and --clean' do
|
274
|
-
parse(%w[-c])[:clean].
|
275
|
-
parse(%w[--clean])[:clean].
|
275
|
+
expect(parse(%w[-c])[:clean]).to eq true
|
276
|
+
expect(parse(%w[--clean])[:clean]).to eq true
|
276
277
|
end
|
277
278
|
end
|
278
279
|
|
279
280
|
describe ':version' do
|
280
281
|
it 'defaults to false' do
|
281
|
-
parse([])[:version].
|
282
|
+
expect(parse([])[:version]).to eq false
|
282
283
|
end
|
283
284
|
|
284
285
|
it 'can be set with -v and --version' do
|
285
|
-
parse(%w[-v])[:version].
|
286
|
-
parse(%w[--version])[:version].
|
286
|
+
expect(parse(%w[-v])[:version]).to eq true
|
287
|
+
expect(parse(%w[--version])[:version]).to eq true
|
287
288
|
end
|
288
289
|
end
|
289
290
|
|
290
291
|
describe ':timeout' do
|
291
292
|
it 'defaults to 0' do
|
292
|
-
parse([])[:timeout].
|
293
|
+
expect(parse([])[:timeout]).to eq 0
|
293
294
|
end
|
294
295
|
|
295
296
|
it_behaves_like 'it requires a non-negative float or int', ['-t', '--timeout']
|
@@ -302,87 +303,87 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
302
303
|
|
303
304
|
# maybe change the default?
|
304
305
|
it 'defaults to AlignChunk' do
|
305
|
-
parse([])[:alignment_strategy].
|
306
|
+
expect(parse([])[:alignment_strategy]).to eq AlignChunk
|
306
307
|
end
|
307
308
|
|
308
309
|
specify '-s and --alignment-strategy sets the alignment strategy' do
|
309
|
-
parse(['-s', 'chunk'])[:alignment_strategy].
|
310
|
-
parse(['--alignment-strategy', 'chunk'])[:alignment_strategy].
|
310
|
+
expect(parse(['-s', 'chunk'])[:alignment_strategy]).to eq AlignChunk
|
311
|
+
expect(parse(['--alignment-strategy', 'chunk'])[:alignment_strategy]).to eq AlignChunk
|
311
312
|
end
|
312
313
|
|
313
314
|
it 'accepts values: file, line, chunk' do
|
314
|
-
parse(['-s', 'file'])[:alignment_strategy].
|
315
|
-
parse(['-s', 'line'])[:alignment_strategy].
|
316
|
-
parse(['-s', 'chunk'])[:alignment_strategy].
|
315
|
+
expect(parse(['-s', 'file'])[:alignment_strategy]).to eq AlignFile
|
316
|
+
expect(parse(['-s', 'line'])[:alignment_strategy]).to eq AlignLine
|
317
|
+
expect(parse(['-s', 'chunk'])[:alignment_strategy]).to eq AlignChunk
|
317
318
|
end
|
318
319
|
|
319
320
|
it 'sets an error if not provided with a strategy, or if provided with an unknown strategy' do
|
320
|
-
parse(['-s', 'file']).
|
321
|
-
parse(['-s', 'abc']).
|
322
|
-
parse(['-s' ]).
|
321
|
+
expect(parse(['-s', 'file'])).to_not have_error /alignment-strategy/
|
322
|
+
expect(parse(['-s', 'abc'])).to have_error /alignment-strategy/
|
323
|
+
expect(parse(['-s' ])).to have_error /alignment-strategy/
|
323
324
|
end
|
324
325
|
end
|
325
326
|
|
326
327
|
describe ':inherit_exit_status' do
|
327
328
|
it 'defaults to false' do
|
328
|
-
parse([])[:inherit_exit_status].
|
329
|
+
expect(parse([])[:inherit_exit_status]).to eq false
|
329
330
|
end
|
330
331
|
|
331
332
|
it 'can be set with --inherit-exit-status or -i' do
|
332
|
-
parse(['--inherit-exit-status'])[:inherit_exit_status].
|
333
|
-
parse(['-i'])[:inherit_exit_status].
|
333
|
+
expect(parse(['--inherit-exit-status'])[:inherit_exit_status]).to be true
|
334
|
+
expect(parse(['-i'])[:inherit_exit_status]).to be true
|
334
335
|
end
|
335
336
|
end
|
336
337
|
|
337
338
|
describe ':xmpfilter_style' do
|
338
339
|
it 'defaults to false' do
|
339
|
-
parse([])[:xmpfilter_style].
|
340
|
+
expect(parse([])[:xmpfilter_style]).to be false
|
340
341
|
end
|
341
342
|
|
342
343
|
it 'can be set with --xmpfilter-style or -x' do
|
343
|
-
parse(['--xmpfilter-style'])[:xmpfilter_style].
|
344
|
-
parse(['-x'])[:xmpfilter_style].
|
344
|
+
expect(parse(['--xmpfilter-style'])[:xmpfilter_style]).to be true
|
345
|
+
expect(parse(['-x'])[:xmpfilter_style]).to be true
|
345
346
|
end
|
346
347
|
end
|
347
348
|
|
348
349
|
describe ':debugger' do
|
349
350
|
it 'defaults to a debugger that is disabled' do
|
350
|
-
parse([], :fake_stream)[:debugger].
|
351
|
+
expect(parse([], :fake_stream)[:debugger]).to_not be_enabled
|
351
352
|
end
|
352
353
|
|
353
354
|
it 'can be enabled with --debug or -g' do
|
354
|
-
parse(['--debug'], :fake_stream)[:debugger].
|
355
|
-
parse(['-g'], :fake_stream)[:debugger].
|
355
|
+
expect(parse(['--debug'], :fake_stream)[:debugger]).to be_enabled
|
356
|
+
expect(parse(['-g'], :fake_stream)[:debugger]).to be_enabled
|
356
357
|
end
|
357
358
|
|
358
359
|
it 'sets the stream to the one passed in' do
|
359
|
-
parse(['-g'], :fake_stream)[:debugger].stream.
|
360
|
+
expect(parse(['-g'], :fake_stream)[:debugger].stream).to eq :fake_stream
|
360
361
|
end
|
361
362
|
end
|
362
363
|
|
363
364
|
describe ':shebang' do
|
364
365
|
it 'defaults to "ruby"' do
|
365
|
-
parse([])[:shebang].
|
366
|
+
expect(parse([])[:shebang]).to eq 'ruby'
|
366
367
|
end
|
367
368
|
|
368
369
|
it 'can be enabled with --shebang' do
|
369
|
-
parse(['--shebang', 'not_ruby'])[:shebang].
|
370
|
+
expect(parse(['--shebang', 'not_ruby'])[:shebang]).to eq 'not_ruby'
|
370
371
|
end
|
371
372
|
|
372
373
|
it 'sets an error if not given a next arg to execute' do
|
373
|
-
parse([]).
|
374
|
-
parse(['--shebang']).
|
374
|
+
expect(parse([])).to_not have_error /--shebang/
|
375
|
+
expect(parse(['--shebang'])).to have_error /--shebang/
|
375
376
|
end
|
376
377
|
end
|
377
378
|
|
378
379
|
describe ':number_of_captures' do
|
379
380
|
it 'defaults to infinity' do
|
380
|
-
parse([])[:number_of_captures].
|
381
|
+
expect(parse([])[:number_of_captures]).to eq Float::INFINITY
|
381
382
|
end
|
382
383
|
|
383
384
|
it 'can be set with --number-of-captures or -n' do
|
384
|
-
parse(['-n', '10'])[:number_of_captures].
|
385
|
-
parse(['--number-of-captures', '10'])[:number_of_captures].
|
385
|
+
expect(parse(['-n', '10'])[:number_of_captures]).to eq 10
|
386
|
+
expect(parse(['--number-of-captures', '10'])[:number_of_captures]).to eq 10
|
386
387
|
end
|
387
388
|
|
388
389
|
it_behaves_like 'it requires a positive int argument', ['-n', '--number-of-captures']
|
@@ -390,12 +391,12 @@ describe SeeingIsBelieving::Binary::ParseArgs do
|
|
390
391
|
|
391
392
|
describe ':result_as_json' do
|
392
393
|
it 'defaults to false' do
|
393
|
-
parse([])[:result_as_json].
|
394
|
+
expect(parse([])[:result_as_json]).to eq false
|
394
395
|
end
|
395
396
|
|
396
397
|
it 'can be enabled with --json or -j' do
|
397
|
-
parse(['--json'])[:result_as_json].
|
398
|
-
parse(['-j'])[:result_as_json].
|
398
|
+
expect(parse(['--json'])[:result_as_json]).to eq true
|
399
|
+
expect(parse(['-j'])[:result_as_json]).to eq true
|
399
400
|
end
|
400
401
|
end
|
401
402
|
end
|