Sha256: 7bc24b38831464527b6f3989f7e8f47fcce2cd856a0e99f7ddd8997ac7f81c14

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require 'ostruct'
require 'spec_helper'

describe Stately::InstanceMethods do
  before do
    @test_class = Class.new(Object) do
      attr_accessor :state

      stately :start => :processing do
        state :completed
      end
    end

    @object = @test_class.new
  end

  describe 'initialize' do
    it 'creates a new Stately::Machine' do
      @object.stately_machine.class.should == Stately::Machine
      @object.stately_machine.should == @test_class.stately_machine
    end

    it 'sets initial state' do
      @object.state.should == 'processing'
    end
  end

  describe '#states' do
    it 'returns known state names in order' do
      @object.states.should == [:processing, :completed]
    end
  end

  describe 'actions' do
    it 'defines action methods' do
      @test_class.method_defined?(:complete).should be_true
      @test_class.method_defined?(:process).should be_true
    end

    it 'defines test methods' do
      @test_class.method_defined?(:processing?).should be_true
      @test_class.method_defined?(:completed?).should be_true
    end
  end

  describe 'stately_machine' do
    it 'defines a class-level accessor called stately_machine' do
      @test_class.respond_to?(:stately_machine).should be_true
    end

    it 'defines an instance-level accessor called stately_machine' do
      @test_class.method_defined?(:stately_machine).should be_true
    end

    it 'defines a class-level setter called stately_machine=' do
      @test_class.respond_to?(:stately_machine=).should be_true
    end

    it 'defines an instance-level setter called stately_machine=' do
      @test_class.method_defined?(:stately_machine=).should be_true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stately-0.3.2 spec/unit/stately_spec.rb