erudite 0.1.0 → 0.2.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 -13
- data/CHANGELOG.md +8 -0
- data/LICENSE.md +18 -18
- data/README.md +54 -16
- data/bin/erudite +6 -0
- data/lib/erudite.rb +10 -9
- data/lib/erudite/example.rb +82 -79
- data/lib/erudite/executable.rb +35 -0
- data/lib/erudite/outcome.rb +19 -19
- data/lib/erudite/parser.rb +54 -54
- data/spec/erudite/example_spec.rb +366 -352
- data/spec/erudite/executable_spec.rb +76 -0
- data/spec/erudite/outcome_spec.rb +53 -53
- data/spec/erudite/parser_spec.rb +104 -104
- data/spec/erudite_spec.rb +0 -1
- data/spec/spec_helper.rb +3 -0
- metadata +30 -11
@@ -0,0 +1,76 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Erudite::Executable do
|
6
|
+
let(:example) { Erudite::Example.new(source, example_result) }
|
7
|
+
let(:source) { '' }
|
8
|
+
let(:example_result) { nil }
|
9
|
+
|
10
|
+
describe '.run' do
|
11
|
+
subject(:result) { described_class.run(io) }
|
12
|
+
let(:io) { StringIO.new(input) }
|
13
|
+
let(:input) { '' }
|
14
|
+
|
15
|
+
before { @stdout, $stdout = $stdout, StringIO.new }
|
16
|
+
after { $stdout = @stdout }
|
17
|
+
|
18
|
+
it 'returns an array' do
|
19
|
+
expect(result).to be_an(Array)
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with input' do
|
23
|
+
let(:input) { ">> p(true)\ntrue\n=> true\n" }
|
24
|
+
|
25
|
+
it 'returns the example' do
|
26
|
+
expect(result).to_not be_empty
|
27
|
+
result.each do |example|
|
28
|
+
expect(example).to be_an(Erudite::Example)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'prints the results' do
|
33
|
+
result
|
34
|
+
expect($stdout.string).to eql("- PASS\n")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '.format_example' do
|
40
|
+
subject(:result) { described_class.format_example(example) }
|
41
|
+
|
42
|
+
context 'passing' do
|
43
|
+
let(:source) { 'true' }
|
44
|
+
let(:example_result) { 'true' }
|
45
|
+
|
46
|
+
it 'starts with "- PASS"' do
|
47
|
+
expect(result).to start_with('- PASS')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'failing' do
|
52
|
+
let(:source) { 'true' }
|
53
|
+
let(:example_result) { 'false' }
|
54
|
+
|
55
|
+
it 'starts with "- FAIL"' do
|
56
|
+
expect(result).to start_with('- FAIL')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '.format_passing_example' do
|
62
|
+
subject(:result) { described_class.format_passing_example(example) }
|
63
|
+
|
64
|
+
it 'starts with "- PASS"' do
|
65
|
+
expect(result).to start_with('- PASS')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '.format_failing_example' do
|
70
|
+
subject(:result) { described_class.format_failing_example(example) }
|
71
|
+
|
72
|
+
it 'starts with "- FAIL"' do
|
73
|
+
expect(result).to start_with('- FAIL')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -1,53 +1,53 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Erudite::Outcome do
|
6
|
-
it 'requires a result' do
|
7
|
-
expect { described_class.new }.to raise_error(ArgumentError)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'requires some output' do
|
11
|
-
expect { described_class.new(nil) }.to raise_error(ArgumentError)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'can be initialized' do
|
15
|
-
expect(described_class.new(nil, nil)).to be_a(described_class)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'sets the result' do
|
19
|
-
result = double
|
20
|
-
outcome = described_class.new(result, nil)
|
21
|
-
expect(outcome.result).to eql(result)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'sets the output' do
|
25
|
-
output = double
|
26
|
-
outcome = described_class.new(nil, output)
|
27
|
-
expect(outcome.output).to eql(output)
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#==' do
|
31
|
-
it 'returns true if they have the same result and output' do
|
32
|
-
result = 'some'
|
33
|
-
output = 'thing'
|
34
|
-
a = described_class.new(result, output)
|
35
|
-
b = described_class.new(result, output)
|
36
|
-
expect(a).to eq(b)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "returns false if they don't have the same result" do
|
40
|
-
output = 'something'
|
41
|
-
a = described_class.new('a', output)
|
42
|
-
b = described_class.new('b', output)
|
43
|
-
expect(a).to_not eq(b)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "returns false if they don't have the same output" do
|
47
|
-
result = 'something'
|
48
|
-
a = described_class.new(result, 'a')
|
49
|
-
b = described_class.new(result, 'b')
|
50
|
-
expect(a).to_not eq(b)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Erudite::Outcome do
|
6
|
+
it 'requires a result' do
|
7
|
+
expect { described_class.new }.to raise_error(ArgumentError)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'requires some output' do
|
11
|
+
expect { described_class.new(nil) }.to raise_error(ArgumentError)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'can be initialized' do
|
15
|
+
expect(described_class.new(nil, nil)).to be_a(described_class)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'sets the result' do
|
19
|
+
result = double
|
20
|
+
outcome = described_class.new(result, nil)
|
21
|
+
expect(outcome.result).to eql(result)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets the output' do
|
25
|
+
output = double
|
26
|
+
outcome = described_class.new(nil, output)
|
27
|
+
expect(outcome.output).to eql(output)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#==' do
|
31
|
+
it 'returns true if they have the same result and output' do
|
32
|
+
result = 'some'
|
33
|
+
output = 'thing'
|
34
|
+
a = described_class.new(result, output)
|
35
|
+
b = described_class.new(result, output)
|
36
|
+
expect(a).to eq(b)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns false if they don't have the same result" do
|
40
|
+
output = 'something'
|
41
|
+
a = described_class.new('a', output)
|
42
|
+
b = described_class.new('b', output)
|
43
|
+
expect(a).to_not eq(b)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns false if they don't have the same output" do
|
47
|
+
result = 'something'
|
48
|
+
a = described_class.new(result, 'a')
|
49
|
+
b = described_class.new(result, 'b')
|
50
|
+
expect(a).to_not eq(b)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/erudite/parser_spec.rb
CHANGED
@@ -1,104 +1,104 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
# Monkey patch String to add ability to strip leading whitespace.
|
6
|
-
class String
|
7
|
-
def dedent
|
8
|
-
gsub(/^#{self[/\A\s*/]}/, '')
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe Erudite::Parser do
|
13
|
-
describe '.parse' do
|
14
|
-
it 'parses an example without output or a result' do
|
15
|
-
examples = described_class.parse(<<-'RUBY'.dedent)
|
16
|
-
>> :something
|
17
|
-
RUBY
|
18
|
-
expect(examples).to eq([
|
19
|
-
Erudite::Example.new(':something')])
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'parses an example with a result' do
|
23
|
-
examples = described_class.parse(<<-'RUBY'.dedent)
|
24
|
-
>> :something
|
25
|
-
=> :something
|
26
|
-
RUBY
|
27
|
-
expect(examples).to eq([
|
28
|
-
Erudite::Example.new(':something', ':something')])
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'parses an example with output' do
|
32
|
-
examples = described_class.parse(<<-'RUBY'.dedent)
|
33
|
-
>> puts :something
|
34
|
-
something
|
35
|
-
RUBY
|
36
|
-
expect(examples).to eq([
|
37
|
-
Erudite::Example.new('puts :something', nil, 'something')])
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'handles STDIN' do
|
41
|
-
examples = described_class.parse(<<-'RUBY'.dedent)
|
42
|
-
>> gets
|
43
|
-
=> nil
|
44
|
-
RUBY
|
45
|
-
expect(examples).to eq([
|
46
|
-
Erudite::Example.new('gets', 'nil')])
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'handles STDOUT' do
|
50
|
-
examples = described_class.parse(<<-'RUBY'.dedent)
|
51
|
-
>> puts :something
|
52
|
-
something
|
53
|
-
=> nil
|
54
|
-
RUBY
|
55
|
-
expect(examples).to eq([
|
56
|
-
Erudite::Example.new('puts :something', 'nil', 'something')])
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'handles STDERR' do
|
60
|
-
examples = described_class.parse(<<-'RUBY'.dedent)
|
61
|
-
>> warn :something
|
62
|
-
something
|
63
|
-
=> nil
|
64
|
-
RUBY
|
65
|
-
expect(examples).to eq([
|
66
|
-
Erudite::Example.new('warn :something', 'nil', 'something')])
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'handles exceptions' do
|
70
|
-
examples = described_class.parse(<<-'RUBY'.dedent)
|
71
|
-
>> fail 'something'
|
72
|
-
RuntimeError: something
|
73
|
-
RUBY
|
74
|
-
expect(examples).to eq([
|
75
|
-
Erudite::Example.new(
|
76
|
-
"fail 'something'", nil, 'RuntimeError: something')])
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'handles multi-line source and output' do
|
80
|
-
examples = described_class.parse(<<-'RUBY'.dedent)
|
81
|
-
>> puts 'some
|
82
|
-
.. thing'
|
83
|
-
some
|
84
|
-
thing
|
85
|
-
=> nil
|
86
|
-
RUBY
|
87
|
-
expect(examples).to eq([
|
88
|
-
Erudite::Example.new("puts 'some\nthing'", 'nil', "some\nthing")])
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'handles multiple examples' do
|
92
|
-
examples = described_class.parse(<<-'RUBY'.dedent)
|
93
|
-
>> def some
|
94
|
-
.. :thing
|
95
|
-
.. end
|
96
|
-
>> some
|
97
|
-
=> :thing
|
98
|
-
RUBY
|
99
|
-
expect(examples).to eq([
|
100
|
-
Erudite::Example.new("def some\n :thing\nend"),
|
101
|
-
Erudite::Example.new('some', ':thing')])
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# Monkey patch String to add ability to strip leading whitespace.
|
6
|
+
class String
|
7
|
+
def dedent
|
8
|
+
gsub(/^#{self[/\A\s*/]}/, '')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Erudite::Parser do
|
13
|
+
describe '.parse' do
|
14
|
+
it 'parses an example without output or a result' do
|
15
|
+
examples = described_class.parse(<<-'RUBY'.dedent)
|
16
|
+
>> :something
|
17
|
+
RUBY
|
18
|
+
expect(examples).to eq([
|
19
|
+
Erudite::Example.new(':something')])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'parses an example with a result' do
|
23
|
+
examples = described_class.parse(<<-'RUBY'.dedent)
|
24
|
+
>> :something
|
25
|
+
=> :something
|
26
|
+
RUBY
|
27
|
+
expect(examples).to eq([
|
28
|
+
Erudite::Example.new(':something', ':something')])
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'parses an example with output' do
|
32
|
+
examples = described_class.parse(<<-'RUBY'.dedent)
|
33
|
+
>> puts :something
|
34
|
+
something
|
35
|
+
RUBY
|
36
|
+
expect(examples).to eq([
|
37
|
+
Erudite::Example.new('puts :something', nil, 'something')])
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'handles STDIN' do
|
41
|
+
examples = described_class.parse(<<-'RUBY'.dedent)
|
42
|
+
>> gets
|
43
|
+
=> nil
|
44
|
+
RUBY
|
45
|
+
expect(examples).to eq([
|
46
|
+
Erudite::Example.new('gets', 'nil')])
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'handles STDOUT' do
|
50
|
+
examples = described_class.parse(<<-'RUBY'.dedent)
|
51
|
+
>> puts :something
|
52
|
+
something
|
53
|
+
=> nil
|
54
|
+
RUBY
|
55
|
+
expect(examples).to eq([
|
56
|
+
Erudite::Example.new('puts :something', 'nil', 'something')])
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'handles STDERR' do
|
60
|
+
examples = described_class.parse(<<-'RUBY'.dedent)
|
61
|
+
>> warn :something
|
62
|
+
something
|
63
|
+
=> nil
|
64
|
+
RUBY
|
65
|
+
expect(examples).to eq([
|
66
|
+
Erudite::Example.new('warn :something', 'nil', 'something')])
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'handles exceptions' do
|
70
|
+
examples = described_class.parse(<<-'RUBY'.dedent)
|
71
|
+
>> fail 'something'
|
72
|
+
RuntimeError: something
|
73
|
+
RUBY
|
74
|
+
expect(examples).to eq([
|
75
|
+
Erudite::Example.new(
|
76
|
+
"fail 'something'", nil, 'RuntimeError: something')])
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'handles multi-line source and output' do
|
80
|
+
examples = described_class.parse(<<-'RUBY'.dedent)
|
81
|
+
>> puts 'some
|
82
|
+
.. thing'
|
83
|
+
some
|
84
|
+
thing
|
85
|
+
=> nil
|
86
|
+
RUBY
|
87
|
+
expect(examples).to eq([
|
88
|
+
Erudite::Example.new("puts 'some\nthing'", 'nil', "some\nthing")])
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'handles multiple examples' do
|
92
|
+
examples = described_class.parse(<<-'RUBY'.dedent)
|
93
|
+
>> def some
|
94
|
+
.. :thing
|
95
|
+
.. end
|
96
|
+
>> some
|
97
|
+
=> :thing
|
98
|
+
RUBY
|
99
|
+
expect(examples).to eq([
|
100
|
+
Erudite::Example.new("def some\n :thing\nend"),
|
101
|
+
Erudite::Example.new('some', ':thing')])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/spec/erudite_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,60 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erudite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Fausak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: coveralls
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ~>
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: 10.3
|
33
|
+
version: '10.3'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - ~>
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: 10.3
|
40
|
+
version: '10.3'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ~>
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
47
|
+
version: '3.1'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ~>
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
54
|
+
version: '3.1'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rubocop
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ~>
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
61
|
+
version: '0.26'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - ~>
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
68
|
+
version: '0.26'
|
55
69
|
description: Executable documentation.
|
56
70
|
email: taylor@fausak.me
|
57
|
-
executables:
|
71
|
+
executables:
|
72
|
+
- erudite
|
58
73
|
extensions: []
|
59
74
|
extra_rdoc_files: []
|
60
75
|
files:
|
@@ -62,11 +77,14 @@ files:
|
|
62
77
|
- CONTRIBUTING.md
|
63
78
|
- LICENSE.md
|
64
79
|
- README.md
|
80
|
+
- bin/erudite
|
65
81
|
- lib/erudite.rb
|
66
82
|
- lib/erudite/example.rb
|
83
|
+
- lib/erudite/executable.rb
|
67
84
|
- lib/erudite/outcome.rb
|
68
85
|
- lib/erudite/parser.rb
|
69
86
|
- spec/erudite/example_spec.rb
|
87
|
+
- spec/erudite/executable_spec.rb
|
70
88
|
- spec/erudite/outcome_spec.rb
|
71
89
|
- spec/erudite/parser_spec.rb
|
72
90
|
- spec/erudite_spec.rb
|
@@ -81,12 +99,12 @@ require_paths:
|
|
81
99
|
- lib
|
82
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
101
|
requirements:
|
84
|
-
- -
|
102
|
+
- - '>='
|
85
103
|
- !ruby/object:Gem::Version
|
86
104
|
version: 1.9.3
|
87
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
106
|
requirements:
|
89
|
-
- -
|
107
|
+
- - '>='
|
90
108
|
- !ruby/object:Gem::Version
|
91
109
|
version: '0'
|
92
110
|
requirements: []
|
@@ -97,6 +115,7 @@ specification_version: 4
|
|
97
115
|
summary: Executable documentation.
|
98
116
|
test_files:
|
99
117
|
- spec/erudite/example_spec.rb
|
118
|
+
- spec/erudite/executable_spec.rb
|
100
119
|
- spec/erudite/outcome_spec.rb
|
101
120
|
- spec/erudite/parser_spec.rb
|
102
121
|
- spec/erudite_spec.rb
|