minitest-rails-assertions 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58f2e8bbc0ed23c25c8aebc5e4a054f8c37e67e5
4
+ data.tar.gz: 41527d3d457ecafcb726f44c8ff9f5ab0f5cd400
5
+ SHA512:
6
+ metadata.gz: a1b7d3dfe0a86c6edf7303fec08fd69f46614dc389f027e4291b0c623dcab7760e70a37a8ffc5ede7914e27c09fbddd5950c0a413c46021a93de7fc694ea42f2
7
+ data.tar.gz: aff02473baa57f0236f1c486717746d7250f44276867a9ede05ff4cd8548e7087c91b209180a1d2404dabe602e3d7c39cd128267ea71a51066381d9c2c4e2e28
@@ -0,0 +1,29 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore RBenv files.
8
+ *.gem
9
+ .rbenv-*
10
+ .ruby-version
11
+ /.gems
12
+
13
+ # Ignore Bundler files.
14
+ *.bundle
15
+ .bundle
16
+ Gemfile.lock
17
+
18
+ # Ignore package files.
19
+ pkg
20
+
21
+ # Ignore all log files and tempfiles.
22
+ log/*.log
23
+ /tmp
24
+
25
+ # Ignore Mac files.
26
+ .DS_Store
27
+
28
+ # Coveralls files.
29
+ /coverage
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.2
6
+ before_install:
7
+ - gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minitest-rails-assertions.gemspec
4
+ gemspec
5
+
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Geoffrey ROGUELON
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.
@@ -0,0 +1,45 @@
1
+ # Minitest::Rails::Assertions
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/minitest-rails-assertions.svg)](http://badge.fury.io/rb/minitest-rails-assertions) [![Build Status](https://travis-ci.org/jules-vernes/minitest-rails-assertions.svg)](https://travis-ci.org/jules-vernes/minitest-rails-assertions) [![Code Climate](https://codeclimate.com/github/jules-vernes/minitest-rails-assertions/badges/gpa.svg)](https://codeclimate.com/github/jules-vernes/minitest-rails-assertions) [![Test Coverage](https://codeclimate.com/github/jules-vernes/minitest-rails-assertions/badges/coverage.svg)](https://codeclimate.com/github/jules-vernes/minitest-rails-assertions)
4
+
5
+ The gem minitest-rails-assertions extends MiniTest to add some assertions for
6
+ Rails specific methods.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'minitest-rails-assertions'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install minitest-rails-assertions
23
+
24
+ ## Usage
25
+
26
+ Add in your `test_helper.rb`:
27
+
28
+ ```ruby
29
+ require 'minitest/rails/assertions'
30
+ ```
31
+
32
+ Use the assertions like the Minitest assertion. For instance:
33
+
34
+ ```ruby
35
+ assert_length_of Product, :name, maximum: 30
36
+ assert_validates Product, :reference, format: { with: /\A\w\d{9}\z/i }, uniqueness: true
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( https://github.com/[my-github-username]/minitest-rails-assertions/fork )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create a new Pull Request
@@ -0,0 +1,16 @@
1
+ begin
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ Bundler::GemHelper.install_tasks
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.test_files = Dir['test/**/*_test.rb']
13
+ t.verbose = false
14
+ end
15
+
16
+ task default: :test
@@ -0,0 +1 @@
1
+ require 'minitest/rails/assertions'
@@ -0,0 +1,9 @@
1
+ require 'minitest/test'
2
+ require 'minitest/rails/assertions/validations'
3
+ require 'minitest/rails/assertions/version'
4
+
5
+ module Minitest
6
+ class Test
7
+ include ::Minitest::Rails::Assertions::Validations
8
+ end
9
+ end
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ module Minitest
4
+ module Rails
5
+ module Assertions
6
+ module Validations
7
+ OPTIONS = {
8
+ absence: {},
9
+ acceptance: { allow_nil: true, accept: '1' },
10
+ associated: {},
11
+ confirmation: {},
12
+ exclusion: {},
13
+ format: {},
14
+ inclusion: {},
15
+ length: {},
16
+ numericality: {},
17
+ presence: {},
18
+ uniqueness: { case_sensitive: true }
19
+ }
20
+
21
+
22
+ def assert_associated(subject, attribute, opts = true)
23
+ assert_validates subject, attribute, associated: opts
24
+ end
25
+
26
+ OPTIONS.keys.each do |type|
27
+ define_method("assert_#{type}_of") do |subject, attribute, opts = true|
28
+ assert_validates subject, attribute, type => opts
29
+ end
30
+ end
31
+
32
+ def assert_validates(subject, attribute, types)
33
+ types.each do |type, opts|
34
+ validators = assert_validator(type, subject, attribute)
35
+ options = OPTIONS[type.to_sym].merge(opts.is_a?(Hash) ? opts : {})
36
+ assert_equal options, validator_options(validators)
37
+ end
38
+ end
39
+
40
+ def assert_validator(type, subject, attribute)
41
+ assert_respond_to subject, :validators_on
42
+ validators = validator_of(type.to_sym, subject, attribute)
43
+ refute validators.empty?, "Expected #{subject} has #{type} validator"
44
+ validators
45
+ end
46
+
47
+ private
48
+
49
+ def validator_of(type, subject, attribute)
50
+ Array(subject.validators_on(attribute).select { |v| v.kind == type })
51
+ end
52
+
53
+ def validator_options(validators)
54
+ validator_options = validators.each_with_object({}) do |v, hash|
55
+ hash.merge!(v.options)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ module Minitest
4
+ module Rails
5
+ module Assertions
6
+ module Version
7
+ MAJOR = 0
8
+ MINOR = 1
9
+ TINY = 0
10
+ PRE = nil
11
+
12
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
13
+ end
14
+
15
+ VERSION = Version::STRING
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'minitest/rails/assertions/version'
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.required_ruby_version = '>= 1.9.3'
10
+
11
+ gem.name = 'minitest-rails-assertions'
12
+ gem.version = Minitest::Rails::Assertions::VERSION
13
+ gem.authors = ['Geoffrey Roguelon', 'Loïc Sence']
14
+ gem.email = ['geoffrey.roguelon@gmail.com', 'senceloic@gmail.com']
15
+ gem.summary = %q{The gem minitest-rails-assertions extends MiniTest to add some assertions to Rails tests.}
16
+ gem.description = %q{The gem minitest-rails-assertions extends MiniTest to add some assertions to Rails tests.}
17
+ gem.homepage = 'https://github.com/jules-vernes/minitest-rails-assertions'
18
+ gem.license = 'MIT'
19
+
20
+ gem.files = `git ls-files`.split($/)
21
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
+ gem.require_paths = ['lib']
24
+
25
+ gem.add_dependency 'rails', '>= 3.0', '< 5.0'
26
+
27
+ gem.add_development_dependency 'bundler', '~> 1.7'
28
+ gem.add_development_dependency 'rake', '~> 10.0'
29
+ gem.add_development_dependency 'activerecord-nulldb-adapter', '~> 0.3.1'
30
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+
5
+ module Minitest
6
+ class Rails::Assertions::ValidationsTest < Test
7
+ test "Category has an associated validator on products" do
8
+ assert_associated Category, :products
9
+ end
10
+
11
+ {
12
+ acceptance: :published,
13
+ absence: :deleted_at,
14
+ confirmation: :secret_code,
15
+ exclusion: [:type1, in: 0..5],
16
+ format: [:reference, with: /\A\w\d{9}\z/i],
17
+ inclusion: [:type2, in: 0..5],
18
+ length: [:secret_code, is: 4],
19
+ presence: :name,
20
+ uniqueness: :reference
21
+ }.each do |validator, value|
22
+ attribute, options = *Array(value)
23
+ test "Product has a #{validator} validator on #{attribute}" do
24
+ send("assert_#{validator}_of", Product, attribute, options)
25
+ end
26
+ end
27
+
28
+ test 'Product has a length validator on name' do
29
+ assert_length_of Product, :name, maximum: 30
30
+ end
31
+
32
+ test 'Product has format & uniqueness validators on reference' do
33
+ assert_validates Product, :reference, format: { with: /\A\w\d{9}\z/i }, uniqueness: true
34
+ end
35
+
36
+ test 'Product has a presence validator on name (validator)' do
37
+ assert_validator :presence, Product, :name
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ require 'active_record'
4
+
5
+ class Category < ActiveRecord::Base
6
+ has_many :products, inverse_of: :category
7
+
8
+ validates :products, associated: true
9
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ require 'active_record'
4
+
5
+ class Product < ActiveRecord::Base
6
+ belongs_to :category, inverse_of: :products
7
+
8
+ validates :type1, exclusion: { in: 0..5 }
9
+ validates :type2, inclusion: { in: 0..5 }
10
+ validates :quantity, numericality: true
11
+ validates :name, presence: true
12
+ validates :reference, uniqueness: true, format: { with: /\A\w\d{9}\z/i }
13
+ validates :secret_code, confirmation: true, length: { is: 4 }
14
+ validates :published, acceptance: true
15
+ validates :deleted_at, absence: true
16
+ # Alias of validates_length_of
17
+ validates_size_of :name, maximum: 30
18
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'active_record'
4
+
5
+ ActiveRecord::Base.establish_connection adapter: :nulldb
6
+
7
+ silence_stream(STDOUT) do
8
+ ActiveRecord::Schema.define do
9
+ create_table :cateogries do |t|
10
+ t.integer :status, default: 0
11
+ t.string :name, null: false
12
+ end
13
+
14
+ create_table :products do |t|
15
+ t.references :category
16
+ t.string :type1, default: 0
17
+ t.string :type2, default: 0
18
+ t.integer :quantity, default: 0
19
+ t.string :name, null: false
20
+ t.string :reference, null: false
21
+ t.string :secret_code, null: false
22
+ t.boolean :published, default: false
23
+ t.datetime :deleted_at
24
+ end
25
+
26
+ add_index :products, :category_id
27
+ add_index :products, :reference, unique: true
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require 'codeclimate-test-reporter'
4
+
5
+ CodeClimate::TestReporter.start
6
+
7
+ require 'minitest/rails/assertions'
8
+ require 'minitest/autorun'
9
+ require 'minitest/pride'
10
+
11
+ require 'schema'
12
+ require 'models/category'
13
+ require 'models/product'
14
+
15
+ class Minitest::Test
16
+ def self.test(name, &block)
17
+ test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
18
+
19
+ if method_defined?(test_name)
20
+ raise "#{test_name} is already defined in #{self}"
21
+ end
22
+
23
+ if block_given?
24
+ define_method(test_name, &block)
25
+ else
26
+ define_method(test_name) do
27
+ flunk "No implementation provided for #{name}"
28
+ end
29
+ end
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-rails-assertions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Geoffrey Roguelon
8
+ - Loïc Sence
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '5.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '3.0'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: activerecord-nulldb-adapter
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.3.1
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.3.1
76
+ description: The gem minitest-rails-assertions extends MiniTest to add some assertions
77
+ to Rails tests.
78
+ email:
79
+ - geoffrey.roguelon@gmail.com
80
+ - senceloic@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - ".gitignore"
86
+ - ".travis.yml"
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - lib/minitest-rails-assertions.rb
92
+ - lib/minitest/rails/assertions.rb
93
+ - lib/minitest/rails/assertions/validations.rb
94
+ - lib/minitest/rails/assertions/version.rb
95
+ - minitest-rails-assertions.gemspec
96
+ - test/minitest/rails/assertions/validations_test.rb
97
+ - test/models/category.rb
98
+ - test/models/product.rb
99
+ - test/schema.rb
100
+ - test/test_helper.rb
101
+ homepage: https://github.com/jules-vernes/minitest-rails-assertions
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 1.9.3
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: The gem minitest-rails-assertions extends MiniTest to add some assertions
125
+ to Rails tests.
126
+ test_files:
127
+ - test/minitest/rails/assertions/validations_test.rb
128
+ - test/models/category.rb
129
+ - test/models/product.rb
130
+ - test/schema.rb
131
+ - test/test_helper.rb