seeing_is_believing 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae86d44e9afffb2928ac761a5bf8f6810ec1c996
4
- data.tar.gz: 4c37f23d51da74cde81e85f2c48b1928daeedce9
3
+ metadata.gz: 5d761a62840425753a50b764d74caad42f1ff790
4
+ data.tar.gz: eb674e4076644502c643453699d1744de4161315
5
5
  SHA512:
6
- metadata.gz: 08e8e66324e9360ee680327765f7d633a0862ab22237148ddd49d0bfc78ebfaa89f9466a4390dc5404126aa791256cbb437aa346ebbfc22c904a231fab042c35
7
- data.tar.gz: bd56f998a57e28b06bcfc04782feb64ccb1e7466503cec372b08f9f77102a70df4c05dd7e9079f45b441ed2c72ded198d02aedc653c8be2c43d69448e48a286f
6
+ metadata.gz: 4e51b01ba8efe1a01b3602132ebb81a7ef935af700dfe05dbf4671cec579729dd3bb86cb83bba124c595bd7623e4612752e7266724fc7f9d3a6ba61b3cee5bba
7
+ data.tar.gz: 70bd344383af51e11e3edf04dcadfdee0c37535dbda6fbe6c1fe4ff582c9c5603a106db38e6b752e0cac47bc710bac803cdd82d7c37c932fe377cc2e605a5407
data/Readme.md CHANGED
@@ -93,18 +93,11 @@ Known Issues
93
93
  * `exit!` ignores callbacks that `SeeingIsBelieving` uses to communicate the results back to the main app. If you call it, `SeeingIsBelieving` will blow up. We could "fix" this by overriding it, but I feel like that would violate the meaning of `exit!`, so basically, just don't call that method.
94
94
  * The code to find the data segment is naive, and could wind up interpolating results into a string or something
95
95
 
96
- Todo
97
- ====
98
-
99
- * Sublime: Merge xmpfilter option into main after 2.0 release
100
- * Make a new video
101
-
102
96
  Shit that will probably never get done (or if it does, won't be until after 2.0)
103
97
  ================================================================================
104
98
 
105
99
  * How about if begin/rescue/end was able to record the result on the rescue section
106
100
  * What about recording the result of a line inside of a string interpolation, e.g. "a#{\n1\n}b" could record line 2 is 1 and line 3 is "a\n1\nb"
107
- * Add a flag to allow you to just get the results so that it can be easily used without a Ruby runtime (difficult in that its unclear how to separate line output from stdout, stderr, exit status, exceptions, etc. Maybe just serialize the result as JSON?)
108
101
  * Be able to clean an invalid file (used to be able to do this, but parser can't identify comments in an invalid file the way that I'm currently using it, cuke is still there, marked as @not-implemented)
109
102
  * If given a file with a unicode character, but not set unicode, inform the user
110
103
 
@@ -184,6 +184,28 @@ Feature: Using flags
184
184
  When I run "seeing_is_believing --line-length 14 line_lengths2.rb"
185
185
  Then stdout is "12345"
186
186
 
187
+ Scenario: --number-of-captures determines how many times a line will be recorded
188
+ Given the file "number_of_captures.rb":
189
+ """
190
+ 5.times do |i|
191
+ i
192
+ end
193
+ """
194
+ When I run "seeing_is_believing --number-of-captures 4 number_of_captures.rb"
195
+ Then stdout is:
196
+ """
197
+ 5.times do |i| # => 5
198
+ i # => 0, 1, 2, 3, ...
199
+ end # => 5
200
+ """
201
+ When I run "seeing_is_believing --number-of-captures 5 number_of_captures.rb"
202
+ Then stdout is:
203
+ """
204
+ 5.times do |i| # => 5
205
+ i # => 0, 1, 2, 3, 4
206
+ end # => 5
207
+ """
208
+
187
209
  Scenario: --xmpfilter-style respects the line formatting (but not currently alignment strategies, it just preserves submitted alignment)
188
210
  Given the file "line_lengths3.rb":
189
211
  """
@@ -537,3 +559,44 @@ Feature: Using flags
537
559
  When I run "chmod +x fake_ruby"
538
560
  When I run "seeing_is_believing -e 123 --shebang ./fake_ruby"
539
561
  Then stdout is "123 # => /omg/"
562
+
563
+ Scenario: --json
564
+ Given the file "all_kinds_of_output.rb":
565
+ """
566
+ 3.times do |i|
567
+ i.to_s
568
+ end
569
+ $stdout.puts "b"
570
+ $stderr.puts "c"
571
+ raise "omg"
572
+ """
573
+ When I run "seeing_is_believing --json all_kinds_of_output.rb"
574
+ Then the exit status is 0
575
+ And stdout is the JSON:
576
+ """
577
+ {
578
+ "lines": {
579
+ "1": { "exception": null, "results": ["3"] },
580
+ "2": { "exception": null, "results": ["\"0\"", "\"1\"", "\"2\""] },
581
+ "3": { "exception": null, "results": ["3"] },
582
+ "4": { "exception": null, "results": ["nil"] },
583
+ "5": { "exception": null, "results": ["nil"] },
584
+ "6": { "exception": { "class_name": "RuntimeError",
585
+ "message": "omg",
586
+ "backtrace": ["all_kinds_of_output.rb:6:in `<main>'"]
587
+ },
588
+ "results": []
589
+ }
590
+ },
591
+ "exception": {
592
+ "line_number_in_this_file": 6,
593
+ "class_name": "RuntimeError",
594
+ "message": "omg",
595
+ "backtrace": ["all_kinds_of_output.rb:6:in `<main>'"]
596
+ },
597
+ "stdout": "b\n",
598
+ "stderr": "c\n",
599
+ "exit_status": 1
600
+ }
601
+ """
602
+
@@ -10,3 +10,9 @@ end
10
10
  Then 'stdout is exactly:' do |code|
11
11
  @last_executed.stdout.should == eval_curlies(code)
12
12
  end
13
+
14
+ Then 'stdout is the JSON:' do |json|
15
+ expected = JSON.parse(json)
16
+ actual = JSON.parse(@last_executed.stdout)
17
+ actual.should == expected
18
+ end
data/for-presentations ADDED
@@ -0,0 +1,33 @@
1
+ # intro
2
+ # show the website!
3
+ # omg, what's it do?
4
+ # integrates with the editors
5
+
6
+ # walk through example of how to use it
7
+ # make a user class or something
8
+ # show the -n flag
9
+
10
+ # features
11
+ # iteration
12
+ # method and invocations
13
+ # multilinezzz
14
+ # mutliple levels of nesting (e.g. class definition)
15
+ # printing to stdout/stderr, respecting DATA segment
16
+ # respecting macros
17
+ # exceptions displayed where they occur
18
+ # records hash results
19
+ # syntax errors
20
+ # total fucking failure
21
+
22
+ # show the snippets
23
+ # s_arb
24
+ # s_sinatra
25
+ # s_nokogiri
26
+ # s_reflection
27
+
28
+ # Show how to customize
29
+ # --line-length n
30
+ # --result-length n
31
+ # --alignment-strategy name
32
+ # --timeout n
33
+ # --debug
@@ -17,16 +17,17 @@ class SeeingIsBelieving
17
17
  end
18
18
 
19
19
  def initialize(program, options={})
20
- @program = program
21
- @matrix_filename = options[:matrix_filename]
22
- @filename = options[:filename]
23
- @stdin = to_stream options.fetch(:stdin, '')
24
- @require = options.fetch :require, []
25
- @load_path = options.fetch :load_path, []
26
- @encoding = options.fetch :encoding, nil
27
- @timeout = options[:timeout]
28
- @debugger = options.fetch :debugger, Debugger.new(stream: nil)
29
- @ruby_executable = options.fetch :ruby_executable, 'ruby'
20
+ @program = program
21
+ @matrix_filename = options[:matrix_filename]
22
+ @filename = options[:filename]
23
+ @stdin = to_stream options.fetch(:stdin, '')
24
+ @require = options.fetch :require, []
25
+ @load_path = options.fetch :load_path, []
26
+ @encoding = options.fetch :encoding, nil
27
+ @timeout = options[:timeout]
28
+ @debugger = options.fetch :debugger, Debugger.new(stream: nil)
29
+ @ruby_executable = options.fetch :ruby_executable, 'ruby'
30
+ @number_of_captures = options.fetch :number_of_captures, Float::INFINITY
30
31
  end
31
32
 
32
33
  def call
@@ -50,7 +51,7 @@ class SeeingIsBelieving
50
51
 
51
52
  def program_that_will_record_expressions
52
53
  WrapExpressions.call "#@program\n",
53
- before_all: "begin;",
54
+ before_all: "begin; $SiB.number_of_captures = #{number_of_captures_as_str}; ",
54
55
  after_all: ";rescue Exception;"\
55
56
  "line_number = $!.backtrace.grep(/\#{__FILE__}/).first[/:\\d+/][1..-1].to_i;"\
56
57
  "$SiB.record_exception line_number, $!;"\
@@ -66,15 +67,21 @@ class SeeingIsBelieving
66
67
  filename = @filename || File.join(dir, 'program.rb')
67
68
  EvaluateByMovingFiles.new(program,
68
69
  filename,
69
- input_stream: @stdin,
70
- matrix_filename: matrix_filename,
71
- require: @require,
72
- load_path: @load_path,
73
- encoding: @encoding,
74
- timeout: @timeout,
75
- ruby_executable: @ruby_executable,
76
- debugger: @debugger)
70
+ input_stream: @stdin,
71
+ matrix_filename: matrix_filename,
72
+ require: @require,
73
+ load_path: @load_path,
74
+ encoding: @encoding,
75
+ timeout: @timeout,
76
+ ruby_executable: @ruby_executable,
77
+ debugger: @debugger,
78
+ number_of_captures: @number_of_captures)
77
79
  .call
78
80
  end
79
81
  end
82
+
83
+ def number_of_captures_as_str
84
+ return 'Float::INFINITY' if @number_of_captures == Float::INFINITY
85
+ @number_of_captures.inspect
86
+ end
80
87
  end
@@ -44,6 +44,7 @@ class SeeingIsBelieving
44
44
  elsif invalid_syntax? then print_syntax_error ; NONDISPLAYABLE_ERROR_STATUS
45
45
  elsif (evaluate_program; program_timedout?) then print_timeout_error ; NONDISPLAYABLE_ERROR_STATUS
46
46
  elsif something_blew_up? then print_unexpected_error ; NONDISPLAYABLE_ERROR_STATUS
47
+ elsif output_as_json? then print_result_as_json ; SUCCESS_STATUS
47
48
  else print_program ; program_exit_status
48
49
  end
49
50
  end
@@ -173,5 +174,40 @@ class SeeingIsBelieving
173
174
  def print_cleaned_program
174
175
  stdout.print CleanBody.call(body, true)
175
176
  end
177
+
178
+ def output_as_json?
179
+ flags[:result_as_json]
180
+ end
181
+
182
+ def print_result_as_json
183
+ require 'json'
184
+ stdout.puts JSON.dump result_as_data_structure
185
+ end
186
+
187
+ def result_as_data_structure
188
+ results = printer.results
189
+ { stdout: results.stdout,
190
+ stderr: results.stderr,
191
+ exit_status: results.exitstatus,
192
+ exception: if results.has_exception?
193
+ { line_number_in_this_file: results.each_with_line_number.find { |line_number, result| result.has_exception? }.first,
194
+ class_name: results.exception.class_name,
195
+ message: results.exception.message,
196
+ backtrace: results.exception.backtrace,
197
+ }
198
+ end,
199
+ lines: results.each_with_line_number.each_with_object(Hash.new) { |(line_number, result), hash|
200
+ hash[line_number] = { results: result.to_a,
201
+ exception: if result.has_exception?
202
+ { class_name: results.exception.class_name,
203
+ message: results.exception.message,
204
+ backtrace: results.exception.backtrace,
205
+ }
206
+ end
207
+ }
208
+ },
209
+ }
210
+ end
211
+
176
212
  end
177
213
  end
@@ -27,14 +27,15 @@ class SeeingIsBelieving
27
27
  self.options = options
28
28
  self.body = CleanBody.call uncleaned_body, !xmpfilter_style
29
29
  self.results = SeeingIsBelieving.call body,
30
- filename: (options[:as] || options[:filename]),
31
- require: options[:require],
32
- load_path: options[:load_path],
33
- encoding: options[:encoding],
34
- stdin: options[:stdin],
35
- timeout: options[:timeout],
36
- debugger: debugger,
37
- ruby_executable: options[:shebang]
30
+ filename: (options[:as] || options[:filename]),
31
+ require: options[:require],
32
+ load_path: options[:load_path],
33
+ encoding: options[:encoding],
34
+ stdin: options[:stdin],
35
+ timeout: options[:timeout],
36
+ debugger: debugger,
37
+ ruby_executable: options[:shebang],
38
+ number_of_captures: options[:number_of_captures]
38
39
  end
39
40
 
40
41
  def call
@@ -30,12 +30,14 @@ class SeeingIsBelieving
30
30
  when '-v', '--version' then options[:version] = true
31
31
  when '-x', '--xmpfilter-style' then options[:xmpfilter_style] = true
32
32
  when '-i', '--inherit-exit-status' then options[:inherit_exit_status] = true
33
+ when '-j', '--json' then options[:result_as_json] = true
33
34
  when '-g', '--debug' then options[:debugger] = Debugger.new(stream: outstream, colour: true)
34
- when '-l', '--start-line' then extract_positive_int_for :start_line, arg
35
- when '-L', '--end-line' then extract_positive_int_for :end_line, arg
36
- when '-d', '--line-length' then extract_positive_int_for :max_line_length, arg
37
- when '-D', '--result-length' then extract_positive_int_for :max_result_length, arg
38
- when '-t', '--timeout' then extract_non_negative_float_for :timeout, arg
35
+ when '-l', '--start-line' then extract_positive_int_for :start_line, arg
36
+ when '-L', '--end-line' then extract_positive_int_for :end_line, arg
37
+ when '-d', '--line-length' then extract_positive_int_for :max_line_length, arg
38
+ when '-D', '--result-length' then extract_positive_int_for :max_result_length, arg
39
+ when '-n', '--number-of-captures' then extract_positive_int_for :number_of_captures, arg
40
+ when '-t', '--timeout' then extract_non_negative_float_for :timeout, arg
39
41
  when '-r', '--require' then next_arg("#{arg} expected a filename as the following argument but did not see one") { |filename| options[:require] << filename }
40
42
  when '-I', '--load-path' then next_arg("#{arg} expected a directory as the following argument but did not see one") { |dir| options[:load_path] << dir }
41
43
  when '-e', '--program' then next_arg("#{arg} expected a program as the following argument but did not see one") { |program| options[:program] = program }
@@ -85,12 +87,14 @@ class SeeingIsBelieving
85
87
  end_line: Float::INFINITY,
86
88
  max_line_length: Float::INFINITY,
87
89
  max_result_length: Float::INFINITY,
90
+ number_of_captures: Float::INFINITY,
88
91
  timeout: 0, # timeout lib treats this as infinity
89
92
  errors: [],
90
93
  require: [],
91
94
  load_path: [],
92
95
  alignment_strategy: AlignChunk,
93
96
  shebang: 'ruby',
97
+ result_as_json: false,
94
98
  }
95
99
  end
96
100
 
@@ -147,6 +151,9 @@ Usage: seeing_is_believing [options] [filename]
147
151
  -L, --end-line n # line number to stop showing results on
148
152
  -d, --line-length n # max length of the entire line (only truncates results, not source lines)
149
153
  -D, --result-length n # max length of the portion after the "#{VALUE_MARKER}"
154
+ -n, --number-of-captures n # how many results to capture for a given line
155
+ if you had 1 million results on a line, it could take a long time to record
156
+ and serialize them, you might limit it to 1000 results as an optimization
150
157
  -s, --alignment-strategy name # select the alignment strategy:
151
158
  chunk (DEFAULT) => each chunk of code is at the same alignment
152
159
  file => the entire file is at the same alignment
@@ -160,6 +167,7 @@ Usage: seeing_is_believing [options] [filename]
160
167
  -c, --clean # remove annotations from previous runs of seeing_is_believing
161
168
  -g, --debug # print debugging information (useful if program is fucking up, or if you want to brag)
162
169
  -x, --xmpfilter-style # annotate marked lines instead of every line
170
+ -j, --json # print results in json format (i.e. so another program can consume them)
163
171
  -i, --inherit-exit-status # exit with the exit status of the program being eval
164
172
  --shebang ruby-executable # if you want SiB to use some ruby other than the one in the path
165
173
  -v, --version # print the version (#{VERSION})
@@ -1,11 +1,8 @@
1
1
  require 'seeing_is_believing/has_exception'
2
+
2
3
  class SeeingIsBelieving
3
4
  # thin wrapper over an array, used by the result
4
5
  class Line
5
- def self.[](*elements)
6
- new(elements)
7
- end
8
-
9
6
  include HasException
10
7
  include Enumerable
11
8
 
@@ -22,8 +19,22 @@ class SeeingIsBelieving
22
19
  end
23
20
  alias to_ary to_a
24
21
 
25
- def initialize(array = [])
26
- @array = array.dup
22
+ def initialize(array = [], max_number_of_captures=Float::INFINITY)
23
+ @array = []
24
+ @max_number_of_captures = max_number_of_captures
25
+ @num_results = 0
26
+ @total_size = 0
27
+ array.each { |element| record_result element }
28
+ end
29
+
30
+ def record_result(value)
31
+ inspected = value.inspect # only invoke inspect once, b/c the inspection may be recorded
32
+ if size < @max_number_of_captures then @array << inspected
33
+ elsif size == @max_number_of_captures then @array << '...'
34
+ end
35
+ @num_results += 1
36
+ @total_size += inspected.size
37
+ self
27
38
  end
28
39
 
29
40
  def ==(ary_or_line)
@@ -33,7 +44,7 @@ class SeeingIsBelieving
33
44
 
34
45
  def inspect
35
46
  inspected_exception = has_exception? ? "#{exception.class}:#{exception.message.inspect}" : "no exception"
36
- "#<SIB:Line#{@array.inspect} #{inspected_exception}>"
47
+ "#<SIB:Line#{@array.inspect} (#@num_results, #@total_size) #{inspected_exception}>"
37
48
  end
38
49
  end
39
50
  end
@@ -6,7 +6,7 @@ class SeeingIsBelieving
6
6
  include HasException
7
7
  include Enumerable
8
8
 
9
- attr_accessor :stdout, :stderr, :exitstatus, :bug_in_sib
9
+ attr_accessor :stdout, :stderr, :exitstatus, :bug_in_sib, :number_of_captures
10
10
 
11
11
  alias bug_in_sib? bug_in_sib
12
12
 
@@ -19,7 +19,7 @@ class SeeingIsBelieving
19
19
  end
20
20
 
21
21
  def record_result(line_number, value)
22
- results_for(line_number) << value.inspect
22
+ results_for(line_number).record_result(value)
23
23
  value
24
24
  end
25
25
 
@@ -40,17 +40,34 @@ class SeeingIsBelieving
40
40
  (1..max).each { |line_number| block.call self[line_number] }
41
41
  end
42
42
 
43
+ def each_with_line_number(&block)
44
+ return to_enum :each_with_line_number unless block
45
+ max = results.keys.max || 1
46
+ (1..max).each { |line_number| block.call line_number, results_for(line_number) }
47
+ end
48
+
43
49
  def inspect
44
50
  results
45
- "#<SIB::Result #{
46
- instance_variables.map { |name| "#{name}=#{instance_variable_get(name).inspect}" }.join("\n ")
47
- }>"
51
+ variables = instance_variables.map do |name|
52
+ value = instance_variable_get(name)
53
+ inspected = if name.to_s == '@results'
54
+ "{#{value.sort_by(&:first).map { |k, v| "#{k.inspect}=>#{v.inspect}"}.join(",\n ")}}"
55
+ else
56
+ value.inspect
57
+ end
58
+ "#{name}=#{inspected}"
59
+ end
60
+ "#<SIB::Result #{variables.join "\n "}>"
61
+ end
62
+
63
+ def number_of_captures
64
+ @number_of_captures || Float::INFINITY
48
65
  end
49
66
 
50
67
  private
51
68
 
52
69
  def results_for(line_number)
53
- results[line_number] ||= Line.new
70
+ results[line_number] ||= Line.new([], number_of_captures)
54
71
  end
55
72
 
56
73
  def results
@@ -1,3 +1,3 @@
1
1
  class SeeingIsBelieving
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
@@ -363,5 +363,29 @@ describe SeeingIsBelieving::Binary::ParseArgs do
363
363
  parse(['--shebang']).should have_error /--shebang/
364
364
  end
365
365
  end
366
+
367
+ describe ':number_of_captures' do
368
+ it 'defaults to infinity' do
369
+ parse([])[:number_of_captures].should == Float::INFINITY
370
+ end
371
+
372
+ it 'can be set with --number-of-captures or -n' do
373
+ parse(['-n', '10'])[:number_of_captures].should == 10
374
+ parse(['--number-of-captures', '10'])[:number_of_captures].should == 10
375
+ end
376
+
377
+ it_behaves_like 'it requires a positive int argument', ['-n', '--number-of-captures']
378
+ end
379
+
380
+ describe ':result_as_json' do
381
+ it 'defaults to false' do
382
+ parse([])[:result_as_json].should == false
383
+ end
384
+
385
+ it 'can be enabled with --json or -j' do
386
+ parse(['--json'])[:result_as_json].should == true
387
+ parse(['-j'])[:result_as_json].should == true
388
+ end
389
+ end
366
390
  end
367
391
 
@@ -100,7 +100,7 @@ describe SeeingIsBelieving::EvaluateByMovingFiles do
100
100
  invoke('print "ç"', encoding: 'u').stdout.should == "ç"
101
101
  end
102
102
 
103
- it 'if it fails, it prints some debugging information and raises an error', t:true do
103
+ it 'if it fails, it prints some debugging information and raises an error' do
104
104
  error_stream = StringIO.new
105
105
  evaluator = described_class.new 'raise "omg"', filename, debugger: SeeingIsBelieving::Debugger.new(stream: error_stream)
106
106
  FileUtils.rm_f evaluator.temp_filename
data/spec/line_spec.rb CHANGED
@@ -1,15 +1,22 @@
1
1
  require 'seeing_is_believing/result'
2
2
 
3
- describe SeeingIsBelieving::Line do
3
+ describe SeeingIsBelieving::Line, t:true do
4
4
  Line = described_class
5
5
 
6
+ def line_for(*args)
7
+ line = Line.new
8
+ args.each { |a| line.record_result a }
9
+ line
10
+ end
11
+
6
12
  it 'inspects prettily' do
7
- Line[].inspect.should == '#<SIB:Line[] no exception>'
8
- Line["a"].inspect.should == '#<SIB:Line["a"] no exception>'
9
- Line["a", 1].inspect.should == '#<SIB:Line["a", 1] no exception>'
10
- line = Line[]
13
+ line_for( ).inspect.should == '#<SIB:Line[] (0, 0) no exception>'
14
+ line_for("a" ).inspect.should == '#<SIB:Line["\"a\""] (1, 3) no exception>'
15
+ line_for("a", 12).inspect.should == '#<SIB:Line["\"a\"", "12"] (2, 5) no exception>'
16
+
17
+ line = Line.new
11
18
  line.exception = RuntimeError.new("omg")
12
- line.inspect.should == '#<SIB:Line[] RuntimeError:"omg">'
19
+ line.inspect.should == '#<SIB:Line[] (0, 0) RuntimeError:"omg">'
13
20
  end
14
21
 
15
22
  it 'knows when it has an exception' do
@@ -32,30 +39,30 @@ describe SeeingIsBelieving::Line do
32
39
  end
33
40
 
34
41
  it 'returns its array for #to_a and #to_ary' do
35
- line = Line[1,2]
42
+ line = line_for 1, 2
36
43
  line.to_a.should be_a_kind_of Array
37
- line.to_a.should == [1, 2]
44
+ line.to_a.should == %w[1 2]
38
45
  line.to_ary.should be_a_kind_of Array
39
- line.to_ary.should == [1, 2]
46
+ line.to_ary.should == %w[1 2]
40
47
  end
41
48
 
42
49
  it 'is equal to arrays with the same elements as its array' do
43
- Line[1, 2].should == [1, 2]
44
- Line[1, 2].should_not == [2, 1]
50
+ line_for(1, 2).should == %w[1 2]
51
+ line_for(1, 2).should_not == %w[2 1]
45
52
  end
46
53
 
47
54
  # Exception equality seems to be based off of the message, and be indifferent to the class, I don't think it's that important to fix it
48
55
  it "is equal to lines with the same elements and the same exception" do
49
56
  exception = RuntimeError.new 'omg'
50
57
 
51
- Line[1, 2].should == Line[1, 2]
52
- Line[1, 2].should_not == Line[2, 1]
58
+ line_for(1, 2).should == line_for(1, 2)
59
+ line_for(1, 2).should_not == line_for(2, 1)
53
60
 
54
- line1 = Line[1, 2]
61
+ line1 = line_for(1, 2)
55
62
  line1.exception = exception
56
- line1.should_not == Line[1, 2]
63
+ line1.should_not == line_for(1, 2)
57
64
 
58
- line2 = Line[1, 2]
65
+ line2 = line_for(1, 2)
59
66
  line2.exception = exception
60
67
  line1.should == line2
61
68
 
@@ -19,6 +19,11 @@ describe SeeingIsBelieving do
19
19
  invoke(input)[2].should == ['"22"']
20
20
  end
21
21
 
22
+ it 'only invokes inspect once' do
23
+ input = "class Fixnum; def inspect; 'NUM'\nend\nend\n1"
24
+ invoke(input)[1].should == ['"NUM"']
25
+ end
26
+
22
27
  it 'remembers context of previous lines' do
23
28
  values_for("a=12\na*2").should == [['12'], ['24']]
24
29
  end
@@ -299,6 +304,13 @@ describe SeeingIsBelieving do
299
304
  ['[6, 12]']]
300
305
  end
301
306
 
307
+ it 'can be limited to a specific number of captures', t:true do
308
+ values_for("2.times do\n1\nend", number_of_captures: 1)
309
+ .should == [['2'],
310
+ ['1', '...'],
311
+ ['2']]
312
+ end
313
+
302
314
  it 'can evaluate under a different ruby executable' do
303
315
  Dir.chdir proving_grounds_dir do
304
316
  File.write 'omg-ruby', "#!/usr/bin/env ruby
@@ -355,7 +367,7 @@ describe SeeingIsBelieving do
355
367
  it 'prints the result' do
356
368
  call
357
369
  stream.string.should include "RESULT:"
358
- stream.string.should include '1=>#<SIB:Line["1"] no exception>'
370
+ stream.string.should include '1=>#<SIB:Line["1"] (1, 1) no exception>'
359
371
  end
360
372
  # should ProgramRewriter have some debug options?
361
373
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seeing_is_believing
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Cheek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-19 00:00:00.000000000 Z
11
+ date: 2013-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -115,6 +115,7 @@ files:
115
115
  - features/flags.feature
116
116
  - features/regression.feature
117
117
  - features/support/env.rb
118
+ - for-presentations
118
119
  - lib/seeing_is_believing.rb
119
120
  - lib/seeing_is_believing/binary.rb
120
121
  - lib/seeing_is_believing/binary/add_annotations.rb
@@ -139,10 +140,10 @@ files:
139
140
  - lib/seeing_is_believing/version.rb
140
141
  - lib/seeing_is_believing/wrap_expressions.rb
141
142
  - seeing_is_believing.gemspec
142
- - spec/binary/arg_parser_spec.rb
143
143
  - spec/binary/clean_body_spec.rb
144
144
  - spec/binary/comment_formatter_spec.rb
145
145
  - spec/binary/comment_lines_spec.rb
146
+ - spec/binary/parse_args_spec.rb
146
147
  - spec/binary/rewrite_comments_spec.rb
147
148
  - spec/debugger_spec.rb
148
149
  - spec/evaluate_by_moving_files_spec.rb
@@ -171,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
172
  version: '0'
172
173
  requirements: []
173
174
  rubyforge_project: seeing_is_believing
174
- rubygems_version: 2.0.5
175
+ rubygems_version: 2.0.3
175
176
  signing_key:
176
177
  specification_version: 4
177
178
  summary: Records results of every line of code in your file
@@ -181,10 +182,10 @@ test_files:
181
182
  - features/flags.feature
182
183
  - features/regression.feature
183
184
  - features/support/env.rb
184
- - spec/binary/arg_parser_spec.rb
185
185
  - spec/binary/clean_body_spec.rb
186
186
  - spec/binary/comment_formatter_spec.rb
187
187
  - spec/binary/comment_lines_spec.rb
188
+ - spec/binary/parse_args_spec.rb
188
189
  - spec/binary/rewrite_comments_spec.rb
189
190
  - spec/debugger_spec.rb
190
191
  - spec/evaluate_by_moving_files_spec.rb