@@ -7,7 +7,7 @@ def initialize(state)
77 @state = state
88 end
99
10- include EnumMachine [ state : { enum : %w[ choice in_delivery ] } ]
10+ include EnumMachine [ state : { enum : %w[ choice in_delivery lost ] } ]
1111end
1212
1313module ValueDecorator
@@ -23,14 +23,17 @@ def initialize(state)
2323 @state = state
2424 end
2525
26- include EnumMachine [ state : { enum : %w[ choice in_delivery ] , value_decorator : ValueDecorator } ]
26+ include EnumMachine [ state : { enum : %w[ choice in_delivery lost ] , value_decorator : ValueDecorator } ]
2727end
2828
2929RSpec . describe "DriverSimpleClass" do
3030 subject ( :item ) { TestClass . new ( "choice" ) }
3131
32- it { expect ( item . state ) . to be_choice }
33- it { expect ( item . state ) . not_to be_in_delivery }
32+ it { expect ( item . state . choice? ) . to be true }
33+ it { expect ( item . state . in_delivery? ) . to be false }
34+ it { expect ( item . state . choice__in_delivery? ) . to be true }
35+ it { expect ( item . state . lost__in_delivery? ) . to be false }
36+ it { expect { item . state . last__in_delivery? } . to raise_error ( NoMethodError ) }
3437 it { expect ( item . state ) . to eq "choice" }
3538 it { expect ( item . state . frozen? ) . to be true }
3639
@@ -68,13 +71,15 @@ def initialize(state)
6871
6972 describe "TestClass::STATE const" do
7073 it "#values" do
71- expect ( TestClass ::STATE . values ) . to eq ( %w[ choice in_delivery ] )
74+ expect ( TestClass ::STATE . values ) . to eq ( %w[ choice in_delivery lost ] )
7275 end
7376
7477 it "#[]" do
7578 expect ( TestClass ::STATE [ "in_delivery" ] ) . to eq "in_delivery"
7679 expect ( TestClass ::STATE [ "in_delivery" ] . in_delivery? ) . to be ( true )
7780 expect ( TestClass ::STATE [ "in_delivery" ] . choice? ) . to be ( false )
81+ expect ( TestClass ::STATE [ "in_delivery" ] . in_delivery__choice? ) . to be ( true )
82+ expect ( TestClass ::STATE [ "in_delivery" ] . lost__choice? ) . to be ( false )
7883 expect ( TestClass ::STATE [ "wrong" ] ) . to be_nil
7984 end
8085
@@ -118,7 +123,7 @@ def initialize(state)
118123 end
119124
120125 it "decorates enum values in enum const" do
121- expect ( TestClassWithDecorator ::STATE . values . map ( &:am_i_choice? ) ) . to eq ( [ true , false ] )
126+ expect ( TestClassWithDecorator ::STATE . values . map ( &:am_i_choice? ) ) . to eq ( [ true , false , false ] )
122127 expect ( ( TestClassWithDecorator ::STATE . values & [ "in_delivery" ] ) . map ( &:am_i_choice? ) ) . to eq ( [ false ] )
123128 end
124129
0 commit comments