mirror of
https://github.com/aasm/aasm
synced 2023-03-27 23:22:41 -04:00
using the latest version of rspec
This commit is contained in:
parent
04187f5ba2
commit
ad48863e7a
6 changed files with 38 additions and 38 deletions
|
@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|||
s.add_development_dependency 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
|
||||
s.add_development_dependency 'rake'
|
||||
s.add_development_dependency 'sdoc'
|
||||
s.add_development_dependency 'rspec', '~> 2.0'
|
||||
s.add_development_dependency 'rspec', '~> 2.14'
|
||||
s.add_development_dependency 'rr'
|
||||
s.add_development_dependency 'sqlite3'
|
||||
s.add_development_dependency 'minitest'
|
||||
|
|
|
@ -51,19 +51,19 @@ describe 'event callbacks' do
|
|||
it "should run error_callback if an exception is raised and error_callback defined" do
|
||||
def @foo.error_callback(e); end
|
||||
|
||||
@foo.stub!(:enter).and_raise(e=StandardError.new)
|
||||
@foo.stub(:enter).and_raise(e=StandardError.new)
|
||||
@foo.should_receive(:error_callback).with(e)
|
||||
|
||||
@foo.safe_close!
|
||||
end
|
||||
|
||||
it "should raise NoMethodError if exceptionis raised and error_callback is declared but not defined" do
|
||||
@foo.stub!(:enter).and_raise(StandardError)
|
||||
@foo.stub(:enter).and_raise(StandardError)
|
||||
lambda{@foo.safe_close!}.should raise_error(NoMethodError)
|
||||
end
|
||||
|
||||
it "should propagate an error if no error callback is declared" do
|
||||
@foo.stub!(:enter).and_raise("Cannot enter safe")
|
||||
@foo.stub(:enter).and_raise("Cannot enter safe")
|
||||
lambda{@foo.close!}.should raise_error(StandardError, "Cannot enter safe")
|
||||
end
|
||||
end
|
||||
|
@ -85,7 +85,7 @@ describe 'event callbacks' do
|
|||
end
|
||||
|
||||
it 'should not call it for failing bang fire' do
|
||||
@foo.aasm.stub!(:set_current_state_with_persistence).and_return(false)
|
||||
@foo.aasm.stub(:set_current_state_with_persistence).and_return(false)
|
||||
@foo.should_not_receive(:aasm_event_fired)
|
||||
@foo.close!
|
||||
end
|
||||
|
@ -108,7 +108,7 @@ describe 'event callbacks' do
|
|||
end
|
||||
|
||||
it 'should not call it if persist fails for bang fire' do
|
||||
@foo.aasm.stub!(:set_current_state_with_persistence).and_return(false)
|
||||
@foo.aasm.stub(:set_current_state_with_persistence).and_return(false)
|
||||
@foo.should_receive(:aasm_event_failed)
|
||||
@foo.close!
|
||||
end
|
||||
|
|
|
@ -60,8 +60,8 @@ end
|
|||
|
||||
describe 'firing an event' do
|
||||
it 'should return nil if the transitions are empty' do
|
||||
obj = mock('object')
|
||||
obj.stub!(:aasm_current_state)
|
||||
obj = double('object')
|
||||
obj.stub(:aasm_current_state)
|
||||
|
||||
event = AASM::Event.new(:event)
|
||||
event.fire(obj).should be_nil
|
||||
|
@ -72,8 +72,8 @@ describe 'firing an event' do
|
|||
transitions :to => :closed, :from => [:open, :received]
|
||||
end
|
||||
|
||||
obj = mock('object')
|
||||
obj.stub!(:aasm_current_state).and_return(:open)
|
||||
obj = double('object')
|
||||
obj.stub(:aasm_current_state).and_return(:open)
|
||||
|
||||
event.fire(obj).should == :closed
|
||||
end
|
||||
|
@ -83,8 +83,8 @@ describe 'firing an event' do
|
|||
transitions :to => :closed, :from => [:open, :received], :guard => :guard_fn
|
||||
end
|
||||
|
||||
obj = mock('object')
|
||||
obj.stub!(:aasm_current_state).and_return(:open)
|
||||
obj = double('object')
|
||||
obj.stub(:aasm_current_state).and_return(:open)
|
||||
obj.should_receive(:guard_fn).with('arg1', 'arg2').and_return(true)
|
||||
|
||||
event.fire(obj, nil, 'arg1', 'arg2').should == :closed
|
||||
|
|
|
@ -33,13 +33,13 @@ describe "instance methods" do
|
|||
end
|
||||
|
||||
it "should return the aasm column when not new and the aasm_column is not nil" do
|
||||
gate.stub!(:new_record?).and_return(false)
|
||||
gate.stub(:new_record?).and_return(false)
|
||||
gate.aasm_state = "state"
|
||||
gate.aasm_current_state.should == :state
|
||||
end
|
||||
|
||||
it "should allow a nil state" do
|
||||
gate.stub!(:new_record?).and_return(false)
|
||||
gate.stub(:new_record?).and_return(false)
|
||||
gate.aasm_state = nil
|
||||
gate.aasm_current_state.should be_nil
|
||||
end
|
||||
|
@ -50,7 +50,7 @@ describe "instance methods" do
|
|||
end
|
||||
|
||||
it "should not call aasm_ensure_initial_state on validation before update" do
|
||||
gate.stub!(:new_record?).and_return(false)
|
||||
gate.stub(:new_record?).and_return(false)
|
||||
gate.should_not_receive(:aasm_ensure_initial_state)
|
||||
gate.valid?
|
||||
end
|
||||
|
|
|
@ -38,7 +38,7 @@ describe AASM::State do
|
|||
it 'should send a message to the record for an action if the action is present as a symbol' do
|
||||
state = new_state(:entering => :foo)
|
||||
|
||||
record = mock('record')
|
||||
record = double('record')
|
||||
record.should_receive(:foo)
|
||||
|
||||
state.fire_callbacks(:entering, record)
|
||||
|
@ -47,7 +47,7 @@ describe AASM::State do
|
|||
it 'should send a message to the record for an action if the action is present as a string' do
|
||||
state = new_state(:entering => 'foo')
|
||||
|
||||
record = mock('record')
|
||||
record = double('record')
|
||||
record.should_receive(:foo)
|
||||
|
||||
state.fire_callbacks(:entering, record)
|
||||
|
@ -56,7 +56,7 @@ describe AASM::State do
|
|||
it 'should send a message to the record for each action' do
|
||||
state = new_state(:entering => [:a, :b, "c", lambda {|r| r.foobar }])
|
||||
|
||||
record = mock('record')
|
||||
record = double('record')
|
||||
record.should_receive(:a)
|
||||
record.should_receive(:b)
|
||||
record.should_receive(:c)
|
||||
|
@ -68,7 +68,7 @@ describe AASM::State do
|
|||
it "should stop calling actions if one of them raises :halt_aasm_chain" do
|
||||
state = new_state(:entering => [:a, :b, :c])
|
||||
|
||||
record = mock('record')
|
||||
record = double('record')
|
||||
record.should_receive(:a)
|
||||
record.should_receive(:b).and_throw(:halt_aasm_chain)
|
||||
record.should_not_receive(:c)
|
||||
|
@ -79,7 +79,7 @@ describe AASM::State do
|
|||
it 'should call a proc, passing in the record for an action if the action is present' do
|
||||
state = new_state(:entering => Proc.new {|r| r.foobar})
|
||||
|
||||
record = mock('record')
|
||||
record = double('record')
|
||||
record.should_receive(:foobar)
|
||||
|
||||
state.fire_callbacks(:entering, record)
|
||||
|
|
|
@ -42,9 +42,9 @@ describe AASM::Transition do
|
|||
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
||||
st = AASM::Transition.new(opts)
|
||||
|
||||
obj = mock('object')
|
||||
obj.stub!(:from).and_return(opts[:from])
|
||||
obj.stub!(:to).and_return(opts[:to])
|
||||
obj = double('object')
|
||||
obj.stub(:from).and_return(opts[:from])
|
||||
obj.stub(:to).and_return(opts[:to])
|
||||
|
||||
st.should == obj
|
||||
end
|
||||
|
@ -53,9 +53,9 @@ describe AASM::Transition do
|
|||
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
||||
st = AASM::Transition.new(opts)
|
||||
|
||||
obj = mock('object')
|
||||
obj.stub!(:from).and_return('blah')
|
||||
obj.stub!(:to).and_return(opts[:to])
|
||||
obj = double('object')
|
||||
obj.stub(:from).and_return('blah')
|
||||
obj.stub(:to).and_return(opts[:to])
|
||||
|
||||
st.should_not == obj
|
||||
end
|
||||
|
@ -64,9 +64,9 @@ describe AASM::Transition do
|
|||
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
||||
st = AASM::Transition.new(opts)
|
||||
|
||||
obj = mock('object')
|
||||
obj.stub!(:from).and_return(opts[:from])
|
||||
obj.stub!(:to).and_return('blah')
|
||||
obj = double('object')
|
||||
obj.stub(:from).and_return(opts[:from])
|
||||
obj.stub(:to).and_return('blah')
|
||||
|
||||
st.should_not == obj
|
||||
end
|
||||
|
@ -84,7 +84,7 @@ describe AASM::Transition, '- when performing guard checks' do
|
|||
opts = {:from => 'foo', :to => 'bar', :guard => :test}
|
||||
st = AASM::Transition.new(opts)
|
||||
|
||||
obj = mock('object')
|
||||
obj = double('object')
|
||||
obj.should_receive(:test)
|
||||
|
||||
st.perform(obj)
|
||||
|
@ -94,7 +94,7 @@ describe AASM::Transition, '- when performing guard checks' do
|
|||
opts = {:from => 'foo', :to => 'bar', :guard => 'test'}
|
||||
st = AASM::Transition.new(opts)
|
||||
|
||||
obj = mock('object')
|
||||
obj = double('object')
|
||||
obj.should_receive(:test)
|
||||
|
||||
st.perform(obj)
|
||||
|
@ -104,7 +104,7 @@ describe AASM::Transition, '- when performing guard checks' do
|
|||
opts = {:from => 'foo', :to => 'bar', :guard => Proc.new {|o| o.test}}
|
||||
st = AASM::Transition.new(opts)
|
||||
|
||||
obj = mock('object')
|
||||
obj = double('object')
|
||||
obj.should_receive(:test)
|
||||
|
||||
st.perform(obj)
|
||||
|
@ -116,7 +116,7 @@ describe AASM::Transition, '- when executing the transition with a Proc' do
|
|||
opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {|o| o.test}}
|
||||
st = AASM::Transition.new(opts)
|
||||
args = {:arg1 => '1', :arg2 => '2'}
|
||||
obj = mock('object')
|
||||
obj = double('object')
|
||||
|
||||
opts[:on_transition].should_receive(:call).with(any_args)
|
||||
|
||||
|
@ -127,7 +127,7 @@ describe AASM::Transition, '- when executing the transition with a Proc' do
|
|||
opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {||}}
|
||||
st = AASM::Transition.new(opts)
|
||||
args = {:arg1 => '1', :arg2 => '2'}
|
||||
obj = mock('object')
|
||||
obj = double('object')
|
||||
|
||||
opts[:on_transition].should_receive(:call).with(no_args)
|
||||
|
||||
|
@ -140,7 +140,7 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|||
opts = {:from => 'foo', :to => 'bar', :on_transition => 'test'}
|
||||
st = AASM::Transition.new(opts)
|
||||
args = {:arg1 => '1', :arg2 => '2'}
|
||||
obj = mock('object')
|
||||
obj = double('object')
|
||||
|
||||
obj.should_receive(:test)
|
||||
|
||||
|
@ -151,7 +151,7 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|||
opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
|
||||
st = AASM::Transition.new(opts)
|
||||
args = {:arg1 => '1', :arg2 => '2'}
|
||||
obj = mock('object')
|
||||
obj = double('object')
|
||||
|
||||
obj.should_receive(:test)
|
||||
|
||||
|
@ -162,7 +162,7 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|||
opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
|
||||
st = AASM::Transition.new(opts)
|
||||
args = {:arg1 => '1', :arg2 => '2'}
|
||||
obj = mock('object')
|
||||
obj = double('object')
|
||||
|
||||
obj.class.class_eval do
|
||||
define_method(:test) {|*args| 'success'}
|
||||
|
@ -177,7 +177,7 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|||
opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
|
||||
st = AASM::Transition.new(opts)
|
||||
args = {:arg1 => '1', :arg2 => '2'}
|
||||
obj = mock('object')
|
||||
obj = double('object')
|
||||
|
||||
obj.class.class_eval do
|
||||
define_method(:test) {|*args| 'success'}
|
||||
|
|
Loading…
Add table
Reference in a new issue