seeing_is_believing 2.0.3 → 2.0.4

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: 6f3a33ebd46b9d9da1919b82f9a1d455f364a6fc
4
- data.tar.gz: 2fef2e75ad635f67bc2ebc3c6d25a9d5ec1bd56b
3
+ metadata.gz: 6adfee9e8967b84be59e45a401f01f143d458ffb
4
+ data.tar.gz: 014dc1b1d8af353f5bef6dd3f46f0ee4d97cb859
5
5
  SHA512:
6
- metadata.gz: 588f7d2d54999b825c89f6a3fa809b09ba240fce0f42921afb0f4bee396a5a9b8cc6b7443d4580316d8cdf1887537af4323c7233870dc3660c3bffba5240c27d
7
- data.tar.gz: 34f1c84303fe466b2b004b7e4017467475c4c305235e14c1f3c761b5214879d539e49f27155d8f05ce0ef3c1ff8a00a9b0ffdb231aaa4116ff4d82a45bc84716
6
+ metadata.gz: 7a3f04bacf9afc8d2e032582140890e24c000b0433be694f1dbd5a3a8029fcc724fa6c4efdc6de71426f9cde5aee033e53f9b562e48db9d75a4d6ee50b432d81
7
+ data.tar.gz: dad2c178e03dcfee0f28aea9ed62edf4d8e44ba3456b7880ad4a6134ab4a3e866a1dedcb28c9ea763d42b1fe5137a97c436af62324adf3885e19faa06b1ddbb8
data/Readme.md CHANGED
@@ -9,7 +9,7 @@ Except, obviously, his is like a million times better.
9
9
 
10
10
  Also comes with a binary to show how it might be used.
11
11
 
12
- For whatever reason, I can't embed videos, but **here's a [video](vimeo.com/73866851)** showing it off.
12
+ For whatever reason, I can't embed videos, but **here's a [video](http://vimeo.com/73866851)** showing it off.
13
13
 
14
14
  Works in Ruby 1.9 and 2.0
15
15
 
@@ -54,7 +54,7 @@ result.exception # => nil
54
54
  Install
55
55
  =======
56
56
 
57
- Currently requires Ruby 1.9 or 2.0 I don't have specific plans to make it available on 1.8,
57
+ Currently requires Ruby 1.9 or 2.0. I don't have specific plans to make it available on 1.8,
58
58
  but it could happen.
59
59
 
60
60
  $ gem install seeing_is_believing
@@ -66,6 +66,8 @@ Editor Integration
66
66
  * [sublime-text-2-seeing-is-believing](https://github.com/JoshCheek/sublime-text-2-seeing-is-believing)
67
67
  * [TextMate 1](https://github.com/JoshCheek/text_mate_1-seeing-is_believing)
68
68
  * [TextMate 2](https://github.com/JoshCheek/text_mate_2-seeing-is_believing)
69
+ * [vim-ruby-xmpfilter](https://github.com/t9md/vim-ruby-xmpfilter) (has support for `seeing_is_believing`)
70
+ * [vim-seeing-is-believing](https://github.com/hwartig/vim-seeing-is-believing)
69
71
 
70
72
  Emacs Integration
71
73
  =================
@@ -89,9 +91,9 @@ or current buffer contents with the output of running it through
89
91
  Known Issues
90
92
  ============
91
93
 
92
- * `BEGIN/END` breaks things and I probably won't ever fix it, becuase it's annoying and its really meant for command-line scripts... but there is currently a spec for it
94
+ * `BEGIN/END` breaks things and I probably won't ever fix it, because it's annoying and it's really meant for command-line scripts... but there is currently a spec for it.
93
95
  * `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
- * The code to find the data segment is naive, and could wind up interpolating results into a string or something
96
+ * The code to find the data segment is naive, and could wind up interpolating results into a string or something.
95
97
 
96
98
  Shit that will probably never get done (or if it does, won't be until after 2.0)
97
99
  ================================================================================
@@ -99,7 +101,7 @@ Shit that will probably never get done (or if it does, won't be until after 2.0)
99
101
  * How about if begin/rescue/end was able to record the result on the rescue section
100
102
  * 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"
101
103
  * 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)
102
- * If given a file with a unicode character, but not set unicode, inform the user
104
+ * If given a file with a Unicode character, but not set Unicode, inform the user
103
105
 
104
106
  License
105
107
  =======
File without changes
Binary file
Binary file
@@ -8,7 +8,6 @@ require 'seeing_is_believing/debugger'
8
8
  require 'seeing_is_believing/evaluate_by_moving_files'
9
9
  require 'seeing_is_believing/wrap_expressions'
10
10
 
11
- # might not work on windows b/c of assumptions about line ends
12
11
  class SeeingIsBelieving
13
12
  BLANK_REGEX = /\A\s*\Z/
14
13
 
@@ -18,12 +17,12 @@ class SeeingIsBelieving
18
17
 
19
18
  def initialize(program, options={})
20
19
  @program = program
21
- @matrix_filename = options[:matrix_filename]
20
+ @matrix_filename = options.fetch :matrix_filename, 'seeing_is_believing/the_matrix' # how to hijack the env
22
21
  @filename = options[:filename]
23
22
  @stdin = to_stream options.fetch(:stdin, '')
24
- @require = options.fetch :require, []
23
+ @require = options.fetch :require, []
25
24
  @load_path = options.fetch :load_path, []
26
- @encoding = options.fetch :encoding, nil
25
+ @encoding = options.fetch :encoding, nil
27
26
  @timeout = options[:timeout]
28
27
  @debugger = options.fetch :debugger, Debugger.new(stream: nil)
29
28
  @ruby_executable = options.fetch :ruby_executable, 'ruby'
@@ -42,7 +41,7 @@ class SeeingIsBelieving
42
41
 
43
42
  private
44
43
 
45
- attr_reader :matrix_filename, :debugger
44
+ attr_reader :debugger
46
45
 
47
46
  def to_stream(string_or_stream)
48
47
  return string_or_stream if string_or_stream.respond_to? :gets
@@ -50,7 +49,7 @@ class SeeingIsBelieving
50
49
  end
51
50
 
52
51
  def program_that_will_record_expressions
53
- WrapExpressions.call "#@program\n",
52
+ WrapExpressions.call "#{@program}\n",
54
53
  before_all: "begin; $SiB.number_of_captures = #{number_of_captures_as_str}; ",
55
54
  after_all: ";rescue Exception;"\
56
55
  "line_number = $!.backtrace.grep(/\#{__FILE__}/).first[/:\\d+/][1..-1].to_i;"\
@@ -65,18 +64,17 @@ class SeeingIsBelieving
65
64
  def result_for(program)
66
65
  Dir.mktmpdir "seeing_is_believing_temp_dir" do |dir|
67
66
  filename = @filename || File.join(dir, 'program.rb')
68
- EvaluateByMovingFiles.new(program,
69
- filename,
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)
79
- .call
67
+ EvaluateByMovingFiles.call program,
68
+ 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,
77
+ number_of_captures: @number_of_captures
80
78
  end
81
79
  end
82
80
 
@@ -45,7 +45,7 @@ class SeeingIsBelieving
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
47
  elsif output_as_json? then print_result_as_json ; SUCCESS_STATUS
48
- else print_program ; program_exit_status
48
+ else print_program ; exit_status
49
49
  end
50
50
  end
51
51
  end
@@ -54,66 +54,10 @@ class SeeingIsBelieving
54
54
 
55
55
  attr_accessor :flags, :interpolated_program
56
56
 
57
- def program_exit_status
58
- if flags[:inherit_exit_status]
59
- results.exitstatus
60
- elsif results.has_exception?
61
- DISPLAYABLE_ERROR_STATUS
62
- else
63
- SUCCESS_STATUS
64
- end
65
- end
66
-
67
57
  def parse_flags
68
58
  self.flags = ParseArgs.call argv, stdout
69
59
  end
70
60
 
71
- def has_filename?
72
- flags[:filename]
73
- end
74
-
75
- def evaluate_program
76
- self.interpolated_program = printer.call
77
- rescue Timeout::Error
78
- self.timeout_error = true
79
- rescue Exception
80
- self.unexpected_exception = $!
81
- end
82
-
83
- # could we make this more obvious? I'd like to to be clear from #call
84
- # that this is when the program gets evaluated
85
- def program_timedout?
86
- timeout_error
87
- end
88
-
89
- def print_timeout_error
90
- stderr.puts "Timeout Error after #{@flags[:timeout]} seconds!"
91
- end
92
-
93
- def body
94
- @body ||= (flags[:program] || (file_is_on_stdin? && stdin.read) || File.read(flags[:filename]))
95
- end
96
-
97
- def something_blew_up?
98
- !!unexpected_exception
99
- end
100
-
101
- def print_unexpected_error
102
- if unexpected_exception.kind_of? BugInSib
103
- stderr.puts unexpected_exception.message
104
- else
105
- stderr.puts unexpected_exception.class, unexpected_exception.message, "", unexpected_exception.backtrace
106
- end
107
- end
108
-
109
- def printer
110
- @printer ||= AddAnnotations.new body, flags.merge(stdin: (file_is_on_stdin? ? '' : stdin))
111
- end
112
-
113
- def results
114
- printer.results
115
- end
116
-
117
61
  def flags_have_errors?
118
62
  flags[:errors].any?
119
63
  end
@@ -138,8 +82,8 @@ class SeeingIsBelieving
138
82
  stdout.puts SeeingIsBelieving::VERSION
139
83
  end
140
84
 
141
- def file_is_on_stdin?
142
- flags[:filename].nil? && flags[:program].nil?
85
+ def has_filename?
86
+ flags[:filename]
143
87
  end
144
88
 
145
89
  def file_dne?
@@ -150,13 +94,12 @@ class SeeingIsBelieving
150
94
  stderr.puts "#{flags[:filename]} does not exist!"
151
95
  end
152
96
 
153
- def print_program
154
- stdout.print interpolated_program
97
+ def should_clean?
98
+ flags[:clean]
155
99
  end
156
100
 
157
- def syntax_error_notice
158
- out, err, syntax_status = Open3.capture3 flags[:shebang], '-c', stdin_data: body
159
- return err unless syntax_status.success?
101
+ def print_cleaned_program
102
+ stdout.print CleanBody.call(body, true)
160
103
  end
161
104
 
162
105
  def invalid_syntax?
@@ -167,18 +110,65 @@ class SeeingIsBelieving
167
110
  stderr.puts syntax_error_notice
168
111
  end
169
112
 
170
- def should_clean?
171
- flags[:clean]
113
+ def evaluate_program
114
+ self.interpolated_program = printer.call
115
+ rescue Timeout::Error
116
+ self.timeout_error = true
117
+ rescue Exception
118
+ self.unexpected_exception = $!
172
119
  end
173
120
 
174
- def print_cleaned_program
175
- stdout.print CleanBody.call(body, true)
121
+ def program_timedout?
122
+ timeout_error
123
+ end
124
+
125
+ def print_timeout_error
126
+ stderr.puts "Timeout Error after #{@flags[:timeout]} seconds!"
127
+ end
128
+
129
+ def something_blew_up?
130
+ !!unexpected_exception
131
+ end
132
+
133
+ def print_unexpected_error
134
+ if unexpected_exception.kind_of? BugInSib
135
+ stderr.puts unexpected_exception.message
136
+ else
137
+ stderr.puts unexpected_exception.class, unexpected_exception.message, "", unexpected_exception.backtrace
138
+ end
176
139
  end
177
140
 
178
141
  def output_as_json?
179
142
  flags[:result_as_json]
180
143
  end
181
144
 
145
+ def print_program
146
+ stdout.print interpolated_program
147
+ end
148
+
149
+ def body
150
+ @body ||= (flags[:program] || (file_is_on_stdin? && stdin.read) || File.read(flags[:filename]))
151
+ end
152
+
153
+ def printer
154
+ @printer ||= AddAnnotations.new body, flags.merge(stdin: (file_is_on_stdin? ? '' : stdin))
155
+ end
156
+
157
+ def results
158
+ printer.results
159
+ end
160
+
161
+ def file_is_on_stdin?
162
+ flags[:filename].nil? && flags[:program].nil?
163
+ end
164
+
165
+ def syntax_error_notice
166
+ @error_notice = begin
167
+ out, err, syntax_status = Open3.capture3 flags[:shebang], '-c', stdin_data: body
168
+ err unless syntax_status.success?
169
+ end
170
+ end
171
+
182
172
  def print_result_as_json
183
173
  require 'json'
184
174
  stdout.puts JSON.dump result_as_data_structure
@@ -209,5 +199,15 @@ class SeeingIsBelieving
209
199
  }
210
200
  end
211
201
 
202
+ def exit_status
203
+ if flags[:inherit_exit_status]
204
+ results.exitstatus
205
+ elsif results.has_exception?
206
+ DISPLAYABLE_ERROR_STATUS
207
+ else
208
+ SUCCESS_STATUS
209
+ end
210
+ end
211
+
212
212
  end
213
213
  end
@@ -23,6 +23,11 @@ require 'seeing_is_believing/hard_core_ensure'
23
23
 
24
24
  class SeeingIsBelieving
25
25
  class EvaluateByMovingFiles
26
+
27
+ def self.call(*args)
28
+ new(*args).call
29
+ end
30
+
26
31
  attr_accessor :program, :filename, :input_stream, :matrix_filename, :require_flags, :load_path_flags, :encoding, :timeout, :ruby_executable, :debugger
27
32
 
28
33
  def initialize(program, filename, options={})
@@ -1,3 +1,3 @@
1
1
  class SeeingIsBelieving
2
- VERSION = '2.0.3'
2
+ VERSION = '2.0.4'
3
3
  end
@@ -35,10 +35,7 @@ class SeeingIsBelieving
35
35
 
36
36
  wrappings.each do |line_num, (range, last_col, meta)|
37
37
  rewriter.insert_before range, before_each.call(line_num)
38
- if meta == :wrap_in_braces
39
- rewriter.insert_before range, '{'
40
- rewriter.insert_after range, '}'
41
- elsif meta == :total_fucking_failure
38
+ if meta == :total_fucking_failure
42
39
  rewriter.replace range, '.....TOTAL FUCKING FAILURE!.....'
43
40
  end
44
41
  rewriter.insert_after range, after_each.call(line_num)
@@ -229,9 +226,9 @@ class SeeingIsBelieving
229
226
  add_to_wrappings heredoc_hack ast
230
227
 
231
228
  when :hash
232
- meta = :wrap_in_braces
233
- meta = nil if ast.location.begin
234
- add_to_wrappings ast, meta
229
+ # method arguments might not have braces around them
230
+ # in these cases, we want to record the value, not the hash
231
+ add_to_wrappings ast, meta if ast.location.begin
235
232
  add_children ast
236
233
 
237
234
  else
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency "parser", "= 2.0.0.pre8"
22
+ s.add_dependency "parser", "~> 2.0.0"
23
23
 
24
24
  s.add_development_dependency "haiti", "~> 0.0.3"
25
25
  s.add_development_dependency "rake", "~> 10.0.3"
@@ -335,19 +335,21 @@ describe SeeingIsBelieving do
335
335
  end
336
336
 
337
337
  it 'does not record BEGIN and END', not_implemented: true do
338
- expect { invoke <<-CODE }.to_not raise_error
339
- puts 1
340
- BEGIN {
341
- puts "begin code"
342
- some_var = 2
343
- }
344
- puts 3
345
- END {
346
- puts "end code"
347
- puts some_var
348
- }
349
- puts 4
350
- CODE
338
+ pending 'not implemented' do
339
+ expect { invoke <<-CODE }.to_not raise_error
340
+ puts 1
341
+ BEGIN {
342
+ puts "begin code"
343
+ some_var = 2
344
+ }
345
+ puts 3
346
+ END {
347
+ puts "end code"
348
+ puts some_var
349
+ }
350
+ puts 4
351
+ CODE
352
+ end
351
353
  end
352
354
 
353
355
  context 'when given a debugger' do
@@ -318,6 +318,10 @@ describe SeeingIsBelieving::WrapExpressions do
318
318
  wrap("a(\n*a\n)").should == "<a(\n*a\n)>"
319
319
  wrap("a(\n*1..2\n)").should == "<a(\n*1..2\n)>"
320
320
  end
321
+
322
+ it 'does not wrap hash args' do
323
+ wrap("a(b: 1,\nc: 2\n)").should == "<a(b: <1>,\nc: <2>\n)>"
324
+ end
321
325
  end
322
326
 
323
327
  describe 'assignment' do
@@ -516,10 +520,6 @@ describe SeeingIsBelieving::WrapExpressions do
516
520
  wrap("{\n1 => 2}").should == "<{\n1 => 2}>"
517
521
  wrap("{\n1 => 2,\n:abc => 3,\ndef: 4\n}").should == "<{\n1 => <2>,\n:abc => <3>,\ndef: <4>\n}>"
518
522
  end
519
-
520
- it 'wraps explicit braces around recorded in method invocations' do
521
- wrap("a(\nb: 1, c: 2\n)").should == "<a(\n<{b: 1, c: 2}>\n)>"
522
- end
523
523
  end
524
524
 
525
525
  describe 'array literals' do
@@ -787,10 +787,12 @@ describe SeeingIsBelieving::WrapExpressions do
787
787
  # which we could do with some meta, just replacing it with the literal when we parse it
788
788
  # but still, moving this out of here will be really annoying, and no one is going to use it, so fuck it
789
789
  it 'does not record them', not_implemented: true do
790
- wrap("BEGIN {}").should == "BEGIN {}"
791
- wrap("END {}").should == "END {}"
792
- wrap("BEGIN {\n123\n}").should == "BEGIN {\n<123>\n}"
793
- wrap("END {\n123\n}").should == "END {\n<123>\n}"
790
+ pending 'not implemented, and probably never will be' do
791
+ wrap("BEGIN {}").should == "BEGIN {}"
792
+ wrap("END {}").should == "END {}"
793
+ wrap("BEGIN {\n123\n}").should == "BEGIN {\n<123>\n}"
794
+ wrap("END {\n123\n}").should == "END {\n<123>\n}"
795
+ end
794
796
  end
795
797
  end
796
798
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seeing_is_believing
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
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-09-16 00:00:00.000000000 Z
11
+ date: 2013-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0.pre8
19
+ version: 2.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.0.pre8
26
+ version: 2.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: haiti
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -110,12 +110,14 @@ files:
110
110
  - Rakefile
111
111
  - Readme.md
112
112
  - bin/seeing_is_believing
113
+ - docs/for-presentations
114
+ - docs/frog-brown.png
115
+ - docs/seeing is believing.psd
113
116
  - features/errors.feature
114
117
  - features/examples.feature
115
118
  - features/flags.feature
116
119
  - features/regression.feature
117
120
  - features/support/env.rb
118
- - for-presentations
119
121
  - lib/seeing_is_believing.rb
120
122
  - lib/seeing_is_believing/binary.rb
121
123
  - lib/seeing_is_believing/binary/add_annotations.rb
@@ -192,3 +194,4 @@ test_files:
192
194
  - spec/line_spec.rb
193
195
  - spec/seeing_is_believing_spec.rb
194
196
  - spec/wrap_expressions_spec.rb
197
+ has_rdoc: