seeing_is_believing 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seeing_is_believing (0.0.9)
4
+ seeing_is_believing (0.0.10)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/Readme.md CHANGED
@@ -48,14 +48,19 @@ believer = SeeingIsBelieving.new("%w[a b c].each do |i|
48
48
  end")
49
49
 
50
50
  result = believer.call
51
- result # => #<SeeingIsBelieving::Result:0x007faeed1a5b78 @max_line_number=3, @min_line_number=1, @results={2=>['"A"', '"B"', '"C"'], 3=>['["a", "b", "c"]']}>
51
+ result # => #<SeeingIsBelieving::Result:0x007f832298e340 @max_line_number=3, @min_line_number=1, @results={2=>#<SeeingIsBelieving::Result::Line:0x007f832298df30 @array=["\"A\"", "\"B\"", "\"C\""]>, 3=>#<SeeingIsBelieving::Result::Line:0x007f832298db98 @array=["[\"a\", \"b\", \"c\"]"]>}, @stdout="", @stderr="">
52
52
 
53
- result.to_a # => [ [1, []],
54
- # [2, ['"A"', '"B"', '"C"']],
55
- # [3, ['["a", "b", "c"]']]
56
- # ]
53
+ result.to_a # => [#<SeeingIsBelieving::Result::Line:0x007f832299adc0 @array=[]>,
54
+ # #<SeeingIsBelieving::Result::Line:0x007f832298df30 @array=['"A"', '"B"', '"C"']>,
55
+ # #<SeeingIsBelieving::Result::Line:0x007f832298db98 @array=['["a", "b", "c"]']>]
57
56
 
58
- result[2] # => ['"A"', '"B"', '"C"']
57
+ result[2] # => #<SeeingIsBelieving::Result::Line:0x007f832298df30 @array=['"A"', '"B"', '"C"']>
58
+
59
+ # this result object is a thin wrapper around its array
60
+ result[2][0] # => '"A"'
61
+ result[2][1] # => '"B"'
62
+ result[2][2] # => '"C"'
63
+ result[2].join(", ") # => '"A", "B", "C"'
59
64
  ```
60
65
 
61
66
  Install
@@ -30,10 +30,7 @@ Feature: Running the binary unsuccessfully
30
30
  'abc
31
31
  """
32
32
  When I run "seeing_is_believing invalid_syntax.rb"
33
- Then stderr is:
34
- """
35
- invalid_syntax.rb:1: unterminated string meets end of file
36
- """
33
+ Then stderr includes "1: unterminated string meets end of file"
37
34
  And the exit status is 1
38
35
  And stdout is empty
39
36
 
@@ -125,6 +125,58 @@ Feature: Using flags
125
125
  When I run "seeing_is_believing --line-length 14 line_lengths2.rb"
126
126
  Then stdout is "12345"
127
127
 
128
+ Scenario: --require
129
+ Given the file "print_1.rb" "puts 1"
130
+ Given the file "print_2.rb" "puts 2"
131
+ And the file "print_3.rb" "puts 3"
132
+ When I run "seeing_is_believing --require ./print_1 --require ./print_2 print_3.rb"
133
+ Then stderr is empty
134
+ And the exit status is 0
135
+ And stdout is:
136
+ """
137
+ puts 3 # => nil
138
+
139
+ # >> 1
140
+ # >> 2
141
+ # >> 3
142
+ """
143
+
144
+ Scenario: --program
145
+ When I run "seeing_is_believing --program '1'"
146
+ Then stderr is empty
147
+ And the exit status is 0
148
+ And stdout is:
149
+ """
150
+ 1 # => 1
151
+ """
152
+
153
+ Scenario: --load-path
154
+ Given the file "print_1.rb" "puts 1"
155
+ And the file "some_dir/print_2.rb" "puts 2"
156
+ And the file "require_print_1.rb" "require 'print_1'"
157
+ When I run "seeing_is_believing require_print_1.rb"
158
+ Then the exit status is 1
159
+ When I run "seeing_is_believing --load-path . -I ./some_dir -r print_2 require_print_1.rb"
160
+ Then stderr is empty
161
+ And stdout is:
162
+ """
163
+ require 'print_1' # => true
164
+
165
+ # >> 2
166
+ # >> 1
167
+ """
168
+ And the exit status is 0
169
+
170
+ Scenario: --encoding
171
+ Given the file "utf-8.rb" "'ç'"
172
+ When I run "seeing_is_believing --encoding u utf-8.rb"
173
+ Then stderr is empty
174
+ And the exit status is 0
175
+ And stdout is:
176
+ """
177
+ 'ç' # => "ç"
178
+ """
179
+
128
180
  Scenario: --help
129
181
  When I run "seeing_is_believing --help"
130
182
  Then stderr is empty
@@ -2,6 +2,10 @@ Given 'the file "$filename":' do |filename, body|
2
2
  CommandLineHelpers.write_file filename, body
3
3
  end
4
4
 
5
+ Given 'the file "$filename" "$body"' do |filename, body|
6
+ CommandLineHelpers.write_file filename, body
7
+ end
8
+
5
9
  Given 'I have the stdin content "$content"' do |content|
6
10
  @stdin_data = content
7
11
  end
@@ -1,8 +1,3 @@
1
- # note:
2
- # reserve -e for script in an argument
3
- # reserve -I for setting load path
4
- # reserve -r for requiring another file
5
-
6
1
  class SeeingIsBelieving
7
2
  class Binary
8
3
  class ArgParser
@@ -26,8 +21,12 @@ class SeeingIsBelieving
26
21
  when '-L', '--end-line' then extract_positive_int_for :end_line, arg
27
22
  when '-d', '--line-length' then extract_positive_int_for :line_length, arg
28
23
  when '-D', '--result-length' then extract_positive_int_for :result_length, arg
24
+ when '-r', '--require' then next_arg("#{arg} expected a filename but did not see one") { |filename| options[:require] << filename }
25
+ when '-I', '--load-path' then next_arg("#{arg} expected a directory but did not see one") { |dir| options[:load_path] << dir }
26
+ when '-e', '--program' then next_arg("#{arg} expects a program as the following argument") { |program| options[:program] = program }
27
+ when '-K', '--encoding' then next_arg("#{arg} expects an encoding, see `man ruby` for possibile values") { |encoding| options[:encoding] = encoding }
29
28
  when /^-/ then options[:errors] << "Unknown option: #{arg.inspect}" # unknown flags
30
- else # filenames
29
+ else
31
30
  filenames << arg
32
31
  options[:filename] = arg
33
32
  end
@@ -44,6 +43,8 @@ class SeeingIsBelieving
44
43
  def normalize_and_validate
45
44
  if 1 < filenames.size
46
45
  options[:errors] << "Can only have one filename, but had: #{filenames.map(&:inspect).join ', '}"
46
+ elsif filenames.any? && options[:program]
47
+ options[:errors] << "You passed the program in an argument, but have also specified the filename #{filenames.first}"
47
48
  end
48
49
 
49
50
  if options[:end_line] < options[:start_line]
@@ -53,15 +54,23 @@ class SeeingIsBelieving
53
54
 
54
55
  def options
55
56
  @options ||= {
57
+ program: nil,
56
58
  filename: nil,
57
59
  errors: [],
58
60
  start_line: 1,
59
61
  line_length: Float::INFINITY,
60
62
  end_line: Float::INFINITY,
61
63
  result_length: Float::INFINITY,
64
+ require: [],
65
+ load_path: [],
62
66
  }
63
67
  end
64
68
 
69
+ def next_arg(error_message, &success_block)
70
+ arg = args.shift
71
+ arg ? success_block.call(arg) : (options[:errors] << error_message)
72
+ end
73
+
65
74
  def extract_positive_int_for(key, flag)
66
75
  string = args.shift
67
76
  int = string.to_i
@@ -85,6 +94,8 @@ Usage: #{$0} [options] [filename]
85
94
  -L, --end-line # line number to stop showing results on
86
95
  -d, --line-length # max length of the entire line (only truncates results, not source lines)
87
96
  -D, --result-length # max length of the portion after the "# => "
97
+ -r, --require # additional files to be required before running the program
98
+ -e, --program # Pass the program to execute as an argument
88
99
  -h, --help # this help screen
89
100
  HELP_SCREEN
90
101
  end
@@ -33,13 +33,16 @@ class SeeingIsBelieving
33
33
 
34
34
  def body
35
35
  @body ||= PrintResultsNextToLines.remove_previous_output_from \
36
- (file_is_on_stdin? ? stdin.read : File.read(flags[:filename]))
36
+ flags[:program] || (file_is_on_stdin? && stdin.read) || File.read(flags[:filename])
37
37
  end
38
38
 
39
39
  def results
40
40
  @results ||= SeeingIsBelieving.call body,
41
- filename: flags[:filename],
42
- stdin: (file_is_on_stdin? ? '' : stdin)
41
+ filename: flags[:filename],
42
+ require: flags[:require],
43
+ load_path: flags[:load_path],
44
+ encoding: flags[:encoding],
45
+ stdin: (file_is_on_stdin? ? '' : stdin)
43
46
  end
44
47
 
45
48
  def printer
@@ -67,7 +70,7 @@ class SeeingIsBelieving
67
70
  end
68
71
 
69
72
  def file_is_on_stdin?
70
- flags[:filename].nil?
73
+ flags[:filename].nil? && flags[:program].nil?
71
74
  end
72
75
 
73
76
  def file_dne?
@@ -83,8 +86,7 @@ class SeeingIsBelieving
83
86
  end
84
87
 
85
88
  def syntax_error_notice
86
- return if file_is_on_stdin? # <-- BUG: should check stdin too
87
- out, err, syntax_status = Open3.capture3 'ruby', '-c', flags[:filename]
89
+ out, err, syntax_status = Open3.capture3 'ruby', '-c', stdin_data: body
88
90
  return err unless syntax_status.success?
89
91
  end
90
92
 
@@ -20,7 +20,7 @@ require 'seeing_is_believing/hard_core_ensure'
20
20
 
21
21
  class SeeingIsBelieving
22
22
  class EvaluateByMovingFiles
23
- attr_accessor :program, :filename, :error_stream, :input_stream, :matrix_filename
23
+ attr_accessor :program, :filename, :error_stream, :input_stream, :matrix_filename, :require_flags, :load_path_flags, :encoding
24
24
 
25
25
  def initialize(program, filename, options={})
26
26
  self.program = program
@@ -28,12 +28,15 @@ class SeeingIsBelieving
28
28
  self.error_stream = options.fetch :error_stream, $stderr # hmm, not really liking the global here
29
29
  self.input_stream = options.fetch :input_stream, StringIO.new('')
30
30
  self.matrix_filename = options[:matrix_filename] || 'seeing_is_believing/the_matrix'
31
+ self.require_flags = options.fetch(:require, []).map { |filename| ['-r', filename] }.flatten
32
+ self.load_path_flags = options.fetch(:load_path, []).map { |dir| ['-I', dir] }.flatten
33
+ self.encoding = options.fetch :encoding, nil
31
34
  end
32
35
 
33
36
  def call
34
37
  @result ||= HardCoreEnsure.call \
35
38
  code: -> {
36
- dont_overwrite_existing_tempfile!
39
+ we_will_not_overwrite_existing_tempfile!
37
40
  move_file_to_tempfile
38
41
  write_program_to_file
39
42
  begin
@@ -62,7 +65,7 @@ class SeeingIsBelieving
62
65
 
63
66
  attr_accessor :stdout, :stderr, :exitstatus
64
67
 
65
- def dont_overwrite_existing_tempfile!
68
+ def we_will_not_overwrite_existing_tempfile!
66
69
  raise TempFileAlreadyExists.new(filename, temp_filename) if File.exist? temp_filename
67
70
  end
68
71
 
@@ -82,22 +85,30 @@ class SeeingIsBelieving
82
85
  end
83
86
 
84
87
  def evaluate_file
85
- Open3.popen3 'ruby', '-W0', # no warnings (b/c I hijack STDOUT/STDERR)
86
- '-I', File.expand_path('../..', __FILE__), # add lib to the load path
87
- '-r', matrix_filename, # hijack the environment so it can be recorded
88
- filename do |i, o, e, t|
89
- out_reader = Thread.new { o.read }
90
- err_reader = Thread.new { e.read }
88
+ Open3.popen3 *popen_args do |process_stdin, process_stdout, process_stderr, thread|
89
+ out_reader = Thread.new { process_stdout.read }
90
+ err_reader = Thread.new { process_stderr.read }
91
91
  Thread.new do
92
- input_stream.each_char { |char| i.write char }
93
- i.close
92
+ input_stream.each_char { |char| process_stdin.write char }
93
+ process_stdin.close
94
94
  end
95
95
  self.stdout = out_reader.value
96
96
  self.stderr = err_reader.value
97
- self.exitstatus = t.value
97
+ self.exitstatus = thread.value
98
98
  end
99
99
  end
100
100
 
101
+ def popen_args
102
+ ['ruby',
103
+ '-W0', # no warnings (b/c I hijack STDOUT/STDERR)
104
+ *(encoding ? ["-K#{encoding}"] : []), # allow the encoding to be set
105
+ '-I', File.expand_path('../..', __FILE__), # add lib to the load path
106
+ '-r', matrix_filename, # hijack the environment so it can be recorded
107
+ *load_path_flags, # users can inject dirs to be added to the load path
108
+ *require_flags, # users can inject files to be required
109
+ filename]
110
+ end
111
+
101
112
  def fail
102
113
  raise "Exitstatus: #{exitstatus.inspect},\nError: #{stderr.inspect}"
103
114
  end
@@ -9,7 +9,7 @@ class SeeingIsBelieving
9
9
  include HasException
10
10
 
11
11
  extend Forwardable
12
- def_delegators :@array, :[], :<<, :any?, :join, :to_ary, :to_a
12
+ def_delegators :@array, :[], :<<, :any?, :join, :to_ary, :to_a, :empty?
13
13
 
14
14
  def initialize
15
15
  @array ||= []
@@ -19,7 +19,7 @@ class SeeingIsBelieving
19
19
  if Array === ary_or_line
20
20
  @array == ary_or_line
21
21
  else
22
- @array == ary_or_line &&
22
+ ary_or_line == @array &&
23
23
  has_exception? == ary_or_line.has_exception?
24
24
  end
25
25
  end
@@ -27,6 +27,7 @@ class SeeingIsBelieving
27
27
 
28
28
  include HasException
29
29
  include TracksLineNumbersSeen
30
+ include Enumerable
30
31
 
31
32
  attr_accessor :stdout, :stderr
32
33
 
@@ -58,11 +59,8 @@ class SeeingIsBelieving
58
59
  results(line_number)
59
60
  end
60
61
 
61
- # probably not really useful, just exists to satisfy the tests, which specified too simple of an interface
62
- def to_a
63
- (min_line_number..max_line_number).map do |line_number|
64
- [line_number, [*self[line_number].to_ary, *Array(self[line_number].exception)]]
65
- end
62
+ def each(&block)
63
+ (min_line_number..max_line_number).each { |line_number| block.call self[line_number] }
66
64
  end
67
65
 
68
66
  private
@@ -5,6 +5,7 @@ class SeeingIsBelieving
5
5
  def track_line_number(line_number)
6
6
  @min_line_number = line_number if line_number < min_line_number
7
7
  @max_line_number = line_number if line_number > max_line_number
8
+ self
8
9
  end
9
10
 
10
11
  def min_line_number
@@ -1,3 +1,3 @@
1
1
  class SeeingIsBelieving
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
@@ -21,18 +21,26 @@ class SeeingIsBelieving
21
21
  @matrix_filename = options[:matrix_filename]
22
22
  @filename = options[:filename]
23
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
24
27
  @line_number = 1
25
28
  end
26
29
 
27
- # :( refactor me
30
+ # I'd lik to refactor this, but I was unsatisfied with the three different things I tried.
31
+ # In the end, I prefer keeping all manipulation of the line number here in the main function
32
+ # And I like that the higher-level construct of how the program gets built can be found here.
28
33
  def call
29
34
  @memoized_result ||= begin
30
- # extract leading comments, leading =begin and magic comments can't be wrapped for exceptions without breaking
31
35
  leading_comments = ''
36
+
37
+ # extract leading comments (e.g. encoding) so they don't get wrapped in begin/rescue/end
32
38
  while next_line_queue.peek =~ /^\s*#/
33
39
  leading_comments << next_line_queue.dequeue << "\n"
34
40
  @line_number += 1
35
41
  end
42
+
43
+ # extract leading =begin/=end so they don't get wrapped in begin/rescue/end
36
44
  while next_line_queue.peek == '=begin'
37
45
  lines = next_line_queue.dequeue << "\n"
38
46
  @line_number += 1
@@ -43,19 +51,24 @@ class SeeingIsBelieving
43
51
  leading_comments << lines
44
52
  end
45
53
 
46
- # extract program
47
- program = ''
54
+ # extract program body
55
+ body = ''
48
56
  until next_line_queue.peek.nil? || data_segment?
49
57
  expression, expression_size = expression_list.call
50
- program << expression
58
+ body << expression
51
59
  track_line_number @line_number
52
60
  @line_number += expression_size
53
61
  end
54
- program = leading_comments + record_exceptions_in(program)
55
62
 
56
63
  # extract data segment
57
- program << "\n" << the_rest_of_the_stream if data_segment?
58
- result_for program, min_line_number, max_line_number
64
+ data_segment = ''
65
+ data_segment = "\n#{the_rest_of_the_stream}" if data_segment?
66
+
67
+ # build the program
68
+ program = leading_comments << record_exceptions_in(body) << data_segment
69
+
70
+ # return the result
71
+ result_for program, max_line_number
59
72
  end
60
73
  end
61
74
 
@@ -95,13 +108,18 @@ class SeeingIsBelieving
95
108
  "end"
96
109
  end
97
110
 
98
- def result_for(program, min_line_number, max_line_number)
111
+ def result_for(program, max_line_number)
99
112
  Dir.mktmpdir "seeing_is_believing_temp_dir" do |dir|
100
113
  filename = @filename || File.join(dir, 'program.rb')
101
- EvaluateByMovingFiles.new(program, filename, input_stream: @stdin, matrix_filename: matrix_filename).call.tap do |result|
102
- result.track_line_number min_line_number
103
- result.track_line_number max_line_number
104
- end
114
+ EvaluateByMovingFiles.new(program,
115
+ filename,
116
+ input_stream: @stdin,
117
+ matrix_filename: matrix_filename,
118
+ require: @require,
119
+ load_path: @load_path,
120
+ encoding: @encoding)
121
+ .call
122
+ .track_line_number(max_line_number)
105
123
  end
106
124
  end
107
125
 
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = "https://github.com/JoshCheek/seeing_is_believing"
11
11
  s.summary = %q{Records results of every line of code in your file}
12
12
  s.description = %q{Records the results of every line of code in your file (intended to be like xmpfilter), inspired by Bret Victor's JavaScript example in his talk "Inventing on Principle"}
13
+ s.license = "WTFPL"
13
14
 
14
15
  s.rubyforge_project = "seeing_is_believing"
15
16
 
@@ -45,11 +45,12 @@ describe SeeingIsBelieving::Binary::ArgParser do
45
45
  parse(['-a']).should have_error 'Unknown option: "-a"'
46
46
  end
47
47
 
48
- example 'example: all the args' do
49
- options = parse(%w[filename -l 12 -L 20 -h])
48
+ example 'example: multiple args' do
49
+ options = parse(%w[filename -l 12 -L 20 -h -r torequire])
50
50
  options[:filename].should == 'filename'
51
51
  options[:start_line].should == 12
52
52
  options[:end_line].should == 20
53
+ options[:require].should == ['torequire']
53
54
  options[:help].should be_a_kind_of String
54
55
  options[:errors].should be_empty
55
56
  end
@@ -129,6 +130,22 @@ describe SeeingIsBelieving::Binary::ArgParser do
129
130
  it_behaves_like 'it requires a positive int argument', ['-d', '--line-length']
130
131
  end
131
132
 
133
+ describe :require do
134
+ it 'defaults to an empty array' do
135
+ parse([])[:require].should be_empty
136
+ end
137
+
138
+ it '-r and --require sets each required file into the result array' do
139
+ parse(%w[-r f1 --require f2])[:require].should == %w[f1 f2]
140
+ end
141
+
142
+ it 'sets an error if not provided with a filename' do
143
+ parse(['--require', 'f']).should_not have_error /-r/
144
+ parse(['-r']).should have_error /-r\b/
145
+ parse(['--require']).should have_error /--require\b/
146
+ end
147
+ end
148
+
132
149
  describe ':help' do
133
150
  it 'defaults to nil' do
134
151
  parse([])[:help].should be_nil
@@ -139,4 +156,60 @@ describe SeeingIsBelieving::Binary::ArgParser do
139
156
  parse(['--help'])[:help].should == described_class.help_screen
140
157
  end
141
158
  end
159
+
160
+ describe ':program' do
161
+ it 'defaults to nil' do
162
+ parse([])[:program].should be_nil
163
+ end
164
+
165
+ it 'is set with -e or --program, and takes the next arg' do
166
+ parse(['-e', '1'])[:program].should == '1'
167
+ parse(['--program', '1'])[:program].should == '1'
168
+ end
169
+
170
+ it 'sets an error if not given a program' do
171
+ parse([]).should_not have_error /-e/
172
+ parse([]).should_not have_error /--program/
173
+ parse(['-e']).should have_error /-e/
174
+ parse(['--program']).should have_error /--program/
175
+ end
176
+
177
+ it 'sets an error if a filename is also give' do
178
+ # parse(['abc']).should_not have_error /abc/
179
+ parse(['-e', '1', 'abc']).should have_error /abc/
180
+ end
181
+ end
182
+
183
+ describe':load_path' do
184
+ it 'defaults to an empty array' do
185
+ parse([])[:load_path].should be_empty
186
+ end
187
+
188
+ specify '-I and --load-path sets each required file into the result array' do
189
+ parse(%w[-I f1 --load-path f2])[:load_path].should == %w[f1 f2]
190
+ end
191
+
192
+ it 'sets an error if not provided with a dir' do
193
+ parse(['--load-path', 'f']).should_not have_error /-I/
194
+ parse(['-I']).should have_error /-I\b/
195
+ parse(['--load-path']).should have_error /--load-path\b/
196
+ end
197
+ end
198
+
199
+ describe ':encoding' do
200
+ it 'defaults to nil' do
201
+ parse([])[:encoding].should be_nil
202
+ end
203
+
204
+ specify '-K and --encoding sets the encoding to the next argument' do
205
+ parse(%w[-K u])[:encoding].should == 'u'
206
+ parse(%w[--encoding u])[:encoding].should == 'u'
207
+ end
208
+
209
+ it 'sets an error if not provided with an encoding' do
210
+ parse(['-K']).should have_error /-K/
211
+ parse(['--encoding']).should have_error /--encoding/
212
+ end
213
+ end
142
214
  end
215
+
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'seeing_is_believing/evaluate_by_moving_files'
2
4
  require 'fileutils'
3
5
 
@@ -61,6 +63,25 @@ describe SeeingIsBelieving::EvaluateByMovingFiles do
61
63
  evaluator.call
62
64
  end
63
65
 
66
+ it 'can require files' do
67
+ other_filename1 = File.join filedir, 'other1.rb'
68
+ other_filename2 = File.join filedir, 'other2.rb'
69
+ File.open(other_filename1, 'w') { |f| f.puts "puts 123" }
70
+ File.open(other_filename2, 'w') { |f| f.puts "puts 456" }
71
+ result = invoke '', require: [other_filename1, other_filename2]
72
+ result.stdout.should == "123\n456\n"
73
+ end
74
+
75
+ it 'can set the load path' do
76
+ File.open(File.join(filedir, 'other1.rb'), 'w') { |f| f.puts "puts 123" }
77
+ result = invoke '', require: ['other1'], load_path: [filedir]
78
+ result.stdout.should == "123\n"
79
+ end
80
+
81
+ it 'will set the encoding' do
82
+ invoke('print "ç"', encoding: 'u').stdout.should == "ç"
83
+ end
84
+
64
85
  it 'prints some error handling code to stderr if it fails' do
65
86
  stderr = StringIO.new
66
87
  evaluator = described_class.new 'raise "omg"', filename, error_stream: stderr
@@ -8,7 +8,7 @@ describe SeeingIsBelieving do
8
8
  end
9
9
 
10
10
  def values_for(input)
11
- invoke(input).to_a.map(&:last)
11
+ invoke(input).to_a
12
12
  end
13
13
 
14
14
  def stream(string)
@@ -19,9 +19,8 @@ describe SeeingIsBelieving do
19
19
 
20
20
  it 'takes a string or stream and returns a result of the line numbers (counting from 1) and each inspected result from that line' do
21
21
  input = "1+1\n'2'+'2'"
22
- output = [[1, ["2"]], [2, ['"22"']]]
23
- invoke(input).to_a.should == output
24
- invoke(stream input).to_a.should == output
22
+ invoke(input)[1].should == ["2"]
23
+ invoke(stream input)[2].should == ['"22"']
25
24
  end
26
25
 
27
26
  it 'remembers context of previous lines' do
@@ -30,8 +29,8 @@ describe SeeingIsBelieving do
30
29
 
31
30
  it 'can be invoked multiple times, returning the same result' do
32
31
  believer = described_class.new("$xyz||=1\n$xyz+=1")
33
- believer.call.to_a.should == [[1, ['1']], [2, ['2']]]
34
- believer.call.to_a.should == [[1, ['1']], [2, ['2']]]
32
+ believer.call.to_a.should == [['1'], ['2']]
33
+ believer.call.to_a.should == [['1'], ['2']]
35
34
  end
36
35
 
37
36
  it 'is evaluated at the toplevel' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seeing_is_believing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-10 00:00:00.000000000 Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70252880676580 !ruby/object:Gem::Requirement
16
+ requirement: &70217249132080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 10.0.3
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70252880676580
24
+ version_requirements: *70217249132080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70252880675820 !ruby/object:Gem::Requirement
27
+ requirement: &70217249131460 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.12.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70252880675820
35
+ version_requirements: *70217249131460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: cucumber
38
- requirement: &70252880691520 !ruby/object:Gem::Requirement
38
+ requirement: &70217249130620 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.2.1
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70252880691520
46
+ version_requirements: *70217249130620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ichannel
49
- requirement: &70252880691040 !ruby/object:Gem::Requirement
49
+ requirement: &70217249129100 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 5.1.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70252880691040
57
+ version_requirements: *70217249129100
58
58
  description: Records the results of every line of code in your file (intended to be
59
59
  like xmpfilter), inspired by Bret Victor's JavaScript example in his talk "Inventing
60
60
  on Principle"
@@ -104,7 +104,8 @@ files:
104
104
  - spec/syntax_analyzer_spec.rb
105
105
  - textmate-integration.png
106
106
  homepage: https://github.com/JoshCheek/seeing_is_believing
107
- licenses: []
107
+ licenses:
108
+ - WTFPL
108
109
  post_install_message:
109
110
  rdoc_options: []
110
111
  require_paths:
@@ -123,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  version: '0'
124
125
  requirements: []
125
126
  rubyforge_project: seeing_is_believing
126
- rubygems_version: 1.8.17
127
+ rubygems_version: 1.8.11
127
128
  signing_key:
128
129
  specification_version: 3
129
130
  summary: Records results of every line of code in your file
@@ -141,3 +142,4 @@ test_files:
141
142
  - spec/queue_spec.rb
142
143
  - spec/seeing_is_believing_spec.rb
143
144
  - spec/syntax_analyzer_spec.rb
145
+ has_rdoc: