rspec-validator_spec_helper 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc5817910463f1eb0d0b60d9d78429a8af45791f
4
- data.tar.gz: 887074bd2c22a50d23c98e26672e87de64d7809f
3
+ metadata.gz: 996cd70358d1d0faada5b70da30d2243b88ca1c1
4
+ data.tar.gz: f43a179c8120a6abb2fde94f649e5b79fcca4906
5
5
  SHA512:
6
- metadata.gz: eccee850f3c6e50e5a2733572f9b3c6b688de4ecd9760637caee4e8df9e5a113459975a56a26c2ae9528b6c49cb3bbbdb181908cffc04339a3e1042b7f1b5c30
7
- data.tar.gz: da323cf8d5258ac0f3c69aba77d61b28b4a066b910ad92e5d270b55124d16f2e8e2c5e75bfd960cfa4ca0752db09afc9d46d44d4d4880270a393896c836c9bac
6
+ metadata.gz: 4bf7d2bc198ef12bfd84bbda2025fea1ea33a0d9b1c58ba6a6ebdcfed34c2ee17fa6eb54b4b0d56d9046b6e1e358f7e84c4cae98b76162c822ac9a27e7674559
7
+ data.tar.gz: 90e7a7091b5460493d8273dfc5e5828008e4e87d117486dc3f130e79b435527f978e71e56569d4154ed40c7994dc9b445f18e24e722c5ea5abc2a607113330f4
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # RSpec::ValidatorSpecHelper
2
2
 
