working tests to prevent foo bleed across multiple scenarios

This commit is contained in:
HoyaBoya 2015-11-05 10:46:06 -05:00
parent e64a84f71f
commit 8002e5a1c8
2 changed files with 31 additions and 17 deletions

View File

@ -1,16 +1,19 @@
class Foo
include AASM
aasm do
state :open, :initial => true, :before_exit => :before_exit
state :closed, :before_enter => :before_enter
state :final
module Fooable
def self.included(base)
base.class_eval do
aasm do
state :open, :initial => true, :before_exit => :before_exit
state :closed, :before_enter => :before_enter
state :final
event :close, :success => :success_callback do
transitions :from => [:open], :to => [:closed]
end
event :close, :success => :success_callback do
transitions :from => [:open], :to => [:closed]
end
event :null do
transitions :from => [:open], :to => [:closed, :final], :guard => :always_false
event :null do
transitions :from => [:open], :to => [:closed, :final], :guard => :always_false
end
end
end
end
@ -23,10 +26,21 @@ class Foo
def before_enter
end
def before_exit
end
end
class Foo
include AASM
include Fooable
end
class FooGlobal
include AASM
include Fooable
end
class FooTwo < Foo
include AASM
aasm do

View File

@ -98,7 +98,7 @@ describe 'callbacks for the new DSL' do
callback = Callbacks::Basic.new(:log => false)
callback.aasm.current_state
expect(callback).to receive(:before_all_events).once.ordered
expect(callback).to receive(:before_all_events).once.ordered
expect(callback).to receive(:before_event).once.ordered
expect(callback).to receive(:event_guard).once.ordered.and_return(false)
expect(callback).to_not receive(:transition_guard)
@ -371,7 +371,7 @@ end
describe 'global error_on_all_events_callback callbacks' do
describe "with an error_on_all_events" do
before do
class Foo
class FooGlobal
# this hack is needed to allow testing of parameters, since RSpec
# destroys a method's arity when mocked
attr_accessor :data
@ -385,12 +385,12 @@ describe 'global error_on_all_events_callback callbacks' do
end
end
@foo = Foo.new
@foo = FooGlobal.new
end
it_behaves_like 'an implemented callback that accepts error' do
let(:aasm_model) { @foo }
let(:callback_name) { :error_on_all_events_callback }
let(:callback_name) { :error_on_all_events_callback }
end
it "should raise NoMethodError if exception is raised and error_callback is declared but not defined" do
@ -408,7 +408,7 @@ end
describe 'global ensure_on_all_events_callback callbacks' do
describe "with an ensure_on_all_events" do
before do
class Foo
class FooGlobal
# this hack is needed to allow testing of parameters, since RSpec
# destroys a method's arity when mocked
attr_accessor :data
@ -422,7 +422,7 @@ describe 'global ensure_on_all_events_callback callbacks' do
end
end
@foo = Foo.new
@foo = FooGlobal.new
end
it_behaves_like 'an implemented callback' do