From 12227e7525f558485b8d89f9bfcb4736c71c97c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20B=C3=B6ttger?= Date: Thu, 17 Sep 2015 18:05:30 +1200 Subject: [PATCH] add test for the Job example from the README (in Usage) --- spec/unit/readme_spec.rb | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spec/unit/readme_spec.rb diff --git a/spec/unit/readme_spec.rb b/spec/unit/readme_spec.rb new file mode 100644 index 0000000..8b53a81 --- /dev/null +++ b/spec/unit/readme_spec.rb @@ -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