opushon 0.0.1 → 0.1.0
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/Rakefile +1 -2
- data/VERSION.semver +1 -1
- data/lib/opushon/error/min_is_greater_than_max_error.rb +8 -0
- data/lib/opushon/error/minlen_is_longer_than_maxlen_error.rb +8 -0
- data/lib/opushon/instance.rb +4 -13
- data/lib/opushon/option_object.rb +19 -39
- data/lib/opushon/parameter/base.rb +47 -0
- data/lib/opushon/parameter/input.rb +34 -0
- data/lib/opushon/parameter/output.rb +10 -0
- data/lib/opushon/parameter.rb +9 -0
- data/lib/opushon/restricted_value.rb +35 -0
- data/lib/opushon/type/array.rb +10 -0
- data/lib/opushon/type/base.rb +12 -5
- data/lib/opushon/type/boolean.rb +0 -3
- data/lib/opushon/type/hash.rb +10 -0
- data/lib/opushon/type/number.rb +15 -13
- data/lib/opushon/type/string.rb +18 -13
- data/lib/opushon/verb.rb +0 -2
- data/lib/opushon/version.rb +2 -0
- data/opushon.gemspec +0 -1
- data/spec/opushon/parameter/input_spec.rb +161 -0
- data/spec/opushon/parameter/output_spec.rb +108 -0
- data/spec/opushon/parameter/spec_helper.rb +1 -0
- data/spec/opushon/restricted_value_spec.rb +42 -0
- data/spec/opushon_spec.rb +313 -323
- data/spec/support/immutable.rb +13 -13
- metadata +19 -18
- data/lib/opushon/attribute.rb +0 -29
- data/lib/opushon/option.rb +0 -14
@@ -0,0 +1,108 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Opushon::Parameter::Output do
|
4
|
+
subject do
|
5
|
+
Opushon::Parameter::Output
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.load' do
|
9
|
+
it 'MUST return the hash' do
|
10
|
+
params = {
|
11
|
+
foo: subject.new(title: 'Foo').to_h,
|
12
|
+
bar: subject.new(title: 'Bar').to_h
|
13
|
+
}
|
14
|
+
|
15
|
+
subject.load(params).must_equal({
|
16
|
+
foo: subject.new(title: 'Foo').to_h,
|
17
|
+
bar: subject.new(title: 'Bar').to_h
|
18
|
+
})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.new' do
|
23
|
+
describe '#to_h' do
|
24
|
+
describe 'default params' do
|
25
|
+
describe 'default type' do
|
26
|
+
it 'MUST return the hash' do
|
27
|
+
o = subject.new
|
28
|
+
|
29
|
+
o.to_h.must_equal(title: '',
|
30
|
+
description: '',
|
31
|
+
type: 'string',
|
32
|
+
nullifiable: true)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'string type' do
|
37
|
+
it 'MUST return the hash' do
|
38
|
+
o = subject.new(type: 'string')
|
39
|
+
|
40
|
+
o.to_h.must_equal(title: '',
|
41
|
+
description: '',
|
42
|
+
type: 'string',
|
43
|
+
nullifiable: true)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'number type' do
|
48
|
+
it 'MUST return the hash' do
|
49
|
+
o = subject.new(type: 'number')
|
50
|
+
|
51
|
+
o.to_h.must_equal(title: '',
|
52
|
+
description: '',
|
53
|
+
type: 'number',
|
54
|
+
nullifiable: true)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'boolean type' do
|
59
|
+
it 'MUST return the hash' do
|
60
|
+
o = subject.new(type: 'boolean')
|
61
|
+
|
62
|
+
o.to_h.must_equal(title: '',
|
63
|
+
description: '',
|
64
|
+
type: 'boolean',
|
65
|
+
nullifiable: true)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'array type' do
|
70
|
+
it 'MUST return the hash' do
|
71
|
+
o = subject.new(type: 'array')
|
72
|
+
|
73
|
+
o.to_h.must_equal(title: '',
|
74
|
+
description: '',
|
75
|
+
type: 'array',
|
76
|
+
nullifiable: true)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'hash type' do
|
81
|
+
it 'MUST return the hash' do
|
82
|
+
o = subject.new(type: 'hash')
|
83
|
+
|
84
|
+
o.to_h.must_equal(title: '',
|
85
|
+
description: '',
|
86
|
+
type: 'hash',
|
87
|
+
nullifiable: true)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'random example' do
|
94
|
+
it 'MUST return the hash' do
|
95
|
+
o = subject.new(
|
96
|
+
description: 'State of the issues to return.',
|
97
|
+
type: 'boolean',
|
98
|
+
nullifiable: true
|
99
|
+
)
|
100
|
+
|
101
|
+
o.to_h.must_equal(title: '',
|
102
|
+
description: 'State of the issues to return.',
|
103
|
+
type: 'boolean',
|
104
|
+
nullifiable: true)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative File.join(*%w(.. spec_helper))
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Opushon::RestrictedValue do
|
4
|
+
subject do
|
5
|
+
Opushon::RestrictedValue
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'passes' do
|
9
|
+
describe '#to_h' do
|
10
|
+
it 'MUST return the hash' do
|
11
|
+
subject.new(value: :foobar).to_h.must_equal({
|
12
|
+
title: '',
|
13
|
+
description: '',
|
14
|
+
value: :foobar
|
15
|
+
})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#to_h' do
|
20
|
+
it 'MUST return the hash' do
|
21
|
+
subject.new(value: :foobar,
|
22
|
+
description: :foobar).to_h.must_equal({
|
23
|
+
title: '',
|
24
|
+
description: 'foobar',
|
25
|
+
value: :foobar
|
26
|
+
})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#value' do
|
31
|
+
it 'MUST return the value' do
|
32
|
+
subject.new(value: :foobar).value.must_equal(:foobar)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'errors' do
|
38
|
+
it 'MUST raise without value' do
|
39
|
+
-> { subject.new(description: :foobar) }.must_raise(ArgumentError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|