1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00
aasm/spec/unit/state_machine_spec.rb

35 lines
1.7 KiB
Ruby
Raw Normal View History

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
describe "state machines" do
def number_of_objects(clazz)
ObjectSpace.each_object(clazz) {}
end
def machines
AASM::StateMachine.instance_variable_get("@machines")
end
it "should be created without memory leak" do
machines_count = machines.size
state_count = number_of_objects(AASM::SupportingClasses::State)
event_count = number_of_objects(AASM::SupportingClasses::Event)
transition_count = number_of_objects(AASM::SupportingClasses::StateTransition)
load File.expand_path(File.dirname(__FILE__) + '/../models/process.rb')
machines.size.should == machines_count + 1 # + Process
number_of_objects(Models::Process).should == 0
number_of_objects(AASM::SupportingClasses::State).should == state_count + 3 # + Process
number_of_objects(AASM::SupportingClasses::Event).should == event_count + 2 # + Process
number_of_objects(AASM::SupportingClasses::StateTransition).should == transition_count + 2 # + Process
Models.send(:remove_const, "Process") if Models.const_defined?("Process")
load File.expand_path(File.dirname(__FILE__) + '/../models/process.rb')
machines.size.should == machines_count + 1 # + Process
number_of_objects(AASM::SupportingClasses::State).should == state_count + 3 # + Process
number_of_objects(AASM::SupportingClasses::Event).should == event_count + 2 # + Process
number_of_objects(AASM::SupportingClasses::StateTransition).should == transition_count + 2 # + Process
end
end