seeing_is_believing 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c99b16d96b21e8940fcb38b3aabecfd237c59d09
4
+ data.tar.gz: 3b871ae98e98cc26ac8cb123a09b31fe8cc3bcea
5
+ SHA512:
6
+ metadata.gz: c68fece19b501e2ce1decdc23a128a010e500a1ddcd1fdf2eedd3047ae8c6807e51c7fc61f04ec40bbdbb0687e12c4d29338a31f5d779255213b1361245fd6e2
7
+ data.tar.gz: bc28374e2d99a03abf05c17e63de56c3388f78afe699644736744d1173f475088c883fa2f2e5f828b683e0e2733716121d841dfc777e3c1b7a8bc4167517e714
@@ -2,3 +2,4 @@ language: ruby
2
2
  script: rake
3
3
  rvm:
4
4
  - 1.9.3
5
+ - 2.0.0
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seeing_is_believing (0.0.10)
4
+ seeing_is_believing (0.0.14)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -21,8 +21,9 @@ module CommandLineHelpers
21
21
  def execute(command, stdin_data=nil)
22
22
  stdin_data ||= ''
23
23
  in_proving_grounds do
24
- bin_in_path = {'PATH' => "#{bin_dir}:#{ENV['PATH']}"}
25
- Invocation.new *Open3.capture3(bin_in_path, command, stdin_data: stdin_data)
24
+ with_bin_in_path do
25
+ Invocation.new *Open3.capture3(command, stdin_data: stdin_data)
26
+ end
26
27
  end
27
28
  end
28
29
 
@@ -53,6 +54,16 @@ module CommandLineHelpers
53
54
  def path_to(filename)
54
55
  in_proving_grounds { File.join proving_grounds_dir, filename }
55
56
  end
57
+
58
+ # workaround for Ruby 2.0 bug where passing the new path as the first arg wasn't working
59
+ # bug report submitted here: http://bugs.ruby-lang.org/issues/8004
60
+ def with_bin_in_path
61
+ original_path = ENV['PATH']
62
+ ENV['PATH'] = "#{bin_dir}:#{ENV['PATH']}"
63
+ yield
64
+ ensure
65
+ ENV['PATH'] = original_path
66
+ end
56
67
  end
57
68
 
58
69
  CommandLineHelpers.make_proving_grounds
@@ -47,7 +47,7 @@ class SeeingIsBelieving
47
47
  if 1 < filenames.size
48
48
  options[:errors] << "Can only have one filename, but had: #{filenames.map(&:inspect).join ', '}"
49
49
  elsif filenames.any? && options[:program]
50
- options[:errors] << "You passed the program in an argument, but have also specified the filename #{filenames.first}"
50
+ options[:errors] << "You passed the program in an argument, but have also specified the filename #{filenames.first.inspect}"
51
51
  end
52
52
 
53
53
  if options[:end_line] < options[:start_line]
@@ -66,7 +66,8 @@ class SeeingIsBelieving
66
66
 
67
67
  def reduce(expressions, offset)
68
68
  expressions.size.times do |i|
69
- expression = expressions[i..-1].map(&:expression) # uhm, should this expression we are checking for validity consider the children?
69
+ expression = expressions[i..-1].map { |e| [e.expression, *e.children] }
70
+ .flatten
70
71
  .join("\n") # must use newline otherwise can get expressions like `a\\+b` that should be `a\\\n+b`, former is invalid
71
72
  return if children_will_never_be_valid? expression
72
73
  next unless valid_ruby? expression
@@ -83,7 +84,7 @@ class SeeingIsBelieving
83
84
 
84
85
  def valid_ruby?(expression)
85
86
  valid = SyntaxAnalyzer.valid_ruby? expression