3
+ [![Build Status](https://travis-ci.org/izumin5210/rspec-validator_spec_helper.svg?branch=master)](https://travis-ci.org/izumin5210/rspec-validator_spec_helper)
4
+
3
5
  Provide dummy class for validator spec
4
6
 
5
7
  ## Installation
@@ -41,6 +43,12 @@ describe EmailValidator, type: :validator do
41
43
  let(:value) { 'kokoro.pyonpyon@example.com' }
42
44
  it { is_expected.to be_valid }
43
45
  end
46
+
47
+ context 'with strict option' do
48
+ let(:options) { { strict: true } }
49
+ let(:value) { 'kokoro..pyonpyon@example.com' }
50
+ it { is_expected.to_not be_valid }
51
+ end
44
52
  end
45
53
  end
46
54
  ```
@@ -50,7 +58,7 @@ end
50
58
 
51
59
  ```ruby
52
60
  describe NotOverlappedValidator, type: :validator do
53
- let(:attribute_names) { [:begin_at, :end] }
61
+ let(:attribute_names) { [:begin_at, :end_at] }
54
62
  let(:begin_at) { Time.parse("2014-12-24T12:00:00+09:00") }
55
63
 
56
64
  describe '#validate' do
@@ -63,6 +71,12 @@ describe NotOverlappedValidator, type: :validator do
63
71
  let(:end_at) { Time.parse("2014-12-24T19:00:00+09:00") }
64
72
  it { is_expected.to be_valid }
65
73
  end
74
+
75
+ context 'with allow_same_time option' do
76
+ let(:options) { { allow_same_time: true } }
77
+ let(:end_at) { begin_at }
78
+ it { is_expected.to be_valid }
79
+ end
66
80
  end
67
81
  end
68
82
  ```
@@ -1,4 +1,7 @@
1
1
  require "rspec/validator_spec_helper/version"
2
+ require 'active_model'
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
2
5
 
3
6
  module RSpec
4
7
  module ValidatorSpecHelper
@@ -28,6 +31,8 @@ module RSpec
28
31
 
29
32
  let(ATTRIBUTE_NAME) { nil }
30
33
 
34
+ let(:options) { nil }
35
+
31
36
  let(:model_class) do
32
37
  example_group = self
33
38
  Struct.new(*attribute_names) do
@@ -38,9 +43,14 @@ module RSpec
38
43
  end
39
44
 
40
45
  if example_group.validator_type == ActiveModel::EachValidator
41
- validates ATTRIBUTE_NAME, :"#{example_group.validation_name}" => true
46
+ args = { :"#{example_group.validation_name}" => (example_group.options || true) }
47
+ validates ATTRIBUTE_NAME, args
42
48
  else
43
- validates_with example_group.validator_class
49
+ if example_group.options.nil?
50
+ validates_with example_group.validator_class
51
+ else
52
+ validates_with example_group.validator_class, example_group.options
53
+ end
44
54
  end
45
55
  end
46
56
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module ValidatorSpecHelper
3
- VERSION = "0.0.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -17,6 +17,9 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
+ spec.add_dependency "rspec", "~> 3.0"
21
+ spec.add_dependency "activemodel"
22
+ spec.add_dependency "activesupport"
20
23
  spec.add_development_dependency "bundler", "~> 1.7"
21
24
  spec.add_development_dependency "rake", "~> 10.0"
22
25
  end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RSpec::ValidatorSpecHelper do
4
+ context 'when the spec is for a validator extended AM::EachValidator' do
5
+ include RSpec::ValidatorSpecHelper
6
+ before(:all) do
7
+ TestEachValidator = Class.new(ActiveModel::EachValidator)
8
+ end
9
+
10
+ before do
11
+ allow(RSpec).to(
12
+ receive_message_chain(:current_example, :full_description)
13
+ .and_return('TestEachValidator')
14
+ )
15
+ end
16
+
17
+ it { expect(validator_class).to eq TestEachValidator }
18
+ it { expect(validator_type).to eq ActiveModel::EachValidator }
19
+ it { expect(validator_name).to eq 'TestEachValidator' }
20
+ it { expect(validation_name).to eq 'test_each' }
21
+ it { expect(value).to be_nil }
22
+
23
+ it 'includes ActiveModel::Validations' do
24
+ expect(model_class).to be_include(ActiveModel::Validations)
25
+ end
26
+
27
+ it 'has TestValidator' do
28
+ expect(model_class.validators).to(be_any { |v| v.is_a? TestEachValidator })
29
+ end
30
+
31
+ it { expect(value).to be_nil }
32
+ it { is_expected.to be_a model_class }
33
+ it { expect(subject.value).to eq value }
34
+
35
+ context 'when the validator has some options' do
36
+ let(:options) { { gochiusa: 'kokoro pyonpyon' } }
37
+ let(:validator) do
38
+ model_class.validators.find { |v| v.is_a? TestEachValidator }
39
+ end
40
+
41
+ it { expect(validator.options).to be_key(:gochiusa) }
42
+ it { expect(validator.options).to be_value(options[:gochiusa]) }
43
+ end
44
+ end
45
+
46
+ context 'when the spec is for a validator extended AM::Validator' do
47
+ include RSpec::ValidatorSpecHelper
48
+ before(:all) do
49
+ TestValidator = Class.new(ActiveModel::Validator)
50
+ end
51
+
52
+ before do
53
+ allow(RSpec).to(
54
+ receive_message_chain(:current_example, :full_description)
55
+ .and_return('TestValidator')
56
+ )
57
+ end
58
+
59
+ it { expect(validator_class).to eq TestValidator }
60
+ it { expect(validator_type).to eq ActiveModel::Validator }
61
+ it { expect(validator_name).to eq 'TestValidator' }
62
+ it { expect(validation_name).to eq 'test' }
63
+ it { expect(value).to be_nil }
64
+
65
+ it 'includes ActiveModel::Validations' do
66
+ expect(model_class).to be_include(ActiveModel::Validations)
67
+ end
68
+
69
+ it 'has TestValidator' do
70
+ expect(model_class.validators).to(be_any { |v| v.is_a? TestValidator })
71
+ end
72
+
73
+ context 'when attribute_names has not set' do
74
+ it { expect(value).to be_nil }
75
+ it { is_expected.to be_a model_class }
76
+ it { expect(subject.value).to eq value }
77
+ end
78
+
79
+ context 'when attribute_names has set' do
80
+ let(:attribute_names) { %i(value1 value2 value3) }
81
+ let(:value1) { 'Cocoa' }
82
+ let(:value2) { 'Chino' }
83
+ let(:value3) { 'Rize' }
84
+
85
+ it { is_expected.to be_a model_class }
86
+ it { expect(subject.value1).to eq value1 }
87
+ it { expect(subject.value2).to eq value2 }
88
+ it { expect(subject.value3).to eq value3 }
89
+ end
90
+
91
+ context 'when the validator has some options' do
92
+ let(:options) { { gochiusa: 'kokoro pyonpyon' } }
93
+ let(:validator) do
94
+ model_class.validators.find { |v| v.is_a? TestValidator }
95
+ end
96
+
97
+ it { expect(validator.options).to be_key(:gochiusa) }
98
+ it { expect(validator.options).to be_value(options[:gochiusa]) }
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'rspec/validator_spec_helper'
3
+
4
+ Dir['./spec/support/**/*.rb'].each { |f| require f }
5
+
6
+ RSpec.configure do |config|
7
+ config.include RSpec::ValidatorSpecHelper, type: :validator
8
+ end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-validator_spec_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masayuki IZUMI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-27 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  - !ruby/object:Gem::Dependency
14
56
  name: bundler
15
57
  requirement: !ruby/object:Gem::Requirement
@@ -46,6 +88,8 @@ extensions: []
46
88
  extra_rdoc_files: []
47
89
  files:
48
90
  - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
49
93
  - Gemfile
50
94
  - LICENSE.txt
51
95
  - README.md
@@ -53,6 +97,8 @@ files:
53
97
  - lib/rspec/validator_spec_helper.rb
54
98
  - lib/rspec/validator_spec_helper/version.rb
55
99
  - rspec-validator_spec_helper.gemspec
100
+ - spec/rspec/validator_spec_helper_spec.rb
101
+ - spec/spec_helper.rb
56
102
  homepage: https://github.com/izumin5210/rspec-validator_spec_helper
57
103
  licenses:
58
104
  - MIT
@@ -73,8 +119,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
119
  version: '0'
74
120
  requirements: []
75
121
  rubyforge_project:
76
- rubygems_version: 2.2.2
122
+ rubygems_version: 2.4.5
77
123
  signing_key:
78
124
  specification_version: 4
79
125
  summary: Provide dummy class for validator spec
80
- test_files: []
126
+ test_files:
127
+ - spec/rspec/validator_spec_helper_spec.rb
128
+ - spec/spec_helper.rb