rspec-validator_spec_helper 0.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +2 -0
- data/lib/rspec/validator_spec_helper/version.rb +5 -0
- data/lib/rspec/validator_spec_helper.rb +55 -0
- data/rspec-validator_spec_helper.gemspec +22 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dc5817910463f1eb0d0b60d9d78429a8af45791f
|
4
|
+
data.tar.gz: 887074bd2c22a50d23c98e26672e87de64d7809f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eccee850f3c6e50e5a2733572f9b3c6b688de4ecd9760637caee4e8df9e5a113459975a56a26c2ae9528b6c49cb3bbbdb181908cffc04339a3e1042b7f1b5c30
|
7
|
+
data.tar.gz: da323cf8d5258ac0f3c69aba77d61b28b4a066b910ad92e5d270b55124d16f2e8e2c5e75bfd960cfa4ca0752db09afc9d46d44d4d4880270a393896c836c9bac
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 izumin5210
|
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,73 @@
|
|
1
|
+
# RSpec::ValidatorSpecHelper
|
2
|
+
|
3
|
+
Provide dummy class for validator spec
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile, then execute `bundle install`.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rspec-validator_spec_helper'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then include `Rspec::ValidatorSpecHelper` into your `RSpec.configuration`.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
# spec/rails_helper.rb or spec/spec_helper.rb
|
17
|
+
RSpec.configure do |config|
|
18
|
+
|
19
|
+
config.include RSpec::ValidatorSpecHelper, type: :validator
|
20
|
+
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
`RSpec::ValidatorSpecHelper` provides some `let` and `subject` to your example groups.
|
28
|
+
|
29
|
+
|
30
|
+
### EachValidator
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
describe EmailValidator, type: :validator do
|
34
|
+
describe '#validate_each' do
|
35
|
+
context 'with invalid format address' do
|
36
|
+
let(:value) { 'kokoro.pyonpyon' }
|
37
|
+
it { is_expected.to_not be_valid }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with valid foramt address' do
|
41
|
+
let(:value) { 'kokoro.pyonpyon@example.com' }
|
42
|
+
it { is_expected.to be_valid }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
|
49
|
+
### Validator
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
describe NotOverlappedValidator, type: :validator do
|
53
|
+
let(:attribute_names) { [:begin_at, :end] }
|
54
|
+
let(:begin_at) { Time.parse("2014-12-24T12:00:00+09:00") }
|
55
|
+
|
56
|
+
describe '#validate' do
|
57
|
+
context 'when end_at is overlapped' do
|
58
|
+
let(:end_at) { Time.parse("2014-12-24T09:00:00+09:00") }
|
59
|
+
it { is_expected.to_not be_valid }
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when end_at is not overlapped' do
|
63
|
+
let(:end_at) { Time.parse("2014-12-24T19:00:00+09:00") }
|
64
|
+
it { is_expected.to be_valid }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
RSpec::ValidatorSpecHelper is licensed under [MIT-LICENSE](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "rspec/validator_spec_helper/version"
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module ValidatorSpecHelper
|
5
|
+
ATTRIBUTE_NAME = :value
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.instance_eval do
|
9
|
+
let(:validator_name) do |example|
|
10
|
+
example.full_description.match(/\A\w+Validator/)[0]
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:validator_class) { Object.const_get(validator_name) }
|
14
|
+
|
15
|
+
let(:validator_type) do
|
16
|
+
if validator_class.ancestors.include? ActiveModel::EachValidator
|
17
|
+
ActiveModel::EachValidator
|
18
|
+
else
|
19
|
+
ActiveModel::Validator
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:validation_name) do
|
24
|
+
validator_name.underscore.gsub(/_validator\Z/, '')
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:attribute_names) { [ATTRIBUTE_NAME] }
|
28
|
+
|
29
|
+
let(ATTRIBUTE_NAME) { nil }
|
30
|
+
|
31
|
+
let(:model_class) do
|
32
|
+
example_group = self
|
33
|
+
Struct.new(*attribute_names) do
|
34
|
+
include ActiveModel::Validations
|
35
|
+
|
36
|
+
def self.name
|
37
|
+
'DummyModel'
|
38
|
+
end
|
39
|
+
|
40
|
+
if example_group.validator_type == ActiveModel::EachValidator
|
41
|
+
validates ATTRIBUTE_NAME, :"#{example_group.validation_name}" => true
|
42
|
+
else
|
43
|
+
validates_with example_group.validator_class
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
subject do
|
49
|
+
attributes = attribute_names.map { |name| eval("#{name}") }
|
50
|
+
model_class.new(*attributes)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/validator_spec_helper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-validator_spec_helper"
|
8
|
+
spec.version = RSpec::ValidatorSpecHelper::VERSION
|
9
|
+
spec.authors = ["Masayuki IZUMI"]
|
10
|
+
spec.email = ["masayuki@izumin.info"]
|
11
|
+
spec.summary = "Provide dummy class for validator spec"
|
12
|
+
spec.homepage = "https://github.com/izumin5210/rspec-validator_spec_helper"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-validator_spec_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masayuki IZUMI
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-27 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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
|
+
- masayuki@izumin.info
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/rspec/validator_spec_helper.rb
|
54
|
+
- lib/rspec/validator_spec_helper/version.rb
|
55
|
+
- rspec-validator_spec_helper.gemspec
|
56
|
+
homepage: https://github.com/izumin5210/rspec-validator_spec_helper
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Provide dummy class for validator spec
|
80
|
+
test_files: []
|