nrser 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe NRSER.method(:to_open_struct) do
4
+
5
+ context "shallow Hash" do
6
+ let(:hash) { {a: 1, b: 2} }
7
+ let(:result) { subject.call hash }
8
+
9
+ it "is converted to an OpenStruct" do
10
+ expect(result).to be_a OpenStruct
11
+ expect(result.a).to be hash[:a]
12
+ expect(result.b).to be hash[:b]
13
+ end # converts to an OpenStruct
14
+
15
+ context "freeze: true" do
16
+ subject { super().call hash, freeze: true }
17
+
18
+ it "is converted to an OpenStruct" do
19
+ expect(subject).to be_a OpenStruct
20
+ expect(subject.a).to be hash[:a]
21
+ expect(subject.b).to be hash[:b]
22
+ end # converts to an OpenStruct
23
+
24
+ it "is frozen" do
25
+ expect(subject.frozen?).to be true
26
+ end # is frozen
27
+
28
+ end # freeze: true
29
+ end # Shallow Hash
30
+
31
+ context "deep Hash" do
32
+ let(:hash) {
33
+ {
34
+ a: {
35
+ x: 'ex',
36
+ y: 'why',
37
+ },
38
+
39
+ b: [
40
+ {z: 'zee!'},
41
+ 3,
42
+ {'w' => nil},
43
+ ],
44
+ }
45
+ }
46
+
47
+ let(:result) { subject.call hash }
48
+
49
+ it "is deeply converted into OpenStruct instances" do
50
+ expect(result).to be_a OpenStruct
51
+ expect(result.a).to be_a OpenStruct
52
+ expect(result.b[2]).to be_a OpenStruct
53
+ expect(result.a.x).to eq 'ex'
54
+ expect(result.b[0].z).to eq 'zee!'
55
+ end # is deeply converted into OpenStruct instances
56
+
57
+
58
+ context "freeze: true" do
59
+
60
+ subject { super().call hash, freeze: true }
61
+
62
+ it "is deeply converted into OpenStruct instances" do
63
+ expect(subject).to be_a OpenStruct
64
+ expect(subject.a).to be_a OpenStruct
65
+ expect(subject.b[2]).to be_a OpenStruct
66
+ expect(subject.a.x).to eq 'ex'
67
+ expect(subject.b[0].z).to eq 'zee!'
68
+ end # is deeply converted into OpenStruct instances
69
+
70
+ it "is frozen" do
71
+ expect(subject.frozen?).to be true
72
+ expect(subject.a.frozen?).to be true
73
+ end # is frozen
74
+
75
+ it "can't be modified" do
76
+ expect { subject.a = 3 }.to raise_error RuntimeError
77
+ expect { subject.q = 3 }.to raise_error RuntimeError
78
+ expect { subject.b[0].z = 3 }.to raise_error RuntimeError
79
+ end # can't be modified
80
+
81
+
82
+ end # freeze: true
83
+
84
+ end # Deep hash
85
+
86
+
87
+ context "not a Hash" do
88
+ it "raises NoMethodError" do
89
+ expect { subject.call 1 }.to raise_error TypeError
90
+ expect { subject.call [1, 2, 3] }.to raise_error TypeError
91
+ end
92
+ end # not a Hash
93
+
94
+ end # NRSER.to_open_struct
@@ -10,4 +10,28 @@ describe 'Refinement Array#map_values' do
10
10
  {x: "Yo I'm x!", y: "Yo I'm y!"}
11
11
  )
12
12
  end
13
- end # Array#map_values
13
+ end # Refinement Array#map_values
14
+
15
+ describe 'Refinement Array#find_bounded' do
16
+ it do
17
+ expect(
18
+ [1, 2, 3].find_bounded(length: 2) { |i| i >= 2 }
19
+ ).to eq [2, 3]
20
+
21
+ expect {
22
+ [1, 2, 3].find_bounded(length: 2) { |i| i == 2 }
23
+ }.to raise_error TypeError
24
+ end
25
+ end # Refinement Array#map_values
26
+
27
+ describe 'Refinement Array#find_only' do
28
+ it do
29
+ expect(
30
+ [1, 2, 3].find_only { |i| i == 2 }
31
+ ).to be 2
32
+
33
+ expect {
34
+ [1, 2, 3].find_only { |i| i >= 2 }
35
+ }.to raise_error TypeError
36
+ end
37
+ end # Refinement Array#map_values
@@ -11,3 +11,33 @@ describe 'Refinement Hash#map_values' do
11
11
  )
