Sha256: dd83ca57dbe8f4c015bc99e6ce1d90ca772b001a0c02aa973743a63ec0212ea8

Contents?: true

Size: 1.7 KB

Versions: 15

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'
require 'examples/slot_machine'

describe SlotMachine do

  before(:each) do
    @sm = SlotMachine.new
  end

  it "should have a 'mode' column" do
    @sm.attributes.should have_key(:mode)
  end

  it "should have a 'power_on' column" do
    @sm.attributes.should have_key(:power_on)
  end

  it "should not have a 'state' column" do
    @sm.attributes.should_not have_key(:state)
  end

  it "should start in the off state" do
    @sm.mode.should == "off"
  end

  it "should start with power_on == false" do
    @sm.power_on.should == false
  end

  describe "in :off mode" do

    before(:each) do
      @sm.mode = :off
      @sm.power_on = false
    end

    it "should allow the mode to be set" do
      @sm.mode = :idle
      @sm.save
      @sm.mode.should == "idle"
    end

    it "turn_on! should work from off mode" do
      @sm.turn_on!
      @sm.mode.should == "idle"
      @sm.power_on.should == true
    end

    it "turn_on! should not work twice in a row" do
      @sm.turn_on!
      lambda {
        @sm.turn_on!
      }.should raise_error(DataMapper::Is::StateMachine::InvalidEvent)
    end

  end

  describe "in :idle mode" do

    before(:each) do
      @sm.mode = :idle
      @sm.power_on = true
    end

    it "turn_on! should raise error" do
      lambda {
        @sm.turn_on!
      }.should raise_error(DataMapper::Is::StateMachine::InvalidEvent)
    end

    it "turn_off! should work" do
      @sm.turn_off!
      @sm.mode.should == "off"
      @sm.power_on.should == false
    end

    it "turn_off! should not work twice in a row" do
      @sm.turn_off!
      lambda {
        @sm.turn_off!
      }.should raise_error(DataMapper::Is::StateMachine::InvalidEvent)
    end

  end

end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
ardm-is-state_machine-1.2.0 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.2.0 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.2.0.rc2 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.2.0.rc1 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.1.0 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.1.0.rc3 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.1.0.rc2 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.1.0.rc1 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.0.2 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.0.1 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.0.0 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.0.0.rc3 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.0.0.rc2 spec/integration/slot_machine_spec.rb
dm-is-state_machine-1.0.0.rc1 spec/integration/slot_machine_spec.rb
dm-is-state_machine-0.10.2 spec/integration/slot_machine_spec.rb