Skip to content

Commit

Permalink
explicitly pass in hashes instead of keyword arguments (#64)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Wang <matt@matthewwang.me>
  • Loading branch information
leifg and mattxwang committed Jul 22, 2022
1 parent a72621f commit 89e2d8d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions spec/coerce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,25 +211,25 @@ class Param2 < T::Struct
context 'when given union types' do
context 'supported union types' do
it 'coerces correctly' do
coerced = TypeCoerce[WithSupportedUnion].new.from(
coerced = TypeCoerce[WithSupportedUnion].new.from({
nilable: 2,
nilable_boolean: 'true'
)
})
expect(coerced.nilable).to eq('2')
expect(coerced.nilable_boolean).to eq(true)
end
end

context 'unsupported union types' do
it 'keeps the values as-is' do
coerced = TypeCoerce[WithUnsupportedUnion].new.from(union: 'a')
coerced = TypeCoerce[WithUnsupportedUnion].new.from({union: 'a'})
expect(coerced.union).to eq('a')

coerced = TypeCoerce[WithUnsupportedUnion].new.from(union: 2)
coerced = TypeCoerce[WithUnsupportedUnion].new.from({union: 2})
expect(coerced.union).to eq(2)

expect do
TypeCoerce[WithUnsupportedUnion].new.from(union: nil)
TypeCoerce[WithUnsupportedUnion].new.from({union: nil})
end.to raise_error(TypeError)
end
end
Expand Down Expand Up @@ -316,18 +316,18 @@ class Param2 < T::Struct

context 'when dealing with enums' do
it 'coerces a serialized enum correctly' do
coerced = TypeCoerce[WithEnum].new.from(myenum: "test")
coerced = TypeCoerce[WithEnum].new.from({myenum: "test"})
expect(coerced.myenum).to eq(TestEnum::Test)
end

it 'handles a real enum correctly' do
coerced = TypeCoerce[WithEnum].new.from(myenum: TestEnum::Test)
coerced = TypeCoerce[WithEnum].new.from({myenum: TestEnum::Test})
expect(coerced.myenum).to eq(TestEnum::Test)
end

it 'handles bad enum' do
expect {
TypeCoerce[WithEnum].new.from(myenum: "bad_key")
TypeCoerce[WithEnum].new.from({myenum: "bad_key"})
}.to raise_error(TypeCoerce::CoercionError)
end
end
Expand Down

0 comments on commit 89e2d8d

Please sign in to comment.