auto_specs 0.0.1.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a4483793151af907e9122b6886669d376466d9ed
4
+ data.tar.gz: a3090e708e8c061d6ebb154082242e494495e661
5
+ SHA512:
6
+ metadata.gz: c4d0e9564b26463792efb941e56ca9b2383b856bc06d98c7df294f73cedea6fe8dcd266ced9af7af43c10b699da2160917223d5e913b9f645146708975d47fee
7
+ data.tar.gz: a9f3713fa900bfdb12ee194ea63f4b988c3819d3cec400477a40e03e7efe0270241170d7928a9a5339cb465639becc03de55e935a4ef7f9c37be492d263d07d3
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in auto_specs.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Aditya Kapoor
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,52 @@
1
+ # AutoSpecs
2
+
3
+ *Don't Write specs yourself.*
4
+
5
+ You might be caught up in the situation where all the development work is done first and then you have to write specs.
6
+
7
+ The purpose of this gem is to serve as the bootstrap tool where all the known specs are already written for you.
8
+
9
+ ## Prerequisites
10
+
11
+ In order to use this gem, the following steps needs to be done before installing this gem.
12
+
13
+ 1. install `rspec-rails` gem. Refer to the official page of the gem to know more.
14
+ 2. install `shoulda-matchers` gem. Refer to the official page of the gem to know more.
15
+
16
+ The reason we chose `rspec` and `shoulda-matcher` is due to their simple and efficient DSL which makes writing tests easier.
17
+
18
+ ### Currently we are generating the `associations` but it is being planned for `validations` too. There is an [open issue](https://github.com/aditya-kapoor/auto-specs/issues/5) for this.
19
+
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'auto_specs'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install auto_specs
36
+
37
+ ## Usage
38
+
39
+ Upon installation in the rails app, the gem presents you with two `rake` tasks namely:
40
+
41
+ 1. auto_specs:model
42
+ 2. auto_spec:controller [TODO]
43
+
44
+ Running `rake auto_specs:model` would generate the model file specs in the `spec` directory.
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( https://github.com/aditya-kapoor/auto_specs/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'auto_specs/tasks'
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'auto_specs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "auto_specs"
8
+ spec.version = AutoSpecs::VERSION
9
+ spec.authors = ["Aditya Kapoor"]
10
+ spec.email = ["aditya.kapoor@vinsol.com"]
11
+ spec.summary = "Adds certain tasks that would automatically generate some specs for you."
12
+ spec.description = ""
13
+ spec.homepage = "https://github.com/aditya-kapoor/auto-specs"
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 "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,13 @@
1
+ module AutoSpecs
2
+ module ActiveRecord
3
+ module Associations
4
+ MAPPINGS = {
5
+ belongs_to: 'belong_to',
6
+ has_many: 'have_many',
7
+ has_one: 'have_one',
8
+ has_many: 'have_many',
9
+ has_and_belongs_to_many: 'have_and_belongs_to_many'
10
+ }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ require 'auto_specs/active_record/associations/mapping'
2
+
3
+ module AutoSpecs
4
+ module ActiveRecord
5
+ module Associations
6
+ class SpecBuilder
7
+ attr_accessor :macro, :name, :options
8
+
9
+ def initialize(ar_reflection_object)
10
+ @macro = ar_reflection_object.macro
11
+ @name = ar_reflection_object.name
12
+ @options = ar_reflection_object.options
13
+ end
14
+
15
+ def to_s
16
+ "it { should #{ shoulda_association_mapping }(:#{ name })#{ through_association }#{ dependent_option } }"
17
+ end
18
+
19
+ private
20
+
21
+ def shoulda_association_mapping
22
+ ActiveRecord::Associations::MAPPINGS[macro.to_sym]
23
+ end
24
+
25
+ # TODO..Improve this..
26
+ def through_association
27
+ options[:through] ? ".through(:#{ options[:through] })" : ""
28
+ end
29
+
30
+ def dependent_option
31
+ options[:dependent] ? ".dependent(:#{ options[:dependent] })" : ""
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ require 'auto_specs/generators/model'
2
+
3
+ module AutoSpecs
4
+ module ActiveRecord
5
+ class Models
6
+ def self.generate_files
7
+ # TODO: Use ActiveRecord::Base.descendants.
8
+ (::ActiveRecord::Base.connection.tables - %w(schema_migrations delayed_jobs)).each do |table|
9
+ model = table.classify.constantize rescue nil
10
+ model ? generate_file_for(model) : puts("Model not found : #{table}")
11
+ end
12
+ end
13
+
14
+ def self.generate_file_for(model)
15
+ puts "Generating Spec File for #{ model }"
16
+ Generators::Model.new(model).push_file
17
+ end
18
+ private_class_method :generate_file_for
19
+ end
20
+ end
21
+ end
22
+
23
+ AutoSpecs::ActiveRecord::Models.generate_files
@@ -0,0 +1,27 @@
1
+ module AutoSpecs
2
+ module Generators
3
+ class Base
4
+ SPEC_DIRECTORY_PATH = Rails.root.join('spec')
5
+
6
+ def self.ensure_specs_directory_exists!
7
+ ensure_path!(SPEC_DIRECTORY_PATH)
8
+ end
9
+
10
+ def self.ensure_path!(path)
11
+ FileUtils.mkdir_p(path) unless File.directory?(path)
12
+ end
13
+
14
+ private_class_method :ensure_specs_directory_exists!,
15
+ :ensure_path!
16
+
17
+ ensure_specs_directory_exists!
18
+
19
+ private
20
+ def write_file
21
+ File.open(file_path, 'w') do |f|
22
+ f.write(file_contents)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,70 @@
1
+ require 'auto_specs/generators/base'
2
+ require 'auto_specs/active_record/associations/spec_builder'
3
+
4
+ module AutoSpecs
5
+ module Generators
6
+ class Model < Base
7
+ MODEL_SPEC_DIRECTORY_PATH = SPEC_DIRECTORY_PATH.join('models')
8
+
9
+ def self.ensure_model_specs_directory_exists!
10
+ ensure_path!(MODEL_SPEC_DIRECTORY_PATH)
11
+ end
12
+
13
+ ensure_model_specs_directory_exists!
14
+
15
+ attr_accessor :model_name, :file_contents
16
+
17
+ def initialize(model_name)
18
+ @model_name = model_name
19
+ @file_contents = ''
20
+ end
21
+
22
+ def push_file
23
+ within_file_code do
24
+ generate_code_for_associations
25
+ # generate_code_for_validations
26
+ end
27
+ write_file
28
+ end
29
+
30
+ private_class_method :ensure_model_specs_directory_exists!
31
+
32
+ private
33
+
34
+ def within_file_code
35
+ self.file_contents += %Q(require 'spec_helper'
36
+
37
+ describe #{ model_name } do)
38
+ yield
39
+ self.file_contents += %Q(end)
40
+ end
41
+
42
+ def generate_code_for_associations
43
+ generate_code_block_for('Associations')
44
+ model_name.reflect_on_all_associations.each do |reflection|
45
+ self.file_contents += %Q(
46
+ #{ AutoSpecs::ActiveRecord::Associations::SpecBuilder.new(reflection).to_s })
47
+ end
48
+ self.file_contents += %Q(
49
+ end
50
+ )
51
+ end
52
+
53
+ def generate_code_for_validations
54
+ generate_code_block_for('Validations')
55
+ model_name.validators.each do |validator|
56
+ # TODO...
57
+ end
58
+ end
59
+
60
+ def generate_code_block_for(entity)
61
+ self.file_contents += %Q(
62
+ context '#{ entity }' do)
63
+ end
64
+
65
+ def file_path
66
+ MODEL_SPEC_DIRECTORY_PATH.join("#{ model_name.to_s.underscore }_spec.rb")
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,13 @@
1
+ namespace :auto_specs do
2
+
3
+ desc 'Generate Specs for Models.'
4
+ task models: :environment do
5
+ AutoSpecs::Base.generate_spec_files_for('models')
6
+ end
7
+
8
+ desc 'Generates Specs for Controllers'
9
+ task :controllers do
10
+ # TODO...
11
+ # AutoSpecs::Base.generate_spec_files_for(:controllers)
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ require 'rake'
2
+
3
+ %w(generate).each do |task|
4
+ load "auto_specs/tasks/#{ task }.rake"
5
+ end
@@ -0,0 +1,3 @@
1
+ module AutoSpecs
2
+ VERSION = "0.0.1.alpha"
3
+ end
data/lib/auto_specs.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'auto_specs/version'
2
+ require 'auto_specs/tasks'
3
+
4
+ module AutoSpecs
5
+ class Base
6
+ def self.generate_spec_files_for(entity)
7
+ if defined?(::ActiveRecord::Base)
8
+ require "auto_specs/active_record/#{ entity }/generator"
9
+ else
10
+ # TODO...
11
+ end
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auto_specs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Aditya Kapoor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-31 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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: ''
42
+ email:
43
+ - aditya.kapoor@vinsol.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - auto_specs.gemspec
54
+ - lib/auto_specs.rb
55
+ - lib/auto_specs/active_record/associations/mapping.rb
56
+ - lib/auto_specs/active_record/associations/spec_builder.rb
57
+ - lib/auto_specs/active_record/models/generator.rb
58
+ - lib/auto_specs/generators/base.rb
59
+ - lib/auto_specs/generators/model.rb
60
+ - lib/auto_specs/tasks.rb
61
+ - lib/auto_specs/tasks/generate.rake
62
+ - lib/auto_specs/version.rb
63
+ homepage: https://github.com/aditya-kapoor/auto-specs
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">"
79
+ - !ruby/object:Gem::Version
80
+ version: 1.3.1
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.2.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Adds certain tasks that would automatically generate some specs for you.
87
+ test_files: []
88
+ has_rdoc: