The current API isn't very nice because it requires you to write when: :some_state for each assertion, which becomes tedious quickly.
describe Vehicle
#3. macros raise exception if specified state_machine is not defined on class
with_state_machine do # 2. uses default state_machine if no arg is passed
it { should have_state :parked }
end
with_state_machine :alarm_state do # 1. macro sets subject for nested `it` blocks
it { should have_states :active, :off }
end
end
The current API isn't very nice because it requires you to write
when: :some_statefor each assertion, which becomes tedious quickly.with_state_machinesets the subject to thestate_machinedefined on a particular attribute. "subject" could either mean the actualsubjectis shifted to thestate_machineinstance (or some sort of facade), or perhaps the other matchers such ashave_statesare aware of the "subject" in some way.with_state_machineuses the defaultstate_machineif no argument is passedwith_state_machineraises an exception if the specifiedstate_machinedoesn't exist, or nostate_machineexists on the class in the first place