12
12
  end
13
13
  end # 'Hash#map_values'
14
+
15
+
16
+ describe 'Refinement Hash#find_bounded' do
17
+ subject { {a: 1, b: 2, c: 3} }
18
+
19
+ it do
20
+ expect(
21
+ subject.find_bounded(length: 2) { |k, v| v >= 2 }
22
+ ).to eq [[:b, 2], [:c, 3]]
23
+
24
+ expect {
25
+ subject.find_bounded(length: 2) { |k, v| v == 2 }
26
+ }.to raise_error TypeError
27
+ end
28
+ end # Refinement Hash#map_values
29
+
30
+
31
+ describe 'Refinement Hash#find_only' do
32
+ subject { {a: 1, b: 2, c: 3} }
33
+
34
+ it do
35
+ expect(
36
+ subject.find_only { |k, i| i == 2 }
37
+ ).to eq [:b, 2]
38
+
39
+ expect {
40
+ subject.find_only { |k, i| i >= 2 }
41
+ }.to raise_error TypeError
42
+ end
43
+ end # Refinement Hash#map_values
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ using NRSER
4
+
5
+ describe 'Refinement Set#map_values' do
6
+ it do
7
+ expect(
8
+ Set[:x, :y].map_values { |value| "Yo I'm #{ value }!" }
9
+ ).to eq(
10
+ {x: "Yo I'm x!", y: "Yo I'm y!"}
11
+ )
12
+ end
13
+ end # Refinement Set#map_values
14
+
15
+ describe 'Refinement Set#find_bounded' do
16
+ subject { Set[1, 2, 3] }
17
+
18
+ it do
19
+ expect(
20
+ subject.find_bounded(length: 2) { |i| i >= 2 }
21
+ ).to eq [2, 3]
22
+
23
+ expect {
24
+ subject.find_bounded(length: 2) { |i| i == 2 }
25
+ }.to raise_error TypeError
26
+ end
27
+ end # Refinement Set#map_values
28
+
29
+ describe 'Refinement Set#find_only' do
30
+ subject { Set[1, 2, 3] }
31
+
32
+ it do
33
+ expect(
34
+ subject.find_only { |i| i == 2 }
35
+ ).to be 2
36
+
37
+ expect {
38
+ subject.find_only { |i| i >= 2 }
39
+ }.to raise_error TypeError
40
+ end
41
+ end # Refinement Set#map_values
@@ -1,8 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
+ require 'nrser/refinements'
4
+ using NRSER
5
+
6
+ require 'nrser/refinements/types'
7
+ using NRSER::Types
8
+
9
+
3
10
  describe NRSER::Types do
4
- t = NRSER::Types
5
-
6
11
  describe 'basic types #test and #check' do
7
12
  {
8
13
  t.any => {
@@ -139,10 +144,15 @@ describe NRSER::Types do
139
144
  }
140
145
  },
141
146
 
147
+ t.respond_to(:each_value) => {
148
+ pass: [ {} ],
149
+ fail: [ [] ],
150
+ },
151
+
142
152
  }.each do |type, tests|
143
153
  if tests[:pass]
144
154
  tests[:pass].each do |value|
145
- it "ACCEPS #{ value.inspect } as #{ type }" do
155
+ it "ACCEPTS #{ value.inspect } as #{ type }" do
146
156
  expect(type.test value).to be true
147
157
  expect {type.check value}.not_to raise_error
148
158
  end
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.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-20 00:00:00.000000000 Z
11
+ date: 2017-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: redcarpet
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: github-markup
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: cmds
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +108,20 @@ dependencies:
80
108
  - - ">="
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  description:
84
126
  email:
85
127
  - neil@neilsouza.com
@@ -94,6 +136,7 @@ files:
94
136
  - lib/nrser/binding.rb
95
137
  - lib/nrser/collection.rb
96
138
  - lib/nrser/enumerable.rb
139
+ - lib/nrser/errors.rb
97
140
  - lib/nrser/exception.rb
98
141
  - lib/nrser/hash.rb
99
142
  - lib/nrser/logger.rb
@@ -103,13 +146,18 @@ files:
103
146
  - lib/nrser/meta/props/base.rb
104
147
  - lib/nrser/meta/props/prop.rb
105
148
  - lib/nrser/no_arg.rb
