validation_examples_matcher 1.0.0 → 1.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 +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +69 -11
- data/lib/validation_examples_matcher/version.rb +1 -1
- data/validation_examples_matcher.gemspec +1 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ace3e8e1efed6fca03a249353e5be6eb1db18d0
|
4
|
+
data.tar.gz: bd3acefb442dfe8d8c6ad997f48f6d881096faf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54d61c7ae81f88aeb9ca2878c12a1799b42c0eeed86d7f4950e23e7d328fde77f8b1b72e764224022670c932c65cefb0da6590e2bdf8476b0d1a079441dc953f
|
7
|
+
data.tar.gz: b21a715342da52f17a716506291f40f9cba03164933fb751a6e151c202cc21b0c40509b4b88a0aa23b20b776e908dbc7de4379e86742753ca7987c8df16c0794
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [v1.0.1](https://github.com/nisshiee/validation_examples_matcher/tree/v1.0.1)
|
4
|
+
|
5
|
+
2016-01-31
|
6
|
+
|
7
|
+
- NOTHING changed in production code
|
8
|
+
- [[#6](https://github.com/nisshiee/validation_examples_matcher/pull/6)] Add README
|
9
|
+
- [[#8](https://github.com/nisshiee/validation_examples_matcher/pull/8)] Mesure coverage
|
10
|
+
|
11
|
+
## [v1.0.0](https://github.com/nisshiee/validation_examples_matcher/tree/v1.0.0)
|
12
|
+
|
13
|
+
2016-01-26
|
14
|
+
|
15
|
+
- First Release
|
data/README.md
CHANGED
@@ -2,9 +2,22 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/nisshiee/validation_examples_matcher)
|
4
4
|
|
5
|
-
|
5
|
+
ValidationExamplesMatcher supports writing rails model's validation specs.
|
6
6
|
|
7
|
-
|
7
|
+
e.g.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
RSpec.describe MyModel do
|
11
|
+
...
|
12
|
+
|
13
|
+
it { is_expected.to be_invalid_on(:name).with(nil) }
|
14
|
+
it { is_expected.to be_invalid_on(:name).with('') }
|
15
|
+
it { is_expected.to be_valid_on(:name).with('my name') }
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
ValidationExamplesMatcher sets a particular value ― nil, empty string and 'my name' ― actually.
|
20
|
+
Then the matcher calls `valid?` or `invalid?` method and checks results of validation.
|
8
21
|
|
9
22
|
## Installation
|
10
23
|
|
@@ -18,26 +31,71 @@ And then execute:
|
|
18
31
|
|
19
32
|
$ bundle
|
20
33
|
|
21
|
-
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
Let me show how to use ValidationExamplesMatcher in case of following model.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
class MyModel < ActiveRecord::Base
|
40
|
+
validates :name, presence: true
|
41
|
+
validates :name, length: { maxmum: 4 }, on: :create
|
42
|
+
end
|
43
|
+
```
|
22
44
|
|
23
|
-
|
45
|
+
First, you have to define `subject` as target model object.
|
46
|
+
It's good to define it as *valid* object.
|
47
|
+
Creating object with [factory_girl](https://github.com/thoughtbot/factory_girl) is very nice.
|
24
48
|
|
25
|
-
|
49
|
+
```ruby
|
50
|
+
RSpec.define MyModel do
|
51
|
+
subject { FactoryGirl.build(:my_model) }
|
52
|
+
# subject { MyModel.new } => also ok but not recommended
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
Second, write *invalid case examples* and *valid case examples* using ValidationExamplesMatcher.
|
57
|
+
In case of `MyModel`, `:name` attribute is invalid when its' value is nil or empty string.
|
58
|
+
`'my name'` is typical valid example.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
RSpec.define MyModel do
|
62
|
+
subject { FactoryGirl.build(:my_model) }
|
63
|
+
|
64
|
+
it { is_expected.to be_invalid_on(:name).with(nil) }
|
65
|
+
it { is_expected.to be_invalid_on(:name).with('') }
|
66
|
+
it { is_expected.to be_valid_on(:name).with('my name') }
|
67
|
+
end
|
68
|
+
```
|
26
69
|
|
27
|
-
|
70
|
+
Arguments of `be_invalid_on` or `be_valid_on` indicate attribute name.
|
71
|
+
And arguments of `with` chain is a value which will be set to the attribute.
|
28
72
|
|
29
|
-
|
73
|
+
`ActiveModel::Validations` can define validations on specific contexts.
|
74
|
+
`MyModel` has `length` validation only on `:create` context.
|
75
|
+
You can also define validation spec for such case using `on_context` chain.
|
30
76
|
|
31
|
-
|
77
|
+
```ruby
|
78
|
+
RSpec.define MyModel do
|
79
|
+
subject { FactoryGirl.build(:my_model) }
|
80
|
+
|
81
|
+
it { is_expected.to be_invalid_on(:name).with(nil) }
|
82
|
+
it { is_expected.to be_invalid_on(:name).with('') }
|
83
|
+
it { is_expected.to be_valid_on(:name).with('my name') }
|
84
|
+
|
85
|
+
it { is_expected.to be_valid_on(:name).with('4cha').on_context(:create) }
|
86
|
+
it { is_expected.to be_invalid_on(:name).with('5char').on_context(:create) }
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
## Changelog
|
32
91
|
|
33
|
-
|
92
|
+
see [CHANGELOG.md](./CHANGELOG.md)
|
34
93
|
|
35
94
|
## Contributing
|
36
95
|
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
96
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nisshiee/validation_examples_matcher.
|
38
97
|
|
39
98
|
|
40
99
|
## License
|
41
100
|
|
42
101
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
43
|
-
|
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.11'
|
26
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'simplecov', '>= 0.11.1', '< 0.12.0'
|
28
29
|
spec.add_development_dependency 'activemodel', '~> 4.2.5'
|
29
30
|
spec.add_development_dependency 'pry-byebug', '~> 3.3.0'
|
30
31
|
spec.add_development_dependency 'rubocop', '>= 0.36.0', '< 0.37.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_examples_matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hirokazu Nishioka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-expectations
|
@@ -66,6 +66,26 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.11.1
|
76
|
+
- - "<"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.12.0
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.11.1
|
86
|
+
- - "<"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.12.0
|
69
89
|
- !ruby/object:Gem::Dependency
|
70
90
|
name: activemodel
|
71
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +147,7 @@ files:
|
|
127
147
|
- ".rubocop.yml"
|
128
148
|
- ".rubocop_todo.yml"
|
129
149
|
- ".travis.yml"
|
150
|
+
- CHANGELOG.md
|
130
151
|
- Gemfile
|
131
152
|
- LICENSE.txt
|
132
153
|
- README.md
|