seeing_is_believing 2.0.4 → 2.1.0

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: 6adfee9e8967b84be59e45a401f01f143d458ffb
4
- data.tar.gz: 014dc1b1d8af353f5bef6dd3f46f0ee4d97cb859
3
+ metadata.gz: abbcb4fd5db54b1a8b6158b07cb9b4705a1d7bc5
4
+ data.tar.gz: 1201fcec0c2768dae5769a6aca6aa06463992a27
5
5
  SHA512:
6
- metadata.gz: 7a3f04bacf9afc8d2e032582140890e24c000b0433be694f1dbd5a3a8029fcc724fa6c4efdc6de71426f9cde5aee033e53f9b562e48db9d75a4d6ee50b432d81
7
- data.tar.gz: dad2c178e03dcfee0f28aea9ed62edf4d8e44ba3456b7880ad4a6134ab4a3e866a1dedcb28c9ea763d42b1fe5137a97c436af62324adf3885e19faa06b1ddbb8
6
+ metadata.gz: 63eb02d6a89e340a6f29cb1a49ed31d7ab5153550be46bba89309b193154faab7894dca268bbb9f367be8d3a0ba713d4b30d94a71b70fef7e7bc51e63498c001
7
+ data.tar.gz: 98fefbaaef519b2e61489c47ce7b9b0425572bd326d9a2d93e6b36b2e1f73349d52fa91f454b15775356d66e615faf32678523664ea31a65e41188114eb862f1
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ gem 'pry'
3
4
  gemspec
data/Readme.md CHANGED
@@ -121,3 +121,4 @@ License
121
121
  0. You just DO WHAT THE FUCK YOU WANT TO.
122
122
 
123
123
 
124
+
@@ -12,6 +12,7 @@ Then 'stdout is exactly:' do |code|
12
12
  end
13
13
 
14
14
  Then 'stdout is the JSON:' do |json|
15
+ require 'json'
15
16
  expected = JSON.parse(json)
16
17
  actual = JSON.parse(@last_executed.stdout)
17
18
  actual.should == expected
@@ -73,8 +73,7 @@ class SeeingIsBelieving
73
73
  encoding: @encoding,
74
74
  timeout: @timeout,
75
75
  ruby_executable: @ruby_executable,
76
- debugger: @debugger,
77
- number_of_captures: @number_of_captures
76
+ debugger: @debugger
78
77
  end
79
78
  end
80
79
 
@@ -3,6 +3,7 @@
3
3
  # removes annotations
4
4
  # only removes "# =>" when should_clean_values is false
5
5
 
6
+ require 'seeing_is_believing/binary'
6
7
  require 'seeing_is_believing/parser_helpers'
7
8
 
8
9
  class SeeingIsBelieving
@@ -25,18 +26,18 @@ class SeeingIsBelieving
25
26
 
26
27
  comments.each do |comment|
27
28
  case comment.text
28
- when /\A#\s*=>/
29
+ when VALUE_REGEX
29
30
  if should_clean_values
30
31
  removed_comments[:result] << comment
31
32
  rewriter.remove comment.location.expression
32
33
  end
33
- when /\A#\s*~>/
34
+ when EXCEPTION_REGEX
34
35
  removed_comments[:exception] << comment
35
36
  rewriter.remove comment.location.expression
36
- when /\A#\s*>>/ then
37
+ when STDOUT_REGEX
37
38
  removed_comments[:stdout] << comment
38
39
  rewriter.remove comment.location.expression
39
- when /\A#\s*!>/ then
40
+ when STDERR_REGEX
40
41
  removed_comments[:stderr] << comment
41
42
  rewriter.remove comment.location.expression
42
43
  end
@@ -81,9 +81,8 @@ class SeeingIsBelieving
81
81
  def ranges_of_atomic_expressions(ast, found_ranges)
82
82
  return found_ranges unless ast.kind_of? ::AST::Node
83
83
  if no_comment_zone?(ast) && heredoc?(ast)
84
- begin_pos = ast.location.expression.begin.begin_pos
85
- begin_pos += (ast.location.expression.source =~ /\n/).next
86
- end_pos = ast.location.expression.end.end_pos.next
84
+ begin_pos = ast.location.heredoc_body.begin_pos
85
+ end_pos = ast.location.heredoc_end.end_pos.next
87
86
  found_ranges << (begin_pos...end_pos)
