spec/elevator_spec.rb in finite-1.0.0 vs spec/elevator_spec.rb in finite-1.1.0
- old
+ new
@@ -1,59 +1,68 @@
require 'spec_helper'
describe Elevator do
- before(:each) do
- @elevator = Elevator.new
- end
+ let(:elevator) { Elevator.new }
+
it 'has a state machine' do
expect(Finite::StateMachine.machines[Elevator]).to_not be_nil
end
context 'states' do
it 'has a current state' do
- expect(@elevator.current_state).to_not be_nil
- expect(@elevator.current_state).to eq(:idle)
+ expect(elevator.current_state).to_not be_nil
+ expect(elevator.current_state).to eq(:idle)
end
it 'has methods to tell whether it is in a state or not' do
- expect(@elevator.idle?).to be_true
- expect(@elevator.moving?).to be_false
+ expect(elevator.idle?).to be true
+ expect(elevator.moving?).to be false
end
it 'can access all states' do
- expect(@elevator.states).to_not be_nil
- expect(@elevator.states.count).to be(9)
+ expect(elevator.states).to_not be_nil
+ expect(elevator.states.count).to be(9)
end
end
context 'events' do
it 'can access all events' do
- expect(@elevator.events).to_not be_nil
- expect(@elevator.events.count).to be(10)
+ expect(elevator.events).to_not be_nil
+ expect(elevator.events.count).to be(10)
end
it 'can access possible events for a given state' do
- expect(@elevator.possible_events).to eq([:prepare])
+ expect(elevator.possible_events).to eq([:prepare])
end
it 'has methods to tell whether an event can be performed' do
- expect(@elevator.can_prepare?).to be_true
- expect(@elevator.can_go_up?).to be_false
+ expect(elevator.can_prepare?).to be true
+ expect(elevator.can_go_up?).to be false
end
it 'can perform events' do
- @elevator.prepare
- expect(@elevator.current_state).to eq(:doors_closing)
- expect(@elevator.doors_closing?).to be_true
- expect(@elevator.idle?).to be_false
- expect(@elevator.possible_events).to eq([:go_up,:go_down])
- expect{@elevator.start}.to raise_error
- @elevator.go_down
- expect(@elevator.can_start?).to be_true
- @elevator.start
- @elevator.approach
- @elevator.stop
+ elevator.prepare
+ expect(elevator.current_state).to eq(:doors_closing)
+ expect(elevator.doors_closing?).to be true
+ expect(elevator.idle?).to be false
+ expect(elevator.possible_events).to eq([:go_up,:go_down])
+ elevator.start
+ expect(elevator.current_state).to eq(:doors_closing)
+ elevator.go_down
+ expect(elevator.can_start?).to be true
+ elevator.start
+ elevator.approach
+ elevator.stop
end
+
+ it 'will respond to conditions' do
+ elevator.broken = true
+ elevator.prepare
+ expect(elevator.current_state).to eq(:idle)
+ elevator.broken = false
+ elevator.prepare
+ expect(elevator.current_state).to eq(:doors_closing)
+ end
end
-end
\ No newline at end of file
+end