Skip to content

Fewer shared specs for library#1371

Open
Earlopain wants to merge 18 commits into
ruby:masterfrom
Earlopain:fewer-shared-specs-lib
Open

Fewer shared specs for library#1371
Earlopain wants to merge 18 commits into
ruby:masterfrom
Earlopain:fewer-shared-specs-lib

Conversation

@Earlopain
Copy link
Copy Markdown
Contributor

For #1364. Only 165 fewer examples since library is not so well-speced compared to core.

Last large-scale PR, I should be done with this now.

@Earlopain Earlopain force-pushed the fewer-shared-specs-lib branch 2 times, most recently from 5a426d7 to a3424ba Compare June 3, 2026 10:40
@Earlopain Earlopain force-pushed the fewer-shared-specs-lib branch from a3424ba to 0b064ba Compare June 3, 2026 10:44
@Earlopain Earlopain force-pushed the fewer-shared-specs-lib branch from 0b064ba to f43d77b Compare June 3, 2026 11:17
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

This PR reduces reliance on shared examples in the library/ specs by inlining the shared behavior into a single “primary” method’s spec and converting aliased methods’ specs into direct alias assertions (per #1364), removing a large number of shared spec files.

Changes:

  • Replaced many it_behaves_like shared-example usages with inlined examples in the canonical spec for a method.
  • Converted many alias-method specs into “is an alias of …” assertions using method/instance_method equality.
  • Removed numerous library/**/shared/*.rb shared example files that are no longer referenced.

Reviewed changes

Copilot reviewed 224 out of 224 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
library/yaml/shared/each_document.rb Removed shared examples (inlined into canonical spec).
library/yaml/load_stream_spec.rb Inlined YAML each-document behavior examples.
library/uri/shared/parse.rb Removed shared examples (inlined into canonical spec).
library/uri/shared/join.rb Removed shared examples (inlined into canonical spec).
library/uri/shared/extract.rb Removed shared examples (inlined into canonical spec).
library/uri/parser/parse_spec.rb Inlined URI::Parser#parse behavior examples.
library/uri/parser/join_spec.rb Inlined URI::Parser#join behavior examples.
library/uri/parser/extract_spec.rb Inlined URI::Parser#extract behavior examples.
library/time/xmlschema_spec.rb Inlined Time.xmlschema behavior examples.
library/time/shared/xmlschema.rb Removed shared examples (moved into xmlschema_spec).
library/time/shared/rfc2822.rb Removed shared examples (moved into rfc2822_spec).
library/time/rfc822_spec.rb Replaced shared examples with alias assertion.
library/time/rfc2822_spec.rb Inlined Time.rfc2822 behavior examples.
library/time/iso8601_spec.rb Replaced shared examples with alias assertion.
library/tempfile/unlink_spec.rb Replaced shared examples with alias assertion.
library/tempfile/size_spec.rb Inlined Tempfile#size behavior examples.
library/tempfile/shared/unlink.rb Removed shared examples (moved/aliased).
library/tempfile/shared/length.rb Removed shared examples (moved/aliased).
library/tempfile/length_spec.rb Replaced shared examples with alias assertion.
library/tempfile/delete_spec.rb Inlined Tempfile#delete behavior examples.
library/syslog/shared/reopen.rb Removed shared examples (moved/aliased).
library/syslog/reopen_spec.rb Replaced shared examples with alias assertion.
library/syslog/open_spec.rb Inlined Syslog.open! behavior examples.
library/stringscanner/shared/pos.rb Removed shared examples (moved/aliased).
library/stringscanner/shared/concat.rb Removed shared examples (moved/aliased).
library/stringscanner/shared/bol.rb Removed shared examples (moved/aliased).
library/stringscanner/pos_spec.rb Inlined pos/pos= behavior examples.
library/stringscanner/pointer_spec.rb Replaced shared examples with alias assertion.
library/stringscanner/concat_spec.rb Replaced shared examples with alias assertion.
library/stringscanner/bol_spec.rb Replaced shared examples with alias assertion.
library/stringscanner/beginning_of_line_spec.rb Inlined beginning_of_line? behavior examples.
library/stringscanner/append_spec.rb Inlined << behavior examples.
library/stringio/tty_spec.rb Inlined tty? example (removed shared).
library/stringio/tell_spec.rb Replaced shared examples with alias assertion.
library/stringio/size_spec.rb Replaced shared examples with alias assertion.
library/stringio/shared/tell.rb Removed shared examples (moved/aliased).
library/stringio/shared/length.rb Removed shared examples (moved/aliased).
library/stringio/shared/isatty.rb Removed shared examples (moved/aliased).
library/stringio/shared/eof.rb Removed shared examples (moved/aliased).
library/stringio/shared/each.rb Removed shared examples (moved to each_line, alias-tested).
library/stringio/shared/each_char.rb Removed shared examples (inlined into each_char_spec).
library/stringio/shared/each_byte.rb Removed shared examples (inlined into each_byte_spec).
library/stringio/shared/codepoints.rb Removed shared examples (inlined into each_codepoint_spec).
library/stringio/pos_spec.rb Inlined pos behavior examples.
library/stringio/length_spec.rb Inlined length behavior example.
library/stringio/isatty_spec.rb Replaced shared examples with alias assertion.
library/stringio/eof_spec.rb Inlined eof? behavior + alias assertion for eof.
library/stringio/each_spec.rb Replaced shared examples with alias assertion.
library/stringio/each_codepoint_spec.rb Inlined each_codepoint behavior examples.
library/stringio/each_char_spec.rb Inlined each_char behavior examples.
library/stringio/each_byte_spec.rb Inlined each_byte behavior examples.
library/socket/unixsocket/socketpair_spec.rb Replaced shared examples with alias assertion.
library/socket/unixsocket/shared/pair.rb Removed shared examples (moved into pair_spec).
library/socket/unixsocket/pair_spec.rb Inlined UNIXSocket.pair behavior examples.
library/socket/socket/socketpair_spec.rb Replaced shared examples with alias assertion.
library/socket/socket/sockaddr_un_spec.rb Inlined sockaddr_un behavior examples.
library/socket/socket/sockaddr_in_spec.rb Inlined sockaddr_in behavior examples.
library/socket/socket/pair_spec.rb Inlined Socket.pair behavior examples.
library/socket/socket/pack_sockaddr_un_spec.rb Replaced shared examples with alias assertion.
library/socket/socket/pack_sockaddr_in_spec.rb Replaced shared examples with alias assertion.
library/socket/shared/socketpair.rb Removed shared examples (moved/aliased).
library/socket/shared/pack_sockaddr.rb Removed shared examples (moved/aliased).
library/socket/addrinfo/to_sockaddr_spec.rb Inlined to_sockaddr behavior examples.
library/socket/addrinfo/to_s_spec.rb Replaced shared examples with alias assertion.
library/socket/addrinfo/shared/to_sockaddr.rb Removed shared examples (moved/aliased).
library/prime/succ_spec.rb Inlined Prime#succ behavior example.
library/prime/shared/next.rb Removed shared examples (moved/aliased).
library/prime/next_spec.rb Replaced shared examples with alias assertion.
library/pathname/shared/plus.rb Removed shared examples (moved/aliased).
library/pathname/plus_spec.rb Inlined Pathname#+ behavior example.
library/pathname/divide_spec.rb Replaced shared examples with alias assertion.
library/pathname/case_compare_spec.rb Added alias assertion for Pathname#===.
library/openstruct/to_s_spec.rb Inlined OpenStruct#to_s behavior examples.
library/openstruct/shared/inspect.rb Removed shared examples (moved/aliased).
library/openstruct/inspect_spec.rb Replaced shared examples with alias assertion.
library/openstruct/equal_value_spec.rb Normalized require quoting.
library/net-http/httpresponse/shared/body.rb Removed shared examples (moved/aliased).
library/net-http/httpresponse/entity_spec.rb Replaced shared examples with alias assertion.
library/net-http/httpresponse/body_spec.rb Inlined HTTPResponse#body behavior examples.
library/net-http/httpheader/size_spec.rb Inlined HTTPHeader#size behavior examples.
library/net-http/httpheader/shared/size.rb Removed shared examples (moved/aliased).
library/net-http/httpheader/shared/set_range.rb Removed shared examples (moved/aliased).
library/net-http/httpheader/shared/set_form_data.rb Removed shared examples (moved/aliased).
library/net-http/httpheader/shared/set_content_type.rb Removed shared examples (moved/aliased).
library/net-http/httpheader/shared/each_name.rb Removed shared examples (moved/aliased).
library/net-http/httpheader/shared/each_header.rb Removed shared examples (moved/aliased).
library/net-http/httpheader/shared/each_capitalized.rb Removed shared examples (moved/aliased).
library/net-http/httpheader/set_range_spec.rb Inlined set_range behavior examples.
library/net-http/httpheader/set_form_data_spec.rb Inlined set_form_data behavior examples.
library/net-http/httpheader/set_content_type_spec.rb Inlined set_content_type behavior examples.
library/net-http/httpheader/range_spec.rb Replaced shared examples with alias assertion.
library/net-http/httpheader/length_spec.rb Replaced shared examples with alias assertion.
library/net-http/httpheader/form_data_spec.rb Replaced shared examples with alias assertion.
library/net-http/httpheader/each_spec.rb Replaced shared examples with alias assertion.
library/net-http/httpheader/each_name_spec.rb Replaced shared examples with alias assertion.
library/net-http/httpheader/each_key_spec.rb Inlined each_key behavior examples.
library/net-http/httpheader/each_header_spec.rb Inlined each_header behavior examples.
library/net-http/httpheader/each_capitalized_spec.rb Inlined each_capitalized behavior examples.
library/net-http/httpheader/content_type_spec.rb Replaced shared examples with alias assertion.
library/net-http/httpheader/canonical_each_spec.rb Replaced shared examples with alias assertion.
library/net-http/http/version_1_2_spec.rb Inlined version_1_2? behavior example.
library/net-http/http/version_1_1_spec.rb Inlined version_1_1? behavior example.
library/net-http/http/started_spec.rb Inlined started? behavior examples.
library/net-http/http/shared/version_1_2.rb Removed shared examples (moved/aliased).
library/net-http/http/shared/version_1_1.rb Removed shared examples (moved/aliased).
library/net-http/http/shared/started.rb Removed shared examples (moved/aliased).
library/net-http/http/shared/request_put.rb Removed shared examples (moved/aliased).
library/net-http/http/shared/request_post.rb Removed shared examples (moved/aliased).
library/net-http/http/shared/request_head.rb Removed shared examples (moved/aliased).
library/net-http/http/shared/request_get.rb Removed shared examples (moved/aliased).
library/net-http/http/request_put_spec.rb Inlined request_put behavior examples.
library/net-http/http/request_post_spec.rb Inlined request_post behavior examples.
library/net-http/http/request_head_spec.rb Inlined request_head behavior examples.
library/net-http/http/request_get_spec.rb Inlined request_get behavior examples.
library/net-http/http/put2_spec.rb Replaced shared examples with alias assertion.
library/net-http/http/post2_spec.rb Replaced shared examples with alias assertion.
library/net-http/http/is_version_1_2_spec.rb Replaced shared examples with alias assertion.
library/net-http/http/is_version_1_1_spec.rb Replaced shared examples with alias assertion.
library/net-http/http/head2_spec.rb Replaced shared examples with alias assertion.
library/net-http/http/get2_spec.rb Replaced shared examples with alias assertion.
library/net-http/http/active_spec.rb Replaced shared examples with alias assertion.
library/matrix/unit_spec.rb Replaced shared examples with alias assertion.
library/matrix/transpose_spec.rb Inlined transpose behavior examples.
library/matrix/trace_spec.rb Inlined trace behavior examples.
library/matrix/tr_spec.rb Replaced shared examples with alias assertion.
library/matrix/t_spec.rb Replaced shared examples with alias assertion.
library/matrix/shared/transpose.rb Removed shared examples (moved/aliased).
library/matrix/shared/trace.rb Removed shared examples (moved/aliased).
library/matrix/shared/rectangular.rb Removed shared examples (moved/aliased).
library/matrix/shared/inverse.rb Removed shared examples (moved/aliased).
library/matrix/shared/imaginary.rb Removed shared examples (moved/aliased).
library/matrix/shared/identity.rb Removed shared examples (moved/aliased).
library/matrix/shared/determinant.rb Removed shared examples (moved/aliased).
library/matrix/shared/conjugate.rb Removed shared examples (moved/aliased).
library/matrix/shared/collect.rb Removed shared examples (moved/aliased).
library/matrix/rectangular_spec.rb Inlined rectangular behavior examples.
library/matrix/rect_spec.rb Replaced shared examples with alias assertion.
library/matrix/map_spec.rb Inlined map behavior examples.
library/matrix/inverse_spec.rb Inlined inverse behavior examples.
library/matrix/inv_spec.rb Replaced shared examples with alias assertion.
library/matrix/imaginary_spec.rb Inlined imaginary behavior examples.
library/matrix/imag_spec.rb Replaced shared examples with alias assertion.
library/matrix/identity_spec.rb Inlined identity behavior examples.
library/matrix/I_spec.rb Replaced shared examples with alias assertion.
library/matrix/determinant_spec.rb Inlined determinant behavior examples.
library/matrix/det_spec.rb Replaced shared examples with alias assertion.
library/matrix/conjugate_spec.rb Inlined conjugate behavior examples.
library/matrix/conj_spec.rb Replaced shared examples with alias assertion.
library/matrix/collect_spec.rb Replaced shared examples with alias assertion.
library/getoptlong/shared/get.rb Removed shared examples (moved/aliased).
library/getoptlong/shared/each.rb Removed shared examples (moved/aliased).
library/getoptlong/get_spec.rb Inlined GetoptLong#get behavior examples.
library/getoptlong/get_option_spec.rb Replaced shared examples with alias assertion.
library/getoptlong/each_spec.rb Inlined GetoptLong#each behavior example.
library/getoptlong/each_option_spec.rb Replaced shared examples with alias assertion.
library/digest/sha512/update_spec.rb Replaced shared examples with alias assertion.
library/digest/sha512/size_spec.rb Replaced shared examples with alias assertion.
library/digest/sha512/shared/update.rb Removed shared examples (moved/aliased).
library/digest/sha512/shared/length.rb Removed shared examples (moved/aliased).
library/digest/sha512/length_spec.rb Inlined SHA512#length behavior example.
library/digest/sha512/append_spec.rb Inlined SHA512#<< behavior example.
library/digest/sha384/update_spec.rb Replaced shared examples with alias assertion.
library/digest/sha384/size_spec.rb Replaced shared examples with alias assertion.
library/digest/sha384/shared/update.rb Removed shared examples (moved/aliased).
library/digest/sha384/shared/length.rb Removed shared examples (moved/aliased).
library/digest/sha384/length_spec.rb Inlined SHA384#length behavior example.
library/digest/sha384/append_spec.rb Inlined SHA384#<< behavior example.
library/digest/sha256/update_spec.rb Replaced shared examples with alias assertion.
library/digest/sha256/size_spec.rb Replaced shared examples with alias assertion.
library/digest/sha256/shared/update.rb Removed shared examples (moved/aliased).
library/digest/sha256/shared/length.rb Removed shared examples (moved/aliased).
library/digest/sha256/length_spec.rb Inlined SHA256#length behavior example.
library/digest/sha256/append_spec.rb Inlined SHA256#<< behavior example.
library/digest/md5/update_spec.rb Replaced shared examples with alias assertion.
library/digest/md5/size_spec.rb Replaced shared examples with alias assertion.
library/digest/md5/shared/update.rb Removed shared examples (moved/aliased).
library/digest/md5/shared/length.rb Removed shared examples (moved/aliased).
library/digest/md5/length_spec.rb Inlined MD5#length behavior example.
library/digest/md5/append_spec.rb Inlined MD5#<< behavior example.
library/digest/instance/update_spec.rb Replaced shared examples with alias assertion.
library/digest/instance/shared/update.rb Removed shared examples (moved/aliased).
library/digest/instance/append_spec.rb Inlined Digest::Instance#<< behavior example.
library/datetime/xmlschema_spec.rb Replaced placeholder with alias assertion.
library/datetime/shared/sec.rb Removed shared examples (moved/aliased).
library/datetime/shared/min.rb Removed shared examples (moved/aliased).
library/datetime/second_spec.rb Replaced shared examples with alias assertion.
library/datetime/second_fraction_spec.rb Replaced placeholder with alias assertion.
library/datetime/sec_spec.rb Inlined DateTime#sec behavior examples.
library/datetime/minute_spec.rb Inlined DateTime#minute behavior examples.
library/datetime/min_spec.rb Replaced shared examples with alias assertion.
library/date/valid_ordinal_spec.rb Inlined Date.valid_ordinal? behavior examples.
library/date/valid_jd_spec.rb Inlined Date.valid_jd? behavior examples.
library/date/valid_date_spec.rb Inlined Date.valid_date? behavior examples.
library/date/valid_commercial_spec.rb Inlined Date.valid_commercial? behavior examples.
library/date/valid_civil_spec.rb Replaced shared examples with alias assertion.
library/date/succ_spec.rb Replaced placeholder with alias assertion.
library/date/shared/valid_ordinal.rb Removed shared examples (moved/aliased).
library/date/shared/valid_jd.rb Removed shared examples (moved/aliased).
library/date/shared/valid_commercial.rb Removed shared examples (moved/aliased).
library/date/shared/valid_civil.rb Removed shared examples (moved/aliased).
library/date/shared/ordinal.rb Removed shared examples (moved/aliased).
library/date/shared/month.rb Removed shared examples (moved/aliased).
library/date/shared/jd.rb Removed shared examples (moved/aliased).
library/date/shared/commercial.rb Removed shared examples (moved/aliased).
library/date/ordinal_spec.rb Inlined Date.ordinal behavior example.
library/date/month_spec.rb Inlined Date#month behavior example.
library/date/mon_spec.rb Replaced shared examples with alias assertion.
library/date/mday_spec.rb Replaced placeholder with alias assertion.
library/date/jd_spec.rb Inlined Date.jd behavior examples.
library/date/ctime_spec.rb Replaced placeholder with alias assertion.
library/date/commercial_spec.rb Inlined Date.commercial behavior examples.
library/bigdecimal/to_int_spec.rb Replaced shared examples with alias assertion.
library/bigdecimal/to_i_spec.rb Inlined BigDecimal#to_i behavior examples.
library/bigdecimal/shared/to_int.rb Removed shared examples (moved/aliased).
library/bigdecimal/shared/modulo.rb Removed now-unreferenced shared section.
library/bigdecimal/shared/eql.rb Removed shared examples (moved/aliased).
library/bigdecimal/shared/clone.rb Removed shared examples (moved/aliased).
library/bigdecimal/modulo_spec.rb Inlined zero-division tests + alias assertion.
library/bigdecimal/equal_value_spec.rb Inlined BigDecimal#== behavior examples.
library/bigdecimal/eql_spec.rb Replaced shared examples with alias assertion.
library/bigdecimal/dup_spec.rb Inlined BigDecimal#dup behavior example.
library/bigdecimal/clone_spec.rb Replaced shared examples with alias assertion.
library/bigdecimal/case_compare_spec.rb Replaced shared examples with alias assertion.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5 to +6
it "is an alias of Net.HTTP#version_1_1?" do
Net::HTTP.method(:is_version_1_1?).should == Net::HTTP.method(:is_version_1_1?)
require_relative '../fixtures/classes'
require_relative '../shared/pack_sockaddr'

describe "Socket#sockaddr_un" do
require_relative '../fixtures/classes'
require_relative '../shared/pack_sockaddr'

describe "Socket#sockaddr_in" do
s2.close
end

it "responses with array of two sockets" do
Comment on lines 4 to 8
describe "BigDecimal#dup" do
it_behaves_like :bigdecimal_clone, :clone
it "is an alias of BigDecimal#clone" do
BigDecimal.instance_method(:dup).should == BigDecimal.instance_method(:clone)
end
end

describe "BigDecimal#to_int" do
it_behaves_like :bigdecimal_to_int, :to_int
it "is an alias of Bigdecimal#to_i" do

describe "BigDecimal#eql?" do
it_behaves_like :bigdecimal_eql, :eql?
it "is an alias of Bigdecimal#==" do

describe "BigDecimal#===" do
it_behaves_like :bigdecimal_eql, :===
it "is an alias of Bigdecimal#==" do
describe "BigDecimal#modulo" do
it_behaves_like :bigdecimal_modulo, :modulo
it_behaves_like :bigdecimal_modulo_zerodivisionerror, :modulo
it "is an alias of Bigdecimal#%" do
require_relative 'shared/clone'
require 'bigdecimal'

describe "BigDecimal#dup" 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.

Suggested change
describe "BigDecimal#dup" do
describe "BigDecimal#clone" do

Comment on lines +5 to +6
it "is an alias of BigDecimal#clone" do
BigDecimal.instance_method(:dup).should == BigDecimal.instance_method(:clone)
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.

Suggested change
it "is an alias of BigDecimal#clone" do
BigDecimal.instance_method(:dup).should == BigDecimal.instance_method(:clone)
it "is an alias of BigDecimal#dup" do
BigDecimal.instance_method(:clone).should == BigDecimal.instance_method(:dup)

Comment on lines +5 to +7
it "is an alias of DateTime#sec" do
DateTime.instance_method(:second).should == DateTime.instance_method(:sec)
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.

Since minute has the specs for consistency it seems best that second has the specs and sec the alias

describe "Net::HTTP.is_version_1_1?" do
it_behaves_like :net_http_version_1_1_p, :is_version_1_1?
it "is an alias of Net.HTTP#version_1_1?" do
Net::HTTP.method(:is_version_1_1?).should == Net::HTTP.method(:is_version_1_1?)
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.

This compares 2 class methods but it should be the instance method

describe "Net::HTTP.is_version_1_2?" do
it_behaves_like :net_http_version_1_2_p, :is_version_1_2?
it "is an alias of Net::HTTP.version_1_2?" do
Net::HTTP.method(:is_version_1_2?).should == Net::HTTP.method(:version_1_2?)
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.

This compares 2 class methods but it should be the instance method


describe "Prime#succ" do
it_behaves_like :prime_next, :succ
it "returns the element at the current position and moves forward" 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.

Could you move the specs to next?
The "next prime" is clear, "succ" seems a poor idea, normally succ is "+ 1" so I'd make that the alias

@eregon
Copy link
Copy Markdown
Member

eregon commented Jun 3, 2026

Nice that Copilot also noticed the issue with library/net-http/http/is_version_1_1_spec.rb but bad that it didn't find the very similar library/net-http/http/is_version_1_2_spec.rb issue

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