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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e02fce1546e9b7523fbff83894476957ca0b335d
4
- data.tar.gz: 49d6ede0ddd7a992b8bd688cc55ef06b0b7a66bd
3
+ metadata.gz: b3c17905def77d1f6f9366a2fd4f3a7326cf5c8c
4
+ data.tar.gz: eeb118194902e69f6ab5ab44a77183e2d0f32ebe
5
5
  SHA512:
6
- metadata.gz: d4db34e23434e46569f8fa530d41bec8a0d8b920e7d13344ed6a0a864a0c416398f4835faa1e1e77b35b8d63025416b1fc32b2e9f17ceb3c85b42678fda9e75e
7
- data.tar.gz: d9d16dd22f86a0da3e37b6e23f68b0c049bc6832dfec864c94fbfe41f6dd6e2e71b8f0f677f35757fddd012b69116853a59bb1db2d3960db9b73d08c3f059a87
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
- Immutable assertions and validations for PORO.
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 <decoupled> objects.
23
+ The primary goal of the gem is to make standalone assertions about objects and validate them.
24
24
 
25
- No `ActiveSupport`, no mutation of any instances.
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="Wrong name(s) for attribute(s): check">
182
+ # => #<Assertion::NameError @message="IsAdult#check is already defined">
182
183
 
183
184
  AdultOnly = Assertion.guards :state
184
- # => #<Assertion::NameError @message="Wrong name(s) for attribute(s): state">
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
@@ -25,5 +25,5 @@ end
25
25
 
26
26
  desc "Runs mutation metric for testing"
27
27
  task :mutant do
28
- system "mutant -r ./spec/spec_helper --use rspec 'Assertion*' --fail-fast"
28
+ system "mutant -r ./spec/spec_helper --use rspec 'Assertion*'"
29
29
  end
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 validation"
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"
@@ -1,2 +1,2 @@
1
1
  ---
2
- minimum_score: 7
2
+ minimum_score: 8
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  folders: # The list of folders to be used by any metric.
3
3
  - lib
4
- - app
5
4
  metrics: # The list of allowed metrics. The other metrics are disabled.
6
5
  - cane
7
6
  - churn
@@ -39,14 +39,19 @@ module Assertion
39
39
  extend DSL::Inversion
40
40
  extend DSL::Caller
41
41
 
42
- # The translator of states for the current class
42
+ # The class-specific translator of assertion states
43
43
  #
44
- # @return [Assertion::Translator]
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
- freeze
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.translator.call(state, attributes)
92
+ self.class.translate(state, attributes)
88
93
  end
89
94
 
90
95
  # Calls the assertion checkup and returns the resulting state
@@ -46,7 +46,7 @@ module Assertion
46
46
  # @private
47
47
  def initialize(object)
48
48
  @object = object
49
- freeze
49
+ IceNine.deep_freeze(self)
50
50
  end
51
51
 
52
52
  # Validates the state of the [#object] and returns valid object back
@@ -20,8 +20,8 @@ module Assertion
20
20
 
21
21
  # @private
22
22
  def initialize(*messages)
23
- @messages = messages.flatten.freeze
24
- freeze
23
+ @messages = messages.flatten
24
+ IceNine.deep_freeze(self)
25
25
  end
26
26
 
27
27
  # @!attribute [r] messages
@@ -32,7 +32,7 @@ module Assertion
32
32
  # @private
33
33
  def initialize(assertion)
34
34
  @assertion = assertion
35
- freeze
35
+ IceNine.deep_freeze(self)
36
36
  end
37
37
 
38
38
  # @!attribute [r] assertion
@@ -36,7 +36,7 @@ module Assertion
36
36
  # @private
37
37
  def initialize(source)
38
38
  @source = source
39
- freeze
39
+ IceNine.deep_freeze(self)
40
40
  end
41
41
 
42
42
  # Initializes a [#source] object and builds a negator for it
@@ -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
@@ -21,8 +21,8 @@ module Assertion
21
21
  # @private
22
22
  def initialize(state, *messages)
23
23
  @state = state
24
- @messages = (state ? [] : messages.flatten.uniq).freeze
25
- freeze
24
+ @messages = state ? [] : messages.flatten.uniq
25
+ IceNine.deep_freeze(self)
26
26
  end
27
27
 
28
28
  # @!attribute [r] messages
@@ -46,7 +46,7 @@ module Assertion
46
46
  # @return [Array<Symbol>]
47
47
  #
48
48
  def self.scope(klass)
49
- [ROOT, Inflector[:to_snake_path][klass.name].to_sym]
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
- freeze
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 for the gem-specific scope for the
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
@@ -4,6 +4,6 @@ module Assertion
4
4
 
5
5
  # The semantic version of the module.
6
6
  # @see http://semver.org/ Semantic versioning 2.0
7
- VERSION = "0.2.1".freeze
7
+ VERSION = "0.2.2".freeze
8
8
 
9
9
  end # module Assertion
data/lib/assertion.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "transproc"
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
@@ -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.1
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-06-23 00:00:00.000000000 Z
11
+ date: 2015-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: transproc
14
+ name: i18n
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.2'
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.2'
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.2.3
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: i18n
42
+ name: inflecto
35
43
  requirement: !ruby/object:Gem::Requirement
36
44
  requirements:
37
45
  - - "~>"
38
46
  - !ruby/object:Gem::Version
39
- version: '0.7'
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.7'
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 validation
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
@@ -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