has_specs 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 +4 -4
- data/.travis.yml +7 -0
- data/README.md +11 -6
- data/lib/has_specs/base.rb +9 -5
- data/lib/has_specs/configuration.rb +19 -11
- data/lib/has_specs/version.rb +1 -1
- data/lib/has_specs.rb +7 -3
- data/spec/base_spec.rb +9 -7
- data/spec/configuration_spec.rb +2 -17
- metadata +3 -5
- data/lib/has_specs/rails_defaults.rb +0 -18
- data/spec/rails_defaults_spec.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7244d52d20052ab4d49023602e6901fc565bc68
|
4
|
+
data.tar.gz: b1653f3a9cb6a735fe46a6dabb52da5a581e74bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c402f08a49c4eba71b74a07fba2bc2543c854f7b2b44068623936f7faafd63eb55eefe0d26867543e47f1e60929dfc2ec508202cd282febcbe31a7222d10689
|
7
|
+
data.tar.gz: 1fd07a9c48ceec0bfd5b5bb72cbbcf0239913ab9da891767345bd66151319dbd43ce4b9f80c9b9f0204fb981cc23908429cfbece035f99ee8e40f3bf7294da27
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# HasSpecs
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/grossadamm/has_specs.svg?branch=master)](https://travis-ci.org/grossadamm/has_specs)
|
4
|
+
|
5
|
+
Very basic gem that allows you to verify that every file in your project has a matching spec or test file.
|
6
|
+
|
7
|
+
It expects that the folder structure of the root directory and spec directory be identical, so it's fairly limited in the fact that it doesn't look at rails route or lib tests.
|
8
|
+
|
9
|
+
It was built with rspec in mind, but I don't see why it couldn't be repurposed for other test harnesses.
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
@@ -19,13 +25,12 @@ Or install it yourself as:
|
|
19
25
|
## Usage
|
20
26
|
|
21
27
|
```
|
22
|
-
# spec_helper.rb
|
28
|
+
# spec_helper.rb (or rails_helper.rb)
|
23
29
|
|
24
30
|
require 'has_specs'
|
25
|
-
|
26
|
-
# ...
|
27
31
|
|
28
|
-
|
32
|
+
# ... in the config block
|
33
|
+
|
29
34
|
HasSpecs.ignore << 'application_controller.rb'
|
30
35
|
HasSpecs.verify
|
31
36
|
```
|
@@ -33,7 +38,6 @@ Or install it yourself as:
|
|
33
38
|
#### Configuration
|
34
39
|
|
35
40
|
```
|
36
|
-
configuration.use_rails_defaults # sets up to use app/ as the root amoungst other things
|
37
41
|
configuration.ignore << 'some_file_to_ignore.rb'
|
38
42
|
configuration.exclude << 'some/whole/dir/to/exclude.rb'
|
39
43
|
configuration.include << 'some/whole/dir/to/optionally/include'
|
@@ -42,6 +46,7 @@ configuration.root = 'some/other/root/for/source/files'
|
|
42
46
|
configuration.spec_root = 'some/other/root/for/tests'
|
43
47
|
```
|
44
48
|
|
49
|
+
|
45
50
|
## Contributing
|
46
51
|
|
47
52
|
1. Fork it ( https://github.com/[my-github-username]/has_specs/fork )
|
data/lib/has_specs/base.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
module HasSpecs
|
2
2
|
class Base
|
3
3
|
def self.verify(config)
|
4
|
+
missing = []
|
4
5
|
config.include.each do |directory|
|
5
|
-
lookat = File.join(config.root, directory,"*"+config.extension)
|
6
|
+
lookat = File.join(config.root, directory,"*[("+config.extension.join(')(')+')]')
|
6
7
|
Dir.glob(lookat).each do |file|
|
7
8
|
spec_dir = File.dirname(file).gsub(config.root, config.spec_root)
|
8
|
-
|
9
|
-
|
9
|
+
extension = File.extname(file)
|
10
|
+
basename = File.basename(file).chomp(extension)
|
11
|
+
spec = config.to_spec_filename(file)
|
12
|
+
spec_file = File.join(spec_dir,spec)
|
10
13
|
unless config.ignore.include?(File.basename file) || File.exist?(spec_file)
|
11
|
-
|
14
|
+
missing.push(spec)
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
18
|
+
return missing
|
15
19
|
end
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
@@ -5,7 +5,11 @@ module HasSpecs
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def root
|
8
|
-
|
8
|
+
if defined? Rails
|
9
|
+
@root ||= File.join(::Rails.root,'app')
|
10
|
+
else
|
11
|
+
@root ||= Dir.pwd
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
def spec_root=(desired_root)
|
@@ -16,12 +20,12 @@ module HasSpecs
|
|
16
20
|
@spec_root ||= File.join(Dir.pwd,'spec')
|
17
21
|
end
|
18
22
|
|
19
|
-
def exclude
|
20
|
-
@exclude
|
23
|
+
def exclude
|
24
|
+
@exclude ||= ['spec', 'assets']
|
21
25
|
end
|
22
26
|
|
23
|
-
def exclude
|
24
|
-
@exclude
|
27
|
+
def exclude=(exclude_dirs)
|
28
|
+
@exclude = exclude_dirs
|
25
29
|
end
|
26
30
|
|
27
31
|
def ignore=(ignore_files)
|
@@ -41,7 +45,7 @@ module HasSpecs
|
|
41
45
|
end
|
42
46
|
|
43
47
|
def extension
|
44
|
-
".rb"
|
48
|
+
[".rb", ".erb", ".jbuilder"]
|
45
49
|
end
|
46
50
|
|
47
51
|
def include
|
@@ -50,17 +54,21 @@ module HasSpecs
|
|
50
54
|
.delete_if do |directory|
|
51
55
|
found = false
|
52
56
|
self.exclude.each do |excluded|
|
53
|
-
|
57
|
+
next if found
|
54
58
|
found = directory.start_with?(excluded)
|
55
59
|
end
|
56
60
|
found
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
+
def to_spec_filename(filename)
|
65
|
+
if File.extname(filename) != '.rb'
|
66
|
+
filename = filename + suffix + ".rb"
|
67
|
+
else
|
68
|
+
extension = File.extname(filename)
|
69
|
+
basename = File.basename(filename, extension)
|
70
|
+
filename = basename + suffix + extension
|
71
|
+
end
|
64
72
|
end
|
65
73
|
end
|
66
74
|
end
|
data/lib/has_specs/version.rb
CHANGED
data/lib/has_specs.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
require "has_specs/version"
|
2
2
|
require "has_specs/configuration"
|
3
|
-
require 'has_specs/rails_defaults'
|
4
3
|
require 'has_specs/base'
|
5
4
|
|
6
5
|
module HasSpecs
|
7
|
-
class MatchingSpecFileDoesNotExist < StandardError; end
|
6
|
+
class MatchingSpecFileDoesNotExist < StandardError; end
|
8
7
|
|
9
8
|
class << self
|
10
9
|
def verify
|
11
|
-
HasSpecs::Base.verify
|
10
|
+
missing = HasSpecs::Base.verify(self.configuration)
|
11
|
+
if missing != []
|
12
|
+
puts "\n######################\nHasSpecs Missing Specs:\n"
|
13
|
+
puts missing.join("\n")
|
14
|
+
puts "\n######################\n\n"
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
def configuration
|
data/spec/base_spec.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'has_specs'
|
2
2
|
|
3
3
|
describe HasSpecs do
|
4
|
-
it "
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
it "returns an empty array if all files have a matching spec" do
|
5
|
+
config = HasSpecs::Configuration.new
|
6
|
+
config.root = File.join(Dir.pwd,'lib','has_specs')
|
7
|
+
config.ignore << "version.rb"
|
8
|
+
expect(HasSpecs::Base.verify(config)).to eq []
|
8
9
|
end
|
9
10
|
|
10
|
-
it "
|
11
|
-
|
12
|
-
|
11
|
+
it "prints messages if any files are missing a matching spec" do
|
12
|
+
config = HasSpecs::Configuration.new
|
13
|
+
config.root = Dir.pwd
|
14
|
+
expect(HasSpecs::Base.verify(config)).to include 'base_spec.rb'
|
13
15
|
end
|
14
16
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe HasSpecs::Configuration do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "defaults to excluding the specs dir" do
|
27
|
-
expect(@config.exclude).to eq ['spec']
|
27
|
+
expect(@config.exclude).to eq ['spec', 'assets']
|
28
28
|
expect(@config.include).not_to include('spec')
|
29
29
|
end
|
30
30
|
|
@@ -43,26 +43,11 @@ describe HasSpecs::Configuration do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "has an extension of .rb" do
|
46
|
-
expect(@config.extension).to eq '.rb'
|
46
|
+
expect(@config.extension).to eq ['.rb', '.erb', '.jbuilder']
|
47
47
|
end
|
48
48
|
|
49
49
|
it "lists included directories" do
|
50
50
|
@config.root = Dir.pwd
|
51
51
|
expect(@config.include).to include('lib')
|
52
52
|
end
|
53
|
-
|
54
|
-
it "can use the rails defaults" do
|
55
|
-
fake_rails_class = Class.new do
|
56
|
-
def self.root
|
57
|
-
'fake_rails_root'
|
58
|
-
end
|
59
|
-
end
|
60
|
-
stub_const("Rails",fake_rails_class)
|
61
|
-
|
62
|
-
@config.use_rails_defaults
|
63
|
-
|
64
|
-
expect(@config.exclude).to include File.join('assets')
|
65
|
-
expect(@config.root).to include 'app'
|
66
|
-
expect(@config.suffix).to eq '_spec'
|
67
|
-
end
|
68
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_specs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Gross
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
63
64
|
- Gemfile
|
64
65
|
- LICENSE.txt
|
65
66
|
- README.md
|
@@ -68,11 +69,9 @@ files:
|
|
68
69
|
- lib/has_specs.rb
|
69
70
|
- lib/has_specs/base.rb
|
70
71
|
- lib/has_specs/configuration.rb
|
71
|
-
- lib/has_specs/rails_defaults.rb
|
72
72
|
- lib/has_specs/version.rb
|
73
73
|
- spec/base_spec.rb
|
74
74
|
- spec/configuration_spec.rb
|
75
|
-
- spec/rails_defaults_spec.rb
|
76
75
|
homepage: ''
|
77
76
|
licenses:
|
78
77
|
- MIT
|
@@ -100,4 +99,3 @@ summary: Validates that each file has a corresponding spec.
|
|
100
99
|
test_files:
|
101
100
|
- spec/base_spec.rb
|
102
101
|
- spec/configuration_spec.rb
|
103
|
-
- spec/rails_defaults_spec.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module HasSpecs
|
2
|
-
class RailsDefaults
|
3
|
-
def self.exclude
|
4
|
-
(@exclude ||= []) << 'assets'
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.root
|
8
|
-
unless defined? Rails
|
9
|
-
raise ArgumentError, "Rails not defined"
|
10
|
-
end
|
11
|
-
File.join(::Rails.root,'app')
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.suffix
|
15
|
-
"_spec"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/spec/rails_defaults_spec.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'has_specs'
|
2
|
-
|
3
|
-
describe HasSpecs::RailsDefaults do
|
4
|
-
it "defaults to excluding the assets dir" do
|
5
|
-
expect(HasSpecs::RailsDefaults.exclude).to include 'assets'
|
6
|
-
end
|
7
|
-
|
8
|
-
it "defaults to using _spec as the suffix" do
|
9
|
-
expect(HasSpecs::RailsDefaults.suffix).to eq '_spec'
|
10
|
-
end
|
11
|
-
end
|