86
- debug { "#{valid ? "\e[31mIS NOT VALID:" : "\e[32mIS VALID:"}: #{expression.inspect}\e[0m" }
87
+ debug { "#{valid ? "\e[32mIS VALID:" : "\e[31mIS NOT VALID:"}: #{expression.inspect}\e[0m" }
87
88
  valid
88
89
  end
89
90
 
@@ -0,0 +1,39 @@
1
+ require 'seeing_is_believing/has_exception'
2
+ class SeeingIsBelieving
3
+ # thin wrapper over an array, used by the result
4
+ class Line
5
+ def self.[](*elements)
6
+ new(elements)
7
+ end
8
+
9
+ include HasException
10
+ include Enumerable
11
+
12
+ # delegate all methods to the array, but return self where the array would be returned
13
+ Array.instance_methods(false).sort.each do |method_name|
14
+ define_method method_name do |*args, &block|
15
+ result = @array.__send__ method_name, *args, &block
16
+ result.equal?(@array) ? self : result
17
+ end
18
+ end
19
+
20
+ def to_a
21
+ @array.dup
22
+ end
23
+ alias to_ary to_a
24
+
25
+ def initialize(array = [])
26
+ @array = array.dup
27
+ end
28
+
29
+ def ==(ary_or_line)
30
+ return @array == ary_or_line if Array === ary_or_line
31
+ ary_or_line == @array && exception == ary_or_line.exception
32
+ end
33
+
34
+ def inspect
35
+ inspected_exception = has_exception? ? "#{exception.class}:#{exception.message.inspect}" : "no exception"
36
+ "#<SIB:Line#{@array.inspect} #{inspected_exception}>"
37
+ end
38
+ end
39
+ end
@@ -1,30 +1,9 @@
1
- require 'forwardable'
1
+ require 'seeing_is_believing/line'
2
2
  require 'seeing_is_believing/has_exception'
3
3
  require 'seeing_is_believing/tracks_line_numbers_seen'
4
4
 
5
5
  class SeeingIsBelieving
6
6
  class Result
7
-
8
- class Line
9
- include HasException
10
-
11
- extend Forwardable
12
- def_delegators :@array, :[], :<<, :any?, :join, :to_ary, :to_a, :empty?
13
-
14
- def initialize
15
- @array ||= []
16
- end
17
-
18
- def ==(ary_or_line)
19
- if Array === ary_or_line
20
- @array == ary_or_line
21
- else
22
- ary_or_line == @array &&
23
- has_exception? == ary_or_line.has_exception?
24
- end
25
- end
26
- end
27
-
28
7
  include HasException
29
8
  include TracksLineNumbersSeen
30
9
  include Enumerable
@@ -135,7 +135,7 @@ class SeeingIsBelieving
135
135
  # this is conspicuosuly inferior, but I can't figure out how to actually parse it
136
136
  # see: http://www.ruby-forum.com/topic/4409633
137
137
  def self.will_return?(code)
138
- /(^|\s)return.*?\Z$/ =~ code
138
+ /(^|\s)return.*?\n?\z$/ =~ code
139
139
  end
140
140
 
141
141
  # HERE DOCS
@@ -1,3 +1,3 @@
1
1
  class SeeingIsBelieving
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.14'
3
3
  end
@@ -175,8 +175,8 @@ describe SeeingIsBelieving::Binary::ArgParser do
175
175
  end
176
176
 
177
177
  it 'sets an error if a filename is also give' do
178
- # parse(['abc']).should_not have_error /abc/
179
- parse(['-e', '1', 'abc']).should have_error /abc/
178
+ parse(['-e', '1']).should_not have_error /-e/
179
+ parse(['-e', '1', 'abc']).should have_error /"abc"/
180
180
  end
181
181
  end
182
182
 
@@ -212,6 +212,9 @@ describe SeeingIsBelieving::Binary::ArgParser do
212
212
  end
213
213
 
214
214
  it 'sets an error if not provided with an encoding' do
215
+ parse(['-Ku']).should_not have_error /-K/
216
+ parse(['-K u']).should_not have_error /-K/
217
+ parse(['--encoding', 'u']).should_not have_error /--encoding/
215
218
  parse(['-K']).should have_error /-K/
216
219
  parse(['--encoding']).should have_error /--encoding/
217
220
  end
@@ -228,8 +231,10 @@ describe SeeingIsBelieving::Binary::ArgParser do
228
231
  end
229
232
 
230
233
  it 'sets an error if not provided with a filename' do
231
- parse(%w[-a]).should have_error /-a/
232
- parse(%w[--as]).should have_error /--as/
234
+ parse(%w[-a f]).should_not have_error /-a/
235
+ parse(%w[-as f]).should_not have_error /--as/
236
+ parse(%w[-a ]).should have_error /-a/
237
+ parse(%w[--as ]).should have_error /--as/
233
238
  end
234
239
  end
235
240
 
@@ -16,7 +16,7 @@ describe SeeingIsBelieving::ExpressionList do
16
16
 
17
17
  example 'example: multiple children' do
18
18
  block_invocations = 0
19
- result, size = call %w[a( b+ c x\\ + y )] do |line, children, completions, offset|
19
+ result, size = call %w[begin b+ c x\\ + y end] do |line, children, completions, offset|
20
20
  case offset
21
21
  when 2
22
22
  line.should == 'b+'
@@ -29,11 +29,11 @@ describe SeeingIsBelieving::ExpressionList do
29
29
  children.should == []
30
30
  completions.should == ['+', 'y']
31
31
  block_invocations += 10
32
- 'x\\+y'
32
+ "x+y"
33
33
  when 6
34
- line.should == 'a('
35
- children.should == ['b+c', 'x\\+y']
36
- completions.should == [')']
34
+ line.should == 'begin'
35
+ children.should == ['b+c', 'x+y']
36
+ completions.should == ['end']
37
37
  block_invocations += 100
38
38
  'ALL DONE!'
39
39
  else
@@ -115,6 +115,27 @@ describe SeeingIsBelieving::ExpressionList do
115
115
  size.should == 4
116
116
  end
117
117
 
118
+ example 'example: completions who requires its children to be considered for the expression to be valid' do
119
+ block_invocations = 0
120
+ result, size = call ["if true &&", "true", "1", "end"] do |line, children, completions, offset|
121
+ case offset
122
+ when 1
123
+ [line, children, completions].should == ['true', [], []]
124
+ block_invocations += 1
125
+ when 2
126
+ [line, children, completions].should == ['1', [], []]
127
+ block_invocations += 10
128
+ when 3
129
+ [line, children, completions].should == ['if true &&', ['true', '1'], ['end']]
130
+ block_invocations += 100
131
+ end
132
+ [line, *children, *completions].join("\n")
133
+ end
134
+ block_invocations.should == 111
135
+ result.should == "if true &&\ntrue\n1\nend"
136
+ size.should == 4
137
+ end
138
+
118
139
  example 'example: multiline strings with valid code in them' do
119
140
  block_invocations = 0
120
141
  call ["'", "1", "'"] do |*expressions, offset|
@@ -0,0 +1,65 @@
1
+ require 'seeing_is_believing/result'
2
+
3
+ describe SeeingIsBelieving::Line do
4
+ Line = described_class
5
+
6
+ it 'inspects prettily' do
7
+ Line[].inspect.should == '#<SIB:Line[] no exception>'
8
+ Line["a"].inspect.should == '#<SIB:Line["a"] no exception>'
9
+ Line["a", 1].inspect.should == '#<SIB:Line["a", 1] no exception>'
10
+ line = Line[]
11
+ line.exception = RuntimeError.new("omg")
12
+ line.inspect.should == '#<SIB:Line[] RuntimeError:"omg">'
13
+ end
14
+
15
+ it 'knows when it has an exception' do
16
+ exception = RuntimeError.new 'omg'
17
+ line = Line.new
18
+ line.should_not have_exception
19
+ line.exception = exception
20
+ line.should have_exception
21
+ line.exception.should equal exception
22
+ end
23
+
24
+ it 'delegates its other methods to array, but returns itself where the array would be returned' do
25
+ line = Line.new
26
+ line.should be_empty
27
+ (line << 1).should equal line
28
+ line.should_not be_empty
29
+ line.map { |i| i * 2 }.should == [2]
30
+ line << 10 << 100
31
+ line.take(2).should == [1, 10]
32
+ end
33
+
34
+ it 'returns its array for #to_a and #to_ary' do
35
+ line = Line[1,2]
36
+ line.to_a.should be_a_kind_of Array
37
+ line.to_a.should == [1, 2]
38
+ line.to_ary.should be_a_kind_of Array
39
+ line.to_ary.should == [1, 2]
40
+ end
41
+
42
+ it 'is equal to arrays with the same elements as its array' do
43
+ Line[1, 2].should == [1, 2]
44
+ Line[1, 2].should_not == [2, 1]
45
+ end
46
+
47
+ # 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
48
+ it "is equal to lines with the same elements and the same exception" do
49
+ exception = RuntimeError.new 'omg'
50
+
51
+ Line[1, 2].should == Line[1, 2]
52
+ Line[1, 2].should_not == Line[2, 1]
53
+
54
+ line1 = Line[1, 2]
55
+ line1.exception = exception
56
+ line1.should_not == Line[1, 2]
57
+
58
+ line2 = Line[1, 2]
59
+ line2.exception = exception
60
+ line1.should == line2
61
+
62
+ line2.exception = RuntimeError.new 'wrong message'
63
+ line1.should_not == line2
64
+ end
65
+ end
@@ -46,7 +46,16 @@ describe SeeingIsBelieving do
46
46
  end
47
47
 
48
48
  it 'evalutes to an empty array for lines that it cannot understand' do
49
+ vs = values_for('if true &&
50
+ if true &&
51
+ true
52
+ 1
53
+ end
54
+ 2
55
+ end').should == [[], [], ['true'], ['1'], ['1'], ['2'], ['2']]
56
+
49
57
  values_for("[3].map do |n|\n n*2\n end").should == [[], ['6'], ['[6]']]
58
+
50
59
  values_for("[1].map do |n1|
51
60
  [2].map do |n2|
52
61
  n1 + n2
metadata CHANGED
@@ -1,60 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seeing_is_believing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
5
- prerelease:
4
+ version: 0.0.14
6
5
  platform: ruby
7
6
  authors:
8
7
  - Josh Cheek
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-16 00:00:00.000000000 Z
11
+ date: 2013-03-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
- requirement: &70333554807460 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
19
  version: 10.0.3
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *70333554807460
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 10.0.3
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rspec
27
- requirement: &70333554806960 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ~>
31
32
  - !ruby/object:Gem::Version
32
33
  version: 2.12.0
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *70333554806960
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.12.0
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: cucumber
38
- requirement: &70333554806500 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
45
  - - ~>
42
46
  - !ruby/object:Gem::Version
43
47
  version: 1.2.1
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *70333554806500
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.1
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: ichannel
49
- requirement: &70333554806040 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
54
61
  version: 5.1.1
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *70333554806040
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 5.1.1
58
69
  description: Records the results of every line of code in your file (intended to be
59
70
  like xmpfilter), inspired by Bret Victor's JavaScript example in his talk "Inventing
60
71
  on Principle"
@@ -87,6 +98,7 @@ files:
87
98
  - lib/seeing_is_believing/expression_list.rb
88
99
  - lib/seeing_is_believing/hard_core_ensure.rb
89
100
  - lib/seeing_is_believing/has_exception.rb
101
+ - lib/seeing_is_believing/line.rb
90
102
  - lib/seeing_is_believing/queue.rb
91
103
  - lib/seeing_is_believing/result.rb
92
104
  - lib/seeing_is_believing/syntax_analyzer.rb
@@ -99,6 +111,7 @@ files:
99
111
  - spec/expression_list_spec.rb
100
112
  - spec/hard_core_ensure_spec.rb
101
113
  - spec/line_formatter_spec.rb
114
+ - spec/line_spec.rb
102
115
  - spec/queue_spec.rb
103
116
  - spec/seeing_is_believing_spec.rb
104
117
  - spec/syntax_analyzer_spec.rb
@@ -106,27 +119,26 @@ files:
106
119
  homepage: https://github.com/JoshCheek/seeing_is_believing
107
120
  licenses:
108
121
  - WTFPL
122
+ metadata: {}
109
123
  post_install_message:
110
124
  rdoc_options: []
111
125
  require_paths:
112
126
  - lib
113
127
  required_ruby_version: !ruby/object:Gem::Requirement
114
- none: false
115
128
  requirements:
116
- - - ! '>='
129
+ - - '>='
117
130
  - !ruby/object:Gem::Version
118
131
  version: '0'
119
132
  required_rubygems_version: !ruby/object:Gem::Requirement
120
- none: false
121
133
  requirements:
122
- - - ! '>='
134
+ - - '>='
123
135
  - !ruby/object:Gem::Version
124
136
  version: '0'
125
137
  requirements: []
126
138
  rubyforge_project: seeing_is_believing
127
- rubygems_version: 1.8.11
139
+ rubygems_version: 2.0.0
128
140
  signing_key:
129
- specification_version: 3
141
+ specification_version: 4
130
142
  summary: Records results of every line of code in your file
131
143
  test_files:
132
144
  - features/errors.feature
@@ -139,7 +151,7 @@ test_files:
139
151
  - spec/expression_list_spec.rb
140
152
  - spec/hard_core_ensure_spec.rb
141
153
  - spec/line_formatter_spec.rb
154
+ - spec/line_spec.rb
142
155
  - spec/queue_spec.rb
143
156
  - spec/seeing_is_believing_spec.rb
144
157
  - spec/syntax_analyzer_spec.rb
145
- has_rdoc: