has_specs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e4300b0ef1cf4c4ff685d2b49807ab219abf9ae
4
+ data.tar.gz: 780c7d39f9bad58b41905d4db5dadef11643b366
5
+ SHA512:
6
+ metadata.gz: ad60197f332cce3f8af8ccb55f9256809b46ec09e32c5d2a8f816b97a5241899a0bf456bea8b651a866d460f0536c6a291711ba9ed209835cb4802c00d421829
7
+ data.tar.gz: 4551b235fb45623facd7bacd8a4f808c7cc8f1c8fc616d862b90ac688b145c4883e238f3edfd1ed7c739db60e7d18448f5c9d76cee51db6000e67442595f49cd
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ **/.DS_Store
23
+ mkmf.log
24
+ has_specs.sublime-project
25
+ has_specs.sublime-workspace
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in has_specs.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Adam Gross
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,51 @@
1
+ # HasSpecs
2
+
3
+ Very basic gem that allows you to verify that every file in your project has a matching spec file.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'has_specs'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install has_specs
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ # spec_helper.rb
23
+
24
+ require 'has_specs'
25
+
26
+ # ...
27
+
28
+ HasSpecs.configuration.use_rails_defaults
29
+ HasSpecs.ignore << 'application_controller.rb'
30
+ HasSpecs.verify
31
+ ```
32
+
33
+ #### Configuration
34
+
35
+ ```
36
+ configuration.use_rails_defaults # sets up to use app/ as the root amoungst other things
37
+ configuration.ignore << 'some_file_to_ignore.rb'
38
+ configuration.exclude << 'some/whole/dir/to/exclude.rb'
39
+ configuration.include << 'some/whole/dir/to/optionally/include'
40
+ configuration.suffix << '_spec'
41
+ configuration.root = 'some/other/root/for/source/files'
42
+ configuration.spec_root = 'some/other/root/for/tests'
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/[my-github-username]/has_specs/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/has_specs.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'has_specs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "has_specs"
8
+ spec.version = HasSpecs::VERSION
9
+ spec.authors = ["Adam Gross"]
10
+ spec.email = ["gross.adamm@gmail.com"]
11
+ spec.summary = %q{Validates that each file has a corresponding spec.}
12
+ spec.description = %q{}
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,17 @@
1
+ module HasSpecs
2
+ class Base
3
+ def self.verify(config)
4
+ config.include.each do |directory|
5
+ lookat = File.join(config.root, directory,"*"+config.extension)
6
+ Dir.glob(lookat).each do |file|
7
+ spec_dir = File.dirname(file).gsub(config.root, config.spec_root)
8
+ basename = File.basename file, config.extension
9
+ spec_file = File.join(spec_dir,basename+config.suffix+config.extension)
10
+ unless config.ignore.include?(File.basename file) || File.exist?(spec_file)
11
+ raise MatchingSpecFileDoesNotExist, "#{spec_file} does not exist for #{file}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,66 @@
1
+ module HasSpecs
2
+ class Configuration
3
+ def root=(desired_root)
4
+ @root = desired_root
5
+ end
6
+
7
+ def root
8
+ @root ||= Dir.pwd
9
+ end
10
+
11
+ def spec_root=(desired_root)
12
+ @spec_root = desired_root
13
+ end
14
+
15
+ def spec_root
16
+ @spec_root ||= File.join(Dir.pwd,'spec')
17
+ end
18
+
19
+ def exclude=(exclude_dirs)
20
+ @exclude = exclude_dirs
21
+ end
22
+
23
+ def exclude
24
+ @exclude ||= ['spec']
25
+ end
26
+
27
+ def ignore=(ignore_files)
28
+ @ignore = ignore_files
29
+ end
30
+
31
+ def ignore
32
+ @ignore ||= []
33
+ end
34
+
35
+ def suffix=(suffix)
36
+ @suffix = suffix
37
+ end
38
+
39
+ def suffix
40
+ @suffix ||= '_spec'
41
+ end
42
+
43
+ def extension
44
+ ".rb"
45
+ end
46
+
47
+ def include
48
+ Dir.glob(File.join(self.root,'**/*/'))
49
+ .map!{|d| d.gsub(@root, '').sub(File::SEPARATOR,'').chomp(File::SEPARATOR) }
50
+ .delete_if do |directory|
51
+ found = false
52
+ self.exclude.each do |excluded|
53
+ continue if found
54
+ found = directory.start_with?(excluded)
55
+ end
56
+ found
57
+ end
58
+ end
59
+
60
+ def use_rails_defaults
61
+ self.exclude.concat(HasSpecs::RailsDefaults.exclude)
62
+ self.root = HasSpecs::RailsDefaults.root
63
+ self.suffix = HasSpecs::RailsDefaults.suffix
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,3 @@
1
+ module HasSpecs
2
+ VERSION = "0.0.1"
3
+ end
data/lib/has_specs.rb ADDED
@@ -0,0 +1,66 @@
1
+ require "has_specs/version"
2
+ require "has_specs/configuration"
3
+ require 'has_specs/rails_defaults'
4
+ require 'has_specs/base'
5
+
6
+ module HasSpecs
7
+ class MatchingSpecFileDoesNotExist < StandardError; end
8
+
9
+ class << self
10
+ def verify
11
+ HasSpecs::Base.verify (self.configuration)
12
+ end
13
+
14
+ def configuration
15
+ @configuration ||= Configuration.new
16
+ end
17
+
18
+ def root=(root)
19
+ self.configuration.root=root
20
+ end
21
+
22
+ def root
23
+ self.configuration.root
24
+ end
25
+
26
+ def spec_root=(spec_root)
27
+ self.configuration.spec_root=spec_root
28
+ end
29
+
30
+ def spec_root
31
+ self.configuration.spec_root
32
+ end
33
+
34
+ def exclude=(exclude)
35
+ self.configuration.exclude=exclude
36
+ end
37
+
38
+ def exclude
39
+ self.configuration.exclude
40
+ end
41
+
42
+ def ignore=(ignore)
43
+ self.configuration.ignore=ignore
44
+ end
45
+
46
+ def ignore
47
+ self.configuration.ignore
48
+ end
49
+
50
+ def suffix=(suffix)
51
+ self.configuration.suffix=suffix
52
+ end
53
+
54
+ def suffix
55
+ self.configuration.suffix
56
+ end
57
+
58
+ def extension
59
+ self.configuration.extension
60
+ end
61
+
62
+ def included
63
+ self.configuration.included
64
+ end
65
+ end
66
+ end
data/spec/base_spec.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'has_specs'
2
+
3
+ describe HasSpecs do
4
+ it "throws no exceptions if all files have a matching spec" do
5
+ HasSpecs.root = File.join(Dir.pwd,'lib','has_specs')
6
+ HasSpecs.ignore << "version.rb"
7
+ HasSpecs.verify
8
+ end
9
+
10
+ it "throws an exception if any files are missing a matching spec" do
11
+ HasSpecs.root = Dir.pwd
12
+ expect{HasSpecs.verify}.to raise_error
13
+ end
14
+ end
@@ -0,0 +1,68 @@
1
+ require 'has_specs'
2
+
3
+ describe HasSpecs::Configuration do
4
+ before(:each) do
5
+ @config = HasSpecs::Configuration.new
6
+ end
7
+
8
+ it "defaults the root to the current dir" do
9
+ expect(@config.root).to eq Dir.pwd
10
+ end
11
+
12
+ it "sets a new root" do
13
+ @config.root = 'somedir'
14
+ expect(@config.root).to eq 'somedir'
15
+ end
16
+
17
+ it "defaults the spec root to the current dirs specs dir " do
18
+ expect(@config.spec_root).to eq File.join(Dir.pwd,'spec')
19
+ end
20
+
21
+ it "sets a new spec root" do
22
+ @config.spec_root = 'somedir'
23
+ expect(@config.spec_root).to eq 'somedir'
24
+ end
25
+
26
+ it "defaults to excluding the specs dir" do
27
+ expect(@config.exclude).to eq ['spec']
28
+ expect(@config.include).not_to include('spec')
29
+ end
30
+
31
+ it "sets new exclusion dirs" do
32
+ @config.exclude = ['somedir']
33
+ expect(@config.exclude).to eq ['somedir']
34
+ end
35
+
36
+ it "defaults to using _spec as the suffix" do
37
+ expect(@config.suffix).to eq '_spec'
38
+ end
39
+
40
+ it "sets new suffix" do
41
+ @config.suffix = '_somesuffix'
42
+ expect(@config.suffix).to eq '_somesuffix'
43
+ end
44
+
45
+ it "has an extension of .rb" do
46
+ expect(@config.extension).to eq '.rb'
47
+ end
48
+
49
+ it "lists included directories" do
50
+ @config.root = Dir.pwd
51
+ expect(@config.include).to include('lib')
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
+ end
@@ -0,0 +1,11 @@
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
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_specs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Gross
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ''
56
+ email:
57
+ - gross.adamm@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - has_specs.gemspec
68
+ - lib/has_specs.rb
69
+ - lib/has_specs/base.rb
70
+ - lib/has_specs/configuration.rb
71
+ - lib/has_specs/rails_defaults.rb
72
+ - lib/has_specs/version.rb
73
+ - spec/base_spec.rb
74
+ - spec/configuration_spec.rb
75
+ - spec/rails_defaults_spec.rb
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Validates that each file has a corresponding spec.
100
+ test_files:
101
+ - spec/base_spec.rb
102
+ - spec/configuration_spec.rb
103
+ - spec/rails_defaults_spec.rb