-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regression in Mock#responds_like behaviour
The regression was inadvertently introduced in this commit [1] and indirectly led to this issue [2]. I've attempted to thoroughly characterise the pre-regression behaviour of Mock#responds_like in a new acceptance test, RespondsLikeTest, in order to reduce the chances of any such regressions occurring in the future. I've also added another acceptance test, ArrayFlattenTest, which reproduced the issue in [2] until the regression was fixed. Investigating this has made me realise that the behaviour of Mock#responds_like in combination with protected & private methods on the responder was not specified in the documentation. I've attempted to reverse engineer the documentation so that it more fully describes the pre-regression behaviour. Note that the CI build for Ruby v1.9 is using an old version of Minitest which doesn't work with the RespondsLikeTest and since support for Ruby v1.9 was dropped in Mocha v2, I don't think it's worth the effort to sort this out so I've just disabled the test for Ruby v1.9. [1]: 365a734 [2]: #580
- Loading branch information
1 parent
113b148
commit ba4d619
Showing
3 changed files
with
451 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require File.expand_path('../acceptance_test_helper', __FILE__) | ||
|
||
class ArrayFlattenTest < Mocha::TestCase | ||
include AcceptanceTest | ||
|
||
def setup | ||
setup_acceptance_test | ||
end | ||
|
||
def teardown | ||
teardown_acceptance_test | ||
end | ||
|
||
def test_flattens_array_containing_mock_which_responds_like_active_record_model | ||
model = Class.new do | ||
# Ref: https://github.com/rails/rails/blob/7db044f38594eb43e1d241cc82025155666cc6f1/activerecord/lib/active_record/core.rb#L734-L745 | ||
def to_ary | ||
nil | ||
end | ||
private :to_ary | ||
end.new | ||
test_result = run_as_test do | ||
m = mock.responds_like(model) | ||
assert_equal [m], [m].flatten | ||
end | ||
assert_passed(test_result) | ||
end | ||
end |
Oops, something went wrong.