seeing_is_believing 3.0.0.beta.6 → 3.0.0.beta.7

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: 8715640842e97ae16fececb478cf4356169e1fdc
4
- data.tar.gz: a2bfb634547740e23c0a71710a953496350fb2b0
3
+ metadata.gz: 866178b03727394e7c24c5cfbaa48ea4edbca4e1
4
+ data.tar.gz: cfe4540e781ec9aa65b79a950d8760058136a85d
5
5
  SHA512:
6
- metadata.gz: a4bbbaaa3640d0dd4b42051eb7416efb940af2b5b7a78df277c8047ec0a91e10b725e0c68a0d0ebf961d20583579ea231c1c2fd90504aded08ce81e20675b9e4
7
- data.tar.gz: 319db0b7ee9047fa6c051659f8da8320f83828141e3e47e38448078f87720e7847c35e773ea50331684d644a70917129f0d2e91890aa535023472d797aa0a211
6
+ metadata.gz: 514947858dab6b669eeb25f8b729e330d9435b438f2821073a56a12226451710a54f775415591e56c8673d071e276c102ec7ca001f4f6f2ce03fe9d2f1282b7b
7
+ data.tar.gz: 341dea9e96e9e1c57565254830f5f22648bcd2b9363d492b1a8718dddc54e30861c449d5374f3822e7ef7c88ce89ea107c79e5049c7e216a35a88c3b8440f735
data/.rspec CHANGED
@@ -1,4 +1,2 @@
1
1
  --colour
2
- --fail-fast
3
- --require error_to_communicate/rspec_formatter
4
- --format WhatWeveGotHereIsAnErrorToCommunicate::RSpecFormatter
2
+ --format documentation
data/.travis.yml CHANGED
@@ -1,8 +1,9 @@
1
1
  language: ruby
2
- script: rake ci
2
+ install: gem install bundler && bundle install --standalone --binstubs bundle/bin
3
+ script: bundle exec rake ci
3
4
  rvm:
4
5
  - 1.9.3
5
6
  - 2.0.0
6
7
  - 2.1.2
7
8
  - 2.2.0
8
- - ruby-head
9
+ - 2.3.0
data/Gemfile CHANGED
@@ -1,3 +1,2 @@
1
1
  source 'http://rubygems.org'
2
-
3
2
  gemspec
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'bundler'
2
2
 
3
3
  desc 'Have Bundler setup a standalone environment -- run tests in this, b/c its faster and safer'
4
- task :build do
4
+ task :install do
5
5
  # Running without rubygems # http://myronmars.to/n/dev-blog/2012/03/faster-test-boot-times-with-bundler-standalone
6
6
  sh 'bundle install --standalone --binstubs bundle/bin'
7
7
  end
@@ -17,14 +17,14 @@ task :clean do
17
17
  ]
18
18
  end
19
19
 
20
- file :bundle do
21
- $stderr.puts "\e[31mLooks like the gems aren\'t installed, run `rake build` to install them\e[39m"
20
+ directory 'bundle' do
21
+ $stderr.puts "\e[31mLooks like the gems aren\'t installed, run `rake install` to install them\e[39m"
22
22
  exit 1
23
23
  end
24
24
 
25
25
  desc 'Run specs'
26
26
  task spec: :bundle do
27
- sh 'ruby', '--disable-gem', *Bundler.load.specs.flat_map(&:full_require_paths).flat_map { |p| ['-I', p ] }, '-S', 'bundle/bin/rspec'
27
+ sh 'ruby', '--disable-gem', *Bundler.load.specs.flat_map(&:full_require_paths).flat_map { |p| ['-I', p ] }, '-S', 'bundle/bin/mrspec'
28
28
  end
29
29
 
30
30
  desc 'Run cukes'
@@ -36,4 +36,4 @@ desc 'Run all specs and cukes'
36
36
  task default: [:spec, :cuke]
37
37
 
38
38
  desc 'Install dependencies and run tests (mainly for Travis CI)'
39
- task ci: [:build, :spec, :cuke]
39
+ task ci: [:install, :spec, :cuke]
data/Readme.md CHANGED
@@ -5,7 +5,7 @@ Seeing Is Believing
5
5
  ===================
