nrser 0.0.24 → 0.0.25
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/lib/nrser/enumerable.rb +12 -6
- data/lib/nrser/hash.rb +182 -0
- data/lib/nrser/meta/props/base.rb +22 -0
- data/lib/nrser/meta/props/prop.rb +84 -12
- data/lib/nrser/meta/props.rb +36 -15
- data/lib/nrser/refinements/hash.rb +13 -0
- data/lib/nrser/refinements/pathname.rb +11 -0
- data/lib/nrser/refinements.rb +2 -0
- data/lib/nrser/spex.rb +68 -0
- data/lib/nrser/types/attrs.rb +83 -30
- data/lib/nrser/types/combinators.rb +54 -6
- data/lib/nrser/types/paths.rb +62 -2
- data/lib/nrser/types/type.rb +122 -2
- data/lib/nrser/types.rb +2 -0
- data/lib/nrser/version.rb +1 -1
- data/lib/nrser.rb +5 -1
- data/spec/nrser/hash/bury_spec.rb +31 -0
- data/spec/nrser/hash/guess_name_type_spec.rb +47 -0
- data/spec/nrser/types/attrs_spec.rb +41 -0
- data/spec/nrser/types/paths_spec.rb +69 -0
- data/spec/nrser/types_spec.rb +0 -10
- data/spec/spec_helper.rb +46 -1
- metadata +12 -2
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "NRSER::Types.dir_path" do
|
4
|
+
subject { NRSER::Types.method :dir_path }
|
5
|
+
|
6
|
+
it_behaves_like 'Type maker method',
|
7
|
+
accepts: [
|
8
|
+
'.',
|
9
|
+
'/',
|
10
|
+
Pathname.getwd,
|
11
|
+
],
|
12
|
+
|
13
|
+
rejects: [
|
14
|
+
'README.md',
|
15
|
+
],
|
16
|
+
|
17
|
+
to_data: {
|
18
|
+
Pathname.getwd => Pathname.getwd.to_s,
|
19
|
+
}
|
20
|
+
|
21
|
+
end # NRSER::Types.dir_path
|
22
|
+
|
23
|
+
describe "NRSER::Types.file_path" do
|
24
|
+
subject { NRSER::Types.method :file_path }
|
25
|
+
|
26
|
+
it_behaves_like 'Type maker method',
|
27
|
+
accepts: [
|
28
|
+
( NRSER::ROOT / 'README.md' ),
|
29
|
+
],
|
30
|
+
|
31
|
+
rejects: [
|
32
|
+
'.',
|
33
|
+
'/',
|
34
|
+
Pathname.getwd,
|
35
|
+
],
|
36
|
+
|
37
|
+
and_is_expected: {
|
38
|
+
to: {
|
39
|
+
have_attributes: {
|
40
|
+
name: 'FilePath',
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
context "custom name" do
|
46
|
+
it_behaves_like 'Type maker method',
|
47
|
+
args: [ name: 'CustomType' ],
|
48
|
+
|
49
|
+
accepts: [
|
50
|
+
( NRSER::ROOT / 'README.md' ),
|
51
|
+
],
|
52
|
+
|
53
|
+
rejects: [
|
54
|
+
'.',
|
55
|
+
'/',
|
56
|
+
Pathname.getwd,
|
57
|
+
],
|
58
|
+
|
59
|
+
and_is_expected: {
|
60
|
+
to: {
|
61
|
+
have_attributes: {
|
62
|
+
name: 'CustomType',
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end # custom name
|
67
|
+
|
68
|
+
|
69
|
+
end # NRSER::Types.dir_path
|
data/spec/nrser/types_spec.rb
CHANGED
@@ -99,16 +99,6 @@ describe NRSER::Types do
|
|
99
99
|
pass: [''],
|
100
100
|
},
|
101
101
|
|
102
|
-
t.length(min: 0, max: 0) => {
|
103
|
-
pass: ['', [], {}],
|
104
|
-
fail: ['x', [1], {x: 1}],
|
105
|
-
},
|
106
|
-
|
107
|
-
t.length(0) => {
|
108
|
-
pass: ['', [], {}],
|
109
|
-
fail: ['x', [1], {x: 1}],
|
110
|
-
},
|
111
|
-
|
112
102
|
t.bounded(min: 0, max: 0) => {
|
113
103
|
pass: [0],
|
114
104
|
},
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'cmds'
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
+
|
4
5
|
require 'nrser'
|
5
6
|
require 'nrser/logger'
|
7
|
+
require 'nrser/spex'
|
6
8
|
|
7
9
|
MAIN = self
|
8
10
|
|
@@ -23,4 +25,47 @@ end
|
|
23
25
|
|
24
26
|
def expect_to_not_log &block
|
25
27
|
expect(&block).to_not output.to_stderr_from_any_process
|
26
|
-
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
shared_examples "Type maker method" do | args: [],
|
32
|
+
accepts: [],
|
33
|
+
rejects: [],
|
34
|
+
to_data: {},
|
35
|
+
**expectations |
|
36
|
+
context "#call( #{ args.map(&:inspect).join ', ' } )" do
|
37
|
+
# Load the type into the subject by applying the parent scope subject,
|
38
|
+
# which should be the Type maker method that we want to test, to the
|
39
|
+
# args we received.
|
40
|
+
refine_subject :call, *args
|
41
|
+
|
42
|
+
# Expect that it's a {NRSER::Types::Type} and any other expectations that
|
43
|
+
# may have been passed in.
|
44
|
+
include_examples "expect subject",
|
45
|
+
{ to: { be_a: NRSER::Types::Type } },
|
46
|
+
*expectations.values
|
47
|
+
|
48
|
+
# Make sure it accepts the accepts
|
49
|
+
accepts.each { |value|
|
50
|
+
it "accepts #{ value.inspect }" do
|
51
|
+
expect( subject.test value ).to be true
|
52
|
+
end
|
53
|
+
}
|
54
|
+
|
55
|
+
# And that it rejects the rejects
|
56
|
+
rejects.each { |value|
|
57
|
+
it "rejects #{ value.inspect }" do
|
58
|
+
expect( subject.test value ).to be false
|
59
|
+
end
|
60
|
+
}
|
61
|
+
|
62
|
+
# {NRSER::Types::Type#to_data} tests
|
63
|
+
to_data.each { |value, data|
|
64
|
+
it "dumps value #{ value.inspect } to data #{ data.inspect }" do
|
65
|
+
expect( subject.to_data value ).to eq data
|
66
|
+
end
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end # Type maker method
|
70
|
+
|
71
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nrser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/nrser/refinements/set.rb
|
161
161
|
- lib/nrser/refinements/string.rb
|
162
162
|
- lib/nrser/refinements/types.rb
|
163
|
+
- lib/nrser/spex.rb
|
163
164
|
- lib/nrser/string.rb
|
164
165
|
- lib/nrser/truthy.rb
|
165
166
|
- lib/nrser/types.rb
|
@@ -187,6 +188,8 @@ files:
|
|
187
188
|
- spec/nrser/dedent_spec.rb
|
188
189
|
- spec/nrser/enumerable_spec.rb
|
189
190
|
- spec/nrser/format_exception_spec.rb
|
191
|
+
- spec/nrser/hash/bury_spec.rb
|
192
|
+
- spec/nrser/hash/guess_name_type_spec.rb
|
190
193
|
- spec/nrser/hash_spec.rb
|
191
194
|
- spec/nrser/indent_spec.rb
|
192
195
|
- spec/nrser/logger/dest_spec.rb
|
@@ -212,8 +215,10 @@ files:
|
|
212
215
|
- spec/nrser/template_spec.rb
|
213
216
|
- spec/nrser/truncate_spec.rb
|
214
217
|
- spec/nrser/truthy_spec.rb
|
218
|
+
- spec/nrser/types/attrs_spec.rb
|
215
219
|
- spec/nrser/types/combinators_spec.rb
|
216
220
|
- spec/nrser/types/is_spec.rb
|
221
|
+
- spec/nrser/types/paths_spec.rb
|
217
222
|
- spec/nrser/types_spec.rb
|
218
223
|
- spec/nrser_spec.rb
|
219
224
|
- spec/spec_helper.rb
|
@@ -248,6 +253,8 @@ test_files:
|
|
248
253
|
- spec/nrser/dedent_spec.rb
|
249
254
|
- spec/nrser/enumerable_spec.rb
|
250
255
|
- spec/nrser/format_exception_spec.rb
|
256
|
+
- spec/nrser/hash/bury_spec.rb
|
257
|
+
- spec/nrser/hash/guess_name_type_spec.rb
|
251
258
|
- spec/nrser/hash_spec.rb
|
252
259
|
- spec/nrser/indent_spec.rb
|
253
260
|
- spec/nrser/logger/dest_spec.rb
|
@@ -273,8 +280,11 @@ test_files:
|
|
273
280
|
- spec/nrser/template_spec.rb
|
274
281
|
- spec/nrser/truncate_spec.rb
|
275
282
|
- spec/nrser/truthy_spec.rb
|
283
|
+
- spec/nrser/types/attrs_spec.rb
|
276
284
|
- spec/nrser/types/combinators_spec.rb
|
277
285
|
- spec/nrser/types/is_spec.rb
|
286
|
+
- spec/nrser/types/paths_spec.rb
|
278
287
|
- spec/nrser/types_spec.rb
|
279
288
|
- spec/nrser_spec.rb
|
280
289
|
- spec/spec_helper.rb
|
290
|
+
has_rdoc:
|