88
87
  elsif no_comment_zone? ast
89
88
  begin_pos = ast.location.expression.begin.begin_pos
@@ -43,7 +43,7 @@ class SeeingIsBelieving
43
43
  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 }
44
44
  when '-e', '--program' then next_arg("#{arg} expected a program as the following argument but did not see one") { |program| options[:program] = program }
45
45
  when '-a', '--as' then next_arg("#{arg} expected a filename as the following argument but did not see one") { |filename| options[:as] = filename }
46
- when '--shebang' then next_arg("#{arg} expects a ruby executable as the following argument but did not see one") { |executable| options[:shebang] = executable }
46
+ when '--shebang' then next_arg("#{arg} expects a ruby executable as the following argument but did not see one") { |executable| options[:shebang] = executable }
47
47
  when '-s', '--alignment-strategy' then extract_alignment_strategy
48
48
  when /\A-K(.+)/ then options[:encoding] = $1
49
49
  when '-K', '--encoding' then next_arg("#{arg} expects an encoding, see `man ruby` for possibile values") { |encoding| options[:encoding] = encoding }
@@ -17,7 +17,7 @@ class SeeingIsBelieving
17
17
  alias enabled? stream
18
18
 
19
19
  def context(name, &block)
20
- if stream
20
+ if enabled?
21
21
  stream << CONTEXT_COLOUR if coloured?
22
22
  stream << "#{name}:"
23
23
  stream << RESET_COLOUR if coloured?
@@ -4,12 +4,12 @@
4
4
  #
5
5
  # Another option is to replace __FILE__ macros ourselves
6
6
  # and then write to a temp file but evaluate in the context
7
- # of the expected directory. I'm not doing that just because
8
- # I don't think the __FILE__ macro can be replaced correctly
9
- # without parsing the code, changing the AST, and then
10
- # regenerating it, which I'm not good enough to do. Though
11
- # I did look at Ripper, and it will invoke on_kw("__FILE__")
12
- # when it sees this.
7
+ # of the expected directory. Some issues could arise with this,
8
+ # though: if you required the file again, it wouldn't already
9
+ # be in the loaded features (might be able to just add it)
10
+ # if you did something like File.read(__FILE__) it would
11
+ # read the wrong file... of course, since we rewrite the file,
12
+ # its body will be incorrect, anyway.
13
13
 
14
14
  require 'yaml'
15
15
  require 'open3'
@@ -52,8 +52,6 @@ class SeeingIsBelieving
52
52
  begin
53
53
  evaluate_file
54
54
  deserialize_result.tap { |result| fail if result.bug_in_sib? }
55
- # Okay, really, I should wrap this in another exception and raise it on up,
56
- # but for now, I'm feeling a little lazy and am not going to do it
57
55
  rescue Exception => error
58
56
  error = wrap_error error if error_implies_bug_in_sib? error
59
57
  raise error
@@ -28,7 +28,12 @@ class SeeingIsBelieving
28
28
  end
29
29
 
30
30
  def record_result(value)
31
- inspected = value.inspect # only invoke inspect once, b/c the inspection may be recorded
31
+ begin
32
+ inspected = value.inspect.to_str # only invoke inspect once, b/c the inspection may be recorded
33
+ rescue NoMethodError
34
+ inspected = "#<no inspect available>"
35
+ end
36
+
32
37
  if size < @max_number_of_captures then @array << inspected
33
38
  elsif size == @max_number_of_captures then @array << '...'
34
39
  end
@@ -4,7 +4,7 @@ class SeeingIsBelieving
4
4
 
5
5
  # override #process so it does not raise an error on
6
6
  # fatal parsings (we want to keep going if possible,
7
- # this allows us to find comments in syntactically invalid files
7
+ # this allows us to find comments in syntactically invalid files)
8
8
  class NullDiagnostics < Parser::Diagnostic::Engine
9
9
  def process(*)
10
10
  # no op
@@ -38,12 +38,12 @@ class SeeingIsBelieving
38
38
  def heredoc?(ast)
39
39
  # some strings are fucking weird.
40
40
  # e.g. the "1" in `%w[1]` returns nil for ast.location.begin
41
- # and `__FILE__` is a string whose location is a Parser::Source::Map instead of a Parser::Source::Map::Collection, so it has no #begin
41
+ # and `__FILE__` is a string whose location is a Parser::Source::Map instead of a Parser::Source::Map::Collection,
42
+ # so it has no #begin
42
43
  ast.kind_of?(Parser::AST::Node) &&
43
44
  (ast.type == :dstr || ast.type == :str) &&
44
45
  (location = ast.location) &&
45
- (the_begin = location.begin) &&
46
- (the_begin.source =~ /^\<\<-?/)
46
+ (ast.location.kind_of? Parser::Source::Map::Heredoc)
47
47
  end
48
48
 
49
49
  def void_value?(ast)
@@ -62,6 +62,7 @@ class SeeingIsBelieving
62
62
  end
63
63
 
64
64
  def heredoc_hack(ast)
65
+ return ast
65
66
  return ast unless heredoc? ast
66
67
  Parser::AST::Node.new :str,
67
68
  [],
@@ -1,3 +1,3 @@
1
1
  class SeeingIsBelieving
2
- VERSION = '2.0.4'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -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"
22
+ s.add_dependency "parser", "~> 2.1.4"
23
23
 
24
24
  s.add_development_dependency "haiti", "~> 0.0.3"
25
25
  s.add_development_dependency "rake", "~> 10.0.3"
data/spec/line_spec.rb CHANGED
@@ -19,6 +19,19 @@ describe SeeingIsBelieving::Line, t:true do
19
19
  line.inspect.should == '#<SIB:Line[] (0, 0) RuntimeError:"omg">'
20
20
  end
21
21
 
22
+ it "doesn't blow up when there is no #inspect available e.g. BasicObject" do
23
+ obj = BasicObject.new
24
+ line_for(obj).inspect.should == '#<SIB:Line["#<no inspect available>"] (1, 23) no exception>'
25
+ end
26
+
27
+ it "doesn't blow up when #inspect returns a not-String (e.g. pathalogical libraries like FactoryGirl)" do
28
+ obj = BasicObject.new
29
+ def obj.inspect
30
+ nil
31
+ end
32
+ line_for(obj).inspect.should == '#<SIB:Line["#<no inspect available>"] (1, 23) no exception>'
33
+ end
34
+
22
35
  it 'knows when it has an exception' do
23
36
  exception = RuntimeError.new 'omg'
24
37
  line = Line.new
@@ -314,7 +314,7 @@ describe SeeingIsBelieving do
314
314
  it 'can evaluate under a different ruby executable' do
315
315
  Dir.chdir proving_grounds_dir do
316
316
  File.write 'omg-ruby', "#!/usr/bin/env ruby
317
- $LOAD_PATH.unshift '#{File.expand_path '../lib', __FILE__}'
317
+ $LOAD_PATH.unshift '#{File.expand_path '../../lib', __FILE__}'
318
318
 
319
319
  require 'seeing_is_believing'
320
320
  result = SeeingIsBelieving::Result.new
@@ -39,7 +39,7 @@ describe SeeingIsBelieving::WrapExpressions do
39
39
  end
40
40
 
41
41
  example 'multiple heredocs' do
42
- # a stupid implementatnio issue from hacking around heredocs
42
+ # a stupid implementation issue from hacking around heredocs
43
43
  # causes the toplevel begin to wrap the whole file.
44
44
  # It's fine b/c it is ultimately the same, but that's why it's
45
45
  # "[<<<<A>\nA\n<<B>]\nB"
@@ -598,9 +598,7 @@ describe SeeingIsBelieving::WrapExpressions do
598
598
  end
599
599
 
600
600
  it 'wraps heredocs with call defined on them (edge cases on edge cases *sigh*)' do
601
- pending "just don't care this much right now, hopefully it will magically be fixed when new parser is released" do
602
- wrap("<<HERE.()\na\nHERE").should == "<<<HERE.()>\na\nHERE"
603
- end
601
+ wrap("<<HERE.()\na\nHERE").should == "<<<HERE.()>\na\nHERE"
604
602
  end
605
603
  end
606
604
 
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.4
4
+ version: 2.1.0
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-11-01 00:00:00.000000000 Z
11
+ date: 2014-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0
19
+ version: 2.1.4
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
26
+ version: 2.1.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: haiti
29
29
  requirement: !ruby/object:Gem::Requirement