seeing_is_believing 0.0.1 → 0.0.2
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.
- data/Readme.md +83 -0
- data/bin/seeing_is_believing +11 -1
- data/features/binary.feature +20 -5
- data/features/step_definitions/steps.rb +5 -1
- data/lib/seeing_is_believing/example_use.rb +15 -6
- data/lib/seeing_is_believing/result.rb +26 -10
- data/lib/seeing_is_believing/version.rb +1 -1
- data/seeing_is_believing.gemspec +1 -1
- metadata +7 -6
data/Readme.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
Seeing Is Believing
|
2
|
+
===================
|
3
|
+
|
4
|
+
Evaluates a file, recording the results of each line of code.
|
5
|
+
You can then use this to display output values like Bret Victor does with JavaScript in his talk ["Inventing on Principle"][inventing_on_principle].
|
6
|
+
Except, obviously, his is like a million better.
|
7
|
+
|
8
|
+
Reeaally rough at the moment, but it works for simple examples.
|
9
|
+
|
10
|
+
Also comes with a binary to show how it might be used.
|
11
|
+
|
12
|
+
Install
|
13
|
+
=======
|
14
|
+
|
15
|
+
gem install seeing_is_believing
|
16
|
+
|
17
|
+
Use
|
18
|
+
===
|
19
|
+
|
20
|
+
$ cat proving_grounds/basic_functionality.rb
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
a = '12'
|
24
|
+
a + a
|
25
|
+
|
26
|
+
5.times do |i|
|
27
|
+
i * 2
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
$ seeing_is_believing proving_grounds/basic_functionality.rb
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
a = '12' # => "12"
|
35
|
+
a + a # => "1212"
|
36
|
+
|
37
|
+
5.times do |i|
|
38
|
+
i * 2 # => 0, 2, 4, 6, 8
|
39
|
+
end # => 5
|
40
|
+
```
|
41
|
+
|
42
|
+
$ cat proving_grounds/raises_exception.rb
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
1 + 1
|
46
|
+
raise "ZOMG!"
|
47
|
+
1 + 1
|
48
|
+
```
|
49
|
+
|
50
|
+
$ bin/seeing_is_believing proving_grounds/raises_exception.rb 2>/dev/null
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
1 + 1 # => 2
|
54
|
+
raise "ZOMG!" # ~> RuntimeError: ZOMG!
|
55
|
+
1 + 1
|
56
|
+
```
|
57
|
+
|
58
|
+
$ bin/seeing_is_believing proving_grounds/raises_exception.rb 1>/dev/null
|
59
|
+
|
60
|
+
```bash
|
61
|
+
ZOMG!
|
62
|
+
```
|
63
|
+
|
64
|
+
License
|
65
|
+
=======
|
66
|
+
|
67
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
68
|
+
Version 2, December 2004
|
69
|
+
|
70
|
+
Copyright (C) 2012 Josh Cheek <josh.cheek@gmail.com>
|
71
|
+
|
72
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
73
|
+
copies of this license document, and changing it is allowed as long
|
74
|
+
as the name is changed.
|
75
|
+
|
76
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
77
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
78
|
+
|
79
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
[inventing_on_principle]: http://vimeo.com/36579366
|
data/bin/seeing_is_believing
CHANGED
@@ -3,6 +3,16 @@
|
|
3
3
|
$LOAD_PATH.unshift File.expand_path '../../lib', __FILE__
|
4
4
|
require 'seeing_is_believing/example_use'
|
5
5
|
|
6
|
+
status = 0
|
7
|
+
|
6
8
|
ARGV.each do |filename|
|
7
|
-
|
9
|
+
believer = SeeingIsBelieving::ExampleUse.new(File.read filename)
|
10
|
+
believer.call
|
11
|
+
$stdout.puts believer.output
|
12
|
+
if believer.has_exception?
|
13
|
+
$stderr.puts believer.exception.message
|
14
|
+
status = 1
|
15
|
+
end
|
8
16
|
end
|
17
|
+
|
18
|
+
exit status
|
data/features/binary.feature
CHANGED
@@ -6,7 +6,7 @@ Feature: Running the binary
|
|
6
6
|
run against every line.
|
7
7
|
|
8
8
|
Scenario: Some basic functionality
|
9
|
-
Given the file "
|
9
|
+
Given the file "basic_functionality.rb":
|
10
10
|
"""
|
11
11
|
a = '12'
|
12
12
|
a + a
|
@@ -15,9 +15,9 @@ Feature: Running the binary
|
|
15
15
|
i * 2
|
16
16
|
end
|
17
17
|
"""
|
18
|
-
When I run "seeing_is_believing
|
19
|
-
|
20
|
-
|
18
|
+
When I run "seeing_is_believing basic_functionality.rb"
|
19
|
+
Then stderr is empty
|
20
|
+
And the exit status is 0
|
21
21
|
And stdout is:
|
22
22
|
"""
|
23
23
|
a = '12' # => "12"
|
@@ -26,10 +26,25 @@ Feature: Running the binary
|
|
26
26
|
5.times do |i|
|
27
27
|
i * 2 # => 0, 2, 4, 6, 8
|
28
28
|
end # => 5
|
29
|
+
"""
|
29
30
|
|
31
|
+
Scenario: Raising exceptions
|
32
|
+
Given the file "raises_exception.rb":
|
33
|
+
"""
|
34
|
+
1 + 1
|
35
|
+
raise "ZOMG!"
|
36
|
+
1 + 1
|
37
|
+
"""
|
38
|
+
When I run "seeing_is_believing raises_exception.rb"
|
39
|
+
Then stderr is "ZOMG!"
|
40
|
+
And the exit status is 1
|
41
|
+
And stdout is:
|
42
|
+
"""
|
43
|
+
1 + 1 # => 2
|
44
|
+
raise "ZOMG!" # ~> RuntimeError: ZOMG!
|
45
|
+
1 + 1
|
30
46
|
"""
|
31
47
|
|
32
48
|
Scenario: Printing within the file
|
33
|
-
Scenario: Raising exceptions
|
34
49
|
Scenario: Requiring other files
|
35
50
|
Scenario: Syntactically invalid file
|
@@ -7,7 +7,11 @@ When 'I run "$command"' do |command|
|
|
7
7
|
end
|
8
8
|
|
9
9
|
Then /^(stderr|stdout) is:$/ do |stream_name, output|
|
10
|
-
@last_executed.send(stream_name).should == output
|
10
|
+
@last_executed.send(stream_name).chomp.should == output
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^(stderr|stdout) is "(.*?)"$/ do |stream_name, output|
|
14
|
+
@last_executed.send(stream_name).chomp.should == output
|
11
15
|
end
|
12
16
|
|
13
17
|
Then 'the exit status is $status' do |status|
|
@@ -2,17 +2,27 @@ require 'seeing_is_believing'
|
|
2
2
|
|
3
3
|
class SeeingIsBelieving
|
4
4
|
class ExampleUse
|
5
|
+
attr_accessor :exception
|
6
|
+
|
5
7
|
def initialize(body)
|
6
8
|
self.body = body
|
7
9
|
end
|
8
10
|
|
9
11
|
def call
|
10
12
|
body.each_line.with_index 1 do |line, index|
|
11
|
-
write_line line.chomp, results[index]
|
13
|
+
write_line line.chomp, results[index]
|
12
14
|
end
|
13
15
|
output
|
14
16
|
end
|
15
17
|
|
18
|
+
def output
|
19
|
+
@result ||= ''
|
20
|
+
end
|
21
|
+
|
22
|
+
def has_exception?
|
23
|
+
!!@exception
|
24
|
+
end
|
25
|
+
|
16
26
|
private
|
17
27
|
|
18
28
|
attr_accessor :body
|
@@ -21,13 +31,12 @@ class SeeingIsBelieving
|
|
21
31
|
@results ||= SeeingIsBelieving.new(body).call
|
22
32
|
end
|
23
33
|
|
24
|
-
def
|
25
|
-
@result ||= ''
|
26
|
-
end
|
27
|
-
|
28
|
-
def write_line(line, results, line_length)
|
34
|
+
def write_line(line, results)
|
29
35
|
if results.any?
|
30
36
|
output << sprintf("%-#{line_length}s# => %s\n", line, results.join(', '))
|
37
|
+
elsif results.has_exception?
|
38
|
+
self.exception = results.exception
|
39
|
+
output << sprintf("%-#{line_length}s# ~> %s: %s\n", line, results.exception.class, results.exception.message)
|
31
40
|
else
|
32
41
|
output << line << "\n"
|
33
42
|
end
|
@@ -1,5 +1,27 @@
|
|
1
1
|
class SeeingIsBelieving
|
2
2
|
class Result
|
3
|
+
class Line
|
4
|
+
attr_reader :results
|
5
|
+
attr_accessor :exception
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@results = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def <<(result)
|
12
|
+
results << result
|
13
|
+
end
|
14
|
+
|
15
|
+
def any?
|
16
|
+
results.any?
|
17
|
+
end
|
18
|
+
|
19
|
+
def join(*args)
|
20
|
+
results.join(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
alias has_exception? exception
|
24
|
+
end
|
3
25
|
attr_reader :min_line_number, :max_line_number
|
4
26
|
|
5
27
|
def initialize
|
@@ -14,18 +36,17 @@ class SeeingIsBelieving
|
|
14
36
|
|
15
37
|
def record_exception(line_number, exception)
|
16
38
|
contains_line_number line_number
|
17
|
-
|
18
|
-
@exception = exception
|
39
|
+
results[line_number].exception = exception
|
19
40
|
end
|
20
41
|
|
21
42
|
def [](line_number)
|
22
43
|
results[line_number]
|
23
44
|
end
|
24
45
|
|
25
|
-
#
|
46
|
+
# probably not really useful, just exists to satisfy the tests
|
26
47
|
def to_a
|
27
48
|
(min_line_number..max_line_number).map do |line_number|
|
28
|
-
[line_number, [*self[line_number], *Array(
|
49
|
+
[line_number, [*self[line_number].results, *Array(self[line_number].exception)]]
|
29
50
|
end
|
30
51
|
end
|
31
52
|
|
@@ -36,13 +57,8 @@ class SeeingIsBelieving
|
|
36
57
|
|
37
58
|
private
|
38
59
|
|
39
|
-
def exception_at(line_number)
|
40
|
-
return unless @exception_line_number == line_number
|
41
|
-
@exception
|
42
|
-
end
|
43
|
-
|
44
60
|
def results
|
45
|
-
@results ||= Hash.new { |hash, line_number| hash[line_number] =
|
61
|
+
@results ||= Hash.new { |hash, line_number| hash[line_number] = Line.new }
|
46
62
|
end
|
47
63
|
end
|
48
64
|
end
|
data/seeing_is_believing.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["josh.cheek@gmail.com"]
|
10
10
|
s.homepage = "https://github.com/JoshCheek/seeing_is_believing"
|
11
11
|
s.summary = %q{Records results of every line of code in your file}
|
12
|
-
s.description = %q{Records the results of every line of code in your file (intended to be like xmpfilter), inspired by
|
12
|
+
s.description = %q{Records the results of every line of code in your file (intended to be like xmpfilter), inspired by Bret Victor's JavaScript example in his talk "Inventing on Principle"}
|
13
13
|
|
14
14
|
s.rubyforge_project = "seeing_is_believing"
|
15
15
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seeing_is_believing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-01-02 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70263953788620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.12.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70263953788620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: cucumber
|
27
|
-
requirement: &
|
27
|
+
requirement: &70263953787880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,9 +32,9 @@ dependencies:
|
|
32
32
|
version: 1.2.1
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70263953787880
|
36
36
|
description: Records the results of every line of code in your file (intended to be
|
37
|
-
like xmpfilter), inspired by
|
37
|
+
like xmpfilter), inspired by Bret Victor's JavaScript example in his talk "Inventing
|
38
38
|
on Principle"
|
39
39
|
email:
|
40
40
|
- josh.cheek@gmail.com
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- .gitignore
|
47
47
|
- Gemfile
|
48
48
|
- Gemfile.lock
|
49
|
+
- Readme.md
|
49
50
|
- bin/seeing_is_believing
|
50
51
|
- features/binary.feature
|
51
52
|
- features/step_definitions/steps.rb
|