-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathsubclassing_spec.rb
51 lines (41 loc) · 1.25 KB
/
subclassing_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true
RSpec.describe "subclassing" do
before do
class Test::Foo
extend Dry::Initializer[undefined: false]
param :foo
option :bar
end
class Test::Bar < Test::Foo
param :baz
option :qux
end
end
let(:instance_of_superclass) do
Test::Foo.new 1, bar: 3
end
let(:instance_of_subclass) do
Test::Bar.new 1, 2, bar: 3, qux: 4
end
it "preserves null definition" do
expect(Test::Foo.dry_initializer.null).to be_nil
expect(Test::Bar.dry_initializer.null).to be_nil
end
it "preserves definitions made in the superclass" do
expect(instance_of_subclass.foo).to eql 1
expect(instance_of_subclass.baz).to eql 2
expect(instance_of_subclass.bar).to eql 3
expect(instance_of_subclass.qux).to eql 4
end
it "does not pollute superclass with definitions from subclass" do
expect(instance_of_superclass).not_to respond_to :baz
expect(instance_of_superclass).not_to respond_to :qux
end
it "calls .inherited hook added by other mixin" do
called = false
mixin = Module.new { define_method(:inherited) { |_| called = true } }
base = Class.new { extend mixin; extend Dry::Initializer }
Class.new(base)
expect(called).to be true
end
end