spec/lib/abstractivator/enum_spec.rb in abstractivator-0.0.29 vs spec/lib/abstractivator/enum_spec.rb in abstractivator-0.0.30
- old
+ new
@@ -36,18 +36,22 @@
expect{Container::Traditional.from_symbol(:baz)}.to raise_error
end
end
describe '::from' do
it 'returns the typed version of the value' do
- x = 'apple'
- result = Container::Fruits.from(x)
+ result = Container::Fruits.from('apple')
expect(result).to eql Container::Fruits::APPLE
end
it 'works if the value is already typed' do
expect(Container::Fruits.from(Container::Fruits::APPLE)).to eql Container::Fruits::APPLE
end
end
+ describe '::new' do
+ it 'cannot be called' do
+ expect{Container::Fruits.new('durian')}.to raise_error NoMethodError
+ end
+ end
end
describe '#define_enum' do
it 'defines an enum given an array of symbols' do
expect(Container::Fruits::APPLE.value).to eql 'apple'
@@ -56,13 +60,13 @@
it 'defines an enum given a hash' do
expect(Container::Vegetables::CUCUMBER.value).to eql 'Cucumis sativus'
expect(Container::Vegetables::EGGPLANT.value).to eql 8
end
it 'values know their parent' do
- expect(Container::Fruits::APPLE.enum_type).to eql Container::Fruits
- expect(Container::Fruits::ORANGE.enum_type).to eql Container::Fruits
- expect(Container::Vegetables::CUCUMBER.enum_type).to eql Container::Vegetables
- expect(Container::Vegetables::EGGPLANT.enum_type).to eql Container::Vegetables
+ expect(Container::Fruits::APPLE).to be_a Container::Fruits
+ expect(Container::Fruits::ORANGE).to be_a Container::Fruits
+ expect(Container::Vegetables::CUCUMBER).to be_a Container::Vegetables
+ expect(Container::Vegetables::EGGPLANT).to be_a Container::Vegetables
end
it 'can define top level enumerations' do
expect(Meats.values.map(&:value)).to eql %w(bacon more_bacon)
end
it 'raises an error when called with bad arguments' do