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 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
require "test_helper"
class DSLOptionsTest < Minitest::Spec
let(:defaults) { { id: 1, connections: { first: 1, second: 2 }, list: [3] } }
Variables = Declarative::Variables
after do
_(Declarative::Inspect(defaults)).must_equal %{{:id=>1, :connections=>{:first=>1, :second=>2}, :list=>[3]}}
end
#- Merge
it "merges Merge over original" do
options = Variables.merge(
defaults,
connections: Variables::Merge( second: 3, third: 4 )
)
_(options).must_equal( { id: 1, connections: { first: 1, second: 3, third: 4 }, :list=>[3] } )
end
it "accepts Procs" do
options = Variables.merge(
defaults,
connections: proc = ->(*) { raise }
)
_(options).must_equal( { id: 1, connections: proc, :list=>[3] } )
end
it "overrides original without Merge" do
options = Variables.merge(
defaults, connections: { second: 3, third: 4 } )
_(options).must_equal( { id: 1, connections: { second: 3, third: 4 }, :list=>[3] } )
end
it "creates new hash if original not existent" do
options = Variables.merge(
defaults,
bla: Variables::Merge( second: 3, third: 4 )
)
_(options).must_equal( {:id=>1, :connections=>{:first=>1, :second=>2}, :list=>[3], :bla=>{:second=>3, :third=>4}} )
end
#- Append
it "appends to Array" do
options = Variables.merge(
defaults,
list: Variables::Append( [3, 4, 5] )
)
_(options).must_equal( { id: 1, connections: { first: 1, second: 2 }, :list=>[3, 3, 4, 5] } )
end
it "creates new array if original not existent" do
options = Variables.merge(
defaults,
another_list: Variables::Append( [3, 4, 5] )
)
_(options).must_equal( { id: 1, connections: { first: 1, second: 2 }, :list=>[3], :another_list=>[3, 4, 5] } )
end
end
|