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

add test for the Job example from the README (in Usage)

This commit is contained in:
Thorsten Böttger 2015-09-17 18:05:30 +12:00
parent 5b885c8a0d
commit 12227e7525

43
spec/unit/readme_spec.rb Normal file
View file

@ -0,0 +1,43 @@
require 'spec_helper'
describe 'testing the README examples' do
it 'Usage' do
class Job
include AASM
aasm do
state :sleeping, :initial => true
state :running
state :cleaning
event :run do
transitions :from => :sleeping, :to => :running
end
event :clean do
transitions :from => :running, :to => :cleaning
end
event :sleep do
transitions :from => [:running, :cleaning], :to => :sleeping
end
end
end
job = Job.new
expect(job.sleeping?).to eql true
expect(job.may_run?).to eql true
job.run
expect(job.running?).to eql true
expect(job.sleeping?).to eql false
expect(job.may_run?).to eql false
expect { job.run }.to raise_error(AASM::InvalidTransition)
end
end