seeing_is_believing 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Rakefile +10 -23
- data/Readme.md +0 -4
- data/appveyor.yml +2 -0
- data/features/flags.feature +14 -0
- data/features/regression.feature +73 -0
- data/lib/seeing_is_believing.rb +3 -1
- data/lib/seeing_is_believing/backup_file.rb +50 -0
- data/lib/seeing_is_believing/binary/annotate_marked_lines.rb +1 -1
- data/lib/seeing_is_believing/binary/config.rb +6 -1
- data/lib/seeing_is_believing/evaluate_by_moving_files.rb +23 -45
- data/lib/seeing_is_believing/event_stream/producer.rb +3 -0
- data/lib/seeing_is_believing/version.rb +1 -1
- data/seeing_is_believing.gemspec +2 -2
- data/spec/binary/config_spec.rb +13 -3
- data/spec/evaluate_by_moving_files_spec.rb +17 -1
- data/spec/event_stream_spec.rb +7 -0
- data/spec/seeing_is_believing_spec.rb +18 -5
- data/spec/wrap_expressions_spec.rb +1 -0
- metadata +8 -9
- data/spec/binary/options_spec.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '05637967d8e40131f85a42ba2246cca7e28c9c53fe02a1ab802dab93cd368a73'
|
4
|
+
data.tar.gz: cb89541eec8388b26643ee4c4adcdbadbe60673ad309fb1df2eef1d8fb5e7c5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3e1fe60f931cfbee373c8bf0cc96a1442e92db587866434ecc35d3e5b638282553265d7576a572206aad91f2b8db73c5c0c01be4b956255e98823f743bc4ee5
|
7
|
+
data.tar.gz: b7304a173678eeb157bc6ce35c4fe16777f9c511eae18240862668b15facd4fa7e4153dc13de0c0630e73fe4da257c8dd5a5a1fc1826bdecec6b317014f241fe
|
data/Rakefile
CHANGED
@@ -1,26 +1,13 @@
|
|
1
1
|
desc 'Have Bundler setup a standalone environment -- run tests in this, b/c its faster and safer'
|
2
2
|
task :install do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
unless Dir.exist? 'bundle'
|
9
|
-
# Running without rubygems # http://myronmars.to/n/dev-blog/2012/03/faster-test-boot-times-with-bundler-standalone
|
10
|
-
sh 'bundle', 'install', '--standalone', '--binstubs', 'bundle/bin'
|
11
|
-
end
|
3
|
+
# Running without rubygems # http://myronmars.to/n/dev-blog/2012/03/faster-test-boot-times-with-bundler-standalone
|
4
|
+
which("bundle") or sh 'gem', 'install', 'bundler', '--no-ri', '--no-rdoc'
|
5
|
+
Dir.exist? 'bundle' or sh 'bundle', 'install', '--standalone', '--binstubs', 'bundle/bin'
|
12
6
|
end
|
13
7
|
|
14
8
|
desc 'Remove generated and irrelevant files'
|
15
9
|
task :clean do
|
16
|
-
rm_rf [
|
17
|
-
'bundle',
|
18
|
-
'.bundle',
|
19
|
-
'Gemfile.lock',
|
20
|
-
'proving_grounds',
|
21
|
-
'tags',
|
22
|
-
*Dir['*.gem'],
|
23
|
-
]
|
10
|
+
rm_rf %w[bundle .bundle Gemfile.lock proving_grounds tags] + Dir['*.gem']
|
24
11
|
end
|
25
12
|
|
26
13
|
directory 'bundle' do
|
@@ -30,11 +17,11 @@ end
|
|
30
17
|
|
31
18
|
def require_paths
|
32
19
|
require 'bundler'
|
33
|
-
|
34
|
-
spec.require_paths
|
35
|
-
|
36
|
-
|
37
|
-
|
20
|
+
Bundler.load.specs.flat_map do |spec|
|
21
|
+
spec.require_paths
|
22
|
+
.map { |path| File.join spec.full_gem_path, path }
|
23
|
+
.flat_map { |p| ['-I', p] }
|
24
|
+
end
|
38
25
|
end
|
39
26
|
|
40
27
|
desc 'Print the require paths for arbitrary binary execution'
|
@@ -78,7 +65,7 @@ task default: [:spec, :cuke]
|
|
78
65
|
desc 'Install dependencies and run tests (mainly for Travis CI)'
|
79
66
|
task ci: [:spec, :cuke]
|
80
67
|
|
81
|
-
def which(exe)
|
68
|
+
def self.which(exe)
|
82
69
|
dirs = ENV["PATH"].split(File::PATH_SEPARATOR)
|
83
70
|
exts = [""]
|
84
71
|
exts.concat(ENV["PathExt"].to_s.split(File::PATH_SEPARATOR))
|
data/Readme.md
CHANGED
@@ -38,10 +38,6 @@ Known Issues
|
|
38
38
|
------------
|
39
39
|
|
40
40
|
* Assumes utf-8 everywhere. If this is an issue, please see the [encodings](https://github.com/JoshCheek/seeing_is_believing/wiki/Encodings) section of the wiki.
|
41
|
-
* `begin; else; break; end` this code (an else without a rescue) will emit a warning in Ruby, and is omitted from `Parser`'s AST.
|
42
|
-
As such, I doubt that anyone will ever write it. But if you were to write it, it would blow up, because SiB rewrites your code, wrapping every expression that could have a value.
|
43
|
-
This code will be wrapped. But using the value is **syntactically** invalid in Ruby, because it constitutes a "void value expression" (aka a pointless time sink and the cause of many bugs in SiB).
|
44
|
-
Unfortunately, I can't easily check it to see if it's void since it's not in the parsed AST. But it's so edge that I don't think it's worth worrying about.
|
45
41
|
|
46
42
|
|
47
43
|
Inspiration
|
data/appveyor.yml
CHANGED
data/features/flags.feature
CHANGED
@@ -600,3 +600,17 @@ Feature: Using flags
|
|
600
600
|
.to_s # => "0", "1", "2"
|
601
601
|
end # => 3
|
602
602
|
"""
|
603
|
+
|
604
|
+
|
605
|
+
Scenario: --local-cwd causes the current working directory to be the same as the file
|
606
|
+
Given the file "subdir/cwd_of_file_test.rb" "__FILE__"
|
607
|
+
When I run "seeing_is_believing subdir/cwd_of_file_test.rb"
|
608
|
+
Then stderr is empty
|
609
|
+
And the exit status is 0
|
610
|
+
And stdout is '__FILE__ # => "subdir/cwd_of_file_test.rb"'
|
611
|
+
When I run "seeing_is_believing subdir/cwd_of_file_test.rb --local-cwd"
|
612
|
+
Then stderr is empty
|
613
|
+
And the exit status is 0
|
614
|
+
And stdout is '__FILE__ # => "cwd_of_file_test.rb"'
|
615
|
+
|
616
|
+
|
data/features/regression.feature
CHANGED
@@ -753,3 +753,76 @@ Feature:
|
|
753
753
|
require 'seeing_is_believing' # => true
|
754
754
|
SeeingIsBelieving.call("1+1").result[1][0] # => "2"
|
755
755
|
"""
|
756
|
+
|
757
|
+
|
758
|
+
Scenario: Errors should not blow away comments (Issue #120)
|
759
|
+
Given the file "sib_with_error_on_uncommented_line.rb" "dne"
|
760
|
+
And the file "sib_with_error_on_commented_line.rb" "dne # this doesn't exist!"
|
761
|
+
When I run "seeing_is_believing -x sib_with_error_on_uncommented_line.rb"
|
762
|
+
Then stdout is:
|
763
|
+
"""
|
764
|
+
dne # ~> NameError: undefined local variable or method `dne' for main:Object
|
765
|
+
|
766
|
+
# ~> NameError
|
767
|
+
# ~> undefined local variable or method `dne' for main:Object
|
768
|
+
# ~>
|
769
|
+
# ~> sib_with_error_on_uncommented_line.rb:1:in `<main>'
|
770
|
+
"""
|
771
|
+
When I run "seeing_is_believing -x sib_with_error_on_commented_line.rb"
|
772
|
+
Then stdout is:
|
773
|
+
"""
|
774
|
+
dne # this doesn't exist!
|
775
|
+
|
776
|
+
# ~> NameError
|
777
|
+
# ~> undefined local variable or method `dne' for main:Object
|
778
|
+
# ~>
|
779
|
+
# ~> sib_with_error_on_commented_line.rb:1:in `<main>'
|
780
|
+
"""
|
781
|
+
When I run "seeing_is_believing sib_with_error_on_uncommented_line.rb"
|
782
|
+
Then stdout is:
|
783
|
+
"""
|
784
|
+
dne # ~> NameError: undefined local variable or method `dne' for main:Object
|
785
|
+
|
786
|
+
# ~> NameError
|
787
|
+
# ~> undefined local variable or method `dne' for main:Object
|
788
|
+
# ~>
|
789
|
+
# ~> sib_with_error_on_uncommented_line.rb:1:in `<main>'
|
790
|
+
"""
|
791
|
+
When I run "seeing_is_believing sib_with_error_on_commented_line.rb"
|
792
|
+
Then stdout is:
|
793
|
+
"""
|
794
|
+
dne # this doesn't exist!
|
795
|
+
|
796
|
+
# ~> NameError
|
797
|
+
# ~> undefined local variable or method `dne' for main:Object
|
798
|
+
# ~>
|
799
|
+
# ~> sib_with_error_on_commented_line.rb:1:in `<main>'
|
800
|
+
"""
|
801
|
+
|
802
|
+
|
803
|
+
Scenario: Errors on files read from stdin with --local-cwd are matched to the correct lines
|
804
|
+
Given the file "local_cwd_and_error_on_uncommented_line.rb" "dne"
|
805
|
+
When I run "seeing_is_believing --local-cwd < local_cwd_and_error_on_uncommented_line.rb"
|
806
|
+
Then stdout includes "dne # ~> NameError: undefined local variable or method `dne' for main:Object"
|
807
|
+
|
808
|
+
|
809
|
+
Scenario: Inspects strings even when they have a singleton class (Issue #118)
|
810
|
+
Given the file "result_of_inspect_has_a_singleton_class.rb":
|
811
|
+
"""
|
812
|
+
str = "a string"
|
813
|
+
def str.inspect
|
814
|
+
self
|
815
|
+
end
|
816
|
+
str # =>
|
817
|
+
"""
|
818
|
+
When I run "seeing_is_believing -x result_of_inspect_has_a_singleton_class.rb"
|
819
|
+
Then stderr is empty
|
820
|
+
And the exit status is 0
|
821
|
+
And stdout is:
|
822
|
+
"""
|
823
|
+
str = "a string"
|
824
|
+
def str.inspect
|
825
|
+
self
|
826
|
+
end
|
827
|
+
str # => a string
|
828
|
+
"""
|
data/lib/seeing_is_believing.rb
CHANGED
@@ -12,6 +12,7 @@ require 'seeing_is_believing/event_stream/handlers/update_result'
|
|
12
12
|
class SeeingIsBelieving
|
13
13
|
class Options < HashStruct
|
14
14
|
predicate(:event_handler) { EventStream::Handlers::UpdateResult.new Result.new }
|
15
|
+
predicate(:local_cwd) { false }
|
15
16
|
attribute(:filename) { nil }
|
16
17
|
attribute(:encoding) { nil }
|
17
18
|
attribute(:stdin) { "" }
|
@@ -50,7 +51,8 @@ class SeeingIsBelieving
|
|
50
51
|
load_path_dirs: options.load_path_dirs,
|
51
52
|
encoding: options.encoding,
|
52
53
|
timeout_seconds: options.timeout_seconds,
|
53
|
-
max_line_captures: options.max_line_captures
|
54
|
+
max_line_captures: options.max_line_captures,
|
55
|
+
local_cwd: options.local_cwd?
|
54
56
|
|
55
57
|
options.event_handler
|
56
58
|
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'seeing_is_believing/error'
|
2
|
+
require 'seeing_is_believing/hard_core_ensure'
|
3
|
+
|
4
|
+
class SeeingIsBelieving
|
5
|
+
class BackupFile
|
6
|
+
def self.call(*args, &block)
|
7
|
+
new(*args, &block).call
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(file_path, backup_filename, &block)
|
11
|
+
self.file_path = file_path
|
12
|
+
self.block = block
|
13
|
+
self.backup_filename = backup_filename
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
HardCoreEnsure.call \
|
18
|
+
code: -> {
|
19
|
+
we_will_not_overwrite_existing_backup_file!
|
20
|
+
backup_existing_file
|
21
|
+
block.call
|
22
|
+
},
|
23
|
+
ensure: -> {
|
24
|
+
set_back_to_initial_conditions
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_accessor :block, :file_path, :backup_filename
|
31
|
+
|
32
|
+
def we_will_not_overwrite_existing_backup_file!
|
33
|
+
raise TempFileAlreadyExists.new(file_path, backup_filename) if File.exist? backup_filename
|
34
|
+
end
|
35
|
+
|
36
|
+
def backup_existing_file
|
37
|
+
return unless File.exist? file_path
|
38
|
+
File.rename file_path, backup_filename
|
39
|
+
@was_backed_up = true
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_back_to_initial_conditions
|
43
|
+
if @was_backed_up
|
44
|
+
File.rename(backup_filename, file_path)
|
45
|
+
else
|
46
|
+
File.delete(file_path)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -111,7 +111,7 @@ class SeeingIsBelieving
|
|
111
111
|
normal_annotation = annotate_this_line && !pp_annotation
|
112
112
|
if exception_result && annotate_this_line
|
113
113
|
[comment.whitespace, FormatComment.call(comment.text_col, value_prefix, exception_result, @options)]
|
114
|
-
elsif exception_result
|
114
|
+
elsif exception_result && comment.text.empty?
|
115
115
|
whitespace = comment.whitespace
|
116
116
|
whitespace = " " if whitespace.empty?
|
117
117
|
[whitespace, FormatComment.call(0, exception_prefix, exception_result, @options)]
|
@@ -181,6 +181,9 @@ class SeeingIsBelieving
|
|
181
181
|
as = filename
|
182
182
|
end
|
183
183
|
|
184
|
+
when '--local-cwd'
|
185
|
+
self.lib_options.local_cwd = true
|
186
|
+
|
184
187
|
when '-s', '--alignment-strategy'
|
185
188
|
strategies = {'file' => AlignFile, 'chunk' => AlignChunk, 'line' => AlignLine}
|
186
189
|
strategy_names = strategies.keys.inspect
|
@@ -326,7 +329,7 @@ Options:
|
|
326
329
|
file => the entire file is at the same alignment
|
327
330
|
line => each line is at its own alignment
|
328
331
|
--[no-]-interline-align # align results on adjacent lines when they have the same number of results
|
329
|
-
|
332
|
+
defaults to --align
|
330
333
|
-t, --timeout-seconds s # how long to evaluate the source file before timing out
|
331
334
|
0 means it will never timeout (this is the default)
|
332
335
|
accepts floating point values (e.g. 0.5 would timeout after half a second)
|
@@ -334,8 +337,10 @@ Options:
|
|
334
337
|
-r, --require file # additional files to be required before running the program
|
335
338
|
-e, --program program-body # pass the program body to execute as an argument
|
336
339
|
-a, --as filename # run the program as if it was the specified filename
|
340
|
+
--local-cwd # run the program from the file's directory instead of the calling program's CWD
|
337
341
|
-c, --clean # remove annotations from previous runs of seeing_is_believing
|
338
342
|
-g, --debug # print debugging information
|
343
|
+
--debug-to FILE # print debugging information to FILE
|
339
344
|
-x, --xmpfilter-style # annotate marked lines instead of every line
|
340
345
|
-j, --json # print results in json format (i.e. so another program can consume them)
|
341
346
|
-i, --inherit-exitstatus # exit with the exit status of the program being evaluated
|
@@ -13,12 +13,13 @@
|
|
13
13
|
|
14
14
|
require 'rbconfig'
|
15
15
|
require 'socket'
|
16
|
-
require
|
16
|
+
require "childprocess"
|
17
|
+
|
17
18
|
require 'seeing_is_believing/result'
|
18
19
|
require 'seeing_is_believing/debugger'
|
19
|
-
require 'seeing_is_believing/
|
20
|
+
require 'seeing_is_believing/backup_file'
|
20
21
|
require 'seeing_is_believing/event_stream/consumer'
|
21
|
-
|
22
|
+
|
22
23
|
ChildProcess.posix_spawn = true # forking locks up for some reason when we run SiB inside of SiB
|
23
24
|
|
24
25
|
class SeeingIsBelieving
|
@@ -27,12 +28,13 @@ class SeeingIsBelieving
|
|
27
28
|
new(*args).call
|
28
29
|
end
|
29
30
|
|
30
|
-
attr_accessor :program, :
|
31
|
+
attr_accessor :program, :provided_input, :require_flags, :load_path_flags, :encoding, :timeout_seconds, :debugger, :event_handler, :max_line_captures
|
32
|
+
|
33
|
+
attr_accessor :file_directory, :file_path, :local_cwd, :relative_filename, :backup_filename
|
31
34
|
|
32
|
-
def initialize(program,
|
35
|
+
def initialize(program, file_path, options={})
|
33
36
|
options = options.dup
|
34
37
|
self.program = program
|
35
|
-
self.filename = filename
|
36
38
|
self.encoding = options.delete(:encoding) || "u"
|
37
39
|
self.timeout_seconds = options.delete(:timeout_seconds) || 0 # 0 is the new infinity
|
38
40
|
self.provided_input = options.delete(:provided_input) || String.new
|
@@ -40,52 +42,27 @@ class SeeingIsBelieving
|
|
40
42
|
self.load_path_flags = (options.delete(:load_path_dirs) || []).map { |dir| ['-I', dir] }.flatten
|
41
43
|
self.require_flags = (options.delete(:require_files) || ['seeing_is_believing/the_matrix']).map { |filename| ['-r', filename] }.flatten
|
42
44
|
self.max_line_captures = (options.delete(:max_line_captures) || Float::INFINITY) # (optimization: child stops producing results at this number, even though it might make more sense for the consumer to stop emitting them)
|
45
|
+
self.local_cwd = options.delete(:local_cwd) || false
|
46
|
+
self.file_path = file_path
|
47
|
+
self.file_directory = File.dirname file_path
|
48
|
+
file_name = File.basename file_path
|
49
|
+
self.relative_filename = local_cwd ? file_name : file_path
|
50
|
+
self.backup_filename = File.join file_directory, "seeing_is_believing_backup.#{file_name}"
|
51
|
+
|
43
52
|
options.any? && raise(ArgumentError, "Unknown options: #{options.inspect}")
|
44
53
|
end
|
45
54
|
|
46
55
|
def call
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
write_program_to_file
|
52
|
-
evaluate_file
|
53
|
-
},
|
54
|
-
ensure: -> {
|
55
|
-
set_back_to_initial_conditions
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
def file_directory
|
60
|
-
File.dirname filename
|
61
|
-
end
|
62
|
-
|
63
|
-
def backup_filename
|
64
|
-
File.join file_directory, "seeing_is_believing_backup.#{File.basename filename}"
|
56
|
+
BackupFile.call file_path, backup_filename do
|
57
|
+
write_program_to_file
|
58
|
+
evaluate_file
|
59
|
+
end
|
65
60
|
end
|
66
61
|
|
67
62
|
private
|
68
63
|
|
69
|
-
def we_will_not_overwrite_existing_backup_file!
|
70
|
-
raise TempFileAlreadyExists.new(filename, backup_filename) if File.exist? backup_filename
|
71
|
-
end
|
72
|
-
|
73
|
-
def backup_existing_file
|
74
|
-
return unless File.exist? filename
|
75
|
-
File.rename filename, backup_filename
|
76
|
-
@was_backed_up = true
|
77
|
-
end
|
78
|
-
|
79
|
-
def set_back_to_initial_conditions
|
80
|
-
if @was_backed_up
|
81
|
-
File.rename(backup_filename, filename)
|
82
|
-
else
|
83
|
-
File.delete(filename)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
64
|
def write_program_to_file
|
88
|
-
File.open(
|
65
|
+
File.open(file_path, 'w', external_encoding: "utf-8") { |f| f.write program.to_s }
|
89
66
|
end
|
90
67
|
|
91
68
|
|
@@ -102,10 +79,11 @@ class SeeingIsBelieving
|
|
102
79
|
event_stream_port: event_server.addr[1],
|
103
80
|
max_line_captures: max_line_captures,
|
104
81
|
num_lines: program.lines.count,
|
105
|
-
filename:
|
82
|
+
filename: relative_filename,
|
106
83
|
)].pack('m0')
|
107
84
|
|
108
85
|
child = ChildProcess.build(*popen_args)
|
86
|
+
child.cwd = file_directory if local_cwd
|
109
87
|
child.leader = true
|
110
88
|
child.duplex = true
|
111
89
|
child.environment.merge!(env)
|
@@ -165,7 +143,7 @@ class SeeingIsBelieving
|
|
165
143
|
'-I', File.realpath('..', __dir__), # add lib to the load path
|
166
144
|
*load_path_flags, # users can inject dirs to be added to the load path
|
167
145
|
*require_flags, # users can inject files to be required
|
168
|
-
|
146
|
+
relative_filename]
|
169
147
|
end
|
170
148
|
|
171
149
|
def close_streams(*streams)
|
@@ -118,6 +118,9 @@ class SeeingIsBelieving
|
|
118
118
|
# for a consideration of many different ways of doing this, see 5633064
|
119
119
|
def to_string_token(string)
|
120
120
|
[Marshal.dump(string.to_s)].pack('m0')
|
121
|
+
rescue TypeError => err
|
122
|
+
raise unless err.message =~ /singleton can't be dumped/
|
123
|
+
to_string_token string.to_s.dup
|
121
124
|
end
|
122
125
|
|
123
126
|
def build_producer_thread(resultstream)
|
data/seeing_is_believing.gemspec
CHANGED
@@ -20,11 +20,11 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
22
|
s.add_dependency "parser", "~> 2.4.0"
|
23
|
-
s.add_dependency "childprocess","~> 0.
|
23
|
+
s.add_dependency "childprocess","~> 0.8.0"
|
24
24
|
|
25
25
|
s.add_development_dependency "pry"
|
26
26
|
s.add_development_dependency "haiti", ">= 0.1", "< 0.3"
|
27
|
-
s.add_development_dependency "rake", "~> 12.
|
27
|
+
s.add_development_dependency "rake", "~> 12.2.0"
|
28
28
|
s.add_development_dependency "mrspec", "~> 0.3.1"
|
29
29
|
s.add_development_dependency "rspec", "~> 3.6.0"
|
30
30
|
s.add_development_dependency "cucumber", "~> 2.4"
|
data/spec/binary/config_spec.rb
CHANGED
@@ -208,6 +208,16 @@ RSpec.describe SeeingIsBelieving::Binary::Config do
|
|
208
208
|
end
|
209
209
|
|
210
210
|
|
211
|
+
describe 'lib_options.local_cwd?' do
|
212
|
+
it 'defaults to false' do
|
213
|
+
expect(parse([]).lib_options.local_cwd?).to eq false
|
214
|
+
end
|
215
|
+
it 'is set to true by --local-cwd' do
|
216
|
+
expect(parse(['--local-cwd']).lib_options.local_cwd?).to eq true
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
|
211
221
|
describe 'annotator_options.max_result_length' do
|
212
222
|
it 'defaults to infinity' do
|
213
223
|
expect(parse([]).annotator_options.max_result_length).to eq Float::INFINITY
|
@@ -677,11 +687,11 @@ RSpec.describe SeeingIsBelieving::Binary::Config do
|
|
677
687
|
end
|
678
688
|
|
679
689
|
describe 'setting the body' do
|
680
|
-
it 'does not override the if already set e.g. with -e' do
|
690
|
+
it 'does not override the body if already set e.g. with -e' do
|
681
691
|
expect(call(body: 'b', filename: nil).body).to eq 'b'
|
682
692
|
end
|
683
693
|
|
684
|
-
it 'is the file body if the filename is
|
694
|
+
it 'is the file body if the filename is provided and exists' do
|
685
695
|
expect(call(body: nil, filename: existing_filename).body)
|
686
696
|
.to eq file_body
|
687
697
|
end
|
@@ -776,7 +786,7 @@ RSpec.describe SeeingIsBelieving::Binary::Config do
|
|
776
786
|
end
|
777
787
|
|
778
788
|
context 'when debug? is a string' do
|
779
|
-
let(:proving_grounds_dir) { File.
|
789
|
+
let(:proving_grounds_dir) { File.expand_path '../../proving_grounds', __dir__ }
|
780
790
|
let(:path) { File.join proving_grounds_dir, 'test.log' }
|
781
791
|
before { Dir.mkdir proving_grounds_dir unless Dir.exist? proving_grounds_dir }
|
782
792
|
|
@@ -7,7 +7,7 @@ require 'fileutils'
|
|
7
7
|
require 'childprocess'
|
8
8
|
|
9
9
|
RSpec.describe SeeingIsBelieving::EvaluateByMovingFiles do
|
10
|
-
let(:filedir) { File.
|
10
|
+
let(:filedir) { File.expand_path '../proving_grounds', __dir__ }
|
11
11
|
let(:filename) { File.join filedir, 'some_filename' }
|
12
12
|
|
13
13
|
before { FileUtils.mkdir_p filedir }
|
@@ -120,6 +120,22 @@ RSpec.describe SeeingIsBelieving::EvaluateByMovingFiles do
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
+
it 'sets the program\'s working directory to the file\'s directory, when given local_cwd' do
|
124
|
+
Dir.chdir '/' do
|
125
|
+
root = File.expand_path '/'
|
126
|
+
result = invoke 'print Dir.pwd'
|
127
|
+
expect(result.stdout).to eq root
|
128
|
+
dir, cwd, file_path = invoke(<<-RUBY, local_cwd: true).stdout.lines.map(&:chomp)
|
129
|
+
puts File.expand_path(__dir__)
|
130
|
+
puts Dir.pwd
|
131
|
+
puts __FILE__
|
132
|
+
RUBY
|
133
|
+
expect(dir).to_not eq root
|
134
|
+
expect(cwd).to eq dir
|
135
|
+
expect(file_path).to eq File.basename(filename)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
123
139
|
it 'does not blow up on exceptions raised in at_exit blocks' do
|
124
140
|
expect { invoke 'at_exit { raise "zomg" }' }.to_not raise_error
|
125
141
|
end
|
data/spec/event_stream_spec.rb
CHANGED
@@ -305,6 +305,13 @@ module SeeingIsBelieving::EventStream
|
|
305
305
|
producer.record_result :type, 1, obj
|
306
306
|
expect(count).to eq 1
|
307
307
|
end
|
308
|
+
|
309
|
+
it 'can deal with results of inspect that have singleton methods' do
|
310
|
+
str = "a string"
|
311
|
+
def str.inspect() self end
|
312
|
+
producer.record_result :type, 1, str
|
313
|
+
expect(consumer.call.inspected).to eq str
|
314
|
+
end
|
308
315
|
end
|
309
316
|
|
310
317
|
context 'inspect performed by the block' do
|
@@ -31,7 +31,7 @@ RSpec.describe SeeingIsBelieving do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
root_path = File.realpath("..", __dir__)
|
34
|
-
proving_grounds_path = File.
|
34
|
+
proving_grounds_path = File.expand_path('proving_grounds', root_path)
|
35
35
|
before(:all) { Dir.mkdir proving_grounds_path unless Dir.exist? proving_grounds_path }
|
36
36
|
around { |spec| Dir.chdir proving_grounds_path, &spec }
|
37
37
|
|
@@ -332,10 +332,23 @@ RSpec.describe SeeingIsBelieving do
|
|
332
332
|
expect(result.stdout).to eq filename
|
333
333
|
end
|
334
334
|
|
335
|
-
|
336
|
-
filename
|
337
|
-
FileUtils.rm_f filename
|
338
|
-
|
335
|
+
describe 'cwd' do
|
336
|
+
let(:filename) { File.join proving_grounds_path, 'mah_file.rb' }
|
337
|
+
before { FileUtils.rm_f filename }
|
338
|
+
|
339
|
+
it 'defaults to the cwd of the the evaluating program' do
|
340
|
+
dir = Dir.chdir '/' do
|
341
|
+
invoke('print File.expand_path(Dir.pwd)', filename: filename).stdout
|
342
|
+
end
|
343
|
+
expect(dir).to eq File.expand_path('/')
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'is the file\'s directory when local_cwd is set' do
|
347
|
+
dir = Dir.chdir '/' do
|
348
|
+
invoke('print File.expand_path(Dir.pwd)', filename: filename, local_cwd: true).stdout
|
349
|
+
end
|
350
|
+
expect(dir).to eq proving_grounds_path
|
351
|
+
end
|
339
352
|
end
|
340
353
|
|
341
354
|
it 'does not capture output from __END__ onward' do
|
@@ -809,6 +809,7 @@ RSpec.describe SeeingIsBelieving::WrapExpressions do
|
|
809
809
|
expect(wrap("def a\n1\nrescue\n2\nend")).to eq "<def a\n<1>\nrescue\n<2>\nend>"
|
810
810
|
expect(wrap("def a\n1\nrescue\n2\nensure\n3\nend")).to eq "<def a\n<1>\nrescue\n<2>\nensure\n<3>\nend>"
|
811
811
|
expect(wrap("def a\n1\nensure\n2\nend")).to eq "<def a\n<1>\nensure\n<2>\nend>"
|
812
|
+
expect(wrap("def a\n1\nelse 2\nend")).to eq "<def a\n<1>\nelse <2>\nend>"
|
812
813
|
end
|
813
814
|
|
814
815
|
it 'wrap a definition as a call to an invocation' do
|
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.
|
4
|
+
version: 3.4.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-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.8.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.8.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: pry
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,14 +78,14 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 12.
|
81
|
+
version: 12.2.0
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 12.
|
88
|
+
version: 12.2.0
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: mrspec
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- features/support/env.rb
|
172
172
|
- features/xmpfilter-style.feature
|
173
173
|
- lib/seeing_is_believing.rb
|
174
|
+
- lib/seeing_is_believing/backup_file.rb
|
174
175
|
- lib/seeing_is_believing/binary.rb
|
175
176
|
- lib/seeing_is_believing/binary/align_chunk.rb
|
176
177
|
- lib/seeing_is_believing/binary/align_file.rb
|
@@ -214,7 +215,6 @@ files:
|
|
214
215
|
- spec/binary/engine_spec.rb
|
215
216
|
- spec/binary/format_comment_spec.rb
|
216
217
|
- spec/binary/marker_spec.rb
|
217
|
-
- spec/binary/options_spec.rb
|
218
218
|
- spec/binary/remove_annotations_spec.rb
|
219
219
|
- spec/binary/rewrite_comments_spec.rb
|
220
220
|
- spec/code_spec.rb
|
@@ -287,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
287
|
version: '0'
|
288
288
|
requirements: []
|
289
289
|
rubyforge_project: seeing_is_believing
|
290
|
-
rubygems_version: 2.
|
290
|
+
rubygems_version: 2.7.2
|
291
291
|
signing_key:
|
292
292
|
specification_version: 4
|
293
293
|
summary: Records results of every line of code in your file
|
@@ -305,7 +305,6 @@ test_files:
|
|
305
305
|
- spec/binary/engine_spec.rb
|
306
306
|
- spec/binary/format_comment_spec.rb
|
307
307
|
- spec/binary/marker_spec.rb
|
308
|
-
- spec/binary/options_spec.rb
|
309
308
|
- spec/binary/remove_annotations_spec.rb
|
310
309
|
- spec/binary/rewrite_comments_spec.rb
|
311
310
|
- spec/code_spec.rb
|
data/spec/binary/options_spec.rb
DELETED
File without changes
|