Sha256: 3b794ecfc33dde9eea290457590640efa91f8f35fe83e7cb943e8ba361a1b960

Contents?: true

Size: 1.89 KB

Versions: 5

Compression:

Stored size: 1.89 KB

Contents

require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
require Pathname(__FILE__).dirname.expand_path.parent + 'examples/slot_machine'

describe SlotMachine do

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

  it "should have an 'id' column" do
    @sm.attributes.should have_key(:id)
  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

5 entries across 5 versions & 1 rubygems

Version Path
dm-is-state_machine-0.9.10 spec/integration/slot_machine_spec.rb
dm-is-state_machine-0.9.7 spec/integration/slot_machine_spec.rb
dm-is-state_machine-0.9.8 spec/integration/slot_machine_spec.rb
dm-is-state_machine-0.9.11 spec/integration/slot_machine_spec.rb
dm-is-state_machine-0.9.9 spec/integration/slot_machine_spec.rb