Skip to content

Move remaining core specs to use fewer shared examples#1369

Open
Earlopain wants to merge 13 commits into
ruby:masterfrom
Earlopain:fewer-shared-specs-2
Open

Move remaining core specs to use fewer shared examples#1369
Earlopain wants to merge 13 commits into
ruby:masterfrom
Earlopain:fewer-shared-specs-2

Conversation

@Earlopain
Copy link
Copy Markdown
Contributor

It's quite chonky but mostly more of the same for #1364. This converts the entirety of core specs.

Before:
3805 files, 35698 examples, 273269 expectations, 0 failure, 0 errors, 0 tagged

After:
3805 files, 34586 examples, 256944 expectations, 0 failure, 0 errors, 0 tagged

1112 fewer specs.

@Earlopain Earlopain force-pushed the fewer-shared-specs-2 branch 2 times, most recently from f311e61 to f51cf1d Compare June 1, 2026 17:50
@eregon eregon requested a review from Copilot June 1, 2026 19:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@Earlopain
Copy link
Copy Markdown
Contributor Author

Let me split this up in two PRs then

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 150 out of 150 changed files in this pull request and generated 4 comments.

Comment thread core/enumerable/find_spec.rb
Comment thread core/matchdata/size_spec.rb Outdated
Comment thread core/file/fnmatch_spec.rb Outdated
Comment thread core/matchdata/equal_value_spec.rb Outdated
Comment thread core/enumerable/map_spec.rb Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 150 out of 150 changed files in this pull request and generated 4 comments.

Comment thread core/kernel/to_enum_spec.rb
Comment thread core/kernel/to_enum_spec.rb
Comment thread core/env/select_spec.rb Outdated
Comment thread core/env/select_spec.rb Outdated
@Earlopain Earlopain force-pushed the fewer-shared-specs-2 branch from 83885f1 to a62129f Compare June 2, 2026 11:20
@Earlopain Earlopain requested a review from Copilot June 2, 2026 11:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 150 out of 150 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (5)

core/io/tty_spec.rb:1

  • This spec can be flaky across CI/container environments because /dev/tty may be missing or inaccessible (e.g., Errno::ENOENT, Errno::EACCES, Errno::ENODEV), not just Errno::ENXIO. Consider broadening the rescued errors (or guarding by checking existence/permissions) so the spec reliably skips when TTY access is not available.
    core/file/to_path_spec.rb:1
  • This platform_is/guard block defines before/after hooks but contains no examples that use @dir. Either add the missing TMPFILE-related examples within this scope or remove the unused hooks to avoid dead setup code.
    core/float/fdiv_spec.rb:1
  • The second example’s description duplicates the first one verbatim, which makes failures harder to interpret. Rename the second description to reflect the distinct intent (e.g., division by a very large Integer).
    core/kernel/dup_spec.rb:1
  • The spec that verified #dup calls #initialize_copy was removed, which drops coverage for an important and observable part of Ruby’s object-copying semantics. Consider re-adding an explicit example asserting initialize_copy is invoked (or adding equivalent coverage elsewhere in the same spec suite) so regressions in dup hooks are caught.
    core/kernel/clone_spec.rb:1
  • Similarly to dup_spec, removing the initialize_copy expectation for #clone reduces coverage for clone’s copy hook behavior. Re-introduce an example that asserts initialize_copy is called during clone to keep coverage of this user-visible contract.

Comment thread core/enumerable/reduce_spec.rb
Copy link
Copy Markdown
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff and some of the deduplication notably for Marshal will be very nice when improving those specs.

Comment thread core/enumerator/shared/enum_for.rb
Comment thread core/env/merge_spec.rb
describe "ENV.merge!" do
it_behaves_like :env_update, :merge!
it "is an alias of ENV.update" do
ENV.method(:merge!).should == ENV.method(:update)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I think merge! is more common than update (for Hash and ENV)

Comment thread core/file/delete_spec.rb
describe "File.delete" do
it_behaves_like :file_unlink, :delete
it "is an alias of File.unlink" do
File.method(:delete).should == File.method(:unlink)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I think File.delete is more common than File.unlink

Comment thread core/kernel/clone_spec.rb
Comment on lines -13 to -17
it "calls #initialize_copy on the new instance" do
clone = @obj.clone
ScratchPad.recorded.should_not == @obj.object_id
ScratchPad.recorded.should == clone.object_id
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed because it's a bad spec and in fact clone calls initialize_clone, which calls initialize_copy?
Also there are specs that initialize_clone is called below, so this is fine.

Comment thread core/kernel/dup_spec.rb
Comment on lines -13 to -17
it "calls #initialize_copy on the new instance" do
dup = @obj.dup
ScratchPad.recorded.should_not == @obj.object_id
ScratchPad.recorded.should == dup.object_id
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed because it's a bad spec and in fact clone calls initialize_dup, which calls initialize_copy?
Seems there is already another spec checking for initialize_copy but not for initialize_dup, but well that's out of scope.
I wonder why so many of these specs use custom objects instead of mocks though, seems unnecessarily obscure. Maybe because MSpec didn't have mocks back then (just a guess)?


describe "MatchData#==" do
it_behaves_like :matchdata_eql, :==
it "is an alias of MatchData#eql?" do
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: == is more frequent than eql? (and eql? for core types is is separate than == for probably only numeric types and maybe 1-2 other classes)

describe "Method#==" do
it_behaves_like :method_equal, :==
it "is an alias of Method#eql?" do
Method.instance_method(:==).should == Method.instance_method(:eql?)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, == is the main one I'd say and eql? the alias

Comment thread core/method/to_s_spec.rb
it_behaves_like :method_to_s, :to_s
it_behaves_like :method_to_s_aliased, :to_s, -> meth { meth }
it "is an alias of Method#inspect" do
Method.instance_method(:to_s).should == Method.instance_method(:inspect)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Float we have inspect is alias of to_s, I think that's good because to_s is more frequent than inspect, could you follow the pattern used for Float for other classes then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants