mdspell 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/mdspell +1 -1
- data/lib/mdspell.rb +25 -11
- data/lib/mdspell/cli.rb +3 -3
- data/lib/mdspell/version.rb +1 -1
- metadata +17 -27
- data/spec/examples.cache +0 -58
- data/spec/examples/complete.md +0 -35
- data/spec/examples/mdspell.config +0 -1
- data/spec/examples/simple.md +0 -5
- data/spec/examples/spanish_errors.md +0 -4
- data/spec/examples/with_errors.md +0 -5
- data/spec/mdspell/cli_spec.rb +0 -54
- data/spec/mdspell/configuration_spec.rb +0 -98
- data/spec/mdspell/spell_checker_spec.rb +0 -82
- data/spec/mdspell/text_line_spec.rb +0 -130
- data/spec/mdspell/typo_spec.rb +0 -83
- data/spec/spec_helper.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df6194fb7f2090573a5c8c393c953f91b7c804d6
|
4
|
+
data.tar.gz: e93822857823d5c93b52264ed30b03d44c94be9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc3bfbf1598db0154ccfc6929db8fe790e5f76ea3df7f618c8a3a657f66bf6146d277eea6ed9a63b98ead8814ca3b4c2df305c30bea6de8676010deaef59a98b
|
7
|
+
data.tar.gz: ab414bf1101f325c63884c1f887027bdf86df3eea897360e730cc55419a942357fa7f91e3178e63d54760b8ad13a0cb6f8afdae09a92b7e2b66e50baebefc92f
|
data/bin/mdspell
CHANGED
data/lib/mdspell.rb
CHANGED
@@ -9,23 +9,27 @@ require 'rainbow'
|
|
9
9
|
|
10
10
|
# This module holds all the MdSpell code (except mdspell shell command).
|
11
11
|
module MdSpell
|
12
|
-
def self.run
|
12
|
+
def self.run(argv)
|
13
13
|
cli = MdSpell::CLI.new
|
14
|
-
cli.run
|
14
|
+
cli.run argv
|
15
|
+
cli.files.each(&method(:check_file))
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
exit_if_had_errors
|
18
|
+
end
|
19
|
+
|
20
|
+
# Private class methods
|
19
21
|
|
20
|
-
|
22
|
+
def self.check_file(filename)
|
23
|
+
spell_checker = SpellChecker.new(filename)
|
24
|
+
filename = spell_checker.filename
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
verbose "Spell-checking #{filename}..."
|
27
|
+
|
28
|
+
spell_checker.typos.each do |typo|
|
29
|
+
error "#{filename}:#{typo.line.location}: #{typo.word}"
|
25
30
|
end
|
26
31
|
end
|
27
|
-
|
28
|
-
# Private class methods
|
32
|
+
private_class_method :check_file
|
29
33
|
|
30
34
|
def self.verbose(str)
|
31
35
|
puts str if Configuration[:verbose]
|
@@ -33,7 +37,17 @@ module MdSpell
|
|
33
37
|
private_class_method :verbose
|
34
38
|
|
35
39
|
def self.error(str)
|
40
|
+
@had_errors = true
|
36
41
|
puts Rainbow(str).red
|
37
42
|
end
|
38
43
|
private_class_method :error
|
44
|
+
|
45
|
+
def self.exit_if_had_errors
|
46
|
+
if @had_errors
|
47
|
+
# If exit will be suppressed (line in tests or using at_exit), we need to clean @had_errors
|
48
|
+
@had_errors = false
|
49
|
+
exit(1)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
private_class_method :exit_if_had_errors
|
39
53
|
end
|
data/lib/mdspell/cli.rb
CHANGED
@@ -32,10 +32,10 @@ module MdSpell
|
|
32
32
|
proc: proc { puts MdSpell::VERSION },
|
33
33
|
exit: 0
|
34
34
|
|
35
|
-
def run(
|
36
|
-
raise ArgumentError, 'expected Array of command line options' unless
|
35
|
+
def run(options)
|
36
|
+
raise ArgumentError, 'expected Array of command line options' unless options.is_a? Array
|
37
37
|
|
38
|
-
parse_options(
|
38
|
+
parse_options(options)
|
39
39
|
|
40
40
|
# Load optional config file if it's present.
|
41
41
|
if config[:config_file]
|
data/lib/mdspell/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdspell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marek Tuchowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
83
97
|
description: Check markdown files for spelling errors.
|
84
98
|
email: marek@tuchowski.com.pl
|
85
99
|
executables:
|
@@ -99,18 +113,6 @@ files:
|
|
99
113
|
- lib/mdspell/text_line.rb
|
100
114
|
- lib/mdspell/typo.rb
|
101
115
|
- lib/mdspell/version.rb
|
102
|
-
- spec/examples.cache
|
103
|
-
- spec/examples/complete.md
|
104
|
-
- spec/examples/mdspell.config
|
105
|
-
- spec/examples/simple.md
|
106
|
-
- spec/examples/spanish_errors.md
|
107
|
-
- spec/examples/with_errors.md
|
108
|
-
- spec/mdspell/cli_spec.rb
|
109
|
-
- spec/mdspell/configuration_spec.rb
|
110
|
-
- spec/mdspell/spell_checker_spec.rb
|
111
|
-
- spec/mdspell/text_line_spec.rb
|
112
|
-
- spec/mdspell/typo_spec.rb
|
113
|
-
- spec/spec_helper.rb
|
114
116
|
homepage: https://github.com/mtuchowski/mdspell
|
115
117
|
licenses:
|
116
118
|
- MIT
|
@@ -137,17 +139,5 @@ rubygems_version: 2.5.1
|
|
137
139
|
signing_key:
|
138
140
|
specification_version: 4
|
139
141
|
summary: A Ruby markdown spell checking tool.
|
140
|
-
test_files:
|
141
|
-
- spec/mdspell/text_line_spec.rb
|
142
|
-
- spec/mdspell/cli_spec.rb
|
143
|
-
- spec/mdspell/typo_spec.rb
|
144
|
-
- spec/mdspell/spell_checker_spec.rb
|
145
|
-
- spec/mdspell/configuration_spec.rb
|
146
|
-
- spec/spec_helper.rb
|
147
|
-
- spec/examples.cache
|
148
|
-
- spec/examples/mdspell.config
|
149
|
-
- spec/examples/complete.md
|
150
|
-
- spec/examples/with_errors.md
|
151
|
-
- spec/examples/spanish_errors.md
|
152
|
-
- spec/examples/simple.md
|
142
|
+
test_files: []
|
153
143
|
has_rdoc:
|
data/spec/examples.cache
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
example_id | status | run_time |
|
2
|
-
--------------------------------------------- | ------ | --------------- |
|
3
|
-
./spec/mdspell/cli_spec.rb[1:1] | passed | 0.00011 seconds |
|
4
|
-
./spec/mdspell/cli_spec.rb[1:2] | passed | 0.00012 seconds |
|
5
|
-
./spec/mdspell/cli_spec.rb[1:3:1] | passed | 0.00016 seconds |
|
6
|
-
./spec/mdspell/cli_spec.rb[1:4:1:1] | passed | 0.00047 seconds |
|
7
|
-
./spec/mdspell/cli_spec.rb[1:4:2:1] | passed | 0.00047 seconds |
|
8
|
-
./spec/mdspell/cli_spec.rb[1:4:3:1] | passed | 0.00172 seconds |
|
9
|
-
./spec/mdspell/configuration_spec.rb[1:1:1] | passed | 0.00031 seconds |
|
10
|
-
./spec/mdspell/configuration_spec.rb[1:1:2:1] | passed | 0.00034 seconds |
|
11
|
-
./spec/mdspell/configuration_spec.rb[1:1:2:2] | passed | 0.00034 seconds |
|
12
|
-
./spec/mdspell/configuration_spec.rb[1:1:3:1] | passed | 0.0004 seconds |
|
13
|
-
./spec/mdspell/configuration_spec.rb[1:2:1] | passed | 0.00031 seconds |
|
14
|
-
./spec/mdspell/configuration_spec.rb[1:2:2:1] | passed | 0.00032 seconds |
|
15
|
-
./spec/mdspell/configuration_spec.rb[1:2:2:2] | passed | 0.00033 seconds |
|
16
|
-
./spec/mdspell/configuration_spec.rb[1:3:1] | passed | 0.00033 seconds |
|
17
|
-
./spec/mdspell/configuration_spec.rb[1:3:2:1] | passed | 0.00031 seconds |
|
18
|
-
./spec/mdspell/configuration_spec.rb[1:3:2:2] | passed | 0.00033 seconds |
|
19
|
-
./spec/mdspell/configuration_spec.rb[1:4:1] | passed | 0.00031 seconds |
|
20
|
-
./spec/mdspell/configuration_spec.rb[1:4:2:1] | passed | 0.00039 seconds |
|
21
|
-
./spec/mdspell/configuration_spec.rb[1:4:2:2] | passed | 0.00039 seconds |
|
22
|
-
./spec/mdspell/spell_checker_spec.rb[1:1:1] | passed | 0.00061 seconds |
|
23
|
-
./spec/mdspell/spell_checker_spec.rb[1:1:2] | passed | 0.00057 seconds |
|
24
|
-
./spec/mdspell/spell_checker_spec.rb[1:1:3] | passed | 0.00114 seconds |
|
25
|
-
./spec/mdspell/spell_checker_spec.rb[1:2:1] | passed | 0.00013 seconds |
|
26
|
-
./spec/mdspell/spell_checker_spec.rb[1:2:2] | passed | 0.00093 seconds |
|
27
|
-
./spec/mdspell/spell_checker_spec.rb[1:2:3] | passed | 0.00054 seconds |
|
28
|
-
./spec/mdspell/spell_checker_spec.rb[1:3:1] | passed | 0.00111 seconds |
|
29
|
-
./spec/mdspell/spell_checker_spec.rb[1:3:2:1] | passed | 0.00045 seconds |
|
30
|
-
./spec/mdspell/spell_checker_spec.rb[1:4:1] | passed | 0.00114 seconds |
|
31
|
-
./spec/mdspell/spell_checker_spec.rb[1:5:1] | passed | 0.04924 seconds |
|
32
|
-
./spec/mdspell/spell_checker_spec.rb[1:5:2] | failed | 0.00073 seconds |
|
33
|
-
./spec/mdspell/spell_checker_spec.rb[1:5:3] | failed | 0.00139 seconds |
|
34
|
-
./spec/mdspell/text_line_spec.rb[1:1:1] | passed | 0.00007 seconds |
|
35
|
-
./spec/mdspell/text_line_spec.rb[1:1:2] | passed | 0.00009 seconds |
|
36
|
-
./spec/mdspell/text_line_spec.rb[1:1:3] | passed | 0.00007 seconds |
|
37
|
-
./spec/mdspell/text_line_spec.rb[1:1:4] | passed | 0.00008 seconds |
|
38
|
-
./spec/mdspell/text_line_spec.rb[1:2:1] | passed | 0.00014 seconds |
|
39
|
-
./spec/mdspell/text_line_spec.rb[1:3:1] | passed | 0.00007 seconds |
|
40
|
-
./spec/mdspell/text_line_spec.rb[1:4:1] | passed | 0.00007 seconds |
|
41
|
-
./spec/mdspell/text_line_spec.rb[1:5:1] | passed | 0.00008 seconds |
|
42
|
-
./spec/mdspell/text_line_spec.rb[1:6:1] | passed | 0.00015 seconds |
|
43
|
-
./spec/mdspell/text_line_spec.rb[1:6:2:1] | passed | 0.00008 seconds |
|
44
|
-
./spec/mdspell/text_line_spec.rb[1:6:3:1] | passed | 0.00012 seconds |
|
45
|
-
./spec/mdspell/text_line_spec.rb[1:6:3:2] | passed | 0.00009 seconds |
|
46
|
-
./spec/mdspell/text_line_spec.rb[1:6:4:1] | passed | 0.00008 seconds |
|
47
|
-
./spec/mdspell/text_line_spec.rb[1:7:1] | passed | 0.00011 seconds |
|
48
|
-
./spec/mdspell/text_line_spec.rb[1:7:2] | passed | 0.00305 seconds |
|
49
|
-
./spec/mdspell/typo_spec.rb[1:1:1] | passed | 0.00008 seconds |
|
50
|
-
./spec/mdspell/typo_spec.rb[1:1:2] | passed | 0.00009 seconds |
|
51
|
-
./spec/mdspell/typo_spec.rb[1:1:3] | passed | 0.00008 seconds |
|
52
|
-
./spec/mdspell/typo_spec.rb[1:2:1] | passed | 0.00011 seconds |
|
53
|
-
./spec/mdspell/typo_spec.rb[1:2:2] | passed | 0.00013 seconds |
|
54
|
-
./spec/mdspell/typo_spec.rb[1:2:3] | passed | 0.00015 seconds |
|
55
|
-
./spec/mdspell/typo_spec.rb[1:3:1] | passed | 0.00044 seconds |
|
56
|
-
./spec/mdspell/typo_spec.rb[1:4:1] | passed | 0.0001 seconds |
|
57
|
-
./spec/mdspell/typo_spec.rb[1:5:1] | passed | 0.00008 seconds |
|
58
|
-
./spec/mdspell/typo_spec.rb[1:5:2] | passed | 0.00009 seconds |
|
data/spec/examples/complete.md
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# First header
|
2
|
-
|
3
|
-
## Second Header
|
4
|
-
|
5
|
-
### Third Header
|
6
|
-
|
7
|
-
#### Fourth Header
|
8
|
-
|
9
|
-
##### Fifth Header
|
10
|
-
|
11
|
-
First paragraph
|
12
|
-
|
13
|
-
Second paragraph
|
14
|
-
|
15
|
-
Multi-line
|
16
|
-
paragraph
|
17
|
-
|
18
|
-
> Block-quote
|
19
|
-
|
20
|
-
Third paragraph (with parenthesis).
|
21
|
-
|
22
|
-
> Another block-quote
|
23
|
-
>
|
24
|
-
> > Nested block-quote
|
25
|
-
|
26
|
-
* Unordered
|
27
|
-
* List
|
28
|
-
|
29
|
-
1. Ordered
|
30
|
-
1. List
|
31
|
-
|
32
|
-
* Multi-line paragraph
|
33
|
-
as list item
|
34
|
-
|
35
|
-
Two quotes: That's one, and here's the other
|
@@ -1 +0,0 @@
|
|
1
|
-
language 'pl'
|
data/spec/examples/simple.md
DELETED
data/spec/mdspell/cli_spec.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
describe MdSpell::CLI do
|
2
|
-
it { is_expected.to respond_to :run }
|
3
|
-
it { is_expected.to respond_to :files }
|
4
|
-
|
5
|
-
after(:all) do
|
6
|
-
MdSpell::Configuration.reset
|
7
|
-
end
|
8
|
-
|
9
|
-
context '#run' do
|
10
|
-
it 'should expect command line options array' do
|
11
|
-
[nil, 'string', 42].each do |argument|
|
12
|
-
expect do
|
13
|
-
subject.run(argument)
|
14
|
-
end.to raise_error ArgumentError, 'expected Array of command line options'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context '#files' do
|
20
|
-
context 'if single file given' do
|
21
|
-
it 'should return its path' do
|
22
|
-
subject.run(['README.md'])
|
23
|
-
expect(subject.files).to have(1).item
|
24
|
-
|
25
|
-
expect(subject.files[0]).to eq 'README.md'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'if directory given' do
|
30
|
-
it 'should return all markdown files in that directory' do
|
31
|
-
subject.run(['spec/examples'])
|
32
|
-
expect(subject.files).to have(4).item
|
33
|
-
|
34
|
-
expect(subject.files).to include('spec/examples/simple.md')
|
35
|
-
expect(subject.files).to include('spec/examples/complete.md')
|
36
|
-
expect(subject.files).to include('spec/examples/with_errors.md')
|
37
|
-
expect(subject.files).to include('spec/examples/spanish_errors.md')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'if both directory and single file given' do
|
42
|
-
it 'should return all files' do
|
43
|
-
subject.run(['README.md', 'spec/examples'])
|
44
|
-
expect(subject.files).to have(5).item
|
45
|
-
|
46
|
-
expect(subject.files).to include('README.md')
|
47
|
-
expect(subject.files).to include('spec/examples/simple.md')
|
48
|
-
expect(subject.files).to include('spec/examples/complete.md')
|
49
|
-
expect(subject.files).to include('spec/examples/with_errors.md')
|
50
|
-
expect(subject.files).to include('spec/examples/spanish_errors.md')
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
describe MdSpell::Configuration do
|
2
|
-
before(:each) do
|
3
|
-
MdSpell::Configuration.reset
|
4
|
-
end
|
5
|
-
|
6
|
-
after(:all) do
|
7
|
-
MdSpell::Configuration.reset
|
8
|
-
end
|
9
|
-
|
10
|
-
def run_app(args = [])
|
11
|
-
MdSpell::CLI.new.run(args)
|
12
|
-
end
|
13
|
-
|
14
|
-
context ':config_file' do
|
15
|
-
it "should default to '~/.mdspell'" do
|
16
|
-
run_app
|
17
|
-
expect(MdSpell::Configuration[:config_file]).to eq '~/.mdspell'
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'command line argument' do
|
21
|
-
it "uses '-c' short flag" do
|
22
|
-
run_app(['-c', 'short'])
|
23
|
-
expect(MdSpell::Configuration[:config_file]).to eq 'short'
|
24
|
-
end
|
25
|
-
|
26
|
-
it "uses '--config' long flag" do
|
27
|
-
run_app(['--config', 'long'])
|
28
|
-
expect(MdSpell::Configuration[:config_file]).to eq 'long'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'if file exists' do
|
33
|
-
it 'should merge its content' do
|
34
|
-
run_app(['-c', 'spec/examples/mdspell.config'])
|
35
|
-
expect(MdSpell::Configuration[:language]).to eq 'pl'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context ':language' do
|
41
|
-
it "should default to 'en_US'" do
|
42
|
-
run_app
|
43
|
-
expect(MdSpell::Configuration[:language]).to eq 'en_US'
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'command line argument' do
|
47
|
-
it "uses '-l' short flag" do
|
48
|
-
run_app(['-l', 'en_GB'])
|
49
|
-
expect(MdSpell::Configuration[:language]).to eq 'en_GB'
|
50
|
-
end
|
51
|
-
|
52
|
-
it "uses '--language' long flag" do
|
53
|
-
run_app(['--language', 'uk'])
|
54
|
-
expect(MdSpell::Configuration[:language]).to eq 'uk'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context ':verbose' do
|
60
|
-
it 'should default to false' do
|
61
|
-
run_app
|
62
|
-
expect(MdSpell::Configuration[:verbose]).to eq false
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'command line argument' do
|
66
|
-
it "uses '-v' short flag" do
|
67
|
-
run_app(['-v'])
|
68
|
-
expect(MdSpell::Configuration[:verbose]).to eq true
|
69
|
-
end
|
70
|
-
|
71
|
-
it "uses '--verbose' long flag" do
|
72
|
-
run_app(['--verbose'])
|
73
|
-
expect(MdSpell::Configuration[:verbose]).to eq true
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context ':version' do
|
79
|
-
it 'should return proper string' do
|
80
|
-
run_app
|
81
|
-
expect(MdSpell::Configuration[:version]).to eq MdSpell::VERSION
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'command line argument' do
|
85
|
-
it "uses '-V' short flag" do
|
86
|
-
expect do
|
87
|
-
run_app(['-V'])
|
88
|
-
end.to raise_error SystemExit
|
89
|
-
end
|
90
|
-
|
91
|
-
it "uses '--version' long flag" do
|
92
|
-
expect do
|
93
|
-
run_app(['--version'])
|
94
|
-
end.to raise_error SystemExit
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
describe MdSpell::SpellChecker do
|
2
|
-
let(:simple) { MdSpell::SpellChecker.new('spec/examples/simple.md') }
|
3
|
-
let(:with_errors) { MdSpell::SpellChecker.new('spec/examples/with_errors.md') }
|
4
|
-
let(:from_stdin) do
|
5
|
-
allow(STDIN).to receive(:read) { '# Header' }
|
6
|
-
MdSpell::SpellChecker.new('-')
|
7
|
-
end
|
8
|
-
|
9
|
-
context 'attributes' do
|
10
|
-
subject { simple }
|
11
|
-
|
12
|
-
it { is_expected.to respond_to :filename }
|
13
|
-
it { is_expected.to respond_to :document }
|
14
|
-
it { is_expected.to respond_to :typos }
|
15
|
-
end
|
16
|
-
|
17
|
-
context '#initialize' do
|
18
|
-
it 'should expect filename' do
|
19
|
-
expect { MdSpell::SpellChecker.new }.to raise_error ArgumentError
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should fail if given wrong filename' do
|
23
|
-
expect { MdSpell::SpellChecker.new('not_existing.md') }.to raise_error Errno::ENOENT
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should read from stdin if given '-' as filename" do
|
27
|
-
allow(STDIN).to receive(:read) { '# Header' }
|
28
|
-
expect { MdSpell::SpellChecker.new('-') }.not_to raise_error
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context '#filename' do
|
33
|
-
it 'should return proper path' do
|
34
|
-
expect(simple.filename).to eq 'spec/examples/simple.md'
|
35
|
-
expect(with_errors.filename).to eq 'spec/examples/with_errors.md'
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'if initialized from stdin' do
|
39
|
-
it "should return 'stdin'" do
|
40
|
-
expect(from_stdin.filename).to eq 'stdin'
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context '#document' do
|
46
|
-
it 'should be of proper type' do
|
47
|
-
expect(simple.document).to be_instance_of Kramdown::Document
|
48
|
-
expect(with_errors.document).to be_instance_of Kramdown::Document
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context '#typos' do
|
53
|
-
it 'should return empty array if there are no errors' do
|
54
|
-
expect(simple.typos).to have(0).items
|
55
|
-
expect(from_stdin.typos).to have(0).items
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should return proper results' do
|
59
|
-
typos = with_errors.typos
|
60
|
-
|
61
|
-
expect(typos).to have(4).items
|
62
|
-
expect(typos[0].word).to eq 'mispelled'
|
63
|
-
expect(typos[1].word).to eq 'qiute'
|
64
|
-
expect(typos[2].word).to eq 'actualy'
|
65
|
-
expect(typos[3].word).to eq 'tobe'
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'should use configured language' do
|
69
|
-
prev_language = MdSpell::Configuration[:language]
|
70
|
-
MdSpell::Configuration[:language] = 'es'
|
71
|
-
|
72
|
-
typos = MdSpell::SpellChecker.new('spec/examples/spanish_errors.md').typos
|
73
|
-
|
74
|
-
expect(typos).to have(3).items
|
75
|
-
expect(typos[0].word).to eq 'vivira'
|
76
|
-
expect(typos[1].word).to eq 'Oscar'
|
77
|
-
expect(typos[2].word).to eq 'Wilde'
|
78
|
-
|
79
|
-
MdSpell::Configuration[:language] = prev_language
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,130 +0,0 @@
|
|
1
|
-
describe MdSpell::TextLine do
|
2
|
-
let(:md_p_element) { Kramdown::Element.new(:p) }
|
3
|
-
let(:md_header_element) { Kramdown::Element.new(:header) }
|
4
|
-
let(:md_text_element) { Kramdown::Element.new(:text, "Joe's shop", nil, location: 42) }
|
5
|
-
let(:md_other_text_element) { Kramdown::Element.new(:text, 'text', nil, location: 42) }
|
6
|
-
let(:md_quote_element) { Kramdown::Element.new(:smart_quote, :lsquo, nil, location: 42) }
|
7
|
-
let(:md_empty_text_element) { Kramdown::Element.new(:text, nil, nil, location: 42) }
|
8
|
-
let(:md_empty_quote_element) { Kramdown::Element.new(:smart_quote, nil, nil, location: 42) }
|
9
|
-
let(:md_text_element_diff_location) { Kramdown::Element.new(:text, 'test', nil, location: 41) }
|
10
|
-
|
11
|
-
subject { MdSpell::TextLine.new(md_text_element) }
|
12
|
-
|
13
|
-
context 'attributes' do
|
14
|
-
it { is_expected.to respond_to :location }
|
15
|
-
it { is_expected.to respond_to :content }
|
16
|
-
it { is_expected.to respond_to :words }
|
17
|
-
it { is_expected.to respond_to :<< }
|
18
|
-
end
|
19
|
-
|
20
|
-
context '#initialize' do
|
21
|
-
it 'should expect Kramdown::Element as argument' do
|
22
|
-
expect { MdSpell::TextLine.new }.to raise_error ArgumentError
|
23
|
-
expect { MdSpell::TextLine.new('test') }.to raise_error ArgumentError
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context '#location' do
|
28
|
-
it 'should return proper value' do
|
29
|
-
expect(subject.location).to eq 42
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context '#content' do
|
34
|
-
it 'should contain proper text' do
|
35
|
-
expect(subject.content).to eq "Joe's shop"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context '#words' do
|
40
|
-
it 'should return proper content' do
|
41
|
-
expect(subject.words).to eq ["Joe's", 'shop']
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context '#<<' do
|
46
|
-
it 'should accept only Kramdown::Element' do
|
47
|
-
expect { subject << 'p_element' }.to raise_error ArgumentError
|
48
|
-
expect { subject << nil }.to raise_error ArgumentError
|
49
|
-
expect { subject << md_empty_text_element }.not_to raise_error
|
50
|
-
expect { subject << md_empty_quote_element }.not_to raise_error
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'when given text element' do
|
54
|
-
it 'should update content' do
|
55
|
-
subject << md_other_text_element
|
56
|
-
expect(subject.content).to eq "Joe's shop text"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'when given smart quote element' do
|
61
|
-
let(:lsquo_element) { Kramdown::Element.new(:smart_quote, :lsquo, nil, location: 42) }
|
62
|
-
let(:rsquo_element) { Kramdown::Element.new(:smart_quote, :rsquo, nil, location: 42) }
|
63
|
-
let(:ldquo_element) { Kramdown::Element.new(:smart_quote, :ldquo, nil, location: 42) }
|
64
|
-
let(:rdquo_element) { Kramdown::Element.new(:smart_quote, :rdquo, nil, location: 42) }
|
65
|
-
|
66
|
-
it 'should translate to content properly' do
|
67
|
-
subject << lsquo_element
|
68
|
-
expect(subject.content).to eq "Joe's shop'"
|
69
|
-
subject << ldquo_element
|
70
|
-
expect(subject.content).to eq "Joe's shop'\""
|
71
|
-
subject << rsquo_element
|
72
|
-
expect(subject.content).to eq "Joe's shop'\"'"
|
73
|
-
subject << rdquo_element
|
74
|
-
expect(subject.content).to eq "Joe's shop'\"'\""
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should properly concatenate words' do
|
78
|
-
subject << md_quote_element
|
79
|
-
subject << md_other_text_element
|
80
|
-
expect(subject.content).to eq "Joe's shop'text"
|
81
|
-
subject << md_other_text_element
|
82
|
-
expect(subject.content).to eq "Joe's shop'text text"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'when given element from different location' do
|
87
|
-
it 'should not update content' do
|
88
|
-
subject << md_text_element_diff_location
|
89
|
-
expect(subject.content).to eq "Joe's shop"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context '::scan' do
|
95
|
-
let(:complete_md) do
|
96
|
-
Kramdown::Document.new(File.read('spec/examples/complete.md'), input: 'GFM')
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'should expect Kramdown::Document as argument' do
|
100
|
-
expect { MdSpell::TextLine.scan }. to raise_error ArgumentError
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'should find proper lines' do
|
104
|
-
lines = MdSpell::TextLine.scan(complete_md)
|
105
|
-
|
106
|
-
expect(lines).to have(20).items
|
107
|
-
|
108
|
-
expect(lines[0].content).to eq 'First header'
|
109
|
-
expect(lines[1].content).to eq 'Second Header'
|
110
|
-
expect(lines[2].content).to eq 'Third Header'
|
111
|
-
expect(lines[3].content).to eq 'Fourth Header'
|
112
|
-
expect(lines[4].content).to eq 'Fifth Header'
|
113
|
-
expect(lines[5].content).to eq 'First paragraph'
|
114
|
-
expect(lines[6].content).to eq 'Second paragraph'
|
115
|
-
expect(lines[7].content).to eq 'Multi-line'
|
116
|
-
expect(lines[8].content).to eq 'paragraph'
|
117
|
-
expect(lines[9].content).to eq 'Block-quote'
|
118
|
-
expect(lines[10].content).to eq 'Third paragraph (with parenthesis).'
|
119
|
-
expect(lines[11].content).to eq 'Another block-quote'
|
120
|
-
expect(lines[12].content).to eq 'Nested block-quote'
|
121
|
-
expect(lines[13].content).to eq 'Unordered'
|
122
|
-
expect(lines[14].content).to eq 'List'
|
123
|
-
expect(lines[15].content).to eq 'Ordered'
|
124
|
-
expect(lines[16].content).to eq 'List'
|
125
|
-
expect(lines[17].content).to eq 'Multi-line paragraph'
|
126
|
-
expect(lines[18].content).to eq 'as list item'
|
127
|
-
expect(lines[19].content).to eq "Two quotes: That's one, and here's the other"
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
data/spec/mdspell/typo_spec.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
describe MdSpell::Typo do
|
2
|
-
let(:text_line) do
|
3
|
-
MdSpell::TextLine.new(Kramdown::Element.new(:text, 'black rabit', nil, location: 42))
|
4
|
-
end
|
5
|
-
let(:misspelled_word) { 'rabit' }
|
6
|
-
let(:suggested_word) { 'rabbit' }
|
7
|
-
|
8
|
-
subject { MdSpell::Typo.new(text_line, misspelled_word, [suggested_word]) }
|
9
|
-
|
10
|
-
context 'attributes' do
|
11
|
-
it { is_expected.to respond_to :line }
|
12
|
-
it { is_expected.to respond_to :word }
|
13
|
-
it { is_expected.to respond_to :suggestions }
|
14
|
-
end
|
15
|
-
|
16
|
-
context '#initialize' do
|
17
|
-
it 'should expect TextLine as first argument' do
|
18
|
-
expect do
|
19
|
-
MdSpell::Typo.new(nil, misspelled_word, [suggested_word])
|
20
|
-
end.to raise_error ArgumentError, 'expected TextLine, got NilClass'
|
21
|
-
|
22
|
-
expect do
|
23
|
-
MdSpell::Typo.new('black rabit', misspelled_word, [suggested_word])
|
24
|
-
end.to raise_error ArgumentError, 'expected TextLine, got String'
|
25
|
-
|
26
|
-
expect do
|
27
|
-
MdSpell::Typo.new(text_line, misspelled_word, [suggested_word])
|
28
|
-
end.not_to raise_error
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should expect word as second argument' do
|
32
|
-
expect do
|
33
|
-
MdSpell::Typo.new(text_line, nil, [suggested_word])
|
34
|
-
end.to raise_error ArgumentError, 'expected String, got NilClass'
|
35
|
-
|
36
|
-
expect do
|
37
|
-
MdSpell::Typo.new(text_line, :c, [suggested_word])
|
38
|
-
end.to raise_error ArgumentError, 'expected String, got Symbol'
|
39
|
-
|
40
|
-
expect do
|
41
|
-
MdSpell::Typo.new(text_line, misspelled_word, [suggested_word])
|
42
|
-
end.not_to raise_error
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should expect array as third argument' do
|
46
|
-
expect do
|
47
|
-
MdSpell::Typo.new(text_line, misspelled_word, nil)
|
48
|
-
end.to raise_error ArgumentError, 'expected Array, got NilClass'
|
49
|
-
|
50
|
-
expect do
|
51
|
-
MdSpell::Typo.new(text_line, misspelled_word, 'a')
|
52
|
-
end.to raise_error ArgumentError, 'expected Array, got String'
|
53
|
-
|
54
|
-
expect { MdSpell::Typo.new(text_line, misspelled_word, []) }.not_to raise_error
|
55
|
-
expect do
|
56
|
-
MdSpell::Typo.new(text_line, misspelled_word, [suggested_word])
|
57
|
-
end.not_to raise_error
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context '#line' do
|
62
|
-
it 'should return proper object' do
|
63
|
-
expect(subject.line).to be text_line
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context '#word' do
|
68
|
-
it 'should return proper word' do
|
69
|
-
expect(subject.word).to eq misspelled_word
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context '#suggestions' do
|
74
|
-
it 'should be an array' do
|
75
|
-
expect(subject.suggestions).to be_instance_of Array
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should return proper items' do
|
79
|
-
expect(subject.suggestions).to have(1).item
|
80
|
-
expect(subject.suggestions).to eq [suggested_word]
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
# Conventionally, all specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
2
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause this file to always
|
3
|
-
# be loaded, without a need to explicitly require it in any files.
|
4
|
-
#
|
5
|
-
# Given that it is always loaded, keep this file as light-weight as possible. Requiring heavyweight
|
6
|
-
# dependencies from this file will add to the boot time of test suite on EVERY test run, even for
|
7
|
-
# an individual file that may not need all of that loaded. Instead, consider making a separate
|
8
|
-
# helper file that requires the additional dependencies and performs the additional setup,
|
9
|
-
# and require it from the spec files that actually need it.
|
10
|
-
#
|
11
|
-
# The `.rspec` file also contains a few flags that are not defaults but that are commonly wanted.
|
12
|
-
#
|
13
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
14
|
-
|
15
|
-
# Setup Code Climate test reporter.
|
16
|
-
require 'codeclimate-test-reporter'
|
17
|
-
|
18
|
-
CodeClimate::TestReporter.start
|
19
|
-
|
20
|
-
# For checking arrays.
|
21
|
-
require 'rspec/collection_matchers'
|
22
|
-
|
23
|
-
# The whole lib is not that big, requiring it here cleans up the specs a little bit.
|
24
|
-
require 'mdspell'
|
25
|
-
|
26
|
-
RSpec.configure do |config|
|
27
|
-
# rspec-expectations config goes here.
|
28
|
-
config.expect_with :rspec do |expectations|
|
29
|
-
# This option will default to `true` in RSpec 4. It makes the `description` and
|
30
|
-
# `failure_message` of custom matchers include text for helper methods defined using
|
31
|
-
# `chain`, e.g.:
|
32
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
33
|
-
# # => "be bigger than 2 and smaller than 4"
|
34
|
-
# ...rather than:
|
35
|
-
# # => "be bigger than 2"
|
36
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
37
|
-
|
38
|
-
# Only allow expect syntax.
|
39
|
-
expectations.syntax = :expect
|
40
|
-
end
|
41
|
-
|
42
|
-
# rspec-mocks config goes here.
|
43
|
-
config.mock_with :rspec do |mocks|
|
44
|
-
# Prevents from mocking or stubbing a method that does not exist on a real object.
|
45
|
-
# This is generally recommended, and will default to `true` in RSpec 4.
|
46
|
-
mocks.verify_partial_doubles = true
|
47
|
-
end
|
48
|
-
|
49
|
-
# Allows RSpec to persist some state between runs in order to support the `--only-failures` and
|
50
|
-
# `--next-failure` CLI options. Source control system should be configured to ignore this file.
|
51
|
-
config.example_status_persistence_file_path = 'spec/examples.cache'
|
52
|
-
|
53
|
-
# Run specs in random order to surface order dependencies. To debug an order dependency after
|
54
|
-
# finding one, fix the order by providing the seed, which is printed after each run.
|
55
|
-
# --seed 1234
|
56
|
-
config.order = :random
|
57
|
-
|
58
|
-
# Seed global randomization in this process using the `--seed` CLI option. Setting this allows
|
59
|
-
# to use `--seed` to deterministically reproduce test failures related to randomization
|
60
|
-
# by passing the same `--seed` value as the one that triggered the failure.
|
61
|
-
Kernel.srand config.seed
|
62
|
-
|
63
|
-
# Allow filtering specs with `focus: true`.
|
64
|
-
config.filter_run focus: true
|
65
|
-
|
66
|
-
# Run all specs if none are filtered.
|
67
|
-
config.run_all_when_everything_filtered = true
|
68
|
-
end
|