seeing_is_believing 3.0.0.beta.4 → 3.0.0.beta.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -8
  3. data/Rakefile +1 -1
  4. data/Readme.md +65 -25
  5. data/bin/seeing_is_believing +1 -0
  6. data/docs/sib-streaming.gif +0 -0
  7. data/features/deprecated-flags.feature +62 -2
  8. data/features/errors.feature +12 -7
  9. data/features/examples.feature +143 -4
  10. data/features/flags.feature +89 -29
  11. data/features/regression.feature +58 -14
  12. data/features/support/env.rb +4 -0
  13. data/features/xmpfilter-style.feature +181 -36
  14. data/lib/seeing_is_believing.rb +44 -33
  15. data/lib/seeing_is_believing/binary.rb +31 -88
  16. data/lib/seeing_is_believing/binary/align_chunk.rb +30 -11
  17. data/lib/seeing_is_believing/binary/annotate_end_of_file.rb +10 -16
  18. data/lib/seeing_is_believing/binary/annotate_every_line.rb +5 -25
  19. data/lib/seeing_is_believing/binary/annotate_marked_lines.rb +136 -0
  20. data/lib/seeing_is_believing/binary/comment_lines.rb +8 -10
  21. data/lib/seeing_is_believing/binary/commentable_lines.rb +20 -26
  22. data/lib/seeing_is_believing/binary/config.rb +392 -0
  23. data/lib/seeing_is_believing/binary/data_structures.rb +57 -0
  24. data/lib/seeing_is_believing/binary/engine.rb +104 -0
  25. data/lib/seeing_is_believing/binary/{comment_formatter.rb → format_comment.rb} +6 -6
  26. data/lib/seeing_is_believing/binary/remove_annotations.rb +29 -28
  27. data/lib/seeing_is_believing/binary/rewrite_comments.rb +42 -43
  28. data/lib/seeing_is_believing/code.rb +105 -49
  29. data/lib/seeing_is_believing/debugger.rb +6 -5
  30. data/lib/seeing_is_believing/error.rb +6 -17
  31. data/lib/seeing_is_believing/evaluate_by_moving_files.rb +78 -129
  32. data/lib/seeing_is_believing/event_stream/consumer.rb +114 -64
  33. data/lib/seeing_is_believing/event_stream/events.rb +169 -11
  34. data/lib/seeing_is_believing/event_stream/handlers/debug.rb +57 -0
  35. data/lib/seeing_is_believing/event_stream/handlers/record_exitstatus.rb +18 -0
  36. data/lib/seeing_is_believing/event_stream/handlers/stream_json_events.rb +45 -0
  37. data/lib/seeing_is_believing/event_stream/handlers/update_result.rb +39 -0
  38. data/lib/seeing_is_believing/event_stream/producer.rb +25 -24
  39. data/lib/seeing_is_believing/hash_struct.rb +206 -0
  40. data/lib/seeing_is_believing/result.rb +20 -3
  41. data/lib/seeing_is_believing/the_matrix.rb +20 -12
  42. data/lib/seeing_is_believing/version.rb +1 -1
  43. data/lib/seeing_is_believing/wrap_expressions.rb +55 -115
  44. data/lib/seeing_is_believing/wrap_expressions_with_inspect.rb +14 -0
  45. data/seeing_is_believing.gemspec +1 -1
  46. data/spec/binary/alignment_specs.rb +27 -0
  47. data/spec/binary/comment_lines_spec.rb +3 -2
  48. data/spec/binary/config_spec.rb +657 -0
  49. data/spec/binary/engine_spec.rb +97 -0
  50. data/spec/binary/{comment_formatter_spec.rb → format_comment_spec.rb} +2 -2
  51. data/spec/binary/marker_spec.rb +71 -0
  52. data/spec/binary/options_spec.rb +0 -0
  53. data/spec/binary/remove_annotations_spec.rb +31 -18
  54. data/spec/binary/rewrite_comments_spec.rb +26 -11
  55. data/spec/code_spec.rb +190 -6
  56. data/spec/debugger_spec.rb +4 -0
  57. data/spec/evaluate_by_moving_files_spec.rb +38 -20
  58. data/spec/event_stream_spec.rb +265 -116
  59. data/spec/hash_struct_spec.rb +514 -0
  60. data/spec/seeing_is_believing_spec.rb +108 -46
  61. data/spec/spec_helper.rb +9 -0
  62. data/spec/wrap_expressions_spec.rb +207 -172
  63. metadata +30 -18
  64. data/docs/for-presentations +0 -33
  65. data/lib/seeing_is_believing/binary/annotate_xmpfilter_style.rb +0 -128
  66. data/lib/seeing_is_believing/binary/interpret_flags.rb +0 -156
  67. data/lib/seeing_is_believing/binary/parse_args.rb +0 -263
  68. data/lib/seeing_is_believing/event_stream/update_result.rb +0 -24
  69. data/lib/seeing_is_believing/inspect_expressions.rb +0 -21
  70. data/lib/seeing_is_believing/parser_helpers.rb +0 -82
  71. data/spec/binary/interpret_flags_spec.rb +0 -332
  72. data/spec/binary/parse_args_spec.rb +0 -415
@@ -1,415 +0,0 @@
1
- require 'spec_helper'
2
- require 'seeing_is_believing/binary/parse_args'
3
-
4
- RSpec.describe SeeingIsBelieving::Binary::ParseArgs do
5
- RSpec::Matchers.define :have_error do |error_assertion|
6
- match do |options|
7
- options[:errors].find do |error|
8
- case error_assertion
9
- when Regexp
10
- error_assertion =~ error
11
- else
12
- error_assertion == error
13
- end
14
- end
15
- end
16
-
17
- failure_message do |options|
18
- "#{error_assertion.inspect} should have matched one of the errors: #{options[:errors].inspect}"
19
- end
20
-
21
- failure_message_when_negated do |options|
22
- "#{error_assertion.inspect} should NOT have matched any of the errors: #{options[:errors].inspect}"
23
- end
24
- end
25
-
26
- def parse(args)
27
- SeeingIsBelieving::Binary::ParseArgs.call args
28
- end
29
-
30
- def matrix_file
31
- 'seeing_is_believing/the_matrix'
32
- end
33
-
34
- shared_examples 'it requires a positive int argument' do |flags|
35
- it 'expects an integer argument' do
36
- flags.each do |flag|
37
- expect(parse([flag, '1'])).to_not have_error /#{flag}/
38
- expect(parse([flag, '0'])).to have_error /#{flag}/
39
- expect(parse([flag, '-1'])).to have_error /#{flag}/
40
- expect(parse([flag, '1.0'])).to have_error /#{flag}/
41
- expect(parse([flag, 'a'])).to have_error /#{flag}/
42
- expect(parse([flag, '' ])).to have_error /#{flag}/
43
- expect(parse([flag ])).to have_error /#{flag}/
44
- end
45
- end
46
- end
47
-
48
- shared_examples 'it requires a non-negative float or int' do |flags|
49
- it 'expects a non-negative float or int argument' do
50
- flags.each do |flag|
51
- expect(parse([flag, '1'])).to_not have_error /#{flag}/
52
- expect(parse([flag, '0'])).to_not have_error /#{flag}/
53
- expect(parse([flag, '-1'])).to have_error /#{flag}/
54
- expect(parse([flag,'-1.0'])).to have_error /#{flag}/
55
- expect(parse([flag, '1.0'])).to_not have_error /#{flag}/
56
- expect(parse([flag, 'a'])).to have_error /#{flag}/
57
- expect(parse([flag, '' ])).to have_error /#{flag}/
58
- expect(parse([flag ])).to have_error /#{flag}/
59
- end
60
- end
61
- end
62
-
63
- it 'does not mutate the input array' do
64
- ary = ['a']
65
- parse(ary)
66
- expect(ary).to eq ['a']
67
- end
68
-
69
- it 'can interpret conjoined short-flags' do
70
- expect(parse(['-hjg'])).to eq parse(['-h', '-j', '-g'])
71
- end
72
-
73
- it 'can interpret conjoined short-flags where one of them is h+' do
74
- expect(parse(['-h+jg'])).to eq parse(['-h+', '-j', '-g'])
75
- expect(parse(['-jh+g'])).to eq parse(['-j', '-h+', '-g'])
76
- expect(parse(['-jgh+'])).to eq parse(['-j', '-g', '-h+'])
77
- end
78
-
79
- specify 'unknown options set an error' do
80
- expect(parse(['--xyz' ])).to have_error 'Unknown option: "--xyz"'
81
- expect(parse(['-y' ])).to have_error 'Unknown option: "-y"'
82
- expect(parse(['-y', 'b'])).to have_error 'Unknown option: "-y"'
83
- expect(parse(['-+h' ])).to have_error 'Unknown option: "-+"'
84
- end
85
-
86
- example 'example: multiple args' do
87
- options = parse(%w[filename -h -r torequire])
88
- expect(options[:filename]).to eq 'filename'
89
- expect(options[:require]).to include 'torequire'
90
- expect(options[:help]).to be_a_kind_of String
91
- expect(options[:errors]).to be_empty
92
- end
93
-
94
- describe ':filename' do
95
- it 'defaults to nil' do
96
- expect(parse([])[:filename]).to be_nil
97
- end
98
-
99
- it 'is the first non-flag' do
100
- expect(parse(['a'])[:filename]).to eq 'a'
101
- expect(parse(['-x', 'a'])[:filename]).to eq 'a'
102
- expect(parse(['a', '-x'])[:filename]).to eq 'a'
103
- end
104
-
105
- it 'records all filenames it sees' do
106
- expect(parse([])[:filenames]).to eq []
107
- expect(parse(['a'])[:filenames]).to eq ['a']
108
- expect(parse(['a', 'b'])[:filenames]).to eq ['a', 'b']
109
- end
110
- end
111
-
112
- describe ':result_length' do
113
- it 'defaults to infinity' do
114
- expect(parse([])[:max_result_length]).to eq Float::INFINITY
115
- end
116
-
117
- it 'is set with -D and --result-length' do
118
- expect(parse(['-D', '10'])[:max_result_length]).to eq 10
119
- expect(parse(['--result-length', '10'])[:max_result_length]).to eq 10
120
- end
121
-
122
- it_behaves_like 'it requires a positive int argument', ['-D', '--result-length']
123
- end
124
-
125
- describe ':max_line_length' do
126
- it 'defaults to infinity' do
127
- expect(parse([])[:max_line_length]).to eq Float::INFINITY
128
- end
129
-
130
- it 'is set with -d and --line-length' do
131
- expect(parse(['-d', '10'])[:max_line_length]).to eq 10
132
- expect(parse(['--line-length', '10'])[:max_line_length]).to eq 10
133
- end
134
-
135
- it_behaves_like 'it requires a positive int argument', ['-d', '--line-length']
136
- end
137
-
138
- describe :require do
139
- it 'defaults to the matrix file array' do
140
- expect(parse([])[:require]).to eq [matrix_file]
141
- end
142
-
143
- it '-r and --require sets each required file into the result array' do
144
- expect(parse(%w[-r f1 --require f2])[:require]).to eq [matrix_file, 'f1', 'f2']
145
- end
146
-
147
- it 'sets an error if not provided with a filename' do
148
- expect(parse(['--require', 'f'])).to_not have_error /-r/
149
- expect(parse(['-r'])).to have_error /-r\b/
150
- expect(parse(['--require'])).to have_error /--require\b/
151
- end
152
- end
153
-
154
- describe ':help' do
155
- it 'defaults to nil' do
156
- expect(parse([])[:help]).to be_nil
157
- end
158
-
159
- it 'is set to "help" with -h and --help and -help' do
160
- expect(parse(['-h'])[:help]).to eq 'help'
161
- expect(parse(['--help'])[:help]).to eq 'help'
162
- end
163
-
164
- it 'is set to "help+" with examples help screen with --help+ and -h+' do
165
- expect(parse(['-h+'])[:help]).to eq 'help+'
166
- expect(parse(['--help+'])[:help]).to eq 'help+'
167
- end
168
- end
169
-
170
- describe 'short and long help_screen' do
171
- specify 'they are the short and long help screens' do
172
- short = parse([])[:short_help_screen]
173
- long = parse([])[:long_help_screen]
174
- expect(short.length).to be < long.length
175
- expect(short).to include 'Usage'
176
- expect(long).to include 'Usage'
177
- expect(short).to_not include 'Examples'
178
- expect(long).to include 'Examples'
179
- end
180
- end
181
-
182
- describe ':program_from_args' do
183
- it 'defaults to nil' do
184
- expect(parse([])[:program_from_args]).to be_nil
185
- end
186
-
187
- it 'is set with -e or --program, and takes the next arg' do
188
- expect(parse(['-e', '1'])[:program_from_args]).to eq '1'
189
- expect(parse(['--program', '1'])[:program_from_args]).to eq '1'
190
- end
191
-
192
- it 'sets an error if not given a program' do
193
- expect(parse([])).to_not have_error /-e/
194
- expect(parse([])).to_not have_error /--program/
195
- expect(parse(['-e'])).to have_error /-e/
196
- expect(parse(['--program'])).to have_error /--program/
197
- end
198
- end
199
-
200
- describe':load_path' do
201
- it 'defaults to an empty array' do
202
- expect(parse([])[:load_path]).to be_empty
203
- end
204
-
205
- specify '-I and --load-path sets each required file into the result array' do
206
- expect(parse(%w[-I f1 --load-path f2])[:load_path]).to eq %w[f1 f2]
207
- end
208
-
209
- it 'sets an error if not provided with a dir' do
210
- expect(parse(['--load-path', 'f'])).to_not have_error /-I/
211
- expect(parse(['-I'])).to have_error /-I\b/
212
- expect(parse(['--load-path'])).to have_error /--load-path\b/
213
- end
214
- end
215
-
216
- describe ':encoding' do
217
- it 'defaults to nil' do
218
- expect(parse([])[:encoding]).to be_nil
219
- end
220
-
221
- specify '-K and --encoding sets the encoding to the next argument' do
222
- expect(parse(%w[-K u])[:encoding]).to eq 'u'
223
- expect(parse(%w[--encoding u])[:encoding]).to eq 'u'
224
- end
225
-
226
- specify 'with -K, the argument can be placed immediately after it (e.g. -Ku) because Ruby allows this' do
227
- expect(parse(['-Ku'])[:encoding]).to eq 'u'
228
- expect(parse(['-Ku'])).to_not have_error /-K/
229
- end
230
-
231
- it 'sets an error if not provided with an encoding' do
232
- expect(parse(['-Ku'])).to_not have_error /-K/
233
- expect(parse(['-K u'])).to_not have_error /-K/
234
- expect(parse(['--encoding', 'u'])).to_not have_error /--encoding/
235
- expect(parse(['-K'])).to have_error /-K/
236
- expect(parse(['--encoding'])).to have_error /--encoding/
237
- end
238
- end
239
-
240
- describe ':as' do
241
- it 'defaults to nil' do
242
- expect(parse([])[:as]).to be_nil
243
- end
244
-
245
- it 'can be set with -a and --as' do
246
- expect(parse(%w[-a abc])[:as]).to eq 'abc'
247
- expect(parse(%w[--as abc])[:as]).to eq 'abc'
248
- end
249
-
250
- it 'sets an error if not provided with a filename' do
251
- expect(parse(%w[-a f])).to_not have_error /-a/
252
- expect(parse(%w[-as f])).to_not have_error /--as/
253
- expect(parse(%w[-a ])).to have_error /-a/
254
- expect(parse(%w[--as ])).to have_error /--as/
255
- end
256
- end
257
-
258
- describe ':clean' do
259
- it 'defaults to false' do
260
- expect(parse([])[:clean]).to eq false
261
- end
262
-
263
- it 'can be set with -c and --clean' do
264
- expect(parse(%w[-c])[:clean]).to eq true
265
- expect(parse(%w[--clean])[:clean]).to eq true
266
- end
267
- end
268
-
269
- describe ':version' do
270
- it 'defaults to false' do
271
- expect(parse([])[:version]).to eq false
272
- end
273
-
274
- it 'can be set with -v and --version' do
275
- expect(parse(%w[-v])[:version]).to eq true
276
- expect(parse(%w[--version])[:version]).to eq true
277
- end
278
- end
279
-
280
- describe ':timeout' do
281
- it 'defaults to 0' do
282
- expect(parse([])[:timeout]).to eq 0
283
- end
284
-
285
- it_behaves_like 'it requires a non-negative float or int', ['-t', '--timeout']
286
- end
287
-
288
- describe ':alignment_strategy' do
289
- # TODO: maybe change the default?
290
- it 'defaults to "chunk"' do
291
- expect(parse([])[:alignment_strategy]).to eq 'chunk'
292
- end
293
-
294
- specify '-s and --alignment-strategy sets the alignment strategy' do
295
- expect(parse(['-s', 'chunk'])[:alignment_strategy]).to eq 'chunk'
296
- expect(parse(['--alignment-strategy', 'chunk'])[:alignment_strategy]).to eq 'chunk'
297
- end
298
-
299
- it 'accepts values: file, line, chunk' do
300
- expect(parse(['-s', 'file'])[:alignment_strategy]).to eq 'file'
301
- expect(parse(['-s', 'line'])[:alignment_strategy]).to eq 'line'
302
- expect(parse(['-s', 'chunk'])[:alignment_strategy]).to eq 'chunk'
303
- end
304
-
305
- it 'sets an error if not provided with a strategy' do
306
- expect(parse(['-s', 'file'])).to_not have_error /alignment-strategy/
307
- end
308
- end
309
-
310
- describe ':inherit_exit_status' do
311
- it 'defaults to false' do
312
- expect(parse([])[:inherit_exit_status]).to eq false
313
- end
314
-
315
- it 'can be set with --inherit-exit-status or -i' do
316
- expect(parse(['--inherit-exit-status'])[:inherit_exit_status]).to be true
317
- expect(parse(['-i'])[:inherit_exit_status]).to be true
318
- end
319
- end
320
-
321
- describe ':xmpfilter_style' do
322
- it 'defaults to false' do
323
- expect(parse([])[:xmpfilter_style]).to be false
324
- end
325
-
326
- it 'can be set with --xmpfilter-style or -x' do
327
- expect(parse(['--xmpfilter-style'])[:xmpfilter_style]).to be true
328
- expect(parse(['-x'])[:xmpfilter_style]).to be true
329
- end
330
- end
331
-
332
- describe ':debug' do
333
- it 'defaults to a false' do
334
- expect(parse([])[:debug]).to eq false
335
- end
336
-
337
- it 'can be enabled with --debug or -g' do
338
- expect(parse(['--debug'])[:debug]).to eq true
339
- expect(parse(['-g'])[:debug]).to eq true
340
- end
341
- end
342
-
343
- describe ':shebang' do
344
- it 'is added to the list of deprecated flags' do
345
- expect(parse([])[:deprecated_flags]).to eq []
346
- parsed = parse(['--shebang', 'not_ruby', 'other'])
347
- expect(parsed[:shebang]).to eq nil
348
- expect(parsed[:deprecated_flags]).to eq ['--shebang', 'not_ruby']
349
- end
350
-
351
- it 'sets an error if not given a next arg to execute' do
352
- expect(parse([])).to_not have_error /--shebang/
353
- expect(parse(['--shebang'])).to have_error /--shebang/
354
- end
355
- end
356
-
357
- describe ':number_of_captures' do
358
- it 'defaults to infinity' do
359
- expect(parse([])[:number_of_captures]).to eq Float::INFINITY
360
- end
361
-
362
- it 'can be set with --number-of-captures or -n' do
363
- expect(parse(['-n', '10'])[:number_of_captures]).to eq 10
364
- expect(parse(['--number-of-captures', '10'])[:number_of_captures]).to eq 10
365
- end
366
-
367
- it_behaves_like 'it requires a positive int argument', ['-n', '--number-of-captures']
368
- end
369
-
370
- describe ':result_as_json' do
371
- it 'defaults to false' do
372
- expect(parse([])[:result_as_json]).to eq false
373
- end
374
-
375
- it 'can be enabled with --json or -j' do
376
- expect(parse(['--json'])[:result_as_json]).to eq true
377
- expect(parse(['-j'])[:result_as_json]).to eq true
378
- end
379
- end
380
-
381
- describe ':markers' do
382
- it 'defaults to a hash with :value, :exception, :stdout, and :stderr' do
383
- expect(parse([])[:markers].keys).to eq [:value, :exception, :stdout, :stderr]
384
- end
385
-
386
- def assert_default(marker_name, value)
387
- expect(parse([])[:markers][marker_name]).to eq value
388
- end
389
-
390
- it('defaults :value to "# => "') { assert_default :value , "# => " }
391
- it('defaults :exception to "# ~> "') { assert_default :exception , "# ~> " }
392
- it('defaults :stdout to "# >> "') { assert_default :stdout , "# >> " }
393
- it('defaults :stderr to "# !> "') { assert_default :stderr , "# !> " }
394
-
395
- # TODO: When things get a little more stable, don't feel like adding all the cukes to play with this right now
396
- it 'overrides :value with --value-marker'
397
- it 'overrides :exception with --exception-marker'
398
- it 'overrides :stdout with --stdout-marker'
399
- it 'overrides :stderr with --stderr-marker'
400
- end
401
-
402
- describe ':marker_regexes' do
403
- it 'is a hash with the same keys as the markers' do
404
- marker_keys = parse([])[:markers].keys
405
- marker_regexes_keys = parse([])[:marker_regexes].keys
406
- expect(marker_regexes_keys).to eq marker_keys
407
- end
408
-
409
- it 'overrides :value with --value-regex'
410
- it 'overrides :exception with --exception-regex'
411
- it 'overrides :stdout with --stdout-regex'
412
- it 'overrides :stderr with --stderr-regex'
413
- end
414
- end
415
-