seeing_is_believing 2.2.0 → 3.0.0.beta.1
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 +4 -4
- data/.gitignore +1 -0
- data/Changelog.md +33 -0
- data/bin/seeing_is_believing +1 -1
- data/features/errors.feature +3 -3
- data/features/examples.feature +6 -6
- data/features/flags.feature +51 -196
- data/features/regression.feature +12 -3
- data/features/safe.feature +33 -0
- data/features/support/env.rb +20 -0
- data/features/xmpfilter-style.feature +156 -0
- data/lib/seeing_is_believing.rb +17 -35
- data/lib/seeing_is_believing/binary.rb +81 -176
- data/lib/seeing_is_believing/binary/align_chunk.rb +5 -7
- data/lib/seeing_is_believing/binary/align_file.rb +4 -5
- data/lib/seeing_is_believing/binary/align_line.rb +4 -4
- data/lib/seeing_is_believing/binary/annotate_end_of_file.rb +60 -0
- data/lib/seeing_is_believing/binary/annotate_every_line.rb +64 -0
- data/lib/seeing_is_believing/binary/annotate_xmpfilter_style.rb +133 -0
- data/lib/seeing_is_believing/binary/comment_formatter.rb +19 -5
- data/lib/seeing_is_believing/binary/comment_lines.rb +1 -1
- data/lib/seeing_is_believing/binary/commentable_lines.rb +1 -1
- data/lib/seeing_is_believing/binary/interpret_flags.rb +149 -0
- data/lib/seeing_is_believing/binary/parse_args.rb +96 -104
- data/lib/seeing_is_believing/binary/remove_annotations.rb +95 -0
- data/lib/seeing_is_believing/binary/rewrite_comments.rb +8 -30
- data/lib/seeing_is_believing/code.rb +99 -0
- data/lib/seeing_is_believing/evaluate_by_moving_files.rb +27 -19
- data/lib/seeing_is_believing/evaluate_with_eval_in.rb +27 -0
- data/lib/seeing_is_believing/event_stream/consumer.rb +111 -0
- data/lib/seeing_is_believing/event_stream/events.rb +16 -0
- data/lib/seeing_is_believing/event_stream/producer.rb +106 -0
- data/lib/seeing_is_believing/event_stream/update_result.rb +21 -0
- data/lib/seeing_is_believing/inspect_expressions.rb +24 -0
- data/lib/seeing_is_believing/parser_helpers.rb +1 -11
- data/lib/seeing_is_believing/result.rb +14 -56
- data/lib/seeing_is_believing/the_matrix.rb +14 -14
- data/lib/seeing_is_believing/version.rb +1 -1
- data/lib/seeing_is_believing/wrap_expressions.rb +32 -9
- data/seeing_is_believing.gemspec +7 -7
- data/spec/binary/comment_formatter_spec.rb +169 -18
- data/spec/binary/comment_lines_spec.rb +1 -1
- data/spec/binary/interpret_flags_spec.rb +307 -0
- data/spec/binary/parse_args_spec.rb +93 -91
- data/spec/binary/{clean_body_spec.rb → remove_annotations_spec.rb} +29 -22
- data/spec/binary/rewrite_comments_spec.rb +13 -13
- data/spec/code_spec.rb +49 -0
- data/spec/debugger_spec.rb +1 -1
- data/spec/evaluate_by_moving_files_spec.rb +7 -3
- data/spec/event_stream_spec.rb +390 -0
- data/spec/hard_core_ensure_spec.rb +1 -1
- data/spec/seeing_is_believing_spec.rb +137 -40
- data/spec/spec_helper.rb +3 -3
- data/spec/wrap_expressions_spec.rb +48 -35
- metadata +58 -35
- data/lib/seeing_is_believing/binary/add_annotations.rb +0 -144
- data/lib/seeing_is_believing/binary/clean_body.rb +0 -95
- data/lib/seeing_is_believing/has_exception.rb +0 -27
- data/lib/seeing_is_believing/line.rb +0 -90
- data/spec/line_spec.rb +0 -86
@@ -1,27 +0,0 @@
|
|
1
|
-
class SeeingIsBelieving
|
2
|
-
|
3
|
-
# We cannot serialize the actual exception because we do not have any guarantee that its class is defined on the SIB side,
|
4
|
-
# so we must use simpler data structures (Strings and arrays)
|
5
|
-
RecordedException = Struct.new :class_name, :message, :backtrace do
|
6
|
-
def self.from_primitive(primitive)
|
7
|
-
return nil unless primitive
|
8
|
-
exception = new
|
9
|
-
exception.class_name = primitive['class_name']
|
10
|
-
exception.message = primitive['message']
|
11
|
-
exception.backtrace = primitive['backtrace']
|
12
|
-
exception
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_primitive
|
16
|
-
{ 'class_name' => class_name,
|
17
|
-
'message' => message,
|
18
|
-
'backtrace' => backtrace,
|
19
|
-
}
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module HasException
|
24
|
-
attr_accessor :exception
|
25
|
-
alias has_exception? exception
|
26
|
-
end
|
27
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'seeing_is_believing/has_exception'
|
2
|
-
|
3
|
-
class SeeingIsBelieving
|
4
|
-
# thin wrapper over an array, used by the result
|
5
|
-
class Line
|
6
|
-
include HasException
|
7
|
-
include Enumerable
|
8
|
-
|
9
|
-
# delegate all methods to the array, but return self where the array would be returned
|
10
|
-
Array.instance_methods(false).sort.each do |method_name|
|
11
|
-
define_method method_name do |*args, &block|
|
12
|
-
result = @array.__send__ method_name, *args, &block
|
13
|
-
result.equal?(@array) ? self : result
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_float(n)
|
18
|
-
return n unless n == Float::INFINITY
|
19
|
-
'FUCKING_INFINITY_AND_JESUS_FUCKING_CHRIST_JSON_AND_MARSHAL_AND_YAML_WHAT_THE_FUCK?'
|
20
|
-
end
|
21
|
-
|
22
|
-
def from_float(n)
|
23
|
-
return n if n.kind_of? Float
|
24
|
-
Float::INFINITY
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_primitive
|
28
|
-
{ 'array' => @array,
|
29
|
-
'max_number_of_captures' => to_float(@max_number_of_captures),
|
30
|
-
'num_results' => @num_results,
|
31
|
-
'total_size' => @total_size,
|
32
|
-
'exception' => (exception && exception.to_primitive)
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
def from_primitive(primitive)
|
37
|
-
@array = primitive['array']
|
38
|
-
@max_number_of_captures = from_float primitive['max_number_of_captures']
|
39
|
-
@num_results = primitive['num_results']
|
40
|
-
@total_size = primitive['total_size']
|
41
|
-
@exception = RecordedException.from_primitive primitive['exception']
|
42
|
-
end
|
43
|
-
|
44
|
-
def to_a
|
45
|
-
@array.dup
|
46
|
-
end
|
47
|
-
alias to_ary to_a
|
48
|
-
|
49
|
-
def initialize(array = [], max_number_of_captures=Float::INFINITY)
|
50
|
-
@array = []
|
51
|
-
@max_number_of_captures = max_number_of_captures
|
52
|
-
@num_results = 0
|
53
|
-
@total_size = 0
|
54
|
-
array.each { |element| record_result element }
|
55
|
-
end
|
56
|
-
|
57
|
-
StackErrors = [SystemStackError]
|
58
|
-
StackErrors << Java::JavaLang::StackOverflowError if defined?(RUBY_PLATFORM) && RUBY_PLATFORM == 'java'
|
59
|
-
def record_result(value)
|
60
|
-
begin
|
61
|
-
inspected = value.inspect.to_str # only invoke inspect once, b/c the inspection may be recorded
|
62
|
-
rescue NoMethodError
|
63
|
-
inspected = "#<no inspect available>"
|
64
|
-
rescue *StackErrors
|
65
|
-
# this is necessary because SystemStackError won't show the backtrace of the method we tried to call
|
66
|
-
# which means there won't be anything showing the user where this came from
|
67
|
-
# so we need to re-raise the error to get a backtrace that shows where we came from
|
68
|
-
# 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
|
69
|
-
raise SystemStackError, "Calling inspect blew the stack (is it recursive w/o a base case?)"
|
70
|
-
end
|
71
|
-
|
72
|
-
if size < @max_number_of_captures then @array << inspected
|
73
|
-
elsif size == @max_number_of_captures then @array << '...'
|
74
|
-
end
|
75
|
-
@num_results += 1
|
76
|
-
@total_size += inspected.size
|
77
|
-
self
|
78
|
-
end
|
79
|
-
|
80
|
-
def ==(ary_or_line)
|
81
|
-
return @array == ary_or_line if Array === ary_or_line
|
82
|
-
ary_or_line == @array && exception == ary_or_line.exception
|
83
|
-
end
|
84
|
-
|
85
|
-
def inspect
|
86
|
-
inspected_exception = has_exception? ? "#{exception.class}:#{exception.message.inspect}" : "no exception"
|
87
|
-
"#<SIB:Line#{@array.inspect} (#@num_results, #@total_size) #{inspected_exception}>"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
data/spec/line_spec.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'seeing_is_believing/result'
|
3
|
-
|
4
|
-
describe SeeingIsBelieving::Line do
|
5
|
-
Line = described_class
|
6
|
-
|
7
|
-
def line_for(*args)
|
8
|
-
line = Line.new
|
9
|
-
args.each { |a| line.record_result a }
|
10
|
-
line
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'inspects prettily' do
|
14
|
-
expect(line_for( ).inspect).to eq '#<SIB:Line[] (0, 0) no exception>'
|
15
|
-
expect(line_for("a" ).inspect).to eq '#<SIB:Line["\"a\""] (1, 3) no exception>'
|
16
|
-
expect(line_for("a", 12).inspect).to eq '#<SIB:Line["\"a\"", "12"] (2, 5) no exception>'
|
17
|
-
|
18
|
-
line = Line.new
|
19
|
-
line.exception = RuntimeError.new("omg")
|
20
|
-
expect(line.inspect).to eq '#<SIB:Line[] (0, 0) RuntimeError:"omg">'
|
21
|
-
end
|
22
|
-
|
23
|
-
it "doesn't blow up when there is no #inspect available e.g. BasicObject" do
|
24
|
-
obj = BasicObject.new
|
25
|
-
expect(line_for(obj).inspect).to eq '#<SIB:Line["#<no inspect available>"] (1, 23) no exception>'
|
26
|
-
end
|
27
|
-
|
28
|
-
it "doesn't blow up when #inspect returns a not-String (e.g. pathalogical libraries like FactoryGirl)" do
|
29
|
-
obj = BasicObject.new
|
30
|
-
def obj.inspect
|
31
|
-
nil
|
32
|
-
end
|
33
|
-
expect(line_for(obj).inspect).to eq '#<SIB:Line["#<no inspect available>"] (1, 23) no exception>'
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'knows when it has an exception' do
|
37
|
-
exception = RuntimeError.new 'omg'
|
38
|
-
line = Line.new
|
39
|
-
expect(line).to_not have_exception
|
40
|
-
line.exception = exception
|
41
|
-
expect(line).to have_exception
|
42
|
-
expect(line.exception).to equal exception
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'delegates its other methods to array, but returns itself where the array would be returned' do
|
46
|
-
line = Line.new
|
47
|
-
expect(line).to be_empty
|
48
|
-
expect((line << 1)).to equal line
|
49
|
-
expect(line).to_not be_empty
|
50
|
-
expect(line.map { |i| i * 2 }).to eq [2]
|
51
|
-
line << 10 << 100
|
52
|
-
expect(line.take(2)).to eq [1, 10]
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'returns its array for #to_a and #to_ary' do
|
56
|
-
line = line_for 1, 2
|
57
|
-
expect(line.to_a).to be_a_kind_of Array
|
58
|
-
expect(line.to_a).to eq %w[1 2]
|
59
|
-
expect(line.to_ary).to be_a_kind_of Array
|
60
|
-
expect(line.to_ary).to eq %w[1 2]
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'is equal to arrays with the same elements as its array' do
|
64
|
-
expect(line_for(1, 2)).to eq %w[1 2]
|
65
|
-
expect(line_for(1, 2)).to_not eq %w[2 1]
|
66
|
-
end
|
67
|
-
|
68
|
-
# Exception equality seems to be based off of the message, and be indifferent to the class, I don't think it's that important to fix it
|
69
|
-
it "is equal to lines with the same elements and the same exception" do
|
70
|
-
exception = RuntimeError.new 'omg'
|
71
|
-
|
72
|
-
expect(line_for(1, 2)).to eq line_for(1, 2)
|
73
|
-
expect(line_for(1, 2)).to_not eq line_for(2, 1)
|
74
|
-
|
75
|
-
line1 = line_for(1, 2)
|
76
|
-
line1.exception = exception
|
77
|
-
expect(line1).to_not eq line_for(1, 2)
|
78
|
-
|
79
|
-
line2 = line_for(1, 2)
|
80
|
-
line2.exception = exception
|
81
|
-
expect(line1).to eq line2
|
82
|
-
|
83
|
-
line2.exception = RuntimeError.new 'wrong message'
|
84
|
-
expect(line1).to_not eq line2
|
85
|
-
end
|
86
|
-
end
|