validation_matcher 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.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/README.md +37 -0
- data/Rakefile +5 -0
- data/lib/validation_matcher/version.rb +3 -0
- data/lib/validation_matcher.rb +37 -0
- data/spec/matchers_spec.rb +9 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/thing_spec.rb +8 -0
- data/validation_matcher.gemspec +26 -0
- metadata +104 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
Validation Matcher
|
2
|
+
==================
|
3
|
+
|
4
|
+
Use Rails 3 validation reflection to test validations.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Add to your Gemfile and run the `bundle` command to install it.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'validation_matcher'
|
13
|
+
```
|
14
|
+
|
15
|
+
**Requires Ruby 1.9.2 or later.**
|
16
|
+
|
17
|
+
Usage
|
18
|
+
-----
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
class Foo < ActiveRecord::Base
|
22
|
+
validates :field_a, presence: true
|
23
|
+
validates :field_b, uniquness: true
|
24
|
+
validates :field_c, presence: true, uniquness: {case_insensitive: false}
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'spec_helper'
|
28
|
+
|
29
|
+
describe Subscription do
|
30
|
+
|
31
|
+
its(:field_a) { should validate :presence }
|
32
|
+
its(:field_b) { should validate :uniqueness }
|
33
|
+
its(:field_c) { should validate :presence }
|
34
|
+
its(:field_c) { should validate :uniqueness, { case_insensitive: false }}
|
35
|
+
|
36
|
+
end
|
37
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'validation_matcher/version'
|
2
|
+
|
3
|
+
module ValidationMatcher
|
4
|
+
|
5
|
+
RSpec::Matchers.define :validate do |kind, expected_options|
|
6
|
+
|
7
|
+
field = example.metadata[:example_group][:description_args].first
|
8
|
+
validator = described_class.validators_on(field).detect { |v| v.kind == kind }
|
9
|
+
options = validator.options rescue {}
|
10
|
+
|
11
|
+
diff = expected_options.present? ? options.diff(expected_options) : nil
|
12
|
+
|
13
|
+
description do
|
14
|
+
msg = "validate the #{ kind } of #{ field.inspect }"
|
15
|
+
msg += " with options: #{ expected_options.inspect }" unless expected_options.blank?
|
16
|
+
msg
|
17
|
+
end
|
18
|
+
|
19
|
+
failure_message_for_should do
|
20
|
+
msg = "Expected #{ described_class } to validate the #{ kind } of #{ field.inspect }"
|
21
|
+
if expected_options.present? and diff.present?
|
22
|
+
msg += "\n with options: #{ expected_options.inspect }"
|
23
|
+
msg += "\n actual options: #{ options.inspect }"
|
24
|
+
end
|
25
|
+
msg
|
26
|
+
end
|
27
|
+
|
28
|
+
failure_message_for_should_not do
|
29
|
+
"Did not expect #{ described_class } to validate the #{ kind } of #{ field.inspect }"
|
30
|
+
end
|
31
|
+
|
32
|
+
match_for_should { validator.present? and diff.blank? }
|
33
|
+
match_for_should_not { validator.blank? }
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/thing_spec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'validation_matcher/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'validation_matcher'
|
7
|
+
s.version = ValidationMatcher::VERSION
|
8
|
+
s.authors = ['BM5k']
|
9
|
+
s.email = ['me@bm5k.com']
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = 'RSpec matcher for ActiveModel validations'
|
12
|
+
s.description = 'Use reflection to spec ActiveModel validations'
|
13
|
+
|
14
|
+
s.rubyforge_project = 'validation_matcher'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
s.add_dependency 'rspec', '~> 2.8.0'
|
22
|
+
|
23
|
+
s.add_development_dependency 'supermodel'
|
24
|
+
s.add_development_dependency 'pry'
|
25
|
+
s.add_development_dependency 'pry-nav'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validation_matcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- BM5k
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70184564228100 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.8.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70184564228100
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: supermodel
|
27
|
+
requirement: &70184564225040 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70184564225040
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: pry
|
38
|
+
requirement: &70184564222540 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70184564222540
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: pry-nav
|
49
|
+
requirement: &70184564237080 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70184564237080
|
58
|
+
description: Use reflection to spec ActiveModel validations
|
59
|
+
email:
|
60
|
+
- me@bm5k.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rspec
|
67
|
+
- Gemfile
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- lib/validation_matcher.rb
|
71
|
+
- lib/validation_matcher/version.rb
|
72
|
+
- spec/matchers_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
- spec/thing_spec.rb
|
75
|
+
- validation_matcher.gemspec
|
76
|
+
homepage: ''
|
77
|
+
licenses: []
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project: validation_matcher
|
96
|
+
rubygems_version: 1.8.10
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: RSpec matcher for ActiveModel validations
|
100
|
+
test_files:
|
101
|
+
- spec/matchers_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- spec/thing_spec.rb
|
104
|
+
has_rdoc:
|