tested_public_methods 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +8 -0
  5. data/Gemfile +2 -0
  6. data/LICENCE +20 -0
  7. data/README.md +40 -0
  8. data/Rakefile +7 -0
  9. data/lib/generators/initializer_generator.rb +7 -0
  10. data/lib/generators/templates/tested_public_methods.rb +7 -0
  11. data/lib/tested_public_methods.rb +3 -0
  12. data/lib/tested_public_methods/detector.rb +116 -0
  13. data/lib/tested_public_methods/module.rb +13 -0
  14. data/lib/tested_public_methods/railtie.rb +13 -0
  15. data/lib/tested_public_methods/rake_task.rb +6 -0
  16. data/spec/lib/tested_public_methods/detector_spec.rb +95 -0
  17. data/spec/lib/tested_public_methods/module_spec.rb +25 -0
  18. data/spec/rails_app/app/controllers/projects_controller.rb +21 -0
  19. data/spec/rails_app/app/models/project.rb +22 -0
  20. data/spec/rails_app/app/models/task.rb +19 -0
  21. data/spec/rails_app/app/models/user.rb +9 -0
  22. data/spec/rails_app/config/application.rb +5 -0
  23. data/spec/rails_app/config/database.yml +24 -0
  24. data/spec/rails_app/config/environment.rb +5 -0
  25. data/spec/rails_app/config/environments/development.rb +14 -0
  26. data/spec/rails_app/config/environments/production.rb +34 -0
  27. data/spec/rails_app/config/environments/test.rb +26 -0
  28. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  29. data/spec/rails_app/config/initializers/inflections.rb +2 -0
  30. data/spec/rails_app/config/initializers/secret_token.rb +3 -0
  31. data/spec/rails_app/config/routes.rb +3 -0
  32. data/spec/rails_app/spec/controllers/projects_controller_spec.rb +11 -0
  33. data/spec/rails_app/spec/models/project_spec.rb +19 -0
  34. data/spec/rails_app/spec/models/task_spec.rb +20 -0
  35. data/spec/rails_app/spec/spec_helper.rb +11 -0
  36. data/spec/rails_app/spec/support/schema.rb +27 -0
  37. data/spec/spec_helper.rb +14 -0
  38. data/tested_public_methods.gemspec +27 -0
  39. metadata +166 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e72cc0bcada4ac13a5d666c2466a2193a89d56f
4
+ data.tar.gz: fb778b70614086c20b69d18987c1eec5fb8c1a61
5
+ SHA512:
6
+ metadata.gz: 23d5636321509823ac867c1487d702864438decbd36f863a691688664baae8c3ff83e44f73abc52727a03903000467ea6063d32138110a171d3d4e5cfc759397
7
+ data.tar.gz: 3fa0737a6f0c2756432791e1deb4ad0b3a99789cc4cdd1ad9cfe8ff5cd79eee50e7c303162c7c58bbfef24dc7124d0bb93d2621e5957efa505886db2067d9f73
@@ -0,0 +1,7 @@
1
+ .idea/
2
+ *.log
3
+ *.swp
4
+ *.gem
5
+ Gemfile.lock
6
+ .rvmrc
7
+ test/debug.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.0.0
5
+ script: bundle exec rake spec
6
+ branches:
7
+ only:
8
+ - master
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
data/LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Tomasz Borowski <http://tbprojects.pl> @TomaszBorowski
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ Tested Public Methods [![Build Status](https://travis-ci.org/tbprojects/tested_public_methods.png)](https://travis-ci.org/tbprojects/tested_public_methods) [![Code Climate](https://codeclimate.com/github/tbprojects/tested_public_methods.png)](https://codeclimate.com/github/tbprojects/tested_public_methods)
2
+ =================
3
+
4
+ Returns list of public methods that do not have their own unit tests.
5
+ Gem checkes classes in app directory againts tests in spec directory.
6
+ Checkout http://betterspecs.org to learn expected conventions in specs.
7
+
8
+ ## Installation:
9
+ ```gem install tested_public_methods```
10
+
11
+ or
12
+
13
+ ```gem 'tested_public_methods'``` in your Gemfile
14
+
15
+ ## Usage & Example
16
+
17
+ Execute ```rake tested_public_methods:analyze``` to list all untested methods or classes.
18
+
19
+ Example of an output:
20
+ ```
21
+ * missing spec file for User
22
+ * missing test for Task#project_name
23
+ * missing test for Task.with_description
24
+ * missing test for Project#formatted_start_at
25
+ * missing test for ProjectsController#index
26
+
27
+ Found 5 issues
28
+ ```
29
+
30
+ ## Configuration
31
+
32
+ Sometimes you may need to skip some classes or methods during analysis. In order to do that
33
+ generate initializer with ```rails generate initializer tested_public_methods``` and fill
34
+ configuration (config.skip_classes and config.skip_methods) according to the example.
35
+
36
+ ## Tests
37
+ Module is tested with rspec. To run it just execute ```rake```
38
+
39
+ ## Credits
40
+ [Tomasz Borowski](http://tbprojects.pl)
@@ -0,0 +1,7 @@
1
+ require "bundler"
2
+ require 'rspec/core/rake_task'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ class InitializerGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path("../templates", __FILE__)
3
+
4
+ def copy_initializer_file
5
+ copy_file "tested_public_methods.rb", "config/initializers/tested_public_methods.rb"
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ TestedPublicMethods.configure do |config|
2
+ # Point out classes which should not be considered during analysis
3
+ # config.skip_classes = [ApplicationController]
4
+ #
5
+ # Point out methods (both instance and class) which should not be considered during analysis
6
+ # config.skip_methods = { User => [:full_name], Project => [:name]}
7
+ end
@@ -0,0 +1,3 @@
1
+ require "tested_public_methods/module"
2
+ require "tested_public_methods/detector"
3
+ require "tested_public_methods/railtie"
@@ -0,0 +1,116 @@
1
+ class TestedPublicMethods::Detector
2
+ CLASS_NAME_REG_EXP = /^[\s]*class[\s]+([\S]+)[\s]+/
3
+ CLASS_METHOD_REG_EXP = /['"]\.([\S]+)['"]/
4
+ INSTANCE_METHOD_REG_EXP = /['"](?:POST|GET|DELETE|PUT|)*[\s]*#([\S]+)['"]/
5
+
6
+ def analyze
7
+ @problem_counter = 0
8
+ @buffer = {missing_test: [], missing_spec: []}
9
+ list_of_classes.keys.each do |klass|
10
+ if has_spec_file? klass
11
+ untested_instance_methods(klass).each do |method_name|
12
+ buffer_warning("* missing test for #{klass.name}##{method_name}", :missing_test)
13
+ end
14
+ untested_class_methods(klass).each do |method_name|
15
+ buffer_warning("* missing test for #{klass.name}.#{method_name}", :missing_test)
16
+ end
17
+ elsif !class_skipped? klass
18
+ buffer_warning("* missing spec file for #{klass.name}", :missing_spec)
19
+ end
20
+ end
21
+ print_summary
22
+ end
23
+
24
+ private
25
+ def source_dir
26
+ File.join(Rails.root, 'app')
27
+ end
28
+
29
+ def spec_dir
30
+ File.join(Rails.root, 'spec')
31
+ end
32
+
33
+ def buffer_warning(text, type)
34
+ @buffer[type].push(text)
35
+ @problem_counter += 1
36
+ end
37
+
38
+ def print_summary
39
+ puts @buffer[:missing_spec].join("\n").red
40
+ puts @buffer[:missing_test].join("\n").red
41
+ if @problem_counter > 0
42
+ puts "\nFound #{@problem_counter} issues".red
43
+ else
44
+ puts "\nGreat, all public methods are tested!".green
45
+ end
46
+ end
47
+
48
+ def has_spec_file?(klass)
49
+ File.exists?(spec_file_path(klass))
50
+ end
51
+
52
+ def class_skipped?(klass)
53
+ config_skip_classes.include? klass.to_s
54
+ end
55
+
56
+ def source_file_path(klass)
57
+ list_of_classes[klass]
58
+ end
59
+
60
+ def spec_file_path(klass)
61
+ source_file_path(klass).gsub(source_dir, spec_dir).gsub('.rb', '_spec.rb')
62
+ end
63
+
64
+ def list_of_classes
65
+ @list_of_classes ||= Dir.glob(File.join(source_dir, "**/*.rb")).each_with_object({}) do |file_path, memo|
66
+ klass_names = File.read(file_path).scan(CLASS_NAME_REG_EXP).flatten
67
+ klass_names.each do |klass_name|
68
+ begin
69
+ memo[klass_name.constantize] = file_path
70
+ rescue
71
+ puts "WARNING: can't analyze unsupported class #{klass_name} in #{file_path}".yellow
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def untested_instance_methods(klass)
78
+ instance_methods_in_class(klass) - instance_methods_in_spec(klass) - skipped_methods(klass)
79
+ end
80
+
81
+ def untested_class_methods(klass)
82
+ class_methods_in_class(klass) - class_methods_in_spec(klass) - skipped_methods(klass)
83
+ end
84
+
85
+ def skipped_methods(klass)
86
+ (config_skip_methods[klass.to_s] || []).map(&:to_sym)
87
+ end
88
+
89
+ def instance_methods_in_class(klass)
90
+ klass.instance_methods(false).select do |method_name|
91
+ klass.instance_method(method_name).source_location.try(:first) == source_file_path(klass)
92
+ end
93
+ end
94
+
95
+ def class_methods_in_class(klass)
96
+ klass.public_methods(false).select do |method_name|
97
+ klass.method(method_name).source_location.try(:first) == source_file_path(klass)
98
+ end
99
+ end
100
+
101
+ def instance_methods_in_spec(klass)
102
+ File.read(spec_file_path(klass)).scan(INSTANCE_METHOD_REG_EXP).flatten.map(&:to_sym)
103
+ end
104
+
105
+ def class_methods_in_spec(klass)
106
+ File.read(spec_file_path(klass)).scan(CLASS_METHOD_REG_EXP).flatten.map(&:to_sym)
107
+ end
108
+
109
+ def config_skip_methods
110
+ TestedPublicMethods.configuration.skip_methods.stringify_keys
111
+ end
112
+
113
+ def config_skip_classes
114
+ TestedPublicMethods.configuration.skip_classes.map(&:to_s)
115
+ end
116
+ end
@@ -0,0 +1,13 @@
1
+ module TestedPublicMethods
2
+ VERSION = '1.0.0'
3
+
4
+ attr_writer :configuration
5
+
6
+ def self.configure
7
+ yield(configuration)
8
+ end
9
+
10
+ def self.configuration
11
+ @configuration ||= OpenStruct.new(skip_classes: [], skip_methods: {})
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module TestedPublicMethods
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ require "tested_public_methods/rake_task"
5
+ end
6
+
7
+ initializer "Include your code in the controller" do
8
+ ActiveSupport.on_load(:action_controller) do
9
+ include TestedPublicMethods
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ namespace :tested_public_methods do
2
+ desc "Returns list of public methods that do not have their own unit tests."
3
+ task analyze: :environment do
4
+ TestedPublicMethods::Detector.new.analyze
5
+ end
6
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe TestedPublicMethods::Detector do
4
+
5
+ describe '#analyze' do
6
+ let(:expected_buffer_test) {["* missing test for Task#project_name",
7
+ "* missing test for Task.with_description",
8
+ "* missing test for Project#formatted_start_at",
9
+ "* missing test for ProjectsController#index"]}
10
+ let(:expected_buffer_spec) {["* missing spec file for User"]}
11
+ before { subject.analyze }
12
+
13
+ it { expect(subject.instance_variable_get('@problem_counter')).to eql 5 }
14
+ it { expect(subject.instance_variable_get('@buffer')[:missing_test]).to match_array expected_buffer_test }
15
+ it { expect(subject.instance_variable_get('@buffer')[:missing_spec]).to match_array expected_buffer_spec }
16
+ end
17
+
18
+ describe '#list_of_classes' do
19
+ it { expect(subject.send(:list_of_classes).keys).to match_array [Project, Task, User, ProjectsController]}
20
+ end
21
+
22
+ describe '#has_spec_file?' do
23
+ { Project => true, Task => true, User => false, ProjectsController => true }.each do |klass, presence|
24
+ it { expect(subject.send(:has_spec_file?, klass)).to eql presence}
25
+ end
26
+ end
27
+
28
+ describe '#untested_instance_methods' do
29
+ context 'without custom config' do
30
+ { Project => [:formatted_start_at],
31
+ Task => [:project_name],
32
+ ProjectsController => [:index]}.each do |klass, methods|
33
+ it { expect(subject.send(:untested_instance_methods, klass)).to match_array methods}
34
+ end
35
+ end
36
+
37
+ context 'with custom config' do
38
+ before { TestedPublicMethods.stub(:configuration).
39
+ and_return(OpenStruct.new(skip_methods: {Project => [:formatted_start_at]})) }
40
+
41
+ it { expect(subject.send(:untested_instance_methods, Project)).to match_array []}
42
+ end
43
+ end
44
+
45
+ describe '#untested_class_methods' do
46
+ context 'without custom config' do
47
+ { Project => [],
48
+ Task => [:with_description],
49
+ ProjectsController => []}.each do |klass, methods|
50
+ it { expect(subject.send(:untested_class_methods, klass)).to match_array methods}
51
+ end
52
+ end
53
+
54
+ context 'with custom config' do
55
+ before { TestedPublicMethods.stub(:configuration).
56
+ and_return(OpenStruct.new(skip_methods: {Task => [:with_description]})) }
57
+
58
+ it { expect(subject.send(:untested_class_methods, Task)).to match_array []}
59
+ end
60
+ end
61
+
62
+ describe '#instance_methods_in_class' do
63
+ { Project => [:label, :formatted_start_at],
64
+ Task => [:project_name, :task_label],
65
+ User => [:label],
66
+ ProjectsController => [:index, :create]}.each do |klass, methods|
67
+ it { expect(subject.send(:instance_methods_in_class, klass)).to match_array methods}
68
+ end
69
+ end
70
+
71
+ describe '#class_methods_in_class' do
72
+ { Project => [],
73
+ Task => [:with_description, :without_description],
74
+ User => [],
75
+ ProjectsController => []}.each do |klass, methods|
76
+ it { expect(subject.send(:class_methods_in_class, klass)).to match_array methods}
77
+ end
78
+ end
79
+
80
+ describe '#instance_methods_in_spec' do
81
+ { Project => [:label],
82
+ Task => [:task_label],
83
+ ProjectsController => [:create]}.each do |klass, methods|
84
+ it { expect(subject.send(:instance_methods_in_spec, klass)).to match_array methods}
85
+ end
86
+ end
87
+
88
+ describe '#class_methods_in_spec' do
89
+ { Project => [],
90
+ Task => [:without_description],
91
+ ProjectsController => []}.each do |klass, methods|
92
+ it { expect(subject.send(:class_methods_in_spec, klass)).to match_array methods}
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe TestedPublicMethods do
4
+ it('version must be defined') { expect(described_class::VERSION).to be_present }
5
+
6
+ describe '.configuration' do
7
+ context 'without defining custom config' do
8
+ let(:expected_config) { OpenStruct.new(skip_classes: [], skip_methods: {}) }
9
+
10
+ it { expect(described_class.configuration).to eql expected_config }
11
+ end
12
+
13
+ context 'with defining custom config' do
14
+ let(:expected_config) { OpenStruct.new(skip_classes: [ProjectsController], skip_methods: { Project => [:label]})}
15
+ before do
16
+ TestedPublicMethods.configure do |config|
17
+ config.skip_classes = [ProjectsController]
18
+ config.skip_methods = {Project => [:label]}
19
+ end
20
+ end
21
+
22
+ it { expect(described_class.configuration).to eql expected_config }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ class ProjectsController < ActionController::Base
2
+
3
+ def index
4
+ render json: Project.all
5
+ end
6
+
7
+ def create
8
+ create_project
9
+ render nothing: true
10
+ end
11
+
12
+ private
13
+ def create_project
14
+ Project.create(project_parameters)
15
+ end
16
+
17
+ def project_parameters
18
+ params.require(:project).permit(:subject)
19
+ end
20
+
21
+ end
@@ -0,0 +1,22 @@
1
+ class Project < ActiveRecord::Base
2
+
3
+ has_many :tasks
4
+ validates :subject, presence: true
5
+
6
+ def label
7
+ company.present? ? label_with_company : label_without_company
8
+ end
9
+
10
+ def formatted_start_at
11
+ start_at.try :to_s, :short
12
+ end
13
+
14
+ private
15
+ def label_with_company
16
+ "#{subject} (#{company})"
17
+ end
18
+
19
+ def label_without_company
20
+ subject
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ class Task < ActiveRecord::Base
2
+
3
+ belongs_to :project
4
+ validates :name, presence: true
5
+
6
+ delegate :name, to: :project, prefix: true
7
+
8
+ def task_label
9
+ "#{name}: #{description}"
10
+ end
11
+
12
+ def self.without_description
13
+ where(description: nil)
14
+ end
15
+
16
+ def self.with_description
17
+ where.not(description: nil)
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ class User < ActiveRecord::Base
2
+
3
+ validates :name, :email, presence: true
4
+
5
+ def label
6
+ "#{name} (#{email})"
7
+ end
8
+
9
+ end
@@ -0,0 +1,5 @@
1
+ module RailsApp
2
+ class Application < Rails::Application
3
+ config.root = File.expand_path('../../', __FILE__)
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ sqlite3mem: &SQLITE3MEM
2
+ adapter: sqlite3
3
+ database: ":memory:"
4
+
5
+ sqlite3: &SQLITE
6
+ adapter: sqlite3
7
+ database: mapped_attributes_test.sqlite3.db
8
+
9
+ postgresql: &POSTGRES
10
+ adapter: postgresql
11
+ username: postgres
12
+ password: postgres
13
+ database: mapped_attributes_test
14
+ min_messages: ERROR
15
+
16
+ mysql: &MYSQL
17
+ adapter: mysql
18
+ host: localhost
19
+ username: root
20
+ password:
21
+ database: mapped_attributes_test
22
+
23
+ test:
24
+ <<: *<%= ENV['DB'] || 'SQLITE3MEM' %>
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ RailsApp::Application.initialize!
@@ -0,0 +1,14 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Show full error reports and disable caching
10
+ config.consider_all_requests_local = true
11
+ config.action_view.debug_rjs = true
12
+ config.action_controller.perform_caching = false
13
+ config.eager_load = false
14
+ end
@@ -0,0 +1,34 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+ config.eager_load = true
12
+
13
+ # See everything in the log (default is :info)
14
+ # config.log_level = :debug
15
+
16
+ # Use a different logger for distributed setups
17
+ # config.logger = SyslogLogger.new
18
+
19
+ # Use a different cache store in production
20
+ # config.cache_store = :mem_cache_store
21
+
22
+ # Disable Rails's static asset server
23
+ # In production, Apache or nginx will already do this
24
+ config.serve_static_assets = false
25
+
26
+ # Enable serving of images, stylesheets, and javascripts from an asset server
27
+ # config.action_controller.asset_host = "http://assets.example.com"
28
+
29
+ # Disable delivery errors, bad email addresses will be ignored
30
+ # config.action_mailer.raise_delivery_errors = false
31
+
32
+ # Enable threaded mode
33
+ # config.threadsafe!
34
+ end
@@ -0,0 +1,26 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Show full error reports and disable caching
11
+ config.consider_all_requests_local = true
12
+ config.action_controller.perform_caching = false
13
+ config.eager_load = false
14
+
15
+ # Disable request forgery protection in test environment
16
+ config.action_controller.allow_forgery_protection = false
17
+
18
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
19
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
20
+ # like if you have constraints or database-specific column types
21
+ # config.active_record.schema_format = :sql
22
+
23
+ config.action_dispatch.show_exceptions = false
24
+
25
+ config.active_support.deprecation = :stderr
26
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,2 @@
1
+ ActiveSupport::Inflector.inflections do |inflect|
2
+ end
@@ -0,0 +1,3 @@
1
+ Rails.application.config.secret_token = 'ea942c41850d502f2c8283e26bdc57829f471bb18224ddff0a192c4f32cdf6cb5aa0d82b3a7a7adbeb640c4b06f3aa1cd5f098162d8240f669b39d6b49680571'
2
+ Rails.application.config.secret_key_base = 'secret value'
3
+ Rails.application.config.session_store :cookie_store, :key => "_my_app"
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ resources :projects
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe ProjectsController do
4
+ describe 'GET #create' do
5
+ let(:attributes) {{subject: 'New project'}}
6
+ let(:call_request) {post :create, project: attributes}
7
+
8
+ it { expect{call_request}.to change{Project.count}.by(1) }
9
+ end
10
+
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Project do
4
+
5
+ subject { Project.new subject: 'Testing project' }
6
+
7
+ describe '#label' do
8
+ context 'with company' do
9
+ before { subject.company = 'Acme' }
10
+
11
+ its(:label) {should eql 'Testing project (Acme)'}
12
+ end
13
+
14
+ context 'without company' do
15
+ its(:label) {should eql 'Testing project'}
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Task do
4
+
5
+ subject { Task.new name: 'Testing task', description: 'Just do it' }
6
+
7
+ describe '#task_label' do
8
+ its(:task_label) { should eql 'Testing task: Just do it' }
9
+ end
10
+
11
+ describe '.without_description' do
12
+ before do
13
+ Task.create name: 'test 1'
14
+ Task.create name: 'test 1', description: 'nice one'
15
+ end
16
+
17
+ it { expect(described_class.without_description.to_a).to have(1).project }
18
+ end
19
+
20
+ end
@@ -0,0 +1,11 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'rails/all'
6
+ require File.expand_path('../../config/environment.rb', __FILE__)
7
+ require 'support/schema'
8
+
9
+ RSpec.configure do |config|
10
+ # some (optional) config here
11
+ end
@@ -0,0 +1,27 @@
1
+ require 'active_record'
2
+ require 'logger'
3
+
4
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
5
+ ActiveRecord::Migration.verbose = false
6
+
7
+ ActiveRecord::Schema.define do
8
+ create_table :projects, :force => true do |t|
9
+ t.column :subject, :string
10
+ t.column :company, :string
11
+ t.column :summary, :text
12
+ t.column :priority, :integer
13
+ t.column :start_at, :date
14
+ end
15
+
16
+ create_table :tasks, :force => true do |t|
17
+ t.column :name, :string
18
+ t.column :description, :text
19
+ t.column :project_id, :integer
20
+ t.column :due_date, :date
21
+ end
22
+
23
+ create_table :users, :force => true do |t|
24
+ t.column :email, :string
25
+ t.column :name, :string
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'rails/all'
6
+ require 'rspec/rails'
7
+ require 'colorize'
8
+ require File.expand_path('../rails_app/config/environment.rb', __FILE__)
9
+ require File.expand_path('../rails_app/spec/support/schema', __FILE__)
10
+ require File.expand_path('../../lib/tested_public_methods.rb', __FILE__)
11
+
12
+ RSpec.configure do |config|
13
+ # some (optional) config here
14
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tested_public_methods/module'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "tested_public_methods"
8
+ gem.version = TestedPublicMethods::VERSION
9
+ gem.authors = ["Tomasz Borowski [tbprojects]"]
10
+ gem.email = 'info.tbprojects@gmail.com'
11
+ gem.description = "Returns list of public methods that do not have their own unit tests. Gem checkes classes in app directory againts tests in spec directory. Checkout http://betterspecs.org to learn expected conventions in specs."
12
+ gem.summary = "Returns list of public methods that do not have their own unit tests."
13
+ gem.homepage = "https://github.com/tbprojects/tested_public_methods"
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec-rails'
23
+ gem.add_development_dependency 'sqlite3'
24
+ gem.add_development_dependency 'colorize'
25
+ gem.add_dependency 'activerecord'
26
+ gem.add_dependency 'colorize'
27
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tested_public_methods
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomasz Borowski [tbprojects]
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
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
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: colorize
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Returns list of public methods that do not have their own unit tests.
98
+ Gem checkes classes in app directory againts tests in spec directory. Checkout http://betterspecs.org
99
+ to learn expected conventions in specs.
100
+ email: info.tbprojects@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .rspec
107
+ - .travis.yml
108
+ - Gemfile
109
+ - LICENCE
110
+ - README.md
111
+ - Rakefile
112
+ - lib/generators/initializer_generator.rb
113
+ - lib/generators/templates/tested_public_methods.rb
114
+ - lib/tested_public_methods.rb
115
+ - lib/tested_public_methods/detector.rb
116
+ - lib/tested_public_methods/module.rb
117
+ - lib/tested_public_methods/railtie.rb
118
+ - lib/tested_public_methods/rake_task.rb
119
+ - spec/lib/tested_public_methods/detector_spec.rb
120
+ - spec/lib/tested_public_methods/module_spec.rb
121
+ - spec/rails_app/app/controllers/projects_controller.rb
122
+ - spec/rails_app/app/models/project.rb
123
+ - spec/rails_app/app/models/task.rb
124
+ - spec/rails_app/app/models/user.rb
125
+ - spec/rails_app/config/application.rb
126
+ - spec/rails_app/config/database.yml
127
+ - spec/rails_app/config/environment.rb
128
+ - spec/rails_app/config/environments/development.rb
129
+ - spec/rails_app/config/environments/production.rb
130
+ - spec/rails_app/config/environments/test.rb
131
+ - spec/rails_app/config/initializers/backtrace_silencers.rb
132
+ - spec/rails_app/config/initializers/inflections.rb
133
+ - spec/rails_app/config/initializers/secret_token.rb
134
+ - spec/rails_app/config/routes.rb
135
+ - spec/rails_app/spec/controllers/projects_controller_spec.rb
136
+ - spec/rails_app/spec/models/project_spec.rb
137
+ - spec/rails_app/spec/models/task_spec.rb
138
+ - spec/rails_app/spec/spec_helper.rb
139
+ - spec/rails_app/spec/support/schema.rb
140
+ - spec/spec_helper.rb
141
+ - tested_public_methods.gemspec
142
+ homepage: https://github.com/tbprojects/tested_public_methods
143
+ licenses:
144
+ - MIT
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.1.11
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: Returns list of public methods that do not have their own unit tests.
166
+ test_files: []