149
+ - lib/nrser/open_struct.rb
106
150
  - lib/nrser/refinements.rb
107
151
  - lib/nrser/refinements/array.rb
108
152
  - lib/nrser/refinements/binding.rb
153
+ - lib/nrser/refinements/enumerable.rb
154
+ - lib/nrser/refinements/enumerator.rb
109
155
  - lib/nrser/refinements/exception.rb
110
156
  - lib/nrser/refinements/hash.rb
111
157
  - lib/nrser/refinements/object.rb
158
+ - lib/nrser/refinements/open_struct.rb
112
159
  - lib/nrser/refinements/pathname.rb
160
+ - lib/nrser/refinements/set.rb
113
161
  - lib/nrser/refinements/string.rb
114
162
  - lib/nrser/refinements/types.rb
115
163
  - lib/nrser/string.rb
@@ -126,6 +174,7 @@ files:
126
174
  - lib/nrser/types/is_a.rb
127
175
  - lib/nrser/types/maybe.rb
128
176
  - lib/nrser/types/numbers.rb
177
+ - lib/nrser/types/responds.rb
129
178
  - lib/nrser/types/strings.rb
130
179
  - lib/nrser/types/symbol.rb
131
180
  - lib/nrser/types/type.rb
@@ -135,6 +184,7 @@ files:
135
184
  - spec/nrser/collection/map_spec.rb
136
185
  - spec/nrser/common_prefix_spec.rb
137
186
  - spec/nrser/dedent_spec.rb
187
+ - spec/nrser/enumerable_spec.rb
138
188
  - spec/nrser/format_exception_spec.rb
139
189
  - spec/nrser/hash_spec.rb
140
190
  - spec/nrser/indent_spec.rb
@@ -148,6 +198,7 @@ files:
148
198
  - spec/nrser/logger/use_spec.rb
149
199
  - spec/nrser/meta/class_attrs_spec.rb
150
200
  - spec/nrser/meta/props_spec.rb
201
+ - spec/nrser/open_struct_spec.rb
151
202
  - spec/nrser/refinements/array_spec.rb
152
203
  - spec/nrser/refinements/erb_spec.rb
153
204
  - spec/nrser/refinements/format_exception_spec.rb
@@ -155,6 +206,7 @@ files:
155
206
  - spec/nrser/refinements/indent_spec.rb
156
207
  - spec/nrser/refinements/object_spec.rb
157
208
  - spec/nrser/refinements/pathname_spec.rb
209
+ - spec/nrser/refinements/set_spec.rb
158
210
  - spec/nrser/refinements/truncate_spec.rb
159
211
  - spec/nrser/template_spec.rb
160
212
  - spec/nrser/truncate_spec.rb
@@ -184,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
236
  version: '0'
185
237
  requirements: []
186
238
  rubyforge_project:
187
- rubygems_version: 2.6.11
239
+ rubygems_version: 2.5.2
188
240
  signing_key:
189
241
  specification_version: 4
190
242
  summary: basic ruby utils i use in a lot of stuff.
@@ -193,6 +245,7 @@ test_files:
193
245
  - spec/nrser/collection/map_spec.rb
194
246
  - spec/nrser/common_prefix_spec.rb
195
247
  - spec/nrser/dedent_spec.rb
248
+ - spec/nrser/enumerable_spec.rb
196
249
  - spec/nrser/format_exception_spec.rb
197
250
  - spec/nrser/hash_spec.rb
198
251
  - spec/nrser/indent_spec.rb
@@ -206,6 +259,7 @@ test_files:
206
259
  - spec/nrser/logger/use_spec.rb
207
260
  - spec/nrser/meta/class_attrs_spec.rb
208
261
  - spec/nrser/meta/props_spec.rb
262
+ - spec/nrser/open_struct_spec.rb
209
263
  - spec/nrser/refinements/array_spec.rb
210
264
  - spec/nrser/refinements/erb_spec.rb
211
265
  - spec/nrser/refinements/format_exception_spec.rb
@@ -213,6 +267,7 @@ test_files:
213
267
  - spec/nrser/refinements/indent_spec.rb
214
268
  - spec/nrser/refinements/object_spec.rb
215
269
  - spec/nrser/refinements/pathname_spec.rb
270
+ - spec/nrser/refinements/set_spec.rb
216
271
  - spec/nrser/refinements/truncate_spec.rb
217
272
  - spec/nrser/template_spec.rb
218
273
  - spec/nrser/truncate_spec.rb