spec_producer 0.1.0

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: 3aff1b57193f8f5c6c9e7d8be9872001f51d1bb1
4
+ data.tar.gz: 81ec6feb940f1e555365ff4548cf3c03735a5e72
5
+ SHA512:
6
+ metadata.gz: 0b1e97eefd7f022cdf07b871bc950a46e532ac90a41d86fe74b626b63b5b8772ff649fbcbd5c2e0fcbea5b4478b1cd824e6a3b7e63f7b62f0485455f965e73c9
7
+ data.tar.gz: 601e8e3a09dd6f7e6ec4afd25f01d86aa7d988f6bf1a568cf0364e4cbfc1761f2c48b7a420a4d1690fc2a0f331694b0496178378f6aed51dc61b34549700e766
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # Ignore idea configuration.
12
+ /.idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spec_producer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Vasilis Kalligas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # SpecProducer
2
+
3
+ SpecProducer is a gem that is meant to assist users in skipping the tedious work of creating spec tests for basic
4
+ functionality. It reads through the files of the project and prepares some of the basic spec tests for you.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'spec_producer'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install spec_producer
21
+
22
+ ## Usage
23
+
24
+ Currently this gem supports the production of spec tests for activemodel Models and routing specs.
25
+
26
+ To produce all possible tests, run:
27
+
28
+ ```ruby
29
+ SpecProducer.produce_specs_for_all_types
30
+ ```
31
+
32
+ To produce all tests for models, run:
33
+
34
+ ```ruby
35
+ SpecProducer.produce_specs_for_models
36
+ ```
37
+
38
+ To produce all tests for routes, run:
39
+
40
+ ```ruby
41
+ SpecProducer.produce_specs_for_routes
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/spec_producer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
53
+
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
58
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "spec_producer"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module SpecProducer
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,101 @@
1
+ require "spec_producer/version"
2
+
3
+ module SpecProducer
4
+ def self.produce_specs_for_all_types
5
+ produce_specs_for_models
6
+ produce_specs_for_routes
7
+ end
8
+
9
+ def self.produce_specs_for_models
10
+ Dir.glob(Rails.root.join('app/models/*.rb')).each do |x|
11
+ require x
12
+ end
13
+
14
+ ActiveRecord::Base.descendants.each do |descendant|
15
+ final_text = "require 'rails_helper'\n"
16
+ final_text << "describe #{descendant.name} do\n"
17
+
18
+ descendant.attribute_names.each do |attribute|
19
+ final_text << "\tit { should respond_to :#{attribute}, :#{attribute}= }\n"
20
+ end
21
+
22
+ final_text << "end"
23
+
24
+ if File.exists?(Rails.root.join("spec/models/#{descendant.name.downcase}_spec.rb"))
25
+ puts '#'*100
26
+ puts "Please, check whether the following lines are included in: " + descendant.name.downcase + "_spec.rb\n"
27
+ puts '#'*100
28
+ puts "\n"
29
+ puts final_text
30
+ else
31
+ unless Dir.exists? Rails.root.join("spec/models")
32
+ puts "Generating spec/models directory"
33
+ Dir.mkdir(Rails.root.join("spec/models"))
34
+ end
35
+
36
+ path = "spec/models/#{descendant.name.downcase}_spec.rb"
37
+ puts "Creating spec file for #{path}"
38
+ f = File.open("#{Rails.root.join(path)}", 'wb+')
39
+ f.write(final_text)
40
+ f.close
41
+ end
42
+ end
43
+
44
+ nil
45
+ end
46
+
47
+ def self.produce_specs_for_routes
48
+ routes = Rails.application.routes.routes.map do |route|
49
+ path = route.path.spec.to_s.gsub(/\(\.:format\)/, "")
50
+ verb = %W{ GET POST PUT PATCH DELETE }.grep(route.verb).first.downcase.to_sym
51
+ controller = route.defaults[:controller]
52
+ action = route.defaults[:action]
53
+
54
+ if controller.present? && !/^rails/.match(controller)
55
+ { :path => path, :verb => verb, :controller => controller, :action => action }
56
+ end
57
+ end.compact
58
+
59
+ routes.group_by { |route| route[:controller] }.each do |route_group|
60
+ final_text = "require 'rails_helper'\n\n"
61
+ final_text << "describe '#{route_group[0]} routes' do\n"
62
+
63
+ route_group[1].each do |route|
64
+ final_text << "\tit \"#{route[:verb].upcase} #{route[:path]} should route to '#{route[:controller]}##{route[:action]}'\" do\n"
65
+
66
+ final_text << "\t\t{ :#{route[:verb]} => '#{route[:path].gsub(/:[a-zA-Z_]+/){ |param| param.gsub(':','').upcase }}'}.\n"
67
+ final_text << "\t\t\tshould route_to(:controller => '#{route[:controller]}',\n"
68
+
69
+ /:[a-zA-Z_]+/.match(route[:path]).to_a.each do |parameter|
70
+ final_text << "\t\t\t\t\t#{parameter} => '#{parameter.gsub(':','').upcase}',\n"
71
+ end
72
+
73
+ final_text << "\t\t\t\t\t:action => '#{route[:action]}')\n"
74
+ final_text << "\t\tend\n\n"
75
+ end
76
+
77
+ final_text << 'end'
78
+
79
+ if File.exists?(Rails.root.join("spec/routing/#{route_group[0]}_routing_spec.rb"))
80
+ puts '#'*100
81
+ puts "Please, check whether the following lines are included in: spec/routing/#{route_group[0]}_routing_spec.rb\n"
82
+ puts '#'*100
83
+ puts "\n"
84
+ puts final_text
85
+ else
86
+ unless Dir.exists? Rails.root.join("spec/routing")
87
+ puts "Generating spec/routing directory"
88
+ Dir.mkdir(Rails.root.join("spec/routing"))
89
+ end
90
+
91
+ path = "spec/routing/#{route_group[0]}_routing_spec.rb"
92
+ puts "Creating spec file for #{route_group[0]}"
93
+ f = File.open("#{Rails.root.join(path)}", 'wb+')
94
+ f.write(final_text)
95
+ f.close
96
+ end
97
+ end
98
+
99
+ nil
100
+ end
101
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spec_producer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spec_producer"
8
+ spec.version = SpecProducer::VERSION
9
+ spec.authors = ["Vasilis Kalligas"]
10
+ spec.email = ["billkall@gmail.com"]
11
+
12
+ spec.summary = %q{This gem can be used in Rails apps to automatically generate rspec tests and files}
13
+ spec.description = %q{This gem reads through the files of the rails app and produces as many specs as possible.}
14
+ spec.homepage = "https://rubygems.org/gems/spec_producer"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spec_producer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vasilis Kalligas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-03 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: This gem reads through the files of the rails app and produces as many
56
+ specs as possible.
57
+ email:
58
+ - billkall@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/spec_producer.rb
74
+ - lib/spec_producer/version.rb
75
+ - spec_producer.gemspec
76
+ homepage: https://rubygems.org/gems/spec_producer
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.4.8
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: This gem can be used in Rails apps to automatically generate rspec tests
100
+ and files
101
+ test_files: []