virtus 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +19 -15
  3. data/Changelog.md +43 -2
  4. data/Gemfile +5 -5
  5. data/README.md +113 -78
  6. data/Rakefile +13 -3
  7. data/lib/virtus.rb +46 -6
  8. data/lib/virtus/attribute.rb +21 -3
  9. data/lib/virtus/attribute/accessor.rb +11 -0
  10. data/lib/virtus/attribute/builder.rb +8 -13
  11. data/lib/virtus/attribute/collection.rb +12 -3
  12. data/lib/virtus/attribute/default_value.rb +2 -0
  13. data/lib/virtus/attribute/hash.rb +3 -3
  14. data/lib/virtus/attribute/nullify_blank.rb +24 -0
  15. data/lib/virtus/attribute/strict.rb +1 -1
  16. data/lib/virtus/attribute_set.rb +2 -2
  17. data/lib/virtus/builder.rb +2 -6
  18. data/lib/virtus/class_inclusions.rb +0 -1
  19. data/lib/virtus/coercer.rb +1 -0
  20. data/lib/virtus/configuration.rb +17 -36
  21. data/lib/virtus/extensions.rb +13 -21
  22. data/lib/virtus/instance_methods.rb +3 -2
  23. data/lib/virtus/model.rb +1 -3
  24. data/lib/virtus/module_extensions.rb +8 -2
  25. data/lib/virtus/support/equalizer.rb +1 -1
  26. data/lib/virtus/support/options.rb +2 -1
  27. data/lib/virtus/support/type_lookup.rb +1 -1
  28. data/lib/virtus/version.rb +1 -1
  29. data/spec/integration/attributes_attribute_spec.rb +28 -0
  30. data/spec/integration/building_module_spec.rb +22 -0
  31. data/spec/integration/collection_member_coercion_spec.rb +34 -13
  32. data/spec/integration/custom_attributes_spec.rb +2 -2
  33. data/spec/integration/custom_collection_attributes_spec.rb +6 -6
  34. data/spec/integration/default_values_spec.rb +8 -8
  35. data/spec/integration/defining_attributes_spec.rb +25 -18
  36. data/spec/integration/embedded_value_spec.rb +5 -5
  37. data/spec/integration/extending_objects_spec.rb +5 -5
  38. data/spec/integration/hash_attributes_coercion_spec.rb +16 -12
  39. data/spec/integration/mass_assignment_with_accessors_spec.rb +5 -5
  40. data/spec/integration/overriding_virtus_spec.rb +4 -4
  41. data/spec/integration/required_attributes_spec.rb +1 -1
  42. data/spec/integration/struct_as_embedded_value_spec.rb +4 -4
  43. data/spec/integration/using_modules_spec.rb +8 -8
  44. data/spec/integration/value_object_with_custom_constructor_spec.rb +4 -4
  45. data/spec/integration/virtus/instance_level_attributes_spec.rb +1 -1
  46. data/spec/integration/virtus/value_object_spec.rb +14 -14
  47. data/spec/shared/freeze_method_behavior.rb +6 -3
  48. data/spec/shared/idempotent_method_behaviour.rb +1 -1
  49. data/spec/shared/options_class_method.rb +3 -3
  50. data/spec/spec_helper.rb +2 -18
  51. data/spec/unit/virtus/attribute/boolean/coerce_spec.rb +3 -3
  52. data/spec/unit/virtus/attribute/boolean/value_coerced_predicate_spec.rb +3 -3
  53. data/spec/unit/virtus/attribute/class_methods/build_spec.rb +64 -24
  54. data/spec/unit/virtus/attribute/class_methods/coerce_spec.rb +2 -2
  55. data/spec/unit/virtus/attribute/coerce_spec.rb +58 -10
  56. data/spec/unit/virtus/attribute/coercible_predicate_spec.rb +2 -2
  57. data/spec/unit/virtus/attribute/collection/class_methods/build_spec.rb +15 -4
  58. data/spec/unit/virtus/attribute/collection/coerce_spec.rb +25 -4
  59. data/spec/unit/virtus/attribute/collection/value_coerced_predicate_spec.rb +31 -0
  60. data/spec/unit/virtus/attribute/comparison_spec.rb +20 -0
  61. data/spec/unit/virtus/attribute/custom_collection_spec.rb +8 -2
  62. data/spec/unit/virtus/attribute/defined_spec.rb +20 -0
  63. data/spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb +30 -15
  64. data/spec/unit/virtus/attribute/embedded_value/coerce_spec.rb +25 -11
  65. data/spec/unit/virtus/attribute/get_spec.rb +2 -2
  66. data/spec/unit/virtus/attribute/hash/class_methods/build_spec.rb +21 -9
  67. data/spec/unit/virtus/attribute/hash/coerce_spec.rb +9 -9
  68. data/spec/unit/virtus/attribute/lazy_predicate_spec.rb +2 -2
  69. data/spec/unit/virtus/attribute/rename_spec.rb +6 -3
  70. data/spec/unit/virtus/attribute/required_predicate_spec.rb +2 -2
  71. data/spec/unit/virtus/attribute/set_default_value_spec.rb +43 -10
  72. data/spec/unit/virtus/attribute/set_spec.rb +1 -1
  73. data/spec/unit/virtus/attribute/value_coerced_predicate_spec.rb +2 -2
  74. data/spec/unit/virtus/attribute_set/append_spec.rb +6 -6
  75. data/spec/unit/virtus/attribute_set/define_reader_method_spec.rb +12 -11
  76. data/spec/unit/virtus/attribute_set/define_writer_method_spec.rb +13 -12
  77. data/spec/unit/virtus/attribute_set/each_spec.rb +21 -16
  78. data/spec/unit/virtus/attribute_set/element_reference_spec.rb +2 -2
  79. data/spec/unit/virtus/attribute_set/element_set_spec.rb +17 -9
  80. data/spec/unit/virtus/attribute_set/merge_spec.rb +7 -5
  81. data/spec/unit/virtus/attribute_set/reset_spec.rb +22 -11
  82. data/spec/unit/virtus/attribute_spec.rb +8 -7
  83. data/spec/unit/virtus/attributes_reader_spec.rb +1 -1
  84. data/spec/unit/virtus/attributes_writer_spec.rb +1 -1
  85. data/spec/unit/virtus/element_reader_spec.rb +1 -1
  86. data/spec/unit/virtus/freeze_spec.rb +23 -3
  87. data/spec/unit/virtus/model_spec.rb +38 -7
  88. data/spec/unit/virtus/module_spec.rb +59 -2
  89. data/spec/unit/virtus/set_default_attributes_spec.rb +10 -3
  90. data/spec/unit/virtus/value_object_spec.rb +15 -5
  91. data/virtus.gemspec +7 -5
  92. metadata +46 -44
  93. data/.ruby-version +0 -1
  94. data/Gemfile.devtools +0 -54
  95. data/config/flay.yml +0 -3
  96. data/config/flog.yml +0 -2
  97. data/config/mutant.yml +0 -15
  98. data/config/reek.yml +0 -146
  99. data/config/yardstick.yml +0 -2
@@ -9,9 +9,9 @@ describe Virtus::AttributeSet, '#[]' do
9
9
  let(:parent) { described_class.new }
10
10
  let(:object) { described_class.new(parent, attributes) }
11
11
 
12
- it { should equal(attribute) }
12
+ it { is_expected.to equal(attribute) }
13
13
 
14
14
  it 'allows indexed access to attributes by the string representation of their name' do
15
- object[name.to_s].should equal(attribute)
15
+ expect(object[name.to_s]).to equal(attribute)
16
16
  end
17
17
  end
@@ -11,7 +11,7 @@ describe Virtus::AttributeSet, '#[]=' do
11
11
  context 'with a new attribute' do
12
12
  let(:attribute) { Virtus::Attribute.build(String, :name => name) }
13
13
 
14
- it { should equal(attribute) }
14
+ it { is_expected.to equal(attribute) }
15
15
 
16
16
  it 'adds an attribute' do
17
17
  expect { subject }.to change { object.to_a }.from(attributes).to([ attribute ])
@@ -35,22 +35,30 @@ describe Virtus::AttributeSet, '#[]=' do
35
35
  let(:attributes) { [ original ] }
36
36
  let(:attribute) { Virtus::Attribute.build(String, :name => name) }
37
37
 
38
- it { should equal(attribute) }
38
+ it { is_expected.to equal(attribute) }
39
39
 
40
- it 'replaces the original attribute' do
41
- expect { subject }.to change { object.to_a }.from(attributes).to([ attribute ])
40
+ it "replaces the original attribute object" do
41
+ expect { subject }.to change { object.to_a.map(&:__id__) }.
42
+ from(attributes.map(&:__id__)).
43
+ to([attribute.__id__])
42
44
  end
43
45
 
44
- it 'allows #[] to access the attribute with a symbol' do
45
- expect { subject }.to change { object['name'] }.from(original).to(attribute)
46
+ it 'allows #[] to access the attribute with a string' do
47
+ expect { subject }.to change { object['name'].__id__ }.
48
+ from(original.__id__).
49
+ to(attribute.__id__)
46
50
  end
47
51
 
48
- it 'allows #[] to access the attribute with a string' do
49
- expect { subject }.to change { object[:name] }.from(original).to(attribute)
52
+ it 'allows #[] to access the attribute with a symbol' do
53
+ expect { subject }.to change { object[:name].__id__ }.
54
+ from(original.__id__).
55
+ to(attribute.__id__)
50
56
  end
51
57
 
52
58
  it 'allows #reset to track overridden attributes' do
53
- expect { subject }.to change { object.reset.to_a }.from(attributes).to([ attribute ])
59
+ expect { subject }.to change { object.reset.to_a.map(&:__id__) }.
60
+ from(attributes.map(&:__id__)).
61
+ to([attribute.__id__])
54
62
  end
55
63
  end
56
64
  end
@@ -12,7 +12,7 @@ describe Virtus::AttributeSet, '#merge' do
12
12
  let(:attributes) { [] }
13
13
  let(:attribute) { Virtus::Attribute.build(String, :name => name) }
14
14
 
15
- it { should equal(object) }
15
+ it { is_expected.to equal(object) }
16
16
 
17
17
  it 'adds an attribute' do
18
18
  expect { subject }.to change { object.to_a }.from(attributes).to([attribute])
@@ -21,12 +21,14 @@ describe Virtus::AttributeSet, '#merge' do
21
21
 
22
22
  context 'with a duplicate attribute' do
23
23
  let(:attributes) { [Virtus::Attribute.build(String, :name => name)] }
24
- let(:attribute) { Virtus::Attribute.build(String, :name => name) }
24
+ let(:attribute) { Virtus::Attribute.build(String, :name => name) }
25
25
 
26
- it { should equal(object) }
26
+ it { is_expected.to equal(object) }
27
27
 
28
- it 'replaces the original attribute' do
29
- expect { subject }.to change { object.to_a }.from(attributes).to([attribute])
28
+ it "replaces the original attribute object" do
29
+ expect { subject }.to change { object.to_a.map(&:__id__) }.
30
+ from(attributes.map(&:__id__)).
31
+ to([attribute.__id__])
30
32
  end
31
33
  end
32
34
  end
@@ -11,27 +11,36 @@ describe Virtus::AttributeSet, '#reset' do
11
11
  context 'when the parent has no attributes' do
12
12
  let(:parent) { described_class.new }
13
13
 
14
- it { should equal(object) }
14
+ it { is_expected.to equal(object) }
15
15
 
16
- its(:to_set) { should == Set[ attribute ] }
16
+ describe '#to_set' do
17
+ subject { super().to_set }
18
+ it { is_expected.to eq(Set[ attribute ]) }
19
+ end
17
20
  end
18
21
 
19
22
  context 'when the parent has attributes that are not duplicates' do
20
23
  let(:parent_attribute) { Virtus::Attribute.build(String, :name => :parent_name) }
21
24
  let(:parent) { described_class.new([ parent_attribute ]) }
22
25
 
23
- it { should equal(object) }
26
+ it { is_expected.to equal(object) }
24
27
 
25
- its(:to_set) { should == Set[ attribute, parent_attribute ] }
28
+ describe '#to_set' do
29
+ subject { super().to_set }
30
+ it { is_expected.to eq(Set[ attribute, parent_attribute ]) }
31
+ end
26
32
  end
27
33
 
28
34
  context 'when the parent has attributes that are duplicates' do
29
35
  let(:parent_attribute) { Virtus::Attribute.build(String, :name => name) }
30
36
  let(:parent) { described_class.new([ parent_attribute ]) }
31
37
 
32
- it { should equal(object) }
38
+ it { is_expected.to equal(object) }
33
39
 
34
- its(:to_set) { should == Set[ attribute ] }
40
+ describe '#to_set' do
41
+ subject { super().to_set }
42
+ it { is_expected.to eq(Set[ attribute ]) }
43
+ end
35
44
  end
36
45
 
37
46
  context 'when the parent has changed' do
@@ -39,19 +48,21 @@ describe Virtus::AttributeSet, '#reset' do
39
48
  let(:parent) { described_class.new([ parent_attribute ]) }
40
49
  let(:new_attribute) { Virtus::Attribute.build(String, :name => :parent_name) }
41
50
 
42
- it { should equal(object) }
51
+ it { is_expected.to equal(object) }
43
52
 
44
53
  it 'includes changes from the parent' do
45
- expect { parent << new_attribute; subject }.to change { object.to_set }.
46
- from(Set[ attribute, parent_attribute ]).
47
- to(Set[ attribute, new_attribute ])
54
+ expect(object.to_set).to eql(Set[attribute, parent_attribute])
55
+
56
+ parent << new_attribute
57
+
58
+ expect(subject.to_set).to eql(Set[attribute, new_attribute])
48
59
  end
49
60
  end
50
61
 
51
62
  context 'when the parent is nil' do
52
63
  let(:parent) { nil }
53
64
 
54
- it { should equal(object) }
65
+ it { is_expected.to equal(object) }
55
66
 
56
67
  it 'includes changes from the parent' do
57
68
  expect { subject }.to_not change { object.to_set }
@@ -4,14 +4,15 @@ describe Virtus, '#attribute' do
4
4
  let(:name) { :test }
5
5
  let(:options) { {} }
6
6
 
7
- share_examples_for 'a class with boolean attribute' do
7
+ shared_examples_for 'a class with boolean attribute' do
8
8
  subject { Test }
9
9
 
10
10
  let(:object) { subject.new }
11
11
 
12
12
  it 'defines reader and writer' do
13
13
  object.test = true
14
- expect(object.test).to be(true)
14
+
15
+ expect(object).to be_test
15
16
  end
16
17
 
17
18
  it 'defines predicate method' do
@@ -21,9 +22,9 @@ describe Virtus, '#attribute' do
21
22
  end
22
23
  end
23
24
 
24
- share_examples_for 'an object with string attribute' do
25
- it { should respond_to(:test) }
26
- it { should respond_to(:test=) }
25
+ shared_examples_for 'an object with string attribute' do
26
+ it { is_expected.to respond_to(:test) }
27
+ it { is_expected.to respond_to(:test=) }
27
28
 
28
29
  it 'can write and read the attribute' do
29
30
  subject.test = :foo
@@ -217,8 +218,8 @@ describe Virtus, '#attribute' do
217
218
  }
218
219
  }
219
220
 
220
- it { should respond_to(:test) }
221
- it { should respond_to(:test=) }
221
+ it { is_expected.to respond_to(:test) }
222
+ it { is_expected.to respond_to(:test=) }
222
223
 
223
224
  it 'writes and reads attributes' do
224
225
  subject.test = :foo
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Virtus, '#attributes' do
4
4
 
5
- share_examples_for 'attribute hash' do
5
+ shared_examples_for 'attribute hash' do
6
6
  it 'includes all attributes' do
7
7
  subject.attributes = { :test => 'Hello World', :test_priv => 'Yo' }
8
8
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Virtus, '#attributes=' do
4
4
 
5
- share_examples_for 'mass-assignment' do
5
+ shared_examples_for 'mass-assignment' do
6
6
  it 'allows writing known attributes' do
7
7
  subject.attributes = { :test => 'Hello World' }
8
8
 
@@ -17,5 +17,5 @@ describe Virtus, '#[]' do
17
17
  object.test = 'foo'
18
18
  end
19
19
 
20
- it { should eq('foo') }
20
+ it { is_expected.to eq('foo') }
21
21
  end
@@ -9,13 +9,33 @@ describe Virtus, '#freeze' do
9
9
 
10
10
  attribute :name, String, :default => 'foo', :lazy => true
11
11
  attribute :age, Integer, :default => 30
12
+ attribute :rand, Float, :default => Proc.new { rand }
12
13
  }
13
14
  }
14
15
 
15
16
  let(:object) { model.new }
16
17
 
17
- it { should be_frozen }
18
+ it { is_expected.to be_frozen }
18
19
 
19
- its(:name) { should eql('foo') }
20
- its(:age) { should be(30) }
20
+ describe '#name' do
21
+ subject { super().name }
22
+ it { is_expected.to eql('foo') }
23
+ end
24
+
25
+ describe '#age' do
26
+ subject { super().age }
27
+ it { is_expected.to be(30) }
28
+ end
29
+
30
+ it "does not change dynamic default values" do
31
+ original_value = object.rand
32
+ object.freeze
33
+ expect(object.rand).to eq original_value
34
+ end
35
+
36
+ it "does not change default attributes that have been explicitly set" do
37
+ object.rand = 3.14
38
+ object.freeze
39
+ expect(object.rand).to eq 3.14
40
+ end
21
41
  end
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Virtus, '.model' do
4
- share_examples_for 'a model with constructor' do
4
+ shared_examples_for 'a model with constructor' do
5
5
  it 'accepts attribute hash' do
6
6
  instance = subject.new(:name => 'Jane')
7
7
  expect(instance.name).to eql('Jane')
8
8
  end
9
9
  end
10
10
 
11
- share_examples_for 'a model with mass-assignment' do
11
+ shared_examples_for 'a model with mass-assignment' do
12
12
  let(:attributes) do
13
13
  { :name => 'Jane', :something => nil }
14
14
  end
@@ -22,7 +22,7 @@ describe Virtus, '.model' do
22
22
  end
23
23
  end
24
24
 
25
- share_examples_for 'a model with strict mode turned off' do
25
+ shared_examples_for 'a model with strict mode turned off' do
26
26
  it 'has attributes with strict set to false' do
27
27
  expect(subject.send(:attribute_set)[:name]).to_not be_strict
28
28
  end
@@ -148,8 +148,8 @@ describe Virtus, '.model' do
148
148
  model.send(:include, mod)
149
149
  end
150
150
 
151
- it { should_not respond_to(:attributes) }
152
- it { should_not respond_to(:attributes=) }
151
+ it { is_expected.not_to respond_to(:attributes) }
152
+ it { is_expected.not_to respond_to(:attributes=) }
153
153
  end
154
154
 
155
155
  context 'with an instance' do
@@ -159,8 +159,39 @@ describe Virtus, '.model' do
159
159
  subject.extend(mod)
160
160
  end
161
161
 
162
- it { should_not respond_to(:attributes) }
163
- it { should_not respond_to(:attributes=) }
162
+ it { is_expected.not_to respond_to(:attributes) }
163
+ it { is_expected.not_to respond_to(:attributes=) }
164
+ end
165
+ end
166
+
167
+ context 'when :required is set' do
168
+ let(:mod) { Virtus.model(:required => false) }
169
+ let(:model) { Class.new }
170
+
171
+ context 'with a class' do
172
+ subject { model.new }
173
+
174
+ before do
175
+ model.send(:include, mod)
176
+ model.attribute :name, String
177
+ end
178
+
179
+ it 'has attributes with :required option inherited from module' do
180
+ expect(model.attribute_set[:name]).to_not be_required
181
+ end
182
+ end
183
+
184
+ context 'with an instance' do
185
+ subject { model.new }
186
+
187
+ before do
188
+ subject.extend(mod)
189
+ subject.attribute :name, String
190
+ end
191
+
192
+ it 'has attributes with strict set to true' do
193
+ expect(subject.send(:attribute_set)[:name]).not_to be_required
194
+ end
164
195
  end
165
196
  end
166
197
  end
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Virtus, '.module' do
4
- share_examples_for 'a valid virtus object' do
4
+ shared_examples_for 'a valid virtus object' do
5
5
  it 'reads and writes attribute' do
6
6
  instance.name = 'John'
7
7
  expect(instance.name).to eql('John')
8
8
  end
9
9
  end
10
10
 
11
- share_examples_for 'an object extended with virtus module' do
11
+ shared_examples_for 'an object extended with virtus module' do
12
12
  context 'with default configuration' do
13
13
  subject { Virtus.module }
14
14
 
@@ -114,4 +114,61 @@ describe Virtus, '.module' do
114
114
  end
115
115
  end
116
116
 
117
+ context 'as a peer to another module within a class' do
118
+ subject { Virtus.module }
119
+ let(:other) { Module.new }
120
+
121
+ before do
122
+ other.send(:include, Virtus.module)
123
+ other.attribute :last_name, String, :default => 'Doe'
124
+ other.attribute :something_else
125
+ model.send(:include, mod)
126
+ model.send(:include, other)
127
+ end
128
+
129
+ it 'provides attributes for the model from both modules' do
130
+ expect(model.attribute_set[:name]).to be_kind_of(Virtus::Attribute)
131
+ expect(model.attribute_set[:something]).to be_kind_of(Virtus::Attribute)
132
+ expect(model.attribute_set[:last_name]).to be_kind_of(Virtus::Attribute)
133
+ expect(model.attribute_set[:something_else]).to be_kind_of(Virtus::Attribute)
134
+ end
135
+
136
+ it 'includes the attributes from both modules' do
137
+ expect(model.new.attributes.keys).to eq(
138
+ [:name, :something, :last_name, :something_else]
139
+ )
140
+ end
141
+ end
142
+
143
+ context 'with multiple other modules mixed into it' do
144
+ subject { Virtus.module }
145
+ let(:other) { Module.new }
146
+ let(:yet_another) { Module.new }
147
+
148
+ before do
149
+ other.send(:include, Virtus.module)
150
+ other.attribute :last_name, String, :default => 'Doe'
151
+ other.attribute :something_else
152
+ yet_another.send(:include, Virtus.module)
153
+ yet_another.send(:include, mod)
154
+ yet_another.send(:include, other)
155
+ yet_another.attribute :middle_name, String, :default => 'Foobar'
156
+ model.send(:include, yet_another)
157
+ end
158
+
159
+ it 'provides attributes for the model from all modules' do
160
+ expect(model.attribute_set[:name]).to be_kind_of(Virtus::Attribute)
161
+ expect(model.attribute_set[:something]).to be_kind_of(Virtus::Attribute)
162
+ expect(model.attribute_set[:last_name]).to be_kind_of(Virtus::Attribute)
163
+ expect(model.attribute_set[:something_else]).to be_kind_of(Virtus::Attribute)
164
+ expect(model.attribute_set[:middle_name]).to be_kind_of(Virtus::Attribute)
165
+ end
166
+
167
+ it 'includes the attributes from all modules' do
168
+ expect(model.new.attributes.keys).to eq(
169
+ [:name, :something, :last_name, :something_else, :middle_name]
170
+ )
171
+ end
172
+ end
173
+
117
174
  end
@@ -18,8 +18,15 @@ describe Virtus, '#set_default_attributes!' do
18
18
  object.set_default_attributes!
19
19
  end
20
20
 
21
- it { should be(object) }
21
+ it { is_expected.to be(object) }
22
22
 
23
- its(:name) { should eql('foo') }
24
- its(:age) { should be(30) }
23
+ describe '#name' do
24
+ subject { super().name }
25
+ it { is_expected.to eql('foo') }
26
+ end
27
+
28
+ describe '#age' do
29
+ subject { super().age }
30
+ it { is_expected.to be(30) }
31
+ end
25
32
  end
@@ -1,13 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Virtus::ValueObject do
4
- share_examples_for 'a valid value object' do
4
+ shared_examples_for 'a valid value object' do
5
5
  subject { model.new(attributes) }
6
6
 
7
7
  let(:attributes) { Hash[:id => 1, :name => 'Jane Doe'] }
8
8
 
9
- its(:id) { should be(1) }
10
- its(:name) { should eql('Jane Doe') }
9
+ describe '#id' do
10
+ subject { super().id }
11
+ it { is_expected.to be(1) }
12
+ end
13
+
14
+ describe '#name' do
15
+ subject { super().name }
16
+ it { is_expected.to eql('Jane Doe') }
17
+ end
11
18
 
12
19
  it 'sets private writers' do
13
20
  expect(subject.class.attribute_set[:id]).to_not be_public_writer
@@ -43,7 +50,7 @@ describe Virtus::ValueObject do
43
50
  end
44
51
  end
45
52
 
46
- share_examples_for 'a valid value object with mass-assignment turned on' do
53
+ shared_examples_for 'a valid value object with mass-assignment turned on' do
47
54
  subject { model.new }
48
55
 
49
56
  it 'disallows mass-assignment' do
@@ -95,7 +102,10 @@ describe Virtus::ValueObject do
95
102
 
96
103
  let(:attributes) { Hash[:id => 1, :name => 'Jane Doe', :email => 'jane@doe.com'] }
97
104
 
98
- its(:email) { should eql('jane@doe.com') }
105
+ describe '#email' do
106
+ subject { super().email }
107
+ it { is_expected.to eql('jane@doe.com') }
108
+ end
99
109
 
100
110
  it 'sets private writers for additional values' do
101
111
  expect(subclass.attribute_set[:email]).to_not be_public_writer