skn_utils 2.0.6 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,123 +0,0 @@
1
- ##
2
- # <project.root>/lib/skn_utils/nested_result_base.rb
3
- #
4
- # Creates an Object with instance variables and associated getters and setters for hash each input key.
5
- # If the key's value is also a hash itself, it too will become an Object.
6
- # if the key's value is a Array of Hashes, each element of the Array will become an Object.
7
- #
8
- # This nesting action is controlled by the value of the option key ':depth'.
9
- # The key :depth defaults to :multi, an has options of :single, or :multi_with_arrays
10
- #
11
- # The ability of the resulting Object to be Marshalled(dump/load) can be preserved by merging
12
- # input params key ':enable_serialization' set to true. It defaults to false for speed purposes
13
- #
14
- ##
15
- # Operational Options
16
- # --------------------------------
17
- # :enable_serialization = false -- [ true | false ], for speed, omits creation of attr_accessor
18
- # :depth = :multi -- [ :single | :multi | :multi_with_arrays ]
19
- ##
20
- # NOTE: Cannot be Marshalled/Serialized unless input params.merge({enable_serialization: true}) -- default is false
21
- # Use GenericBean if serialization is needed, it sets this value to true automatically
22
- ##
23
-
24
-
25
- module SknUtils
26
-
27
- class NestedResultBase
28
- include AttributeHelpers
29
-
30
- # :depth controls how deep into input hash/arrays we convert
31
- # :depth => :single | :multi | :multi_with_arrays
32
- # :depth defaults to :multi
33
- # :enable_serialization controls the use of singleton_method() to preserve the ability to Marshal
34
- # :enable_serialization defaults to false
35
- #:nodoc:
36
- def initialize(params={})
37
- @skn_enabled_depth = params.delete(:depth) {|not_found| :multi }
38
- @skn_enable_serialization = params.delete(:enable_serialization) {|not_found| false }
39
- case @skn_enabled_depth
40
- when :single
41
- single_level_initializer(params)
42
- when :multi_with_arrays
43
- multi_level_incl_arrays_initializer(params)
44
- else
45
- multi_level_initializer(params)
46
- end
47
- end
48
-
49
- #:nodoc:
50
- def single_level_initializer(params={}) # Single Level Initializer -- ignore value eql hash
51
- params.each do |k,v|
52
- key = clean_key(k)
53
- singleton_class.send(:attr_accessor, key) unless respond_to?(key) or serialization_required?
54
- instance_variable_set("@#{key}".to_sym,v)
55
- end
56
- end
57
-
58
- #:nodoc:
59
- def multi_level_initializer(params={}) # Multi Level Initializer -- value eql hash then interate
60
- params.each do |k,v|
61
- key = clean_key(k)
62
- singleton_class.send(:attr_accessor, key) unless respond_to?(key) or serialization_required?
63
- if v.kind_of?(Hash)
64
- instance_variable_set("@#{key}".to_sym, self.class.new(v))
65
- else
66
- instance_variable_set("@#{key}".to_sym,v)
67
- end
68
- end
69
- end
70
-
71
- #:nodoc:
72
- def multi_level_incl_arrays_initializer(params={}) # Multi Level Initializer including Arrays of Hashes
73
- params.each do |k,v|
74
- key = clean_key(k)
75
- singleton_class.send(:attr_accessor, key) unless respond_to?(key) or serialization_required?
76
- if v.kind_of?(Array) and v.first.kind_of?(Hash)
77
- instance_variable_set("@#{key}".to_sym, (v.map {|nobj| self.class.new(nobj)}) )
78
- elsif v.kind_of?(Hash)
79
- instance_variable_set("@#{key}".to_sym, self.class.new(v))
80
- else
81
- instance_variable_set("@#{key}".to_sym,v)
82
- end
83
- end
84
- end
85
-
86
- # enablement for latter additions
87
- def serialization_required?
88
- @skn_enable_serialization
89
- end
90
-
91
- # enablement for latter additions
92
- def depth_level
93
- @skn_enabled_depth
94
- end
95
-
96
- # determines if this is one of our objects
97
- #:nodoc:
98
- def attribute_helper_object
99
- true
100
- end
101
-
102
- # Some keys have chars not suitable for symbol keys => @,#,:,-
103
- #:nodoc:
104
- def clean_key(original)
105
- formatted_key = original.to_s.gsub(/[#|@]/,'').gsub(/[:|-]/,'_')
106
-
107
- # if /^[#|@|:]/.match(formatted_key) # filter out (@xsi) from '@xsi:type' keys
108
- # label = /@(.+):(.+)/.match(formatted_key) || /[#|@|:](.+)/.match(formatted_key) || []
109
- # formatted_key = case label.size
110
- # when 1
111
- # label[1].to_s
112
- # when 2
113
- # "#{label[1]}_#{label[2]}"
114
- # else
115
- # original # who knows what it was, give it back
116
- # end
117
- # end
118
- # formatted_key
119
- end
120
-
121
-
122
- end
123
- end
@@ -1,21 +0,0 @@
1
- ##
2
- # <project.root>/lib/skn_utils/page_controls.rb
3
- #
4
- # *** See SknUtils::NestedResultBase for details ***
5
- #
6
- ##
7
- # (Defaults)
8
- # :enable_serialization = true -- for function
9
- # :depth = :multi_with_arrays
10
- ##
11
-
12
- module SknUtils
13
-
14
- class PageControls < NestedResultBase
15
- #:nodoc:
16
- def initialize(params={})
17
- super( params.merge({enable_serialization: true, depth: :multi_with_arrays}) )
18
- end
19
- end
20
-
21
- end
@@ -1,17 +0,0 @@
1
- ##
2
- # <project.root>/lib/skn_utils/result_bean.rb
3
- #
4
- # *** See SknUtils::NestedResultBase for details ***
5
- #
6
- ##
7
- # (Defaults)
8
- # :enable_serialization = false -- for speed
9
- # :depth = :multi
10
- ##
11
-
12
- module SknUtils
13
-
14
- class ResultBean < NestedResultBase
15
- end
16
-
17
- end
@@ -1,20 +0,0 @@
1
- ##
2
- # <project.root>/lib/skn_utils/generic_bean.rb
3
- #
4
- # *** See SknUtils::NestedResultBase for details ***
5
- #
6
- ##
7
- # (Defaults)
8
- # :enable_serialization = true
9
- # :depth = :single
10
-
11
- module SknUtils
12
-
13
- class ValueBean < NestedResultBase
14
- #:nodoc:
15
- def initialize(params={})
16
- super( params.merge({enable_serialization: true, depth: :single}) )
17
- end
18
- end # end class
19
-
20
- end # end module
@@ -1,96 +0,0 @@
1
- ##
2
- # spec/lib/skn_utils/generic_bean_spec.rb
3
- #
4
-
5
- RSpec.describe SknUtils::GenericBean, "Generic Marshal'able Bean class " do
6
- let(:object) {
7
- SknUtils::GenericBean.new({one: "one",
8
- two: "two",
9
- three: {four: 4, five: 5, six: {seven: 7, eight: "eight" }},
10
- four: {any_key: "any value"}, five: []}
11
- )
12
- }
13
-
14
- context "Internal Operations, assuming :dept => :multi and enable_serialization => true" do
15
- it "Creates an empty bean if no params are passed" do
16
- is_expected.to be
17
- end
18
- it "Can be Marshalled after dynamically adding a key/value." do
19
- expect { object.fifty = {any_key: "any value"} }.not_to raise_error
20
- expect { object.sixty = 60 }.not_to raise_error
21
- dmp = obj = ""
22
- expect { dmp = Marshal.dump(object) }.not_to raise_error
23
- expect { obj = Marshal.load(dmp) }.not_to raise_error
24
- expect(obj).to be_a(SknUtils::GenericBean)
25
- expect(obj.fifty.any_key).to eql "any value"
26
- expect(obj.sixty).to eql 60
27
- end
28
- it "Initializes from a hash" do
29
- expect(SknUtils::GenericBean.new({one: "one", two: "two"})).to be
30
- end
31
- it "Does not modify the base class, only singleton instance methods" do
32
- obj1 = SknUtils::GenericBean.new({one: "one", two: "two"})
33
- obj2 = SknUtils::GenericBean.new({three: "3", four: "4"})
34
- expect(obj1.one).to eql "one"
35
- expect(obj2.three).to eql "3"
36
- expect(obj2.one?).to be false
37
- expect(obj1.three?).to be false
38
- expect { obj1.three }.to raise_error NoMethodError
39
- expect { obj2.one }.to raise_error NoMethodError
40
- end
41
- it "Supports - respond_to? - method, because it has accessors or method_missing coverage" do
42
- expect(object).to respond_to(:one)
43
- expect(object.one).to eql "one"
44
- expect{ object.fifty = {any_key: "any value"} }.not_to raise_error
45
- expect( object.fifty).to respond_to(:any_key)
46
- end
47
- it "nest objects if multi-level hash is given" do
48
- expect(object.one).to be_eql("one")
49
- expect(object.two).to be_eql("two")
50
- expect(object.three).to be_a(SknUtils::GenericBean)
51
- expect(object.three.five).to eq(5)
52
- end
53
- it "#attributes method returns a hash of all attributes and their values." do
54
- expect(object.to_hash).to be_a(Hash)
55
- expect(object.to_hash[:one]).to be_eql("one")
56
- expect(object.to_hash[:three]).to be_a(Hash)
57
- end
58
- end
59
-
60
- shared_examples_for "retains initialization options" do
61
- it "retains depth_level option flag" do
62
- expect(@obj.depth_level).to eql(:multi)
63
- end
64
- it "retains serialization option flag" do
65
- expect(@obj.serialization_required?).to be true
66
- end
67
- end
68
-
69
- context "Basic Operations without marshaling " do
70
- before :each do
71
- @obj = object
72
- end
73
-
74
- it_behaves_like "retains initialization options"
75
- it_behaves_like "marshalable ruby pojo"
76
- end
77
- context "Basic Operations after Yaml marshaling " do
78
- before :each do
79
- dmp = YAML::dump(object)
80
- @obj = YAML::load(dmp)
81
- end
82
-
83
- it_behaves_like "retains initialization options"
84
- it_behaves_like "marshalable ruby pojo"
85
- end
86
- context "Basic Operations after Marshal marshaling " do
87
- before :each do
88
- dmp = Marshal.dump(object)
89
- @obj = Marshal.load(dmp)
90
- end
91
-
92
- it_behaves_like "retains initialization options"
93
- it_behaves_like "marshalable ruby pojo"
94
- end
95
-
96
- end
@@ -1,124 +0,0 @@
1
- ##
2
- # spec/lib/skn_utils/generic_bean_spec.rb
3
- #
4
-
5
- RSpec.describe SknUtils::PageControls, "PageControls Marshal'able Bean class " do
6
- let(:object) {
7
- SknUtils::PageControls.new({one: "one",
8
- two: "two",
9
- three: {four: 4, five: 5, six: {seven: 7, eight: "eight" }},
10
- four: {any_key: "any value"},
11
- five: [],
12
- six: [{any_key: "any value"},
13
- {four: 4,
14
- five: 5,
15
- six: {seven: 7, eight: "eight" },
16
- twenty:[{seven: 7, eight: 8 }, {nine: 9, ten: 10 }]
17
- }
18
- ]
19
- })
20
- }
21
-
22
- context "Internal Operations, assuming :dept => :multi_with_arrays and enable_serialization => true" do
23
- it "Creates an empty bean if no params are passed" do
24
- is_expected.to be
25
- end
26
- it "Can be Marshalled after dynamically adding a key/value." do
27
- expect { object.fifty = {any_key: "any value"} }.not_to raise_error
28
- expect { object.sixty = 60 }.not_to raise_error
29
- dmp = obj = ""
30
- expect { dmp = Marshal.dump(object) }.not_to raise_error
31
- expect { obj = Marshal.load(dmp) }.not_to raise_error
32
- expect(obj).to be_a(SknUtils::PageControls)
33
- expect( obj.fifty.any_key).to eql "any value"
34
- expect( obj.sixty).to eql 60
35
- end
36
- it "Initializes from a hash" do
37
- expect(object).to be
38
- end
39
- it "Does not modify the base class, only singleton instance methods" do
40
- obj1 = SknUtils::PageControls.new({one: "one", two: "two"})
41
- obj2 = SknUtils::PageControls.new({three: "3", four: "4"})
42
- expect(obj1.one).to eql "one"
43
- expect(obj2.three).to eql "3"
44
- expect(obj2.one?).to be false
45
- expect(obj1.three?).to be false
46
- expect { obj1.three }.to raise_error NoMethodError
47
- expect { obj2.one }.to raise_error NoMethodError
48
- end
49
- it "Supports predicates(?)" do
50
- expect(object.one?).to be true
51
- expect(object.three.five?).to be true
52
- expect(object.fourtyfive?).to be false
53
- end
54
- it "Supports - respond_to? - method, because it has accessor or method_missing coverage" do
55
- expect(object).to respond_to(:one)
56
- expect(object.one).to eql "one"
57
- end
58
- it "nest objects if multi-level hash is given" do
59
- expect(object.three).to be_a(SknUtils::PageControls)
60
- expect(object.three.five).to eq(5)
61
- end
62
- it "nest objects if multi-level array of hashes is given" do
63
- expect(object.six).to be_a(Array)
64
- expect(object.six.first).to be_a(SknUtils::PageControls)
65
- expect(object.six.last).to be_a(SknUtils::PageControls)
66
- expect(object.six.last.six.eight).to eq('eight')
67
- end
68
- it "nest objects if multi-level array of hashes, and an element contains another array of hashes, is given" do
69
- expect(object.six.first).to be_a(SknUtils::PageControls)
70
- expect(object.six).to be_a(Array)
71
- expect(object.six.last.twenty).to be_a(Array)
72
- expect(object.six.last.twenty.first).to be_a(SknUtils::PageControls)
73
- expect(object.six.last.twenty.last).to be_a(SknUtils::PageControls)
74
- expect(object.six.last.twenty.first.eight).to eq(8)
75
- expect(object.six.last.twenty.last.ten).to eq(10)
76
- end
77
- it "nest arrays of objects if array of hashes is dynamically given (post-create)" do
78
- expect { object.one_array = [{one: "one", two: "two"},{one: 1, two: 2}] }.not_to raise_error
79
- expect(object.one_array.first.one).to eql("one")
80
- expect(object.one_array.last.two).to eql(2)
81
- expect(object.one_array[0]).to be_a(SknUtils::PageControls)
82
- end
83
- it "#attributes method returns a hash of all attributes and their values." do
84
- expect(object.to_hash).to be_a(Hash)
85
- expect(object.to_hash[:one]).to be_eql("one")
86
- expect(object.to_hash[:three]).to be_a(Hash)
87
- expect(object.to_hash[:six].last[:six][:eight]).to eql('eight')
88
- end
89
- end
90
-
91
- shared_examples_for "retains initialization options" do
92
- it "retains depth_level option flag" do
93
- expect(@obj.depth_level).to eql(:multi_with_arrays)
94
- end
95
- it "retains serialization option flag" do
96
- expect(@obj.serialization_required?).to be true
97
- end
98
- end
99
-
100
- context "Basic Operations without marshaling " do
101
- before :each do
102
- @obj = object
103
- end
104
- it_behaves_like "retains initialization options"
105
- it_behaves_like "marshalable ruby pojo"
106
- end
107
- context "Basic Operations after Yaml marshaling " do
108
- before :each do
109
- dmp = YAML::dump(object)
110
- @obj = YAML::load(dmp)
111
- end
112
- it_behaves_like "retains initialization options"
113
- it_behaves_like "marshalable ruby pojo"
114
- end
115
- context "Basic Operations after Marshal marshaling " do
116
- before :each do
117
- dmp = Marshal.dump(object)
118
- @obj = Marshal.load(dmp)
119
- end
120
- it_behaves_like "retains initialization options"
121
- it_behaves_like "marshalable ruby pojo"
122
- end
123
-
124
- end
@@ -1,98 +0,0 @@
1
- ##
2
- # spec/lib/skn_utils/result_bean_spec.rb
3
- #
4
-
5
- RSpec.describe SknUtils::ResultBean, "Result Bean class - Basic usage." do
6
- let(:object) {
7
- SknUtils::ResultBean.new({one: "one",
8
- two: "two",
9
- three: {four: 4, five: 5, six: {seven: 7, eight: "eight" }},
10
- four: {any_key: "any value"},
11
- five: [],
12
- six: [{four: 4, five: 5, six: {seven: 7, eight: "eight" }},
13
- {four: 4, five: 5, six: {nine: 9, ten: "ten" }}
14
- ]
15
- })
16
- }
17
-
18
- context "Internal Operations, assuming :dept => :multi and enable_serialization => false" do
19
- it "Creates an empty bean if no params are passed" do
20
- is_expected.to be
21
- end
22
- it "Initializes from a hash" do
23
- expect(SknUtils::ResultBean.new({one: "one", two: "two"})).to be
24
- end
25
- it "Does not modify the base class, only singleton instance methods" do
26
- obj1 = SknUtils::ResultBean.new({one: "one", two: "two"})
27
- obj2 = SknUtils::ResultBean.new({three: 3, four: "4"})
28
- expect(obj1.one).to eql "one"
29
- expect(obj2.three).to eql 3
30
- expect(obj2.one?).to be false
31
- expect(obj1.three?).to be false
32
- expect { obj1.three }.to raise_error NoMethodError
33
- expect { obj2.one }.to raise_error NoMethodError
34
- end
35
- it "Supports - respond_to - methods, because it has accessor methods" do
36
- expect(object).to respond_to(:one)
37
- end
38
- it "Supports - respond_to - methods, because it has respond_to_missing? method" do
39
- expect(object.method(:one)).to be
40
- end
41
- end
42
-
43
- shared_examples_for "retains initialization options" do
44
- it "retains depth_level option flag" do
45
- expect(@obj.depth_level).to eql(:multi)
46
- end
47
- it "retains serialization option flag" do
48
- expect(@obj.serialization_required?).to be false
49
- end
50
- end
51
-
52
- context "Basic Operations after Marshal marshaling " do
53
- it "Singleton objects (like ResultBean) cannot be marshaled" do
54
- expect { Marshal.dump(object) }.to raise_error TypeError
55
- end
56
- end
57
- context "Basic Operations without marshaling " do
58
- before :each do
59
- @obj = object
60
- end
61
- it_behaves_like "retains initialization options"
62
- it_behaves_like "ruby pojo"
63
- end
64
- context "Basic Operations after Yaml marshaling " do
65
- before :each do
66
- dmp = YAML::dump(object)
67
- @obj = YAML::load(dmp)
68
- end
69
- it_behaves_like "retains initialization options"
70
- it_behaves_like "ruby pojo"
71
- end
72
- context "ResultBeans stripped of their internal singleton accessors can be Marshaled! " do
73
- before :each do
74
- dmp = YAML::dump(object)
75
- obj = YAML::load(dmp) # Yaml'ing removes singleton accessor methods'
76
- # by initializing object without using its
77
- # initialize() method
78
-
79
- dmp = Marshal.dump(obj) # Now Marshal load/dump will work
80
- @obj = Marshal.load(dmp) # Use GenericBean if Marshal support is needed
81
- end
82
- it_behaves_like "retains initialization options"
83
- it_behaves_like "ruby pojo"
84
- end
85
- context "Basic Operations after Yaml marshaling via restored accessors " do
86
- before :each do
87
- dmp = YAML::dump(object)
88
- @obj = YAML::load(dmp)
89
- # Restore setters
90
- # @obj.attributes.keys.each do |k|
91
- # @obj.singleton_class.send(:attr_accessor, k)
92
- # end
93
- end
94
- it_behaves_like "retains initialization options"
95
- it_behaves_like "ruby pojo"
96
- end
97
-
98
- end
@@ -1,96 +0,0 @@
1
- ##
2
- # spec/lib/skn_utils/Value_bean_spec.rb
3
- #
4
-
5
- RSpec.describe SknUtils::ValueBean, "Basic Value Bean class " do
6
- let(:object) {
7
- SknUtils::ValueBean.new({one: "one",
8
- two: "two",
9
- three: {four: 4, five: 5, six: {seven: 7, eight: "eight" }},
10
- four: {any_key: "any value"}, five: []}
11
- )
12
- }
13
-
14
- context "Internal Operations, assuming :dept => :multi and enable_serialization => true" do
15
- it "Creates an empty bean if no params are passed" do
16
- is_expected.to be
17
- end
18
- it "Can be Marshalled after dynamically adding a key/value." do
19
- expect { object.fifty = {any_key: "any value"} }.not_to raise_error
20
- expect { object.sixty = 60 }.not_to raise_error
21
- dmp = obj = ""
22
- expect { dmp = Marshal.dump(object) }.not_to raise_error
23
- expect { obj = Marshal.load(dmp) }.not_to raise_error
24
- expect(obj).to be_a(SknUtils::ValueBean)
25
- expect(obj.fifty[:any_key]).to eql "any value"
26
- expect(obj.sixty).to eql 60
27
- end
28
- it "Initializes from a hash" do
29
- expect(SknUtils::ValueBean.new({one: "one", two: "two"})).to be
30
- end
31
- it "Does not modify the base class, only singleton instance methods" do
32
- obj1 = SknUtils::ValueBean.new({one: "one", two: "two"})
33
- obj2 = SknUtils::ValueBean.new({three: "3", four: "4"})
34
- expect(obj1.one).to eql "one"
35
- expect(obj2.three).to eql "3"
36
- expect(obj2.one?).to be false
37
- expect(obj1.three?).to be false
38
- expect { obj1.three }.to raise_error NoMethodError
39
- expect { obj2.one }.to raise_error NoMethodError
40
- end
41
- it "Supports - respond_to? - method, because it has accessors or method_missing coverage" do
42
- expect(object).to respond_to(:one)
43
- expect(object.one).to eql "one"
44
- expect{ object.fifty = {any_key: "any value"} }.not_to raise_error
45
- expect( object.fifty).not_to respond_to(:any_key)
46
- end
47
- it "nest objects if multi-level hash is given" do
48
- expect(object.one).to be_eql("one")
49
- expect(object.two).to be_eql("two")
50
- expect(object.three).to be_a(Hash)
51
- expect(object.three[:five]).to eq(5)
52
- end
53
- it "#attributes method returns a hash of all attributes and their values." do
54
- expect(object.to_hash).to be_a(Hash)
55
- expect(object.to_hash[:one]).to be_eql("one")
56
- expect(object.to_hash[:three]).to be_a(Hash)
57
- end
58
- end
59
-
60
- shared_examples_for "retains initialization options" do
61
- it "retains depth_level option flag" do
62
- expect(@obj.depth_level).to eql(:single)
63
- end
64
- it "retains serialization option flag" do
65
- expect(@obj.serialization_required?).to be true
66
- end
67
- end
68
-
69
- context "Basic Operations without marshaling " do
70
- before :each do
71
- @obj = object
72
- end
73
-
74
- it_behaves_like "retains initialization options"
75
- it_behaves_like "marshalable ruby pojo"
76
- end
77
- context "Basic Operations after Yaml marshaling " do
78
- before :each do
79
- dmp = YAML::dump(object)
80
- @obj = YAML::load(dmp)
81
- end
82
-
83
- it_behaves_like "retains initialization options"
84
- it_behaves_like "marshalable ruby pojo"
85
- end
86
- context "Basic Operations after Marshal marshaling " do
87
- before :each do
88
- dmp = Marshal.dump(object)
89
- @obj = Marshal.load(dmp)
90
- end
91
-
92
- it_behaves_like "retains initialization options"
93
- it_behaves_like "marshalable ruby pojo"
94
- end
95
-
96
- end
@@ -1,54 +0,0 @@
1
- ##
2
- # <root>/spec/support/shared_example_marshalable_ruby_pojo.rb
3
- #
4
- # refs: page_controls, generic_bean
5
- #
6
-
7
- RSpec.shared_examples "marshalable ruby pojo" do
8
- it "provides getters" do
9
- expect(@obj.one).to be_eql("one")
10
- expect(@obj.two).to be_eql("two")
11
- end
12
- it "provides setters" do
13
- @obj.one = "1"
14
- @obj.two = "2"
15
- expect(@obj.two).to be_eql("2")
16
- expect(@obj.one).to be_eql("1")
17
- end
18
- it "#clear_attribute sets given attribute to nil." do
19
- expect(@obj.two).to be_eql("two")
20
- expect(@obj.clear_two).to be_nil
21
- end
22
- it "#attribute? returns true or false based on true presence and non-blank contents of attribute." do
23
- expect(@obj.two?).to be true
24
- @obj.two = false
25
- expect(@obj.two?).to be true
26
- @obj.clear_two
27
- expect(@obj.two?).to be false
28
- expect(@obj.three?).to be true
29
- expect(@obj.four?).to be true
30
- @obj.clear_three
31
- expect(@obj.three?).to be false
32
- @obj.clear_four
33
- expect(@obj.four?).to be false
34
- end
35
- it "#attribute? returns false when attribute is not defined or unknown" do
36
- expect(@obj.address?).to be false
37
- end
38
- it "raises an 'NoMethodError' error when attribute does not exist" do
39
- expect { @obj.address }.to raise_error NoMethodError
40
- end
41
- it "#to_hash method excludes internal attributes unless overridden." do
42
- expect(@obj.to_hash[:skn_enabled_depth]).to be_nil
43
- expect(@obj.to_hash(false)[:skn_enabled_depth]).to be_nil
44
- expect(@obj.to_hash(true)[:skn_enabled_depth]).to eql @obj.depth_level
45
- end
46
- context "transformations are enabled with " do
47
- it "#to_hash method returns a serialized version of this object." do
48
- expect(@obj.to_hash).to be_a(Hash)
49
- end
50
- it "#attributes method returns original input hash." do
51
- expect(@obj.attributes).to be_a(Hash)
52
- end
53
- end
54
- end