Skip to content

Commit

Permalink
Require mocha for tests. Get rid of uses_mocha helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed Nov 19, 2008
1 parent a1ce400 commit 5b7d07f
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 189 deletions.
34 changes: 16 additions & 18 deletions activemodel/test/observing_test.rb
Expand Up @@ -40,24 +40,22 @@ def setup
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
Expand Down
10 changes: 4 additions & 6 deletions activemodel/test/state_machine/event_test.rb
Expand Up @@ -20,12 +20,10 @@ def new_event
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

Expand Down
38 changes: 18 additions & 20 deletions activemodel/test/state_machine/state_test.rb
Expand Up @@ -43,32 +43,30 @@ def new_state(options={})
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
104 changes: 50 additions & 54 deletions activemodel/test/state_machine/state_transition_test.rb
Expand Up @@ -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

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)

obj = stub
obj.stubs(:from).returns(opts[:from])
obj.stubs(:to).returns('blah')
obj = stub
obj.stubs(:from).returns(opts[:from])
obj.stubs(:to).returns('blah')

assert_not_equal st, obj
end
assert_not_equal st, obj
end
end

Expand All @@ -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)

obj = stub
obj.expects(:test_guard)

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)

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)
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

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
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

0 comments on commit 5b7d07f

Please sign in to comment.