seeing_is_believing 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Rakefile +2 -0
- data/Readme.md +3 -2
- data/features/regression.feature +1 -1
- data/lib/seeing_is_believing/binary/commentable_lines.rb +11 -2
- data/lib/seeing_is_believing/code.rb +9 -0
- data/lib/seeing_is_believing/event_stream/producer.rb +5 -1
- data/lib/seeing_is_believing/safe.rb +9 -0
- data/lib/seeing_is_believing/version.rb +1 -1
- data/seeing_is_believing.gemspec +5 -4
- data/spec/binary/comment_lines_spec.rb +7 -0
- data/spec/event_stream_spec.rb +15 -7
- data/spec/seeing_is_believing_spec.rb +3 -2
- data/spec/wrap_expressions_spec.rb +36 -0
- metadata +27 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c1356fef9747e418a57e2f151e4bc2f7625d6d8
|
4
|
+
data.tar.gz: 27c33822870a7f0bf0f25172ed626d581b1b4906
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4ba3ac50ac5ac732c097e7dcffebdcd58c7345f8f40df8b1086b33c9d9ef69b5e030ebf139401edc57e89622475eeab1c0cf2a92b966bd0671c9bad6181e144
|
7
|
+
data.tar.gz: 8bc5907b40214aa58377aec602033e08e47837239bed71d028e3833c4d9a75f28b59e88c55ec04f6c751e4a577695fb9175407b22340bfa3e41fcf7a5d8eb282
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -51,11 +51,13 @@ desc 'Run cukes'
|
|
51
51
|
task cuke: :bundle do
|
52
52
|
require 'bundler'
|
53
53
|
platform_filter = Gem.win_platform? ? %W[--tags ~@not-windows] : []
|
54
|
+
ruby_version_without_patchlevel = RUBY_VERSION[/^\d+\.\d+/]
|
54
55
|
sh 'ruby', '--disable-gem',
|
55
56
|
*require_paths,
|
56
57
|
'-S', 'bundle/bin/cucumber',
|
57
58
|
'--tags', '~@not-implemented',
|
58
59
|
'--tags', "~@not-#{RUBY_VERSION}",
|
60
|
+
'--tags', "~@not-#{ruby_version_without_patchlevel}",
|
59
61
|
*platform_filter
|
60
62
|
end
|
61
63
|
|
data/Readme.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
Unix/Mac: [![Unix Build Status](https://secure.travis-ci.org/JoshCheek/seeing_is_believing.
|
1
|
+
Unix/Mac: [![Unix Build Status](https://secure.travis-ci.org/JoshCheek/seeing_is_believing.svg?branch=master)](http://travis-ci.org/JoshCheek/seeing_is_believing)
|
2
|
+
Windows: [![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/JoshCheek/seeing_is_believing?branch=master&svg=true)](https://ci.appveyor.com/project/JoshCheek/seeing-is-believing)
|
2
3
|
|
3
4
|
Seeing Is Believing
|
4
5
|
===================
|
@@ -28,7 +29,7 @@ Examples
|
|
28
29
|
|
29
30
|
* Watch a [longer video](http://vimeo.com/73866851).
|
30
31
|
* Watch John Cinnamond use it in a [presentation](http://brightonruby.com/2016/the-point-of-objects-john-cinnamond/)
|
31
|
-
at the 10 minute mark.
|
32
|
+
at the 10:22 minute mark.
|
32
33
|
* [Avdi](https://github.com/avdi) uses it in [Ruby Tapas](https://www.rubytapas.com/),
|
33
34
|
an amazing resource for developers in general and Ruby Developers in particular!
|
34
35
|
|
data/features/regression.feature
CHANGED
@@ -470,7 +470,7 @@ Feature:
|
|
470
470
|
#
|
471
471
|
# Not going to get too detailed on what it prints, b/c that message seems pretty fragile,
|
472
472
|
# but just generally that it doesn't fkn blow up
|
473
|
-
@not-2.4
|
473
|
+
@not-2.4
|
474
474
|
Scenario: Old JSON bug
|
475
475
|
Given the file "json_and_encodings.rb":
|
476
476
|
"""
|
@@ -52,8 +52,17 @@ class SeeingIsBelieving
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def remove_lines_whose_newline_is_escaped(line_num_to_location)
|
55
|
-
|
56
|
-
|
55
|
+
ors_indexes = code_obj.indexes_of_ors_at_eol
|
56
|
+
line_num_to_location
|
57
|
+
.select { |line_number, (index_of_newline, col)|
|
58
|
+
code[index_of_newline-1] == '\\'
|
59
|
+
}
|
60
|
+
.reject { |line_number, (index_of_newline, col)|
|
61
|
+
ors_indexes.include? index_of_newline
|
62
|
+
}
|
63
|
+
.each { |line_number, (index_of_newline, col)|
|
64
|
+
line_num_to_location.delete line_number
|
65
|
+
}
|
57
66
|
end
|
58
67
|
|
59
68
|
def remove_lines_ending_in_comments(line_num_to_location, comments)
|
@@ -7,6 +7,7 @@ class << (Parser ||= Module.new)
|
|
7
7
|
remove_method :warn
|
8
8
|
end
|
9
9
|
|
10
|
+
require 'set'
|
10
11
|
require 'seeing_is_believing/hash_struct'
|
11
12
|
|
12
13
|
class SeeingIsBelieving
|
@@ -87,6 +88,14 @@ class SeeingIsBelieving
|
|
87
88
|
].freeze
|
88
89
|
end
|
89
90
|
|
91
|
+
def indexes_of_ors_at_eol
|
92
|
+
Set.new(
|
93
|
+
@tokens.select { |type, *| type == :tGVAR }
|
94
|
+
.select { |_, (var, range)| var == '$\\'.freeze }
|
95
|
+
.map { |_, (var, range)| range.end_pos }
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
90
99
|
private
|
91
100
|
|
92
101
|
def comments_and_tokens(builder, buffer)
|
@@ -60,7 +60,11 @@ class SeeingIsBelieving
|
|
60
60
|
# otherwise it looks like the bug is in SiB and not the user's program, see https://github.com/JoshCheek/seeing_is_believing/issues/37
|
61
61
|
raise SystemStackError, "Calling inspect blew the stack (is it recursive w/o a base case?)"
|
62
62
|
rescue Exception
|
63
|
-
|
63
|
+
begin
|
64
|
+
inspected = Kernel.instance_method(:inspect).bind(value).call
|
65
|
+
rescue Exception
|
66
|
+
inspected = "#<no inspect available>"
|
67
|
+
end
|
64
68
|
end
|
65
69
|
queue << "result #{line_number.to_s} #{type.to_s} #{to_string_token inspected}"
|
66
70
|
elsif count == max_line_captures
|
@@ -5,6 +5,15 @@ class SeeingIsBelieving
|
|
5
5
|
alias === ===
|
6
6
|
end
|
7
7
|
|
8
|
+
begin
|
9
|
+
refine Kernel do
|
10
|
+
alias inspect inspect
|
11
|
+
end
|
12
|
+
rescue TypeError
|
13
|
+
# Ruby < 2.4 can't refine a module,
|
14
|
+
# so this optimization is only available on >= 2.4
|
15
|
+
end
|
16
|
+
|
8
17
|
refine Queue do
|
9
18
|
alias << <<
|
10
19
|
alias shift shift
|
data/seeing_is_believing.gemspec
CHANGED
@@ -19,13 +19,14 @@ 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", "
|
23
|
-
s.add_dependency "childprocess","~> 0.
|
22
|
+
s.add_dependency "parser", "~> 2.4.0"
|
23
|
+
s.add_dependency "childprocess","~> 0.7.1"
|
24
24
|
|
25
|
+
s.add_development_dependency "pry"
|
25
26
|
s.add_development_dependency "haiti", ">= 0.1", "< 0.3"
|
26
|
-
s.add_development_dependency "rake", "~>
|
27
|
+
s.add_development_dependency "rake", "~> 12.0.0"
|
27
28
|
s.add_development_dependency "mrspec", "~> 0.3.1"
|
28
|
-
s.add_development_dependency "rspec", "~> 3.
|
29
|
+
s.add_development_dependency "rspec", "~> 3.6.0"
|
29
30
|
s.add_development_dependency "cucumber", "~> 2.4"
|
30
31
|
s.add_development_dependency "ripper-tags", "~> 0.3"
|
31
32
|
|
@@ -17,6 +17,13 @@ RSpec.describe SeeingIsBelieving::Binary::CommentLines, 'passes in the each comm
|
|
17
17
|
expect(call("1 +\\\n2") { |_, line_number| "--#{line_number}--" }).to eq "1 +\\\n2--2--"
|
18
18
|
end
|
19
19
|
|
20
|
+
it "doesn\'t confuse OUTPUT_RECORD_SEPARATOR with an escaped line" do
|
21
|
+
expect(call("$\\") { ';' }).to eq "$\\;"
|
22
|
+
expect(call("$\\\\\n1") { ';' }).to eq "$\\\\\n1;"
|
23
|
+
expect(call("1\n$\\") { ';' }).to eq "1;\n$\\;"
|
24
|
+
expect(call("1\n$var\\\n2") { ';' }).to eq "1;\n$var\\\n2;"
|
25
|
+
end
|
26
|
+
|
20
27
|
it "doesn't comment lines inside of strings" do
|
21
28
|
expect(call(<<-INPUT) { |_, line_number| "--#{line_number}--" }).to eq <<-OUTPUT
|
22
29
|
"a\#{1+1
|
data/spec/event_stream_spec.rb
CHANGED
@@ -23,6 +23,11 @@ module SeeingIsBelieving::EventStream
|
|
23
23
|
consumer.join
|
24
24
|
end
|
25
25
|
|
26
|
+
def inspected(obj)
|
27
|
+
Kernel.instance_method(:inspect).bind(obj).call
|
28
|
+
end
|
29
|
+
|
30
|
+
|
26
31
|
before do
|
27
32
|
self.eventstream_consumer, self.eventstream_producer = IO.pipe("utf-8")
|
28
33
|
self.stdout_consumer, self.stdout_producer = IO.pipe("utf-8")
|
@@ -272,20 +277,23 @@ module SeeingIsBelieving::EventStream
|
|
272
277
|
end
|
273
278
|
|
274
279
|
context 'calls #inspect when no block is given' do
|
275
|
-
it
|
280
|
+
it 'uses Kernel\'s inspect if there is no #inspect available e.g. BasicObject' do
|
276
281
|
obj = BasicObject.new
|
277
282
|
producer.record_result :type, 1, obj
|
278
|
-
expect(consumer.call).to eq Events::LineResult.new(type: :type, line_number: 1, inspected:
|
283
|
+
expect(consumer.call).to eq Events::LineResult.new(type: :type, line_number: 1, inspected: inspected(obj))
|
279
284
|
end
|
280
285
|
|
281
|
-
|
282
|
-
it "doesn't blow up when #inspect returns a not-String (e.g. pathalogical libraries like FactoryGirl)" do
|
286
|
+
it "uses Kernel's #inspect when the object\'s #inspect returns a not-String (e.g. pathalogical libraries like FactoryGirl)" do
|
283
287
|
obj = BasicObject.new
|
284
288
|
def obj.inspect
|
285
289
|
nil
|
286
290
|
end
|
287
291
|
producer.record_result :type, 1, obj
|
288
|
-
expect(consumer.call).to eq Events::LineResult.new(type: :type, line_number: 1, inspected:
|
292
|
+
expect(consumer.call).to eq Events::LineResult.new(type: :type, line_number: 1, inspected: inspected(obj))
|
293
|
+
end
|
294
|
+
|
295
|
+
it "uses a null-inspect string when even Kernel's inspect doesn't work" do
|
296
|
+
skip 'uhm, no idea how to get it into such a state'
|
289
297
|
end
|
290
298
|
|
291
299
|
it 'only calls inspect once' do
|
@@ -311,13 +319,13 @@ module SeeingIsBelieving::EventStream
|
|
311
319
|
it 'doesn\'t blow up if the block raises' do
|
312
320
|
o = Object.new
|
313
321
|
producer.record_result(:type, 1, o) { raise Exception, "zomg" }
|
314
|
-
expect(consumer.call).to eq Events::LineResult.new(type: :type, line_number: 1, inspected:
|
322
|
+
expect(consumer.call).to eq Events::LineResult.new(type: :type, line_number: 1, inspected: inspected(o))
|
315
323
|
end
|
316
324
|
|
317
325
|
it 'doesn\'t blow up if the block returns a non-string' do
|
318
326
|
o = Object.new
|
319
327
|
producer.record_result(:type, 1, o) { nil }
|
320
|
-
expect(consumer.call).to eq Events::LineResult.new(type: :type, line_number: 1, inspected:
|
328
|
+
expect(consumer.call).to eq Events::LineResult.new(type: :type, line_number: 1, inspected: inspected(o))
|
321
329
|
|
322
330
|
stringish = Object.new
|
323
331
|
def stringish.to_str() 'actual string' end
|
@@ -844,11 +844,12 @@ RSpec.describe SeeingIsBelieving do
|
|
844
844
|
end
|
845
845
|
|
846
846
|
# defined? is a macro, not a method, otherwise I'd test that here
|
847
|
-
specify 'when Kernel does not have kind_of
|
847
|
+
specify 'when Kernel does not have kind_of?, inspect' do
|
848
848
|
expect(invoke('module Kernel
|
849
849
|
undef kind_of?
|
850
|
+
undef inspect
|
850
851
|
end
|
851
|
-
1').to_a).to eq [[], [], ['nil'], ['1']]
|
852
|
+
1').to_a).to eq [[], [], [], ['nil'], ['1']]
|
852
853
|
end
|
853
854
|
|
854
855
|
specify 'when Enumerable does not have map' do
|
@@ -425,6 +425,12 @@ RSpec.describe SeeingIsBelieving::WrapExpressions do
|
|
425
425
|
expect(wrap("a[1\n]=2")).to eq "<a[<1>\n]=2>"
|
426
426
|
expect(wrap("a[1,\n2\n]=3")).to eq "<a[<1>,\n<2>\n]=3>"
|
427
427
|
end
|
428
|
+
|
429
|
+
it 'wraps 2.4 style multiple assignment' do
|
430
|
+
next if ruby_version < '2.4'
|
431
|
+
expect(wrap("if (a,b=1,2)\nend")).to eq "<if <(a,b=1,2)>\nend>"
|
432
|
+
expect(wrap("if (a,b=1)\nend")).to eq "<if <(a,b=1)>\nend>"
|
433
|
+
end
|
428
434
|
end
|
429
435
|
|
430
436
|
describe 'conditionals' do
|
@@ -924,6 +930,36 @@ RSpec.describe SeeingIsBelieving::WrapExpressions do
|
|
924
930
|
end
|
925
931
|
end
|
926
932
|
|
933
|
+
describe 'Perl style globals' do
|
934
|
+
# from English.rb
|
935
|
+
specify('$ERROR_INFO $!') { expect(wrap('$!')).to eq '<$!>' }
|
936
|
+
specify('$ERROR_POSITION $@') { expect(wrap('$@')).to eq '<$@>' }
|
937
|
+
specify('$FS $;') { expect(wrap('$;')).to eq '<$;>' }
|
938
|
+
specify('$FIELD_SEPARATOR $;') { expect(wrap('$;')).to eq '<$;>' }
|
939
|
+
specify('$OFS $,') { expect(wrap('$,')).to eq '<$,>' }
|
940
|
+
specify('$OUTPUT_FIELD_SEPARATOR $,') { expect(wrap('$,')).to eq '<$,>' }
|
941
|
+
specify('$RS $/') { expect(wrap('$/')).to eq '<$/>' }
|
942
|
+
specify('$INPUT_RECORD_SEPARATOR $/') { expect(wrap('$/')).to eq '<$/>' }
|
943
|
+
specify('$ORS $\\') { expect(wrap('$\\')).to eq '<$\\>' }
|
944
|
+
specify('$OUTPUT_RECORD_SEPARATOR $\\') { expect(wrap('$\\')).to eq '<$\\>' }
|
945
|
+
specify('$INPUT_LINE_NUMBER $.') { expect(wrap('$.')).to eq '<$.>' }
|
946
|
+
specify('$NR $.') { expect(wrap('$.')).to eq '<$.>' }
|
947
|
+
specify('$LAST_READ_LINE $_') { expect(wrap('$_')).to eq '<$_>' }
|
948
|
+
specify('$DEFAULT_OUTPUT $>') { expect(wrap('$>')).to eq '<$>>' }
|
949
|
+
specify('$DEFAULT_INPUT $<') { expect(wrap('$<')).to eq '<$<>' }
|
950
|
+
specify('$PID $$') { expect(wrap('$$')).to eq '<$$>' }
|
951
|
+
specify('$PROCESS_ID $$') { expect(wrap('$$')).to eq '<$$>' }
|
952
|
+
specify('$CHILD_STATUS $?') { expect(wrap('$?')).to eq '<$?>' }
|
953
|
+
specify('$LAST_MATCH_INFO $~') { expect(wrap('$~')).to eq '<$~>' }
|
954
|
+
specify('$IGNORECASE $=') { expect(wrap('$=')).to eq '<$=>' }
|
955
|
+
specify('$ARGV $*') { expect(wrap('$*')).to eq '<$*>' }
|
956
|
+
specify('$MATCH $&') { expect(wrap('$&')).to eq '<$&>' }
|
957
|
+
specify('$PREMATCH $`') { expect(wrap('$`')).to eq '<$`>' }
|
958
|
+
specify('$POSTMATCH $\'') { expect(wrap("$'")).to eq "<$'>" }
|
959
|
+
specify('$LAST_PAREN_MATCH $+') { expect(wrap('$+')).to eq '<$+>' }
|
960
|
+
end
|
961
|
+
|
962
|
+
|
927
963
|
# only checking on 2.2 b/c its hard to figure out when different pieces were introduced
|
928
964
|
# we'll assume that if it passes on 2.2, it will pass on 2.0 or 2.1, if the feature is available on that Ruby
|
929
965
|
major, minor, * = RUBY_VERSION.split(".").map(&:to_i)
|
metadata
CHANGED
@@ -1,49 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seeing_is_believing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.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: 2017-
|
11
|
+
date: 2017-09-11 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
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 2.3.0.7
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
19
|
+
version: 2.4.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 2.3.0.7
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
26
|
+
version: 2.4.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: childprocess
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.
|
33
|
+
version: 0.7.1
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - "~>"
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.
|
40
|
+
version: 0.7.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: haiti
|
49
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,14 +78,14 @@ dependencies:
|
|
70
78
|
requirements:
|
71
79
|
- - "~>"
|
72
80
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
81
|
+
version: 12.0.0
|
74
82
|
type: :development
|
75
83
|
prerelease: false
|
76
84
|
version_requirements: !ruby/object:Gem::Requirement
|
77
85
|
requirements:
|
78
86
|
- - "~>"
|
79
87
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
88
|
+
version: 12.0.0
|
81
89
|
- !ruby/object:Gem::Dependency
|
82
90
|
name: mrspec
|
83
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,14 +106,14 @@ dependencies:
|
|
98
106
|
requirements:
|
99
107
|
- - "~>"
|
100
108
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
109
|
+
version: 3.6.0
|
102
110
|
type: :development
|
103
111
|
prerelease: false
|
104
112
|
version_requirements: !ruby/object:Gem::Requirement
|
105
113
|
requirements:
|
106
114
|
- - "~>"
|
107
115
|
- !ruby/object:Gem::Version
|
108
|
-
version:
|
116
|
+
version: 3.6.0
|
109
117
|
- !ruby/object:Gem::Dependency
|
110
118
|
name: cucumber
|
111
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -279,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
279
287
|
version: '0'
|
280
288
|
requirements: []
|
281
289
|
rubyforge_project: seeing_is_believing
|
282
|
-
rubygems_version: 2.
|
290
|
+
rubygems_version: 2.5.2
|
283
291
|
signing_key:
|
284
292
|
specification_version: 4
|
285
293
|
summary: Records results of every line of code in your file
|