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:
parent
5b885c8a0d
commit
12227e7525
1 changed files with 43 additions and 0 deletions
43
spec/unit/readme_spec.rb
Normal file
43
spec/unit/readme_spec.rb
Normal 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
|
Loading…
Reference in a new issue