Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate current method dispatch behavior(jmock1) #448

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/mocha/expectation_list.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
require 'mocha/deprecation'

module Mocha
class ExpectationList
def initialize(expectations = [])
@expectations = expectations
end

def add(expectation)
if @expectations.any?
Deprecation.warning(
'Expectations are currently searched from newest to oldest to find one that matches the invocation.',
' This search order will be reversed in the future, such that expectations are searched from oldest to newest to find one that matches the invocation.',
' This means you will have to reverse the order of `expects` and `stubs` calls on the same object if you want to retain the current behavior.'
)
end
@expectations.unshift(expectation)
expectation
end
Expand Down
14 changes: 14 additions & 0 deletions test/unit/expectation_list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,18 @@ def test_should_combine_two_expectation_lists_into_one
expectation_list = expectation_list1 + expectation_list2
assert_equal [expectation1, expectation2], expectation_list.to_a
end

def test_should_display_deprecation_warning_when_multiple_expectations_are_added
DeprecationDisabler.disable_deprecations do
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)
end
assert message = Deprecation.messages.last
assert message.include?('Expectations are currently searched from newest to oldest to find one that matches the invocation.')
assert message.include?('This search order will be reversed in the future, such that expectations are searched from oldest to newest to find one that matches the invocation.')
assert message.include?('This means you will have to reverse the order of `expects` and `stubs` calls on the same object if you want to retain the current behavior.')
end
end