Skip to content

Commit

Permalink
Fix match expectation for module method visiblity changes
Browse files Browse the repository at this point in the history
* Ruby 3.1.3 changed that module inherited methods that underwent
  visibiltiy changes are now owned by the class.
* This makes it impossible for mutant to exclude these methods anymore
  from the class coverage subjects.
* This may actually be preferable for public methods as they form part
  of the public interface.
* Mutant now emits more subjects, eventually users will have to use
  explicit targeting to cover that "re-appearing" subjects.
* As the case to "just" change visibiltiy in module inherited methods is
  quite rare I expect no significant user experience changes.
  • Loading branch information
mbj committed Jan 6, 2023
1 parent 77d49d6 commit 6778c40
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
ruby: [ruby-2.7, ruby-3.0, ruby-3.1.2, ruby-3.1.3]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
Expand All @@ -36,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
ruby: [ruby-2.7, ruby-3.0, ruby-3.1.2, ruby-3.1.3]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
Expand All @@ -54,7 +54,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
ruby: [ruby-2.7, ruby-3.0, ruby-3.1.2, ruby-3.1.3]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
Expand All @@ -74,7 +74,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
ruby: [ruby-2.7, ruby-3.0, ruby-3.1.2, ruby-3.1.3]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
Expand All @@ -90,7 +90,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
ruby: [ruby-2.7, ruby-3.0, ruby-3.1.2, ruby-3.1.3]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
Expand All @@ -106,7 +106,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
ruby: [ruby-2.7, ruby-3.0, ruby-3.1.2, ruby-3.1.3]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
Expand All @@ -122,7 +122,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: [ruby-2.7, ruby-3.0, ruby-3.1]
ruby: [ruby-2.7, ruby-3.0, ruby-3.1.2, ruby-3.1.3]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v3
Expand Down
8 changes: 8 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v0.11.18 unreleased

* [#1362](http://github.com/mbj/mutant/pull/1362)

Adapt to behavior change in ruby 3.1.3 where methods inherited
from module inclusions that just got visibility changes are now
owned by the included module/class.

# v0.11.17 2022-11-12

* [#1352](https://github.com/mbj/mutant/pull/1352)
Expand Down
18 changes: 15 additions & 3 deletions spec/unit/mutant/matcher/methods/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,26 @@ def method_c; end
let(:subject_a) { instance_double(Mutant::Subject) }
let(:subject_b) { instance_double(Mutant::Subject) }
let(:subject_c) { instance_double(Mutant::Subject) }
let(:subjects) { [subject_a, subject_b, subject_c] }
let(:subject_d) { instance_double(Mutant::Subject) }

let(:subjects) do
[subject_a, subject_b, subject_c].tap do |value|
value << subject_d if RUBY_VERSION >= '3.1.3'
end
end

before do
{
expected_subjects = {
method_a: subject_a,
method_b: subject_b,
method_c: subject_c
}.each do |method, subject|
}

if RUBY_VERSION >= '3.1.3'
expected_subjects[:method_d] = subject_d
end

expected_subjects.each do |method, subject|
matcher = instance_double(Mutant::Matcher)
expect(matcher).to receive(:call).with(env).and_return([subject])

Expand Down

0 comments on commit 6778c40

Please sign in to comment.