assertion 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Guardfile +0 -5
- data/README.md +69 -6
- data/Rakefile +1 -1
- data/assertion.gemspec +3 -2
- data/config/metrics/flay.yml +1 -1
- data/config/metrics/metric_fu.yml +0 -1
- data/lib/assertion/base.rb +9 -4
- data/lib/assertion/guard.rb +1 -1
- data/lib/assertion/invalid_error.rb +2 -2
- data/lib/assertion/inversion.rb +1 -1
- data/lib/assertion/inverter.rb +1 -1
- data/lib/assertion/rspec.rb +156 -0
- data/lib/assertion/state.rb +2 -2
- data/lib/assertion/translator.rb +3 -4
- data/lib/assertion/version.rb +1 -1
- data/lib/assertion.rb +3 -4
- data/spec/integration/rspec_spec.rb +75 -0
- data/spec/shared/fr.yml +10 -0
- metadata +26 -21
- data/lib/assertion/inflector.rb +0 -41
- data/spec/unit/assertion/inflector/to_path_spec.rb +0 -19
- data/spec/unit/assertion/inflector/to_snake_path_spec.rb +0 -19
- data/spec/unit/assertion/inflector/to_snake_spec.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3c17905def77d1f6f9366a2fd4f3a7326cf5c8c
|
4
|
+
data.tar.gz: eeb118194902e69f6ab5ab44a77183e2d0f32ebe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dfbe9226b7fede756b1b9e30890b880afa3495758677d1b2530900f44ddf0fbf3b27d56101bb984c4d8e426902647d6c17319dfcc2a6765ad8bf001a8bd53f3
|
7
|
+
data.tar.gz: 5e99ccb9c8a6228f0f027556dc0cacf4ec2f099a1a3cfa947a2843ab34e96c17512d0074888aaee44f3c5c5a86c8ab86c7a12ddd8b2659f90b5dbbdf55503ed2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## v0.2.2 2015-07-11
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* New shared examples: `:validating_assertions`, and `:accepting_objects`
|
6
|
+
to specify assertions and guards correspondingly (nepalez)
|
7
|
+
|
8
|
+
### Internal
|
9
|
+
|
10
|
+
* Switched to `ice_nine` gem to freezing objects deeply (nepalez)
|
11
|
+
* Switched to `inflecto` and dropped module own transformations (nepalez)
|
12
|
+
|
13
|
+
[Compare v0.2.1...v0.2.2](https://github.com/nepalez/assertion/compare/v0.2.1...0.2.2)
|
14
|
+
|
1
15
|
## v0.2.1 2015-06-23
|
2
16
|
|
3
17
|
### Bugs Fixed
|
data/Guardfile
CHANGED
@@ -8,11 +8,6 @@ guard :rspec, cmd: "bundle exec rspec" do
|
|
8
8
|
"spec/unit/#{m[1]}_spec.rb"
|
9
9
|
end
|
10
10
|
|
11
|
-
watch("lib/assertion/dsl.rb") { "spec/unit/assertion_spec.rb" }
|
12
|
-
watch("lib/assertion/base_dsl.rb") { "spec/unit/assertion/base_spec.rb" }
|
13
|
-
watch("lib/assertion/guard_dsl.rb") { "spec/unit/assertion/guard_spec.rb" }
|
14
|
-
watch("lib/assertion/inflector.rb") { "spec/unit/assertion/inflector" }
|
15
|
-
|
16
11
|
watch("spec/spec_helper.rb") { "spec" }
|
17
12
|
|
18
13
|
end # guard :rspec
|
data/README.md
CHANGED
@@ -15,14 +15,14 @@ Assertion
|
|
15
15
|
[travis]: https://travis-ci.org/nepalez/assertion
|
16
16
|
[inch]: https://inch-ci.org/github/nepalez/assertion
|
17
17
|
|
18
|
-
|
18
|
+
Standalone PORO assertions and validations.
|
19
19
|
|
20
20
|
Synopsis
|
21
21
|
--------
|
22
22
|
|
23
|
-
The primary goal of the gem is to make assertions about
|
23
|
+
The primary goal of the gem is to make standalone assertions about objects and validate them.
|
24
24
|
|
25
|
-
No
|
25
|
+
No monkey patching, no dependency from ActiveSupport, no mutable instances of any class.
|
26
26
|
|
27
27
|
[About](https://github.com/mbj/mutant/issues/356) 100% [mutant]-covered.
|
28
28
|
|
@@ -174,14 +174,77 @@ This is not necessary, but for verbosity you could follow the rules:
|
|
174
174
|
Edge Cases
|
175
175
|
----------
|
176
176
|
|
177
|
-
You cannot define attributes with names already defined as istance methods
|
177
|
+
You cannot define attributes with names already defined as istance methods,
|
178
|
+
or reserved by `Base#check` and `Guard#state`:
|
178
179
|
|
179
180
|
```ruby
|
180
181
|
IsAdult = Assertion.about :check
|
181
|
-
# => #<Assertion::NameError @message="
|
182
|
+
# => #<Assertion::NameError @message="IsAdult#check is already defined">
|
182
183
|
|
183
184
|
AdultOnly = Assertion.guards :state
|
184
|
-
# => #<Assertion::NameError @message="
|
185
|
+
# => #<Assertion::NameError @message="AdultOnly#state is already defined">
|
186
|
+
```
|
187
|
+
|
188
|
+
Testing
|
189
|
+
-------
|
190
|
+
|
191
|
+
The gem provides two sets of RSpec shared examples to specify assertions and guards in the expressive way.
|
192
|
+
To include them, require `assertion/rspec`.
|
193
|
+
|
194
|
+
### Assertions
|
195
|
+
|
196
|
+
Use `:validating_attributes` example:
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
require "spec_helper"
|
200
|
+
require "assertion/rspec"
|
201
|
+
|
202
|
+
describe IsAdult do # defines described_class
|
203
|
+
it_behaves_like :validating_attributes do
|
204
|
+
let(:attributes) { { name: "Joe", age: 10 } }
|
205
|
+
let(:locale) { :fr } # :en by default
|
206
|
+
|
207
|
+
subject(:valid) { false } # false by default
|
208
|
+
subject(:message) { "Joe est un enfant (10 ans)" } # can be skipped
|
209
|
+
end
|
210
|
+
end
|
211
|
+
```
|
212
|
+
|
213
|
+
If the spec description doesn't declare `described_class` implicitly, you should define `assertion` explicitly:
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
it_behaves_like :validating_attributes do
|
217
|
+
let(:assertion) { IsAdult }
|
218
|
+
# ...
|
219
|
+
end
|
220
|
+
```
|
221
|
+
|
222
|
+
### Guards
|
223
|
+
|
224
|
+
Use `:accepting_object` example:
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
require "spec_helper"
|
228
|
+
require "assertion/rspec"
|
229
|
+
|
230
|
+
describe IsAdult do # defines described_class
|
231
|
+
it_behaves_like :accepting_object do
|
232
|
+
let(:object) { { name: "Joe", age: 10 } }
|
233
|
+
let(:locale) { :fr } # :en by default
|
234
|
+
|
235
|
+
subject(:accepted) { false } # false by default
|
236
|
+
subject(:message) { "Joe est un enfant (10 ans)" } # can be skipped
|
237
|
+
end
|
238
|
+
end
|
239
|
+
```
|
240
|
+
|
241
|
+
If the spec description doesn't declare `described_class` implicitly, you should define `guard` explicitly:
|
242
|
+
|
243
|
+
```ruby
|
244
|
+
it_behaves_like :accepting_object do
|
245
|
+
let(:guard) { AdultOnly }
|
246
|
+
# ...
|
247
|
+
end
|
185
248
|
```
|
186
249
|
|
187
250
|
Installation
|
data/Rakefile
CHANGED
data/assertion.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.author = "Andrew Kozin"
|
9
9
|
gem.email = "andrew.kozin@gmail.com"
|
10
10
|
gem.homepage = "https://github.com/nepalez/assertion"
|
11
|
-
gem.summary = "PORO assertions and
|
11
|
+
gem.summary = "Standalone PORO assertions and validations"
|
12
12
|
gem.license = "MIT"
|
13
13
|
|
14
14
|
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
@@ -18,8 +18,9 @@ Gem::Specification.new do |gem|
|
|
18
18
|
|
19
19
|
gem.required_ruby_version = "~> 1.9"
|
20
20
|
|
21
|
-
gem.add_runtime_dependency "transproc", "~> 0.2", "> 0.2.3"
|
22
21
|
gem.add_runtime_dependency "i18n", "~> 0.7"
|
22
|
+
gem.add_runtime_dependency "ice_nine", "~> 0.11"
|
23
|
+
gem.add_runtime_dependency "inflecto", "~> 0.0"
|
23
24
|
|
24
25
|
gem.add_development_dependency "hexx-rspec", "~> 0.4"
|
25
26
|
gem.add_development_dependency "equalizer", "~> 0.0"
|
data/config/metrics/flay.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
---
|
2
|
-
minimum_score:
|
2
|
+
minimum_score: 8
|
data/lib/assertion/base.rb
CHANGED
@@ -39,14 +39,19 @@ module Assertion
|
|
39
39
|
extend DSL::Inversion
|
40
40
|
extend DSL::Caller
|
41
41
|
|
42
|
-
# The translator of states
|
42
|
+
# The class-specific translator of assertion states
|
43
43
|
#
|
44
|
-
# @
|
44
|
+
# @private
|
45
45
|
#
|
46
46
|
def self.translator
|
47
47
|
@translator ||= Translator.new(self)
|
48
48
|
end
|
49
49
|
|
50
|
+
# @private
|
51
|
+
def self.translate(state, attributes)
|
52
|
+
translator.call(state, attributes)
|
53
|
+
end
|
54
|
+
|
50
55
|
# @!attribute [r] attributes
|
51
56
|
#
|
52
57
|
# @example
|
@@ -74,7 +79,7 @@ module Assertion
|
|
74
79
|
def initialize(args = {})
|
75
80
|
keys = self.class.attributes
|
76
81
|
@attributes = Hash[keys.zip(args.values_at(*keys))]
|
77
|
-
|
82
|
+
IceNine.deep_freeze(self)
|
78
83
|
end
|
79
84
|
|
80
85
|
# Returns the message describing the current state
|
@@ -84,7 +89,7 @@ module Assertion
|
|
84
89
|
# @return [String]
|
85
90
|
#
|
86
91
|
def message(state = nil)
|
87
|
-
self.class.
|
92
|
+
self.class.translate(state, attributes)
|
88
93
|
end
|
89
94
|
|
90
95
|
# Calls the assertion checkup and returns the resulting state
|
data/lib/assertion/guard.rb
CHANGED
data/lib/assertion/inversion.rb
CHANGED
data/lib/assertion/inverter.rb
CHANGED
@@ -0,0 +1,156 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# ==============================================================================
|
4
|
+
# Collection of shared examples for testing assertions and guards
|
5
|
+
# ==============================================================================
|
6
|
+
|
7
|
+
shared_context :assertion_translations do
|
8
|
+
|
9
|
+
def lang
|
10
|
+
defined?(locale) ? locale : :en
|
11
|
+
end
|
12
|
+
|
13
|
+
# allows to skip check for error messages
|
14
|
+
def errors
|
15
|
+
defined?(messages) ? Array[*messages] : nil
|
16
|
+
end
|
17
|
+
|
18
|
+
around do |example|
|
19
|
+
old, I18n.locale = I18n.locale, lang
|
20
|
+
example.run
|
21
|
+
I18n.locale = old
|
22
|
+
end
|
23
|
+
|
24
|
+
end # shared context
|
25
|
+
|
26
|
+
# Specifies the assertion
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# it_behaves_like :validating_attributes do
|
30
|
+
# let(:assertion) { IsAdult }
|
31
|
+
# let(:attributes) { { name: "Joe", age: 10 } } # {} by default
|
32
|
+
# let(:locale) { :fr } # :en by default
|
33
|
+
# let(:message) { "Joe est un enfant (10 ans)" } # optional
|
34
|
+
# let(:valid) { false } # false by default
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# describe IsAdult do # `described_class` will be used instead of `assertion`
|
38
|
+
# it_behaves_like :validating_attributes do
|
39
|
+
# let(:attributes) { { name: "Joe", age: 18 } }
|
40
|
+
# let(:valid) { true }
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# it_behaves_like :validating_attributes do
|
44
|
+
# let(:attributes) { { name: "Joe", age: 10 } }
|
45
|
+
# let(:message) { "Joe is adult (age 10)" }
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
shared_examples :validating_attributes do
|
49
|
+
|
50
|
+
# allows to skip `assertion` definition when described_class is defined
|
51
|
+
def klass
|
52
|
+
defined?(assertion) ? assertion : described_class
|
53
|
+
end
|
54
|
+
|
55
|
+
# allows to skip `valid` definition to test messages only
|
56
|
+
def result
|
57
|
+
defined?(valid) ? valid : false
|
58
|
+
end
|
59
|
+
|
60
|
+
subject(:state) { klass[attributes] }
|
61
|
+
|
62
|
+
include_context :assertion_translations
|
63
|
+
|
64
|
+
it "[validates]" do
|
65
|
+
expect(state.valid?).to eql(result), <<-REPORT.gsub(/.+\|/, "")
|
66
|
+
|
|
67
|
+
|#{klass}[#{attributes.to_s[1..-2]}]
|
68
|
+
|
|
69
|
+
| expected: to be #{result ? "valid" : "invalid"}
|
70
|
+
| got: #{state.valid? ? "valid" : "invalid"}
|
71
|
+
REPORT
|
72
|
+
end
|
73
|
+
|
74
|
+
it "[raises expected message]" do
|
75
|
+
if !result && state.invalid? && errors
|
76
|
+
expect(state.messages)
|
77
|
+
.to match_array(errors), <<-REPORT.gsub(/.+\|/, "")
|
78
|
+
|
|
79
|
+
|Language: #{locale.to_s.upcase}
|
80
|
+
|Error messages from #{klass}[#{attributes.to_s[1..-2]}]
|
81
|
+
|
|
82
|
+
| expected: #{errors.inspect}
|
83
|
+
| got: #{state.messages.inspect}
|
84
|
+
REPORT
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end # shared examples
|
89
|
+
|
90
|
+
# Specifies the guard
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# it_behaves_like :accepting_object do
|
94
|
+
# let(:guard) { AdultOnly }
|
95
|
+
# let(:object) { { name: "Joe", age: 10 } }
|
96
|
+
# let(:locale) { :fr }
|
97
|
+
#
|
98
|
+
# subject(:accepted) { false }
|
99
|
+
# subject(:messages) { [""] }
|
100
|
+
# end
|
101
|
+
#
|
102
|
+
shared_examples :accepting_object do
|
103
|
+
|
104
|
+
# allows to skip `guard` definition when described_class is defined
|
105
|
+
def klass
|
106
|
+
defined?(guard) ? guard : described_class
|
107
|
+
end
|
108
|
+
|
109
|
+
# allows to skip `valid` definition to test messages only
|
110
|
+
def result
|
111
|
+
defined?(accepted) ? accepted : false
|
112
|
+
end
|
113
|
+
|
114
|
+
subject(:checkup) { guard[object] }
|
115
|
+
|
116
|
+
include_context :assertion_translations
|
117
|
+
|
118
|
+
it "[guards]" do
|
119
|
+
if result
|
120
|
+
expect { checkup }
|
121
|
+
.not_to raise_error, <<-REPORT.gsub(/.+\|/, "")
|
122
|
+
|
|
123
|
+
|#{klass}[#{object.inspect}]
|
124
|
+
|
|
125
|
+
| expected: #{object.inspect}
|
126
|
+
| got: #{begin; checkup; rescue => err; err.inspect; end}
|
127
|
+
REPORT
|
128
|
+
else
|
129
|
+
expect { checkup }
|
130
|
+
.to raise_error(Assertion::InvalidError), <<-REPORT.gsub(/.+\|/, "")
|
131
|
+
|
|
132
|
+
|#{klass}[#{object.inspect}]
|
133
|
+
|
|
134
|
+
| expected: #<Assertion::InvalidError>
|
135
|
+
| got: #{object.inspect}
|
136
|
+
REPORT
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "[raises expected message]" do
|
141
|
+
begin
|
142
|
+
checkup if !result && errors
|
143
|
+
rescue => err
|
144
|
+
expect(err.messages)
|
145
|
+
.to match_array(errors), <<-REPORT.gsub(/.+\|/, "")
|
146
|
+
|
|
147
|
+
|Language: #{locale.to_s.upcase}
|
148
|
+
|Error messages from #{klass}[#{object.inspect}]
|
149
|
+
|
|
150
|
+
| expected: #{errors.inspect}
|
151
|
+
| got: #{err.messages.inspect}
|
152
|
+
REPORT
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
end # shared examples
|
data/lib/assertion/state.rb
CHANGED
@@ -21,8 +21,8 @@ module Assertion
|
|
21
21
|
# @private
|
22
22
|
def initialize(state, *messages)
|
23
23
|
@state = state
|
24
|
-
@messages =
|
25
|
-
|
24
|
+
@messages = state ? [] : messages.flatten.uniq
|
25
|
+
IceNine.deep_freeze(self)
|
26
26
|
end
|
27
27
|
|
28
28
|
# @!attribute [r] messages
|
data/lib/assertion/translator.rb
CHANGED
@@ -46,7 +46,7 @@ module Assertion
|
|
46
46
|
# @return [Array<Symbol>]
|
47
47
|
#
|
48
48
|
def self.scope(klass)
|
49
|
-
[ROOT,
|
49
|
+
[ROOT, Inflecto.underscore(klass).to_sym]
|
50
50
|
end
|
51
51
|
|
52
52
|
# @!attribute [r] scope
|
@@ -73,13 +73,12 @@ module Assertion
|
|
73
73
|
def initialize(assertion)
|
74
74
|
@assertion = assertion
|
75
75
|
@scope = self.class.scope(assertion)
|
76
|
-
|
76
|
+
IceNine.deep_freeze(self)
|
77
77
|
end
|
78
78
|
|
79
79
|
# Returns the message describing the desired state of given assertion
|
80
80
|
#
|
81
|
-
# The translation is provided
|
82
|
-
# current class
|
81
|
+
# The translation is provided in a gem-specific scope for the current class
|
83
82
|
#
|
84
83
|
# @param [Boolean] state The state of the assertion
|
85
84
|
# @param [Hash] args The hash of arguments to be avaliable in a translation
|
data/lib/assertion/version.rb
CHANGED
data/lib/assertion.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require "
|
4
|
-
|
5
|
-
require_relative "assertion/inflector"
|
6
|
-
require_relative "assertion/invalid_error"
|
3
|
+
require "inflecto"
|
4
|
+
require "ice_nine"
|
7
5
|
|
8
6
|
require_relative "assertion/dsl/caller"
|
9
7
|
require_relative "assertion/dsl/attribute"
|
@@ -11,6 +9,7 @@ require_relative "assertion/dsl/attributes"
|
|
11
9
|
require_relative "assertion/dsl/inversion"
|
12
10
|
require_relative "assertion/dsl/builder"
|
13
11
|
|
12
|
+
require_relative "assertion/invalid_error"
|
14
13
|
require_relative "assertion/translator"
|
15
14
|
require_relative "assertion/state"
|
16
15
|
require_relative "assertion/base"
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "shared/i18n"
|
4
|
+
require "assertion/rspec"
|
5
|
+
|
6
|
+
describe "shared examples" do
|
7
|
+
|
8
|
+
include_context "preloaded translations"
|
9
|
+
|
10
|
+
before do
|
11
|
+
IsAdult = Assertion.about :name, :age do
|
12
|
+
age.to_i >= 18
|
13
|
+
end
|
14
|
+
|
15
|
+
AdultOnly = Assertion.guards :user do
|
16
|
+
IsAdult[user]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it_behaves_like :validating_attributes do
|
21
|
+
let(:assertion) { IsAdult }
|
22
|
+
let(:attributes) { { name: "Joe", age: 18 } }
|
23
|
+
let(:locale) { :en }
|
24
|
+
|
25
|
+
subject(:valid) { true }
|
26
|
+
end
|
27
|
+
|
28
|
+
it_behaves_like :validating_attributes do
|
29
|
+
let(:assertion) { IsAdult }
|
30
|
+
let(:attributes) { { name: "Joe", age: 10 } }
|
31
|
+
let(:locale) { :en }
|
32
|
+
|
33
|
+
subject(:valid) { false }
|
34
|
+
subject(:messages) { "Joe is a child (age 10)" }
|
35
|
+
end
|
36
|
+
|
37
|
+
it_behaves_like :validating_attributes do
|
38
|
+
let(:described_class) { IsAdult }
|
39
|
+
let(:attributes) { { name: "Joe", age: 10 } }
|
40
|
+
let(:locale) { :fr }
|
41
|
+
|
42
|
+
subject(:messages) { ["Joe est un enfant (10 ans)"] }
|
43
|
+
end
|
44
|
+
|
45
|
+
it_behaves_like :validating_attributes do
|
46
|
+
let(:assertion) { IsAdult.not }
|
47
|
+
let(:attributes) { { name: "Joe", age: 18 } }
|
48
|
+
let(:locale) { :fr }
|
49
|
+
|
50
|
+
subject(:valid) { false }
|
51
|
+
subject(:messages) { ["Joe est majeur (18 ans)"] }
|
52
|
+
end
|
53
|
+
|
54
|
+
it_behaves_like :accepting_object do
|
55
|
+
let(:guard) { AdultOnly }
|
56
|
+
let(:object) { { name: "Joe", age: 18 } }
|
57
|
+
|
58
|
+
subject(:accepted) { true }
|
59
|
+
end
|
60
|
+
|
61
|
+
it_behaves_like :accepting_object do
|
62
|
+
let(:guard) { AdultOnly }
|
63
|
+
let(:object) { { name: "Joe", age: 10 } }
|
64
|
+
let(:locale) { :fr }
|
65
|
+
|
66
|
+
subject(:accepted) { false }
|
67
|
+
subject(:messages) { ["Joe est un enfant (10 ans)"] }
|
68
|
+
end
|
69
|
+
|
70
|
+
after do
|
71
|
+
Object.send :remove_const, :AdultOnly
|
72
|
+
Object.send :remove_const, :IsAdult
|
73
|
+
end
|
74
|
+
|
75
|
+
end # describe Assertion
|
data/spec/shared/fr.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Translations of messages for examples in the `./assertion_spec.rb`
|
2
|
+
---
|
3
|
+
fr:
|
4
|
+
assertion:
|
5
|
+
is_adult:
|
6
|
+
truthy: "%{name} est majeur (%{age} ans)"
|
7
|
+
falsey: "%{name} est un enfant (%{age} ans)"
|
8
|
+
is_male:
|
9
|
+
truthy: "%{name} est un mâle"
|
10
|
+
falsey: "%{name} est une femelle"
|
metadata
CHANGED
@@ -1,49 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assertion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kozin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: i18n
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
20
|
-
- - ">"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.2.3
|
19
|
+
version: '0.7'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0.
|
30
|
-
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ice_nine
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
33
|
+
version: '0.11'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.11'
|
33
41
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
42
|
+
name: inflecto
|
35
43
|
requirement: !ruby/object:Gem::Requirement
|
36
44
|
requirements:
|
37
45
|
- - "~>"
|
38
46
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0.
|
47
|
+
version: '0.0'
|
40
48
|
type: :runtime
|
41
49
|
prerelease: false
|
42
50
|
version_requirements: !ruby/object:Gem::Requirement
|
43
51
|
requirements:
|
44
52
|
- - "~>"
|
45
53
|
- !ruby/object:Gem::Version
|
46
|
-
version: '0.
|
54
|
+
version: '0.0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: hexx-rspec
|
49
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,16 +121,18 @@ files:
|
|
113
121
|
- lib/assertion/dsl/caller.rb
|
114
122
|
- lib/assertion/dsl/inversion.rb
|
115
123
|
- lib/assertion/guard.rb
|
116
|
-
- lib/assertion/inflector.rb
|
117
124
|
- lib/assertion/invalid_error.rb
|
118
125
|
- lib/assertion/inversion.rb
|
119
126
|
- lib/assertion/inverter.rb
|
127
|
+
- lib/assertion/rspec.rb
|
120
128
|
- lib/assertion/state.rb
|
121
129
|
- lib/assertion/translator.rb
|
122
130
|
- lib/assertion/version.rb
|
123
131
|
- spec/integration/assertion_spec.rb
|
124
132
|
- spec/integration/guard_spec.rb
|
133
|
+
- spec/integration/rspec_spec.rb
|
125
134
|
- spec/shared/en.yml
|
135
|
+
- spec/shared/fr.yml
|
126
136
|
- spec/shared/i18n.rb
|
127
137
|
- spec/spec_helper.rb
|
128
138
|
- spec/unit/assertion/base_spec.rb
|
@@ -132,9 +142,6 @@ files:
|
|
132
142
|
- spec/unit/assertion/dsl/caller_spec.rb
|
133
143
|
- spec/unit/assertion/dsl/inversion_spec.rb
|
134
144
|
- spec/unit/assertion/guard_spec.rb
|
135
|
-
- spec/unit/assertion/inflector/to_path_spec.rb
|
136
|
-
- spec/unit/assertion/inflector/to_snake_path_spec.rb
|
137
|
-
- spec/unit/assertion/inflector/to_snake_spec.rb
|
138
145
|
- spec/unit/assertion/invalid_error_spec.rb
|
139
146
|
- spec/unit/assertion/inversion_spec.rb
|
140
147
|
- spec/unit/assertion/inverter_spec.rb
|
@@ -164,17 +171,15 @@ rubyforge_project:
|
|
164
171
|
rubygems_version: 2.4.6
|
165
172
|
signing_key:
|
166
173
|
specification_version: 4
|
167
|
-
summary: PORO assertions and
|
174
|
+
summary: Standalone PORO assertions and validations
|
168
175
|
test_files:
|
169
176
|
- spec/spec_helper.rb
|
177
|
+
- spec/integration/rspec_spec.rb
|
170
178
|
- spec/integration/assertion_spec.rb
|
171
179
|
- spec/integration/guard_spec.rb
|
172
180
|
- spec/unit/assertion_spec.rb
|
173
181
|
- spec/unit/assertion/invalid_error_spec.rb
|
174
182
|
- spec/unit/assertion/state_spec.rb
|
175
|
-
- spec/unit/assertion/inflector/to_snake_path_spec.rb
|
176
|
-
- spec/unit/assertion/inflector/to_snake_spec.rb
|
177
|
-
- spec/unit/assertion/inflector/to_path_spec.rb
|
178
183
|
- spec/unit/assertion/dsl/builder_spec.rb
|
179
184
|
- spec/unit/assertion/dsl/caller_spec.rb
|
180
185
|
- spec/unit/assertion/dsl/inversion_spec.rb
|
data/lib/assertion/inflector.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module Assertion
|
2
|
-
|
3
|
-
# The collection of pure functions for converting constants
|
4
|
-
# to corresponding path names.
|
5
|
-
#
|
6
|
-
# @api private
|
7
|
-
#
|
8
|
-
# @todo Extract this module to the external gem `transproc-inflector`
|
9
|
-
#
|
10
|
-
module Inflector
|
11
|
-
|
12
|
-
extend ::Transproc::Registry
|
13
|
-
|
14
|
-
# @private
|
15
|
-
def to_snake(name)
|
16
|
-
name.gsub(/([a-z])([A-Z])/, '\1_\2').gsub(/_+/, "_").downcase
|
17
|
-
end
|
18
|
-
|
19
|
-
# @private
|
20
|
-
def to_path(name)
|
21
|
-
name.split(%r{\:\:|-|/}).reject(&:empty?).join("/")
|
22
|
-
end
|
23
|
-
|
24
|
-
# Converts the name of the constant to the corresponding path
|
25
|
-
#
|
26
|
-
# @example
|
27
|
-
# fn = Inflector[:to_snake_path]
|
28
|
-
# fn["::Foo::BarBaz"]
|
29
|
-
# # => "foo/bar_baz"
|
30
|
-
#
|
31
|
-
# @param [String] name The name of the constant
|
32
|
-
#
|
33
|
-
# @return [String] The path
|
34
|
-
#
|
35
|
-
def to_snake_path(name)
|
36
|
-
to_path(to_snake(name))
|
37
|
-
end
|
38
|
-
|
39
|
-
end # module Inflector
|
40
|
-
|
41
|
-
end # module Assertion
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
describe Assertion::Inflector, "#to_path" do
|
4
|
-
|
5
|
-
subject { fn[input] }
|
6
|
-
|
7
|
-
let(:fn) { described_class[:to_path] }
|
8
|
-
let(:input) { "::/Foo-bar::baz/qux" }
|
9
|
-
let(:output) { "Foo/bar/baz/qux" }
|
10
|
-
|
11
|
-
it "doesn't mutate the input" do
|
12
|
-
expect { subject }.not_to change { input }
|
13
|
-
end
|
14
|
-
|
15
|
-
it "returns the string converted to snake case" do
|
16
|
-
expect(subject).to eql output
|
17
|
-
end
|
18
|
-
|
19
|
-
end # describe Assertion::Inflector#to_path
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
describe Assertion::Inflector, "#to_snake_path" do
|
4
|
-
|
5
|
-
subject { fn[input] }
|
6
|
-
|
7
|
-
let(:fn) { described_class[:to_snake_path] }
|
8
|
-
let(:input) { "::Foo::BarBAZ::Qux" }
|
9
|
-
let(:output) { "foo/bar_baz/qux" }
|
10
|
-
|
11
|
-
it "doesn't mutate the input" do
|
12
|
-
expect { subject }.not_to change { input }
|
13
|
-
end
|
14
|
-
|
15
|
-
it "returns the string converted to snake case" do
|
16
|
-
expect(subject).to eql output
|
17
|
-
end
|
18
|
-
|
19
|
-
end # describe Assertion::Inflector#to_snake_path
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
describe Assertion::Inflector, "#to_snake" do
|
4
|
-
|
5
|
-
subject { fn[input] }
|
6
|
-
|
7
|
-
let(:fn) { described_class[:to_snake] }
|
8
|
-
let(:input) { "FooBarBAz___qux" }
|
9
|
-
let(:output) { "foo_bar_baz_qux" }
|
10
|
-
|
11
|
-
it "doesn't mutate the input" do
|
12
|
-
expect { subject }.not_to change { input }
|
13
|
-
end
|
14
|
-
|
15
|
-
it "returns the string converted to snake case" do
|
16
|
-
expect(subject).to eql output
|
17
|
-
end
|
18
|
-
|
19
|
-
end # describe Assertion::Inflector#to_snake
|