readme_spec 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +5 -0
- data/lib/readme_spec.rb +97 -0
- data/lib/readme_spec/version.rb +3 -0
- data/readme_spec.gemspec +26 -0
- data/spec/fixtures/HasInvalidRubyCode.md +7 -0
- data/spec/fixtures/HasValidRubyCode.md +24 -0
- data/spec/readme_spec/markdown_spec.rb +52 -0
- data/spec/spec_helper.rb +17 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77cad944e7ae512c01ee9b39769613b9a139a7c7
|
4
|
+
data.tar.gz: 4cbe6364f60b482948704329a33dc845ac1d6c62
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6886244745b13fe885b8daf26153593b70c7701f24477096dbb0c689010b982fa773e893bbca808ae2f91c5e49b283bd7a13e8a829ca6ec9cb6a04b3c5e62309
|
7
|
+
data.tar.gz: 6d7fc273d6c6cae2de729d95c08868ef3b784aa3b58479b4f43759a41ff5d7156adb99e6b2ebac186b4894ed1db356885e4617fd098c7f6ff47758c3525e8b5d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 gong023
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# ReadmeSpec
|
2
|
+
[![Build Status](https://travis-ci.org/gong023/readme_spec.svg?branch=master)](https://travis-ci.org/gong023/readme_spec)
|
3
|
+
|
4
|
+
Test your spec in README
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
Set you readme file absolute path.
|
9
|
+
|
10
|
+
```
|
11
|
+
# spec_helper.rb
|
12
|
+
RSpec.configure do |c|
|
13
|
+
c.readme_file_path = File.dirname(__FILE__) + '/../README.md'
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
Write spec in README.
|
18
|
+
|
19
|
+
<pre>
|
20
|
+
Your awesome description.
|
21
|
+
|
22
|
+
Your sample code.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
class YourClass
|
26
|
+
def do_something
|
27
|
+
true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
your_class = YourClass.new
|
32
|
+
expect(your_class.do_something).to be_true
|
33
|
+
</pre>
|
34
|
+
|
35
|
+
Call `ReadmeSpec.evaluate(binding)` in your test code.
|
36
|
+
|
37
|
+
```
|
38
|
+
expect { ReadmeSpec.evaluate(binding) }.not_to raise_error
|
39
|
+
```
|
40
|
+
|
41
|
+
Readme.evaluate evals your code in README sorrounded by `ruby`. You can keep correct code in README.md
|
42
|
+
|
43
|
+
In this repository, below code is tested in `spec/`.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
a = 1
|
47
|
+
b = 2
|
48
|
+
expect(a + b).to be 3
|
49
|
+
```
|
50
|
+
|
51
|
+
If README code is wrong, you can get error message as it is.
|
52
|
+
|
53
|
+
```
|
54
|
+
Failure/Error: it { expect { ReadmeSpec.evaluate(binding) }.not_to raise_error }
|
55
|
+
expected no Exception, got #<RSpec::Expectations::ExpectationNotMetError:
|
56
|
+
expected #<Fixnum:3> => 1
|
57
|
+
got #<Fixnum:7> => 3
|
58
|
+
```
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it ( https://github.com/gong023/readme_spec/fork )
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/readme_spec.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require "readme_spec/version"
|
2
|
+
require 'qiita-markdown'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.add_setting :readme_file_path
|
6
|
+
end
|
7
|
+
|
8
|
+
module ReadmeSpec
|
9
|
+
def self.evaluate(binding)
|
10
|
+
context = Context.new(binding)
|
11
|
+
config_path = Configure.new.load_path
|
12
|
+
content = File.new(config_path).load_content
|
13
|
+
Markdown.parse(content).ruby_codes.each { |c| context.evaluate(c.text) }
|
14
|
+
end
|
15
|
+
|
16
|
+
class Context
|
17
|
+
def initialize(binding)
|
18
|
+
@binding = binding
|
19
|
+
end
|
20
|
+
|
21
|
+
def evaluate(code)
|
22
|
+
@binding.eval(code)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Configure
|
27
|
+
def load_path
|
28
|
+
validate
|
29
|
+
file_path
|
30
|
+
end
|
31
|
+
|
32
|
+
def validate
|
33
|
+
unless RSpec.configuration.readme_file_path?
|
34
|
+
raise ReadmeSpecMissingFilePathError
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def file_path
|
39
|
+
RSpec.configuration.readme_file_path
|
40
|
+
end
|
41
|
+
|
42
|
+
class ReadmeSpecMissingFilePathError < Exception; end
|
43
|
+
end
|
44
|
+
|
45
|
+
class File
|
46
|
+
def initialize(path)
|
47
|
+
@path = path
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_content
|
51
|
+
validate
|
52
|
+
content
|
53
|
+
end
|
54
|
+
|
55
|
+
def validate
|
56
|
+
unless ::File.file?(@path)
|
57
|
+
raise ReadmeSpecInvalidFileError, @path
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def content
|
62
|
+
::File.read(@path)
|
63
|
+
end
|
64
|
+
|
65
|
+
class ReadmeSpecInvalidFileError < Exception; end
|
66
|
+
end
|
67
|
+
|
68
|
+
class Markdown
|
69
|
+
def self.parse(content)
|
70
|
+
parser = ::Qiita::Markdown::Processor.new
|
71
|
+
self.new(parser.call(content))
|
72
|
+
end
|
73
|
+
|
74
|
+
def initialize(text)
|
75
|
+
@text = text
|
76
|
+
end
|
77
|
+
|
78
|
+
def ruby_codes
|
79
|
+
codes = @text[:codes].inject([]) { |codes, text| codes << Code.new(text) }
|
80
|
+
codes.select { |c| c.language === 'ruby' }
|
81
|
+
end
|
82
|
+
|
83
|
+
class Code
|
84
|
+
def initialize(pre_text)
|
85
|
+
@pre_text = pre_text
|
86
|
+
end
|
87
|
+
|
88
|
+
def text
|
89
|
+
@pre_text[:code]
|
90
|
+
end
|
91
|
+
|
92
|
+
def language
|
93
|
+
@pre_text[:language]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/readme_spec.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'readme_spec/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "readme_spec"
|
8
|
+
spec.version = ReadmeSpec::VERSION
|
9
|
+
spec.authors = ["gong023"]
|
10
|
+
spec.email = ["gon.gong.gone@gmail.com"]
|
11
|
+
spec.summary = %q{Guard spec in readme}
|
12
|
+
spec.description = %q{Evaluate ruby code in your README.md}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'qiita-markdown', '>= 0.4.2'
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "> 3.0.0"
|
25
|
+
spec.add_development_dependency "guard-rspec"
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# test markdown
|
2
|
+
|
3
|
+
description
|
4
|
+
|
5
|
+
- hoge
|
6
|
+
- fuga
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
a = 1
|
10
|
+
b = 2
|
11
|
+
expect(a + 2).to be 3
|
12
|
+
```
|
13
|
+
|
14
|
+
```php
|
15
|
+
$a = 1;
|
16
|
+
$b = 2;
|
17
|
+
$this->assertSame(3, $a + $b);
|
18
|
+
```
|
19
|
+
|
20
|
+
```
|
21
|
+
a = 1i
|
22
|
+
b = 2i
|
23
|
+
assert_eq!(3i, a + b)
|
24
|
+
```
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'README' do
|
4
|
+
it { expect { ReadmeSpec.evaluate(binding) }.not_to raise_error }
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ReadmeSpec do
|
8
|
+
subject { described_class }
|
9
|
+
|
10
|
+
context 'HasValidRubyCode' do
|
11
|
+
before(:context) do
|
12
|
+
RSpec.configure do |c|
|
13
|
+
c.readme_file_path = File.dirname(__FILE__) + '/../fixtures/HasValidRubyCode.md'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
it { expect { subject.evaluate(binding) }.not_to raise_error }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'HasInvalidRubyCode' do
|
20
|
+
before(:context) do
|
21
|
+
RSpec.configure do |c|
|
22
|
+
c.readme_file_path = File.dirname(__FILE__) + '/../fixtures/HasInvalidRubyCode.md'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:expected_message) do
|
27
|
+
<<'EOL'
|
28
|
+
expected #<Fixnum:3> => 1
|
29
|
+
got #<Fixnum:7> => 3
|
30
|
+
EOL
|
31
|
+
end
|
32
|
+
|
33
|
+
it { expect { subject.evaluate(binding) }.to raise_error(/#{expected_message}/) }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ReadmeSpec::Markdown do
|
37
|
+
context 'HasValidRubyCode' do
|
38
|
+
subject { described_class.parse(load_md('HasValidRubyCode')) }
|
39
|
+
|
40
|
+
context 'ruby_codes' do
|
41
|
+
subject { described_class.parse(load_md('HasValidRubyCode')).ruby_codes }
|
42
|
+
|
43
|
+
it 'returns only ruby code' do
|
44
|
+
expect(subject.size).to be 1
|
45
|
+
end
|
46
|
+
|
47
|
+
it { expect(subject.first).to be_instance_of ReadmeSpec::Markdown::Code }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'readme_spec'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.expect_with :rspec do |expectations|
|
5
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
6
|
+
end
|
7
|
+
|
8
|
+
config.mock_with :rspec do |mocks|
|
9
|
+
mocks.verify_partial_doubles = true
|
10
|
+
end
|
11
|
+
|
12
|
+
config.readme_file_path = File.dirname(__FILE__) + '/../README.md'
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_md(file_name)
|
16
|
+
File.read("#{File.dirname(__FILE__)}/fixtures/#{file_name}.md")
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: readme_spec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- gong023
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: qiita-markdown
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.4.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.4.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>'
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>'
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Evaluate ruby code in your README.md
|
84
|
+
email:
|
85
|
+
- gon.gong.gone@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- .travis.yml
|
93
|
+
- Gemfile
|
94
|
+
- Guardfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/readme_spec.rb
|
99
|
+
- lib/readme_spec/version.rb
|
100
|
+
- readme_spec.gemspec
|
101
|
+
- spec/fixtures/HasInvalidRubyCode.md
|
102
|
+
- spec/fixtures/HasValidRubyCode.md
|
103
|
+
- spec/readme_spec/markdown_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: ''
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.0.3
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Guard spec in readme
|
129
|
+
test_files:
|
130
|
+
- spec/fixtures/HasInvalidRubyCode.md
|
131
|
+
- spec/fixtures/HasValidRubyCode.md
|
132
|
+
- spec/readme_spec/markdown_spec.rb
|
133
|
+
- spec/spec_helper.rb
|