1
0
Fork 0
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:
Thorsten Böttger 2013-11-15 11:19:26 +01:00
parent 04187f5ba2
commit ad48863e7a
6 changed files with 38 additions and 38 deletions

View file

@ -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 'mongoid' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
s.add_development_dependency 'rake' s.add_development_dependency 'rake'
s.add_development_dependency 'sdoc' 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 'rr'
s.add_development_dependency 'sqlite3' s.add_development_dependency 'sqlite3'
s.add_development_dependency 'minitest' s.add_development_dependency 'minitest'

View file

@ -51,19 +51,19 @@ describe 'event callbacks' do
it "should run error_callback if an exception is raised and error_callback defined" do it "should run error_callback if an exception is raised and error_callback defined" do
def @foo.error_callback(e); end 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.should_receive(:error_callback).with(e)
@foo.safe_close! @foo.safe_close!
end end
it "should raise NoMethodError if exceptionis raised and error_callback is declared but not defined" do 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) lambda{@foo.safe_close!}.should raise_error(NoMethodError)
end end
it "should propagate an error if no error callback is declared" do 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") lambda{@foo.close!}.should raise_error(StandardError, "Cannot enter safe")
end end
end end
@ -85,7 +85,7 @@ describe 'event callbacks' do
end end
it 'should not call it for failing bang fire' do 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.should_not_receive(:aasm_event_fired)
@foo.close! @foo.close!
end end
@ -108,7 +108,7 @@ describe 'event callbacks' do
end end
it 'should not call it if persist fails for bang fire' do 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.should_receive(:aasm_event_failed)
@foo.close! @foo.close!
end end

View file

@ -60,8 +60,8 @@ end
describe 'firing an event' do describe 'firing an event' do
it 'should return nil if the transitions are empty' do it 'should return nil if the transitions are empty' do
obj = mock('object') obj = double('object')
obj.stub!(:aasm_current_state) obj.stub(:aasm_current_state)
event = AASM::Event.new(:event) event = AASM::Event.new(:event)
event.fire(obj).should be_nil event.fire(obj).should be_nil
@ -72,8 +72,8 @@ describe 'firing an event' do
transitions :to => :closed, :from => [:open, :received] transitions :to => :closed, :from => [:open, :received]
end end
obj = mock('object') obj = double('object')
obj.stub!(:aasm_current_state).and_return(:open) obj.stub(:aasm_current_state).and_return(:open)
event.fire(obj).should == :closed event.fire(obj).should == :closed
end end
@ -83,8 +83,8 @@ describe 'firing an event' do
transitions :to => :closed, :from => [:open, :received], :guard => :guard_fn transitions :to => :closed, :from => [:open, :received], :guard => :guard_fn
end end
obj = mock('object') obj = double('object')
obj.stub!(:aasm_current_state).and_return(:open) obj.stub(:aasm_current_state).and_return(:open)
obj.should_receive(:guard_fn).with('arg1', 'arg2').and_return(true) obj.should_receive(:guard_fn).with('arg1', 'arg2').and_return(true)
event.fire(obj, nil, 'arg1', 'arg2').should == :closed event.fire(obj, nil, 'arg1', 'arg2').should == :closed

View file

@ -33,13 +33,13 @@ describe "instance methods" do
end end
it "should return the aasm column when not new and the aasm_column is not nil" do 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_state = "state"
gate.aasm_current_state.should == :state gate.aasm_current_state.should == :state
end end
it "should allow a nil state" do 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_state = nil
gate.aasm_current_state.should be_nil gate.aasm_current_state.should be_nil
end end
@ -50,7 +50,7 @@ describe "instance methods" do
end end
it "should not call aasm_ensure_initial_state on validation before update" do 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.should_not_receive(:aasm_ensure_initial_state)
gate.valid? gate.valid?
end end

View file

@ -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 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) state = new_state(:entering => :foo)
record = mock('record') record = double('record')
record.should_receive(:foo) record.should_receive(:foo)
state.fire_callbacks(:entering, record) 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 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') state = new_state(:entering => 'foo')
record = mock('record') record = double('record')
record.should_receive(:foo) record.should_receive(:foo)
state.fire_callbacks(:entering, record) 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 it 'should send a message to the record for each action' do
state = new_state(:entering => [:a, :b, "c", lambda {|r| r.foobar }]) state = new_state(:entering => [:a, :b, "c", lambda {|r| r.foobar }])
record = mock('record') record = double('record')
record.should_receive(:a) record.should_receive(:a)
record.should_receive(:b) record.should_receive(:b)
record.should_receive(:c) 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 it "should stop calling actions if one of them raises :halt_aasm_chain" do
state = new_state(:entering => [:a, :b, :c]) state = new_state(:entering => [:a, :b, :c])
record = mock('record') record = double('record')
record.should_receive(:a) record.should_receive(:a)
record.should_receive(:b).and_throw(:halt_aasm_chain) record.should_receive(:b).and_throw(:halt_aasm_chain)
record.should_not_receive(:c) 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 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}) state = new_state(:entering => Proc.new {|r| r.foobar})
record = mock('record') record = double('record')
record.should_receive(:foobar) record.should_receive(:foobar)
state.fire_callbacks(:entering, record) state.fire_callbacks(:entering, record)

View file

@ -42,9 +42,9 @@ describe AASM::Transition do
opts = {:from => 'foo', :to => 'bar', :guard => 'g'} opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
obj = mock('object') obj = double('object')
obj.stub!(:from).and_return(opts[:from]) obj.stub(:from).and_return(opts[:from])
obj.stub!(:to).and_return(opts[:to]) obj.stub(:to).and_return(opts[:to])
st.should == obj st.should == obj
end end
@ -53,9 +53,9 @@ describe AASM::Transition do
opts = {:from => 'foo', :to => 'bar', :guard => 'g'} opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
obj = mock('object') obj = double('object')
obj.stub!(:from).and_return('blah') obj.stub(:from).and_return('blah')
obj.stub!(:to).and_return(opts[:to]) obj.stub(:to).and_return(opts[:to])
st.should_not == obj st.should_not == obj
end end
@ -64,9 +64,9 @@ describe AASM::Transition do
opts = {:from => 'foo', :to => 'bar', :guard => 'g'} opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
obj = mock('object') obj = double('object')
obj.stub!(:from).and_return(opts[:from]) obj.stub(:from).and_return(opts[:from])
obj.stub!(:to).and_return('blah') obj.stub(:to).and_return('blah')
st.should_not == obj st.should_not == obj
end end
@ -84,7 +84,7 @@ describe AASM::Transition, '- when performing guard checks' do
opts = {:from => 'foo', :to => 'bar', :guard => :test} opts = {:from => 'foo', :to => 'bar', :guard => :test}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
obj = mock('object') obj = double('object')
obj.should_receive(:test) obj.should_receive(:test)
st.perform(obj) st.perform(obj)
@ -94,7 +94,7 @@ describe AASM::Transition, '- when performing guard checks' do
opts = {:from => 'foo', :to => 'bar', :guard => 'test'} opts = {:from => 'foo', :to => 'bar', :guard => 'test'}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
obj = mock('object') obj = double('object')
obj.should_receive(:test) obj.should_receive(:test)
st.perform(obj) 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}} opts = {:from => 'foo', :to => 'bar', :guard => Proc.new {|o| o.test}}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
obj = mock('object') obj = double('object')
obj.should_receive(:test) obj.should_receive(:test)
st.perform(obj) 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}} opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {|o| o.test}}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
args = {:arg1 => '1', :arg2 => '2'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = double('object')
opts[:on_transition].should_receive(:call).with(any_args) 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 {||}} opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {||}}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
args = {:arg1 => '1', :arg2 => '2'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = double('object')
opts[:on_transition].should_receive(:call).with(no_args) 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'} opts = {:from => 'foo', :to => 'bar', :on_transition => 'test'}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
args = {:arg1 => '1', :arg2 => '2'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = double('object')
obj.should_receive(:test) 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} opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
args = {:arg1 => '1', :arg2 => '2'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = double('object')
obj.should_receive(:test) 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} opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
args = {:arg1 => '1', :arg2 => '2'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = double('object')
obj.class.class_eval do obj.class.class_eval do
define_method(:test) {|*args| 'success'} 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} opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
st = AASM::Transition.new(opts) st = AASM::Transition.new(opts)
args = {:arg1 => '1', :arg2 => '2'} args = {:arg1 => '1', :arg2 => '2'}
obj = mock('object') obj = double('object')
obj.class.class_eval do obj.class.class_eval do
define_method(:test) {|*args| 'success'} define_method(:test) {|*args| 'success'}