6
6
 
7
7
  Evaluates Ruby code, recording the results of each line.
8
- Integrates with any extensible editor (I've integrated it with many already, see [the list](https://github.com/JoshCheek/seeing_is_believing#editor-integration).
8
+ Integrates with any extensible editor (I've integrated it with many already, see [the list](https://github.com/JoshCheek/seeing_is_believing#editor-integration)).
9
9
 
10
10
  ![example](https://s3.amazonaws.com/josh.cheek/images/scratch/sib-example1.gif)
11
11
 
@@ -72,7 +72,7 @@ Editor Integration
72
72
  Vim
73
73
  ===
74
74
 
75
- I didn't write either of these, but they both support Seeing Is Beleiving. I've looked through the code, it works reasonably. One of them, I wound up having to edit the installed package, don't remember which.
75
+ I didn't write either of these, but they both support Seeing Is Believing. I've looked through the code, it works reasonably. One of them, I wound up having to edit the installed package, don't remember which.
76
76
 
77
77
  * [vim-ruby-xmpfilter](https://github.com/t9md/vim-ruby-xmpfilter)
78
78
  * [vim-seeing-is-believing](https://github.com/hwartig/vim-seeing-is-believing)
@@ -80,7 +80,9 @@ I didn't write either of these, but they both support Seeing Is Beleiving. I've
80
80
  Emacs Integration
81
81
  =================
82
82
 
83
- Add this function to your Emacs configuration:
83
+ You can use my friend's configuration [file](https://github.com/jcinnamond/seeing-is-believing).
84
+
85
+ Or, adding this function to your Emacs configuration will get you pretty far:
84
86
 
85
87
  ```scheme
86
88
  (defun seeing-is-believing ()
@@ -88,8 +90,10 @@ Add this function to your Emacs configuration:
88
90
  of seeing_is_believing."
89
91
  (interactive)
90
92
  (let ((beg (if (region-active-p) (region-beginning) (point-min)))
91
- (end (if (region-active-p) (region-end) (point-max))))
92
- (shell-command-on-region beg end "seeing_is_believing" nil 'replace)))
93
+ (end (if (region-active-p) (region-end) (point-max)))
94
+ (origin (point)))
95
+ (shell-command-on-region beg end "seeing_is_believing" nil 'replace)
96
+ (goto-char origin)))
93
97
  ```
94
98
 
95
99
  You can now call `seeing-is-believing` to replace the current region
@@ -459,8 +459,7 @@ Feature:
459
459
  b"
460
460
 
461
461
  # ~> NoMethodError
462
- # ~> undefined method `a
463
- # ~> b' for 1:Fixnum
462
+ # ~> undefined method
464
463
  """
465
464
 
466
465
 
@@ -12,7 +12,7 @@ class SeeingIsBelieving
12
12
  exception_output_for(results, options)
13
13
 
14
14
  code = Code.new(new_body)
15
- code.rewriter.insert_after code.body_range, output
15
+ code.rewriter.insert_after_multi code.body_range, output
16
16
  new_body.replace code.rewriter.process
17
17
  end
18
18
 
@@ -27,19 +27,30 @@ class SeeingIsBelieving
27
27
  WrapExpressions.call \
28
28
  program,
29
29
  before_each: -> line_number {
30
+ # 74 b/c pretty print_defaults to 79 (guessing 80 chars with 1 reserved for newline), and
31
+ # 79 - "# => ".length # => 4
32
+ inspect = "$SiB.record_result(:inspect, #{line_number}, ("
33
+ pp = "$SiB.record_result(:pp, #{line_number}, ("
34
+
30
35
  should_inspect = inspect_linenos.include? line_number
31
36
  should_pp = pp_linenos.include? line_number
32
- should_inspect || should_pp ? '(' : ''
37
+
38
+ if should_inspect && should_pp then "#{pp}#{inspect}"
39
+ elsif should_inspect then inspect
40
+ elsif should_pp then pp
41
+ else ""
42
+ end
33
43
  },
34
44
  after_each: -> line_number {
35
- # 74 b/c pretty print_defaults to 79 (guessing 80 chars with 1 reserved for newline), and
36
- # 79 - "# => ".length # => 4
37
- inspect = "$SiB.record_result :inspect, #{line_number}, v"
38
- pp = "$SiB.record_result(:pp, #{line_number}, v) { PP.pp v, '', 74 }"
45
+ inspect = "))"
46
+ pp = ")) { |v| PP.pp v, '', 74 }"
47
+
48
+ should_inspect = inspect_linenos.include? line_number
49
+ should_pp = pp_linenos.include? line_number
39
50
 
40
- if should_inspect && should_pp then ").tap { |v| #{inspect}; #{pp} }"
41
- elsif should_inspect then ").tap { |v| #{inspect} }"
42
- elsif should_pp then ").tap { |v| #{pp} }"
51
+ if should_inspect && should_pp then "#{inspect}#{pp}"
52
+ elsif should_inspect then inspect
53
+ elsif should_pp then pp
43
54
  else ""
44
55
  end
45
56
  }
@@ -22,7 +22,7 @@ class SeeingIsBelieving
22
22
  first_index -= 1 while first_index > 0 && raw_code[first_index-1] != "\n"
23
23
  comment_text = commenter.call raw_code[first_index...last_index], line_number
24
24
  range = Parser::Source::Range.new(commentable_lines.buffer, first_index, last_index)
25
- commentable_lines.rewriter.insert_after range, comment_text
25
+ commentable_lines.rewriter.insert_after_multi range, comment_text
26
26
  end
27
27
  commentable_lines.rewriter.process
28
28
  end
@@ -24,20 +24,19 @@ class SeeingIsBelieving
24
24
  @raw = raw_code
25
25
  @buffer = Parser::Source::Buffer.new(name||"SeeingIsBelieving")
26
26
  @buffer.source = raw
27
- builder = Parser::Builders::Default.new.tap { |b| b.emit_file_line_as_literals = false }
28
27
  @rewriter = Parser::Source::Rewriter.new buffer
29
- @raw_comments, tokens = comments_and_tokens(builder, buffer)
30
- @body_range = body_range_from_tokens(tokens)
28
+ builder = Parser::Builders::Default.new.tap { |b| b.emit_file_line_as_literals = false }
31
29
  @parser = Parser::CurrentRuby.new builder
32
- @inline_comments = raw_comments.select(&:inline?).map { |c| wrap_comment c }
33
- begin
34
- @root = @parser.parse(@buffer)
35
- @syntax = Syntax.new
36
- rescue Parser::SyntaxError
37
- @syntax = Syntax.new error_message: $!.message, line_number: index_to_linenum($!.diagnostic.location.begin_pos)
38
- ensure
39
- @root ||= null_node
30
+ @syntax = Syntax.new
31
+ parser.diagnostics.consumer = lambda do |diagnostic|
32
+ if :fatal == diagnostic.level || :error == diagnostic.level
33
+ @syntax = Syntax.new error_message: diagnostic.message, line_number: index_to_linenum(diagnostic.location.begin_pos)
34
+ end
40
35
  end
36
+ @root, @raw_comments, @tokens = parser.tokenize(@buffer, true)
37
+ @body_range = body_range_from_tokens(@tokens)
38
+ @inline_comments = raw_comments.select(&:inline?).map { |c| wrap_comment c }
39
+ @root ||= null_node
41
40
  end
42
41
 
43
42
  def range_for(start_index, end_index)
@@ -91,32 +90,8 @@ class SeeingIsBelieving
91
90
  private
92
91
 
93
92
  def comments_and_tokens(builder, buffer)
94
- # THIS IS SO WE CAN EXTRACT COMMENTS FROM INVALID FILES.
95
- # We do it by telling Parser's diagnostic to not blow up.
96
- # https://github.com/whitequark/parser/blob/2d69a1b5f34ef15b3a8330beb036ac4bf4775e29/lib/parser/diagnostic/engine.rb
97
- # However, this probably implies SiB won't work on Rbx/JRuby
98
- # https://github.com/whitequark/parser/blob/2d69a1b5f34ef15b3a8330beb036ac4bf4775e29/lib/parser/base.rb#L129-134
99
- # Ideally we could just do this
100
- # parser.diagnostics.all_errors_are_fatal = false
101
- # parser.diagnostics.ignore_warnings = false
102
- # But, the parser will still blow up on "fatal" errors (e.g. unterminated string) So we need to actually change it.
103
- # https://github.com/whitequark/parser/blob/2d69a1b5f34ef15b3a8330beb036ac4bf4775e29/lib/parser/diagnostic/engine.rb#L99
104
- # We could make a NullDiagnostics like this:
105
- # class NullDiagnostics < Parser::Diagnostic::Engine
106
- # def process(*)
107
- # # no op
108
- # end
109
- # end
110
- # But we don't control initialization of the variable, and the value gets passed around, at least into the lexer.
111
- # https://github.com/whitequark/parser/blob/2d69a1b5f34ef15b3a8330beb036ac4bf4775e29/lib/parser/base.rb#L139
112
- # and since it's all private, it could change at any time (Parser is very state based),
113
- # so I think it's just generally safer to mutate that one object, as we do now.
114
93
  parser = Parser::CurrentRuby.new builder
115
- diagnostics = parser.diagnostics
116
- def diagnostics.process(*)
117
- self
118
- end
119
- _, all_comments, tokens = parser.tokenize(@buffer)
94
+ _, all_comments, tokens = parser.tokenize(@buffer, true)
120
95
  [all_comments, tokens]
121
96
  end
122
97
 
@@ -24,6 +24,10 @@ real_exit_bang = method :exit!
24
24
  Kernel.module_eval do
25
25
  private
26
26
 
27
+ define_method :warn do |*args, &block|
28
+ $stderr.puts *args
29
+ end
30
+
27
31
  define_method :exec do |*args, &block|
28
32
  $SiB.record_exec(args)
29
33
  finish.call
@@ -1,3 +1,3 @@
1
1
  class SeeingIsBelieving
2
- VERSION = '3.0.0.beta.6'
2
+ VERSION = '3.0.0.beta.7'
3
3
  end
@@ -23,20 +23,27 @@ class SeeingIsBelieving
23
23
  @called ||= begin
24
24
  wrap_recursive code.root
25
25
 
26
- rewriter.insert_before root_range, before_all.call
26
+ wrappings = wrappings().sort_by(&:first)
27
27
 
28
28
  wrappings.each do |line_num, (range, last_col, meta)|
29
- rewriter.insert_before range, before_each.call(line_num)
30
29
  case meta
31
30
  when :total_fucking_failure
32
31
  rewriter.replace range, '.....TOTAL FUCKING FAILURE!.....'
33
32
  when :match_current_line
34
- rewriter.insert_before range, '~' # Regexp#~
33
+ rewriter.insert_before_multi range, '~' # Regexp#~
35
34
  end
36
- rewriter.insert_after range, after_each.call(line_num)
37
35
  end
38
36
 
39
- rewriter.insert_after root_range, after_all_text
37
+ wrappings.each do |line_num, (range, last_col, meta)|
38
+ rewriter.insert_before_multi range, before_each.call(line_num)
39
+ end
40
+
41
+ wrappings.each do |line_num, (range, last_col, meta)|
42
+ rewriter.insert_after_multi range, after_each.call(line_num)
43
+ end
44
+
45
+ rewriter.insert_before_multi root_range, before_all.call
46
+ rewriter.insert_after_multi root_range, after_all_text
40
47
  rewriter.process
41
48
  end
42
49
  end
@@ -2,12 +2,14 @@ require 'seeing_is_believing/wrap_expressions'
2
2
  class SeeingIsBelieving
3
3
  module WrapExpressionsWithInspect
4
4
  def self.call(program)
5
+ # NOTE: if it received the AST, it could figure out if it needs
6
+ # to always wrap the expression in parentheses
5
7
  WrapExpressions.call program,
6
8
  before_each: -> line_number {
7
- "("
9
+ "$SiB.record_result(:inspect, #{line_number}, ("
8
10
  },
9
11
  after_each: -> line_number {
10
- ").tap { |v| $SiB.record_result :inspect, #{line_number}, v }"
12
+ "))"
11
13
  }
12
14
  end
13
15
  end
@@ -19,11 +19,12 @@ 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.2.0.3", "< 3.0"
22
+ s.add_dependency "parser", ">= 2.3.0.7", "< 3.0"
23
23
 
24
24
  s.add_development_dependency "what_weve_got_here_is_an_error_to_communicate"
25
25
  s.add_development_dependency "haiti", ">= 0.1", "< 0.3"
26
26
  s.add_development_dependency "rake", "~> 10.0"
27
+ s.add_development_dependency "mrspec", "~> 0.3.0"
27
28
  s.add_development_dependency "rspec", "~> 3.2"
28
29
  s.add_development_dependency "cucumber", "~> 1.2"
29
30
  s.add_development_dependency "ichannel", "~> 5.1"
@@ -394,7 +394,7 @@ module SeeingIsBelieving::EventStream
394
394
  backtrace_filename: __FILE__
395
395
  end
396
396
 
397
- example 'Example: Common edge case: name error', t:true do
397
+ example 'Example: Common edge case: name error' do
398
398
  backtrace_line = record_exception(99) { BasicObject.new.instance_eval { not_a_local_or_meth } }
399
399
  backtrace_frame = 0
400
400
  backtrace_frame += 1 if defined? Rubinius # their method missing goes into the kernel
@@ -503,6 +503,10 @@ RSpec.describe SeeingIsBelieving do
503
503
  expect(values_for "File.read(__FILE__).lines.count").to eq [['1']]
504
504
  end
505
505
 
506
+ it 'records instances of BasicObject' do
507
+ expect(values_for 'o = BasicObject.new; def o.inspect; "some obj"; end; o').to eq [['some obj']]
508
+ end
509
+
506
510
  context 'when given a debugger' do
507
511
  let(:stream) { StringIO.new }
508
512
  let(:debugger) { SeeingIsBelieving::Debugger.new stream: stream }
@@ -551,6 +555,10 @@ RSpec.describe SeeingIsBelieving do
551
555
  it 'gets the exit status off of the child process' do
552
556
  expect(invoke('exec "ruby", "-e", "exit 5"').exitstatus).to eq 5
553
557
  end
558
+
559
+ it 'emits otuput on expicit invocations to warn' do
560
+ expect(invoke('warn "hello"').stderr).to eq "hello\n"
561
+ end
554
562
  end
555
563
 
556
564
  # Looked through the implementation of event_stream/producer to find a list of core behaviour it depends on
@@ -104,13 +104,11 @@ RSpec.describe SeeingIsBelieving::WrapExpressions do
104
104
  end
105
105
 
106
106
  it 'passes the current line number to the before_each and after_each wrappers' do
107
- pre_line_num = post_line_num = nil
108
- described_class.call("\na\n",
109
- before_each: -> _pre_line_num { pre_line_num = _pre_line_num; '<' },
110
- after_each: -> _post_line_num { post_line_num = _post_line_num; '>' }
111
- )
112
- expect(pre_line_num).to eq 2
113
- expect(post_line_num).to eq 2
107
+ result = described_class.call("a.each { |b|\n}\n",
108
+ before_each: -> n { "(#{n})" },
109
+ after_each: -> n { "<#{n}>" }
110
+ )
111
+ expect(result).to eq "(2)(1)a<1>.each { |b|\n}<2>\n"
114
112
  end
115
113
 
116
114
  it 'does nothing for an empty program' do
@@ -168,9 +166,7 @@ RSpec.describe SeeingIsBelieving::WrapExpressions do
168
166
  0b001_001
169
167
 
170
168
  ?a
171
- ?\C-a
172
- ?\M-a
173
- ?\M-\C-a
169
+ ?\\C-a
174
170
 
175
171
  1..2
176
172
  1...2
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: 3.0.0.beta.6
4
+ version: 3.0.0.beta.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Cheek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.2.0.3
19
+ version: 2.3.0.7
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '3.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 2.2.0.3
29
+ version: 2.3.0.7
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3.0'
@@ -78,6 +78,20 @@ dependencies:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
80
  version: '10.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: mrspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: 0.3.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: 0.3.0
81
95
  - !ruby/object:Gem::Dependency
82
96
  name: rspec
83
97
  requirement: !ruby/object:Gem::Requirement