1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
require File.join(File.dirname(__FILE__), "..", "test_helper")
require 'mocha/expectation_list'
require 'mocha/expectation'
require 'set'
require 'method_definer'
class ExpectationListTest < Test::Unit::TestCase
include Mocha
def test_should_return_added_expectation
expectation_list = ExpectationList.new
expectation = Expectation.new(nil, :my_method)
assert_same expectation, expectation_list.add(expectation)
end
def test_should_find_matching_expectation
expectation_list = ExpectationList.new
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
expectation_list.add(expectation1)
expectation_list.add(expectation2)
assert_same expectation1, expectation_list.match(:my_method, :argument1, :argument2)
end
def test_should_find_most_recent_matching_expectation
expectation_list = ExpectationList.new
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
expectation2 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
expectation_list.add(expectation1)
expectation_list.add(expectation2)
assert_same expectation2, expectation_list.match(:my_method, :argument1, :argument2)
end
def test_should_find_matching_expectation_allowing_invocation
expectation_list = ExpectationList.new
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
expectation1.define_instance_method(:invocations_allowed?) { true }
expectation2.define_instance_method(:invocations_allowed?) { true }
expectation_list.add(expectation1)
expectation_list.add(expectation2)
assert_same expectation1, expectation_list.match_allowing_invocation(:my_method, :argument1, :argument2)
end
def test_should_find_most_recent_matching_expectation_allowing_invocation
expectation_list = ExpectationList.new
expectation1 = Expectation.new(nil, :my_method)
expectation2 = Expectation.new(nil, :my_method)
expectation1.define_instance_method(:invocations_allowed?) { true }
expectation2.define_instance_method(:invocations_allowed?) { false }
expectation_list.add(expectation1)
expectation_list.add(expectation2)
assert_same expectation1, expectation_list.match_allowing_invocation(:my_method)
end
end
|