mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Require mocha for tests. Get rid of uses_mocha helper.
This commit is contained in:
parent
a1ce4008c8
commit
5b7d07f423
5 changed files with 170 additions and 192 deletions
|
@ -40,24 +40,22 @@ class ObservingTest < ActiveModel::TestCase
|
|||
assert ObservedModel.observers.include?(:bar), ":bar not in #{ObservedModel.observers.inspect}"
|
||||
end
|
||||
|
||||
uses_mocha "observer instantiation" do
|
||||
test "instantiates observer names passed as strings" do
|
||||
ObservedModel.observers << 'foo_observer'
|
||||
FooObserver.expects(:instance)
|
||||
ObservedModel.instantiate_observers
|
||||
end
|
||||
|
||||
test "instantiates observer names passed as symbols" do
|
||||
ObservedModel.observers << :foo_observer
|
||||
FooObserver.expects(:instance)
|
||||
ObservedModel.instantiate_observers
|
||||
end
|
||||
|
||||
test "instantiates observer classes" do
|
||||
ObservedModel.observers << ObservedModel::Observer
|
||||
ObservedModel::Observer.expects(:instance)
|
||||
ObservedModel.instantiate_observers
|
||||
end
|
||||
test "instantiates observer names passed as strings" do
|
||||
ObservedModel.observers << 'foo_observer'
|
||||
FooObserver.expects(:instance)
|
||||
ObservedModel.instantiate_observers
|
||||
end
|
||||
|
||||
test "instantiates observer names passed as symbols" do
|
||||
ObservedModel.observers << :foo_observer
|
||||
FooObserver.expects(:instance)
|
||||
ObservedModel.instantiate_observers
|
||||
end
|
||||
|
||||
test "instantiates observer classes" do
|
||||
ObservedModel.observers << ObservedModel::Observer
|
||||
ObservedModel::Observer.expects(:instance)
|
||||
ObservedModel.instantiate_observers
|
||||
end
|
||||
|
||||
test "passes observers to subclasses" do
|
||||
|
|
|
@ -20,12 +20,10 @@ class EventTest < ActiveModel::TestCase
|
|||
assert_equal @success, new_event.success
|
||||
end
|
||||
|
||||
uses_mocha 'StateTransition creation' do
|
||||
test 'should create StateTransitions' do
|
||||
ActiveModel::StateMachine::StateTransition.expects(:new).with(:to => :closed, :from => :open)
|
||||
ActiveModel::StateMachine::StateTransition.expects(:new).with(:to => :closed, :from => :received)
|
||||
new_event
|
||||
end
|
||||
test 'should create StateTransitions' do
|
||||
ActiveModel::StateMachine::StateTransition.expects(:new).with(:to => :closed, :from => :open)
|
||||
ActiveModel::StateMachine::StateTransition.expects(:new).with(:to => :closed, :from => :received)
|
||||
new_event
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -43,32 +43,30 @@ class StateTest < ActiveModel::TestCase
|
|||
assert_equal new_state, new_state
|
||||
end
|
||||
|
||||
uses_mocha 'state actions' do
|
||||
test 'should send a message to the record for an action if the action is present as a symbol' do
|
||||
state = new_state(:entering => :foo)
|
||||
test '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 = stub
|
||||
record.expects(:foo)
|
||||
record = stub
|
||||
record.expects(:foo)
|
||||
|
||||
state.call_action(:entering, record)
|
||||
end
|
||||
state.call_action(:entering, record)
|
||||
end
|
||||
|
||||
test 'should send a message to the record for an action if the action is present as a string' do
|
||||
state = new_state(:entering => 'foo')
|
||||
test '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 = stub
|
||||
record.expects(:foo)
|
||||
record = stub
|
||||
record.expects(:foo)
|
||||
|
||||
state.call_action(:entering, record)
|
||||
end
|
||||
state.call_action(:entering, record)
|
||||
end
|
||||
|
||||
test '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})
|
||||
test '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 = stub
|
||||
record.expects(:foobar)
|
||||
|
||||
state.call_action(:entering, record)
|
||||
end
|
||||
record = stub
|
||||
record.expects(:foobar)
|
||||
|
||||
state.call_action(:entering, record)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,39 +10,37 @@ class StateTransitionTest < ActiveModel::TestCase
|
|||
assert_equal opts, st.options
|
||||
end
|
||||
|
||||
uses_mocha 'checking ActiveModel StateMachine transitions' do
|
||||
test 'should pass equality check if from and to are the same' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
test 'should pass equality check if from and to are the same' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
|
||||
obj = stub
|
||||
obj.stubs(:from).returns(opts[:from])
|
||||
obj.stubs(:to).returns(opts[:to])
|
||||
obj = stub
|
||||
obj.stubs(:from).returns(opts[:from])
|
||||
obj.stubs(:to).returns(opts[:to])
|
||||
|
||||
assert_equal st, obj
|
||||
end
|
||||
assert_equal st, obj
|
||||
end
|
||||
|
||||
test 'should fail equality check if from are not the same' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
test 'should fail equality check if from are not the same' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
|
||||
obj = stub
|
||||
obj.stubs(:from).returns('blah')
|
||||
obj.stubs(:to).returns(opts[:to])
|
||||
obj = stub
|
||||
obj.stubs(:from).returns('blah')
|
||||
obj.stubs(:to).returns(opts[:to])
|
||||
|
||||
assert_not_equal st, obj
|
||||
end
|
||||
|
||||
test 'should fail equality check if to are not the same' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
assert_not_equal st, obj
|
||||
end
|
||||
|
||||
obj = stub
|
||||
obj.stubs(:from).returns(opts[:from])
|
||||
obj.stubs(:to).returns('blah')
|
||||
test 'should fail equality check if to are not the same' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
|
||||
assert_not_equal st, obj
|
||||
end
|
||||
obj = stub
|
||||
obj.stubs(:from).returns(opts[:from])
|
||||
obj.stubs(:to).returns('blah')
|
||||
|
||||
assert_not_equal st, obj
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -54,35 +52,33 @@ class StateTransitionGuardCheckTest < ActiveModel::TestCase
|
|||
assert st.perform(nil)
|
||||
end
|
||||
|
||||
uses_mocha 'checking ActiveModel StateMachine transition guard checks' do
|
||||
test 'should call the method on the object if guard is a symbol' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => :test_guard}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
test 'should call the method on the object if guard is a symbol' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => :test_guard}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
|
||||
obj = stub
|
||||
obj.expects(:test_guard)
|
||||
|
||||
obj = stub
|
||||
obj.expects(:test_guard)
|
||||
|
||||
st.perform(obj)
|
||||
end
|
||||
st.perform(obj)
|
||||
end
|
||||
|
||||
test 'should call the method on the object if guard is a string' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => 'test_guard'}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
|
||||
obj = stub
|
||||
obj.expects(:test_guard)
|
||||
|
||||
test 'should call the method on the object if guard is a string' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => 'test_guard'}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
|
||||
obj = stub
|
||||
obj.expects(:test_guard)
|
||||
|
||||
st.perform(obj)
|
||||
end
|
||||
|
||||
test 'should call the proc passing the object if the guard is a proc' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => Proc.new {|o| o.test_guard}}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
|
||||
obj = stub
|
||||
obj.expects(:test_guard)
|
||||
|
||||
st.perform(obj)
|
||||
end
|
||||
st.perform(obj)
|
||||
end
|
||||
|
||||
test 'should call the proc passing the object if the guard is a proc' do
|
||||
opts = {:from => 'foo', :to => 'bar', :guard => Proc.new {|o| o.test_guard}}
|
||||
st = ActiveModel::StateMachine::StateTransition.new(opts)
|
||||
|
||||
obj = stub
|
||||
obj.expects(:test_guard)
|
||||
|
||||
st.perform(obj)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -122,24 +122,22 @@ class StateMachineEventFiringWithPersistenceTest < ActiveModel::TestCase
|
|||
assert_equal :closed, @subj.current_state
|
||||
end
|
||||
|
||||
uses_mocha "StateMachineEventFiringWithPersistenceTest with callbacks" do
|
||||
test 'fires the Event' do
|
||||
@subj.class.state_machine.events[:close].expects(:fire).with(@subj)
|
||||
@subj.close!
|
||||
test 'fires the Event' do
|
||||
@subj.class.state_machine.events[:close].expects(:fire).with(@subj)
|
||||
@subj.close!
|
||||
end
|
||||
|
||||
test 'calls the success callback if one was provided' do
|
||||
@subj.expects(:success_callback)
|
||||
@subj.close!
|
||||
end
|
||||
|
||||
test 'attempts to persist if write_state is defined' do
|
||||
def @subj.write_state
|
||||
end
|
||||
|
||||
test 'calls the success callback if one was provided' do
|
||||
@subj.expects(:success_callback)
|
||||
@subj.close!
|
||||
end
|
||||
|
||||
test 'attempts to persist if write_state is defined' do
|
||||
def @subj.write_state
|
||||
end
|
||||
|
||||
@subj.expects(:write_state)
|
||||
@subj.close!
|
||||
end
|
||||
@subj.expects(:write_state)
|
||||
@subj.close!
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -151,98 +149,90 @@ class StateMachineEventFiringWithoutPersistence < ActiveModel::TestCase
|
|||
assert_equal :closed, subj.current_state
|
||||
end
|
||||
|
||||
uses_mocha 'StateMachineEventFiringWithoutPersistence' do
|
||||
test 'fires the Event' do
|
||||
subj = StateMachineSubject.new
|
||||
test 'fires the Event' do
|
||||
subj = StateMachineSubject.new
|
||||
|
||||
StateMachineSubject.state_machine.events[:close].expects(:fire).with(subj)
|
||||
subj.close
|
||||
StateMachineSubject.state_machine.events[:close].expects(:fire).with(subj)
|
||||
subj.close
|
||||
end
|
||||
|
||||
test 'attempts to persist if write_state is defined' do
|
||||
subj = StateMachineSubject.new
|
||||
|
||||
def subj.write_state
|
||||
end
|
||||
|
||||
test 'attempts to persist if write_state is defined' do
|
||||
subj = StateMachineSubject.new
|
||||
subj.expects(:write_state_without_persistence)
|
||||
|
||||
def subj.write_state
|
||||
end
|
||||
|
||||
subj.expects(:write_state_without_persistence)
|
||||
|
||||
subj.close
|
||||
end
|
||||
subj.close
|
||||
end
|
||||
end
|
||||
|
||||
uses_mocha 'StateMachinePersistenceTest' do
|
||||
class StateMachinePersistenceTest < ActiveModel::TestCase
|
||||
test 'reads the state if it has not been set and read_state is defined' do
|
||||
subj = StateMachineSubject.new
|
||||
def subj.read_state
|
||||
end
|
||||
|
||||
subj.expects(:read_state).with(StateMachineSubject.state_machine)
|
||||
|
||||
subj.current_state
|
||||
class StateMachinePersistenceTest < ActiveModel::TestCase
|
||||
test 'reads the state if it has not been set and read_state is defined' do
|
||||
subj = StateMachineSubject.new
|
||||
def subj.read_state
|
||||
end
|
||||
|
||||
subj.expects(:read_state).with(StateMachineSubject.state_machine)
|
||||
|
||||
subj.current_state
|
||||
end
|
||||
end
|
||||
|
||||
uses_mocha 'StateMachineEventCallbacksTest' do
|
||||
class StateMachineEventCallbacksTest < ActiveModel::TestCase
|
||||
test 'should call aasm_event_fired if defined and successful for bang fire' do
|
||||
subj = StateMachineSubject.new
|
||||
def subj.aasm_event_fired(from, to)
|
||||
end
|
||||
|
||||
subj.expects(:event_fired)
|
||||
|
||||
subj.close!
|
||||
class StateMachineEventCallbacksTest < ActiveModel::TestCase
|
||||
test 'should call aasm_event_fired if defined and successful for bang fire' do
|
||||
subj = StateMachineSubject.new
|
||||
def subj.aasm_event_fired(from, to)
|
||||
end
|
||||
|
||||
test 'should call aasm_event_fired if defined and successful for non-bang fire' do
|
||||
subj = StateMachineSubject.new
|
||||
def subj.aasm_event_fired(from, to)
|
||||
end
|
||||
subj.expects(:event_fired)
|
||||
|
||||
subj.expects(:event_fired)
|
||||
subj.close!
|
||||
end
|
||||
|
||||
subj.close
|
||||
test 'should call aasm_event_fired if defined and successful for non-bang fire' do
|
||||
subj = StateMachineSubject.new
|
||||
def subj.aasm_event_fired(from, to)
|
||||
end
|
||||
|
||||
test 'should call aasm_event_failed if defined and transition failed for bang fire' do
|
||||
subj = StateMachineSubject.new
|
||||
def subj.event_failed(event)
|
||||
end
|
||||
subj.expects(:event_fired)
|
||||
|
||||
subj.expects(:event_failed)
|
||||
subj.close
|
||||
end
|
||||
|
||||
subj.null!
|
||||
test 'should call aasm_event_failed if defined and transition failed for bang fire' do
|
||||
subj = StateMachineSubject.new
|
||||
def subj.event_failed(event)
|
||||
end
|
||||
|
||||
test 'should call aasm_event_failed if defined and transition failed for non-bang fire' do
|
||||
subj = StateMachineSubject.new
|
||||
def subj.aasm_event_failed(event)
|
||||
end
|
||||
subj.expects(:event_failed)
|
||||
|
||||
subj.expects(:event_failed)
|
||||
subj.null!
|
||||
end
|
||||
|
||||
subj.null
|
||||
test 'should call aasm_event_failed if defined and transition failed for non-bang fire' do
|
||||
subj = StateMachineSubject.new
|
||||
def subj.aasm_event_failed(event)
|
||||
end
|
||||
|
||||
subj.expects(:event_failed)
|
||||
|
||||
subj.null
|
||||
end
|
||||
end
|
||||
|
||||
uses_mocha 'StateMachineStateActionsTest' do
|
||||
class StateMachineStateActionsTest < ActiveModel::TestCase
|
||||
test "calls enter when entering state" do
|
||||
subj = StateMachineSubject.new
|
||||
subj.expects(:enter)
|
||||
subj.close
|
||||
end
|
||||
class StateMachineStateActionsTest < ActiveModel::TestCase
|
||||
test "calls enter when entering state" do
|
||||
subj = StateMachineSubject.new
|
||||
subj.expects(:enter)
|
||||
subj.close
|
||||
end
|
||||
|
||||
test "calls exit when exiting state" do
|
||||
subj = StateMachineSubject.new
|
||||
subj.expects(:exit)
|
||||
subj.close
|
||||
end
|
||||
test "calls exit when exiting state" do
|
||||
subj = StateMachineSubject.new
|
||||
subj.expects(:exit)
|
||||
subj.close
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -306,19 +296,17 @@ class StateMachineWithComplexTransitionsTest < ActiveModel::TestCase
|
|||
assert_equal :working, @subj.current_state(:chetan_patil)
|
||||
end
|
||||
|
||||
uses_mocha "StateMachineWithComplexTransitionsTest on_transition tests" do
|
||||
test 'calls on_transition method with args' do
|
||||
@subj.wakeup! :showering
|
||||
|
||||
@subj.expects(:wear_clothes).with('blue', 'jeans')
|
||||
@subj.dress! :working, 'blue', 'jeans'
|
||||
end
|
||||
|
||||
test 'calls on_transition proc' do
|
||||
@subj.wakeup! :showering
|
||||
|
||||
@subj.expects(:wear_clothes).with('purple', 'slacks')
|
||||
@subj.dress!(:dating, 'purple', 'slacks')
|
||||
end
|
||||
test 'calls on_transition method with args' do
|
||||
@subj.wakeup! :showering
|
||||
|
||||
@subj.expects(:wear_clothes).with('blue', 'jeans')
|
||||
@subj.dress! :working, 'blue', 'jeans'
|
||||
end
|
||||
|
||||
test 'calls on_transition proc' do
|
||||
@subj.wakeup! :showering
|
||||
|
||||
@subj.expects(:wear_clothes).with('purple', 'slacks')
|
||||
@subj.dress!(:dating, 'purple', 'slacks')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue