doctest-core 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODJmYWE0ZjE4Yjc4MTNkNDE4Y2UzOWI4YThhY2NlY2IwMTA3NDk1Yg==
5
- data.tar.gz: !binary |-
6
- NzUxYTc5YWQyNTZmOTAyZGE1MTk4MWJiZDVjNGRkNTAxZGExZTk0MQ==
2
+ SHA1:
3
+ metadata.gz: 5d5df458235fdf44570f12f2f231464e157333f8
4
+ data.tar.gz: 41f9d7e562a06bc4a5c4c87c25e15e17bea76a57
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MTE5MTAyMWQxMGZmNTE4NDY1ZmQ4YzNhM2U1MThlMzBjNmRmNzNjYThiMGQz
10
- MGExZGE3ODQzZWQxMzE5Y2FkNjdiNDYxMjY0ZWRlYzljNTlkMzRkZGVlMTgz
11
- YmVhMGQ2N2MyZWM0MmU3MDU1ZmEyYzM0MDZiMWIwYTQ2ZTdjOGE=
12
- data.tar.gz: !binary |-
13
- NDE0NGYyODM1ZWJjYzQ3YjBiYTU5OWFiODU5ZmM0MTlhYjVmMWQ0ZThkMjI1
14
- ZmQzN2Y3Y2M2M2FkM2ZhZDNiNWU2MzAyZWRiNzA3MTIxYjk4N2YzM2ViMjhi
15
- Y2MwMzIwNWE4NmQ2OThlZTlkNjgxOGY2YmFjOGE5MmI1YmIwMTE=
6
+ metadata.gz: efc87512029a259d72cdfdcde0737d904e3f4f52ec720c9a1cd811ee6f450dcad647234abc0d514cf885f3812fb939cb5b3e97e6611ffa028ae91aadf4c978fe
7
+ data.tar.gz: a2e42d00c021188399bad1a2223ae8694cbafc233d5e5fb587d347f95834a90364f141905d407800a4ffef101b7bae4db140ae630f0981c693925bee8488399e
@@ -1,5 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.1.1
4
+ - 2.0.0
3
5
  - 1.9.3
4
6
  - jruby-19mode
5
7
  - rbx-19mode
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [![Code Climate](https://codeclimate.com/github/hzeus/doctest-core.png)](https://codeclimate.com/github/hzeus/doctest-core)
2
- [![Build Status](https://travis-ci.org/hzeus/doctest-core.png)](https://travis-ci.org/hzeus/doctest-core)
1
+ [![Code Climate](https://codeclimate.com/github/doctest/doctest-core.png)](https://codeclimate.com/github/doctest/doctest-core)
2
+ [![Build Status](https://travis-ci.org/doctest/doctest-core.png)](https://travis-ci.org/doctest/doctest-core)
3
3
 
4
4
  # Doctest::Core
5
5
 
@@ -49,8 +49,24 @@ You can then run
49
49
  ```ruby
50
50
  Doctest::Core.extract_from(ClassWithDoctests)
51
51
  ```
52
+ to get a collection of doctest instances.
52
53
 
53
- to get a simple array of doctest occurrences. Those contain
54
+ ### Syntax
55
+
56
+ This searches for doctests within the source files of the given class. It checks for the following syntax:
57
+
58
+ ```ruby
59
+ # >> ruby_expression
60
+ ```
61
+ for a test command,
62
+ ```ruby
63
+ # => ruby_expression
64
+ ````
65
+ for a test result. A doctest consists of one or more consecutive test commands and one result line. There must be no empty lines between, but you can add any number of spaces before and after the ```#``` at the beginning of the comment line.
66
+
67
+ ### Doctest instances
68
+
69
+ A doctest instance consists of
54
70
  * ```code_string```: The source code string (`'ClassWithDoctests.a'`)
55
71
  * ```result_string```: The result code string (`'b'`)
56
72
  * ```original_file```: The source location of the file that contains the doctest
@@ -58,7 +74,7 @@ to get a simple array of doctest occurrences. Those contain
58
74
 
59
75
  You can also access ```code_evaluation``` and ```result_evaluation``` for the results of the both code blocks.
60
76
 
61
- Those results can be used to implement test framework-specific gems.
77
+ Those instances can be used to implement test framework-specific gems.
62
78
 
63
79
  ## Contributing
64
80
 
@@ -23,7 +23,7 @@ module Doctest
23
23
  end
24
24
 
25
25
  def analyze
26
- @str.lines.with_index do |line, index|
26
+ @str.lines.each.with_index do |line, index|
27
27
  case line
28
28
  when CODE_REGEXP
29
29
  handle_code(Regexp.last_match['code'])
@@ -49,7 +49,7 @@ module Doctest
49
49
  @current_code = [code]
50
50
  @state = :match
51
51
  when :match
52
- @current << code
52
+ @current_code << code
53
53
  end
54
54
  end
55
55
 
@@ -4,7 +4,7 @@ module Doctest
4
4
 
5
5
  def self.to_filenames(source)
6
6
  case source
7
- when Class
7
+ when Class, Module
8
8
  constant_filenames(source)
9
9
  else
10
10
  [ source ]
@@ -1,5 +1,5 @@
1
1
  module Doctest
2
2
  module Core
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,3 +1,8 @@
1
+ # Sample multi-line code
2
+ #
3
+ # >> a = 3
4
+ # >> a + 2
5
+ # => 5
1
6
  class ClassWithDoctests
2
7
 
3
8
  # Always returns 'a'
@@ -0,0 +1,3 @@
1
+ module SimpleModule
2
+ def first_method; end
3
+ end
@@ -10,9 +10,9 @@ describe Doctest::Core::Base do
10
10
  analyzer = Doctest::Core::Base.new(str)
11
11
 
12
12
  doctests = analyzer.analyze
13
- doctests.should have(1).entries
13
+ expect(doctests.length).to equal 1
14
14
 
15
- doctests[0].should == Doctest::Core::Doctest.new("3 + 2", "5", nil, 2)
15
+ expect(doctests[0]).to eql Doctest::Core::Doctest.new("3 + 2", "5", nil, 2)
16
16
  end
17
17
 
18
18
  it 'extracts multiple samples from a string' do
@@ -27,10 +27,10 @@ describe Doctest::Core::Base do
27
27
  analyzer = Doctest::Core::Base.new(str)
28
28
 
29
29
  doctests = analyzer.analyze
30
- doctests.should have(2).entries
30
+ expect(doctests.length).to equal 2
31
31
 
32
- doctests[0].should == Doctest::Core::Doctest.new("3 + 2", "5", nil, 2)
33
- doctests[1].should == Doctest::Core::Doctest.new("4 + 2", "6", nil, 6)
32
+ expect(doctests[0]).to eql Doctest::Core::Doctest.new("3 + 2", "5", nil, 2)
33
+ expect(doctests[1]).to eql Doctest::Core::Doctest.new("4 + 2", "6", nil, 6)
34
34
  end
35
35
 
36
36
  end
@@ -7,7 +7,7 @@ module Doctest::Core
7
7
  context "doctests for #{source}" do
8
8
  ::Doctest::Core.extract_from(source).each do |doctest|
9
9
  it "at #{doctest.original_file}:#{doctest.line}" do
10
- doctest.code_evaluation.should == doctest.result_evaluation
10
+ expect(doctest.code_evaluation).to eql doctest.result_evaluation
11
11
  end
12
12
  end
13
13
  end
@@ -19,12 +19,12 @@ module Doctest::Core
19
19
  context 'evaluation' do
20
20
 
21
21
  it 'evaluates the result string' do
22
- Doctest.new(nil, '5', nil, nil).result_evaluation.should == 5
23
- Doctest.new(nil, '3 + 2', nil, nil).result_evaluation.should == 5
22
+ expect(Doctest.new(nil, '5', nil, nil).result_evaluation).to equal 5
23
+ expect(Doctest.new(nil, '3 + 2', nil, nil).result_evaluation).to equal 5
24
24
  end
25
25
 
26
26
  it 'evaluates the code string' do
27
- Doctest.new("a = 3\na + 2", nil, nil, nil).code_evaluation.should == 5
27
+ expect(Doctest.new("a = 3\na + 2", nil, nil, nil).code_evaluation).to equal 5
28
28
  end
29
29
 
30
30
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require fixture('simple_class.rb')
3
3
  require fixture('simple_class_reopened.rb')
4
+ require fixture('simple_module.rb')
4
5
 
5
6
  module Doctest::Core
6
7
  describe 'Source' do
@@ -8,16 +9,22 @@ module Doctest::Core
8
9
  context 'to_code_locations' do
9
10
 
10
11
  it 'wraps a filename in an array' do
11
- Source.to_filenames(fixture('simple_file.rb')).should == [ fixture('simple_file.rb') ]
12
+ expect(Source.to_filenames(fixture('simple_file.rb'))).to eql [ fixture('simple_file.rb') ]
12
13
  end
13
14
 
14
15
  it 'resolves the filenames of a ruby class' do
15
- Source.to_filenames(SimpleClass).should == [
16
+ expect(Source.to_filenames(SimpleClass)).to eql [
16
17
  fixture('simple_class.rb'),
17
18
  fixture('simple_class_reopened.rb')
18
19
  ]
19
20
  end
20
21
 
22
+ it 'resolves the filenames of a ruby module' do
23
+ expect(Source.to_filenames(SimpleModule)).to eql [
24
+ fixture('simple_module.rb'),
25
+ ]
26
+ end
27
+
21
28
  end
22
29
 
23
30
  end
@@ -6,10 +6,11 @@ describe Doctest::Core do
6
6
  it 'extracts doctests from ruby classes' do
7
7
  orig_file = fixture('class_with_doctests.rb')
8
8
  doctests = Doctest::Core.extract_from(ClassWithDoctests)
9
- doctests.should have(2).entries
9
+ expect(doctests.length).to equal 3
10
10
 
11
- doctests[0].should == Doctest::Core::Doctest.new("ClassWithDoctests.a", "'a'", orig_file, 6)
12
- doctests[1].should == Doctest::Core::Doctest.new("ClassWithDoctests.b", "'b'", orig_file, 14)
11
+ expect(doctests[0]).to eql Doctest::Core::Doctest.new("a = 3;a + 2", "5", orig_file, 5)
12
+ expect(doctests[1]).to eql Doctest::Core::Doctest.new("ClassWithDoctests.a", "'a'", orig_file, 11)
13
+ expect(doctests[2]).to eql Doctest::Core::Doctest.new("ClassWithDoctests.b", "'b'", orig_file, 19)
13
14
  end
14
15
 
15
16
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doctest-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heiko Zeus
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-01 00:00:00.000000000 Z
11
+ date: 2014-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: guard-rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Extract doctests from ruby files
@@ -87,8 +87,8 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
92
  - Gemfile
93
93
  - Guardfile
94
94
  - LICENSE.txt
@@ -104,6 +104,7 @@ files:
104
104
  - spec/fixtures/simple_class.rb
105
105
  - spec/fixtures/simple_class_reopened.rb
106
106
  - spec/fixtures/simple_file.rb
107
+ - spec/fixtures/simple_module.rb
107
108
  - spec/lib/doctest/core/base_spec.rb
108
109
  - spec/lib/doctest/core/doctest_spec.rb
109
110
  - spec/lib/doctest/core/source_spec.rb
@@ -119,17 +120,17 @@ require_paths:
119
120
  - lib
120
121
  required_ruby_version: !ruby/object:Gem::Requirement
121
122
  requirements:
122
- - - ! '>='
123
+ - - ">="
123
124
  - !ruby/object:Gem::Version
124
125
  version: '0'
125
126
  required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  requirements:
127
- - - ! '>='
128
+ - - ">="
128
129
  - !ruby/object:Gem::Version
129
130
  version: '0'
130
131
  requirements: []
131
132
  rubyforge_project:
132
- rubygems_version: 2.1.5
133
+ rubygems_version: 2.2.2
133
134
  signing_key:
134
135
  specification_version: 4
135
136
  summary: This aims to provide the basis for elixir-like doctests. It should be used
@@ -139,9 +140,9 @@ test_files:
139
140
  - spec/fixtures/simple_class.rb
140
141
  - spec/fixtures/simple_class_reopened.rb
141
142
  - spec/fixtures/simple_file.rb
143
+ - spec/fixtures/simple_module.rb
142
144
  - spec/lib/doctest/core/base_spec.rb
143
145
  - spec/lib/doctest/core/doctest_spec.rb
144
146
  - spec/lib/doctest/core/source_spec.rb
145
147
  - spec/lib/doctest/core_spec.rb
146
148
  - spec/spec_helper.rb
147
- has_rdoc: