More redundant test code removing

This commit is contained in:
Mitchell Hashimoto 2010-04-08 23:32:26 -07:00
parent 4e54cc77a2
commit c0c3313fdd
3 changed files with 13 additions and 10 deletions

View File

@ -91,7 +91,7 @@ class Test::Unit::TestCase
[mock_vm, vm, action] [mock_vm, vm, action]
end end
def stub_default_action_dependecies(mock, klass=MockAction) def stub_default_action_dependecies(mock)
mock.stubs(:precedes).returns([]) mock.stubs(:precedes).returns([])
mock.stubs(:follows).returns([]) mock.stubs(:follows).returns([])
end end
@ -105,6 +105,3 @@ class Test::Unit::TestCase
end end
end end
class MockAction; end
class MockActionOther; end

View File

@ -1,6 +1,9 @@
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
class CollectionTest < Test::Unit::TestCase class CollectionTest < Test::Unit::TestCase
class MockAction; end
class MockActionOther; end
context "checking uniqueness" do context "checking uniqueness" do
setup do setup do
@actions = Vagrant::Actions::Collection.new([1]) @actions = Vagrant::Actions::Collection.new([1])
@ -10,14 +13,14 @@ class CollectionTest < Test::Unit::TestCase
@actions << 1 @actions << 1
assert @actions.duplicates? assert @actions.duplicates?
end end
should "return false it all the classes are unique" do should "return false it all the classes are unique" do
@actions << 1.0 << "foo" @actions << 1.0 << "foo"
assert !@actions.duplicates? assert !@actions.duplicates?
end end
should "raise an exception when there are duplicates" do should "raise an exception when there are duplicates" do
@actions << 1 @actions << 1
assert_raise Vagrant::Actions::DuplicateActionException do assert_raise Vagrant::Actions::DuplicateActionException do
@actions.duplicates! @actions.duplicates!
end end
@ -42,7 +45,7 @@ class CollectionTest < Test::Unit::TestCase
stub_default_action_dependecies(@mock_action) stub_default_action_dependecies(@mock_action)
stub_default_action_dependecies(@mock_action2) stub_default_action_dependecies(@mock_action2)
end end
context "that come before an action" do context "that come before an action" do
setup do setup do
@mock_action.stubs(:follows).returns([MockActionOther]) @mock_action.stubs(:follows).returns([MockActionOther])
@ -52,7 +55,7 @@ class CollectionTest < Test::Unit::TestCase
collection.new([@mock_action]).dependencies! collection.new([@mock_action]).dependencies!
end end
end end
should "not raise an exception if they are met" do should "not raise an exception if they are met" do
assert_nothing_raised do assert_nothing_raised do
collection.new([@mock_action2, @mock_action]).dependencies! collection.new([@mock_action2, @mock_action]).dependencies!
@ -97,7 +100,7 @@ class CollectionTest < Test::Unit::TestCase
end end
end end
end end
context "klasses" do context "klasses" do
should "return a list of the collection element's classes" do should "return a list of the collection element's classes" do
@action = mock('action') @action = mock('action')

View File

@ -1,6 +1,9 @@
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
class ActionRunnerTest < Test::Unit::TestCase class ActionRunnerTest < Test::Unit::TestCase
class MockAction; end
class MockActionOther; end
def mock_fake_action(action_klass = nil, runner = nil) def mock_fake_action(action_klass = nil, runner = nil)
action = action_klass ? action_klass.new(runner) : mock("action") action = action_klass ? action_klass.new(runner) : mock("action")
action.stubs(:prepare) action.stubs(:prepare)
@ -162,7 +165,7 @@ class ActionRunnerTest < Test::Unit::TestCase
[MockAction, MockActionOther].each_with_index do |klass, i| [MockAction, MockActionOther].each_with_index do |klass, i|
action = mock("action#{i}") action = mock("action#{i}")
action.expects(:class).returns(klass) action.expects(:class).returns(klass)
stub_default_action_dependecies(action, klass) stub_default_action_dependecies(action)
@runner.actions << action @runner.actions << action
actions << action actions << action
end end