-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathattributes_spec.rb
40 lines (33 loc) · 1.01 KB
/
attributes_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
# frozen_string_literal: true
RSpec.describe Dry::Initializer, "dry_initializer.attributes" do
subject { instance.class.dry_initializer.attributes(instance) }
context "when class has params" do
before do
class Test::Foo
extend Dry::Initializer
param :foo, proc(&:to_s)
param :bar, default: proc { 1 }
param :baz, optional: true
end
end
let(:instance) { Test::Foo.new(:FOO) }
it "collects coerced params with default values" do
expect(subject).to eq({foo: "FOO", bar: 1})
end
end
context "when class has options" do
before do
class Test::Foo
extend Dry::Initializer
option :foo
option :bar, default: proc { 1 }
option :baz, optional: true
option :qux, proc(&:to_s), as: :quxx
end
end
let(:instance) { Test::Foo.new(foo: :FOO, qux: :QUX) }
it "collects coerced and renamed options with default values" do
expect(subject).to eq({foo: :FOO, bar: 1, quxx: "QUX"})
end
end
end