Skip to content

Move remaining core specs to use fewer shared examples - Part 2#1370

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

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

Conversation

@Earlopain
Copy link
Copy Markdown
Contributor

Because #1369 was too big for the automatic review

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 continues the work from #1369 by reducing reliance on shared examples in core specs, inlining the relevant expectations directly into the individual spec files, and replacing many “synonym” expectations with explicit alias checks (e.g., instance_method equality). This helps shrink the spec suite and makes individual spec files more self-contained.

Changes:

  • Inline previously-shared examples into the concrete spec files and delete the corresponding shared/*.rb files.
  • Replace many “same behavior as X” shared-example usages with direct alias assertions (e.g., Time#day is an alias of Time#mday).
  • Add a few new standalone alias-spec files for Set and Range.

Reviewed changes

Copilot reviewed 176 out of 176 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
core/unboundmethod/to_s_spec.rb Replace shared examples with a direct alias check to inspect.
core/unboundmethod/shared/to_s.rb Remove shared examples for UnboundMethod#to_s/#inspect.
core/unboundmethod/inspect_spec.rb Inline the former shared to_s/inspect expectations into inspect_spec.
core/time/xmlschema_spec.rb Inline xmlschema expectations (Ruby 3.4+ guarded).
core/time/utc_spec.rb Inline Time.utc behavior and replace Time#utc with alias check to gmtime.
core/time/utc_offset_spec.rb Replace shared coverage with alias check to gmtoff.
core/time/usec_spec.rb Replace behavioral specs with alias check to tv_usec.
core/time/tv_usec_spec.rb Replace placeholder with microseconds behavioral expectations.
core/time/tv_sec_spec.rb Replace shared coverage with alias check to to_i.
core/time/tv_nsec_spec.rb Replace placeholder with nanoseconds behavioral expectations.
core/time/to_i_spec.rb Inline to_i behavioral expectations (previously shared).
core/time/shared/xmlschema.rb Remove shared xmlschema example group.
core/time/shared/to_i.rb Remove shared to_i example group.
core/time/shared/month.rb Remove shared month/mon example group.
core/time/shared/isdst.rb Remove shared isdst/dst? example group.
core/time/shared/gmtime.rb Remove shared gmtime/utc example group.
core/time/shared/gmt_offset.rb Remove shared gmtoff/gmt_offset/utc_offset example group.
core/time/shared/gm.rb Remove shared gm/utc constructor example group.
core/time/shared/getgm.rb Remove shared getgm/getutc example group.
core/time/shared/day.rb Remove shared day/mday example group.
core/time/shared/asctime.rb Remove shared asctime/ctime example group.
core/time/nsec_spec.rb Replace behavioral specs with alias check to tv_nsec.
core/time/month_spec.rb Replace shared coverage with alias check to mon.
core/time/mon_spec.rb Inline mon behavioral expectations (previously shared).
core/time/mktime_spec.rb Replace multiple shared behaviors with alias check to Time.local.
core/time/mday_spec.rb Inline mday behavioral expectations (previously shared).
core/time/iso8601_spec.rb Replace shared xmlschema behavior with alias check to xmlschema (Ruby 3.4+).
core/time/isdst_spec.rb Inline DST behavioral expectations (previously shared).
core/time/gmtoff_spec.rb Inline gmtoff behavioral expectations (previously shared).
core/time/gmtime_spec.rb Inline gmtime behavioral expectations (previously shared).
core/time/gmt_spec.rb Replace behavioral specs with alias check to utc?.
core/time/gmt_offset_spec.rb Replace shared coverage with alias check to gmtoff.
core/time/gm_spec.rb Replace multiple shared behaviors with alias check to Time.utc.
core/time/getutc_spec.rb Replace shared coverage with alias check to getgm.
core/time/getgm_spec.rb Inline getgm behavior (previously shared).
core/time/dst_spec.rb Replace shared behavior with alias check to isdst.
core/time/day_spec.rb Replace shared behavior with alias check to mday.
core/time/ctime_spec.rb Inline ctime/asctime behavior (previously shared).
core/time/asctime_spec.rb Replace shared behavior with alias check to ctime.
core/thread/to_s_spec.rb Inline Thread#to_s expectations (previously shared).
core/thread/terminate_spec.rb Replace shared exit behavior with alias check to Thread#exit.
core/thread/start_spec.rb Inline Thread.start behavior (previously shared).
core/thread/shared/to_s.rb Remove shared Thread#to_s example group.
core/thread/shared/start.rb Remove shared Thread.start/fork example group.
core/thread/shared/exit.rb Remove shared Thread#exit/kill/terminate example group.
core/thread/kill_spec.rb Inline former shared thread_exit expectations into Thread#kill.
core/thread/inspect_spec.rb Replace shared behavior with alias check to to_s.
core/thread/fork_spec.rb Replace shared behavior with alias check to Thread.start.
core/thread/exit_spec.rb Replace shared behavior with alias check to Thread#kill.
core/symbol/to_s_spec.rb Inline to_s expectations (previously shared).
core/symbol/succ_spec.rb Inline succ expectations (previously shared).
core/symbol/slice_spec.rb Replace shared behavior with alias check to Symbol#[].
core/symbol/size_spec.rb Replace shared behavior with alias check to length.
core/symbol/shared/succ.rb Remove shared succ/next example group.
core/symbol/shared/slice.rb Remove shared slice/[] example group.
core/symbol/shared/length.rb Remove shared length/size example group.
core/symbol/shared/id2name.rb Remove shared id2name/to_s example group.
core/symbol/next_spec.rb Replace shared behavior with alias check to succ.
core/symbol/length_spec.rb Inline length expectations (previously shared).
core/symbol/intern_spec.rb Replace behavioral specs with alias check to to_sym.
core/symbol/id2name_spec.rb Replace shared behavior with alias check to to_s.
core/symbol/element_reference_spec.rb Inline Symbol#[] expectations (previously shared).
core/symbol/case_compare_spec.rb Replace behavioral specs with alias check to ==.
core/struct/values_spec.rb Replace behavioral specs with alias check to to_a.
core/struct/to_s_spec.rb Replace shared behavior with alias check to inspect.
core/struct/shared/select.rb Remove shared select/filter example group.
core/struct/shared/inspect.rb Remove shared inspect/to_s example group.
core/struct/select_spec.rb Inline select expectations (previously shared).
core/struct/length_spec.rb Replace behavioral specs with alias check to size.
core/struct/inspect_spec.rb Inline inspect expectations (previously shared).
core/struct/filter_spec.rb Replace shared behavior with alias check to select.
core/struct/deconstruct_spec.rb Replace behavioral specs with alias check to to_a.
core/string/uminus_spec.rb Inline String#-@ (dedup) behavior (previously shared).
core/string/to_sym_spec.rb Replace shared behavior with alias check to intern.
core/string/to_str_spec.rb Replace shared behavior with alias check to to_s.
core/string/to_s_spec.rb Inline to_s expectations (previously shared).
core/string/succ_spec.rb Inline succ/succ! expectations (previously shared).
core/string/slice_spec.rb Replace shared coverage with alias check to String#[].
core/string/size_spec.rb Replace shared behavior with alias check to length.
core/string/shared/to_sym.rb Remove shared to_sym/intern example group.
core/string/shared/to_s.rb Remove shared to_s/to_str example group.
core/string/shared/succ.rb Remove shared succ/next example group.
core/string/shared/length.rb Remove shared length/size example group.
core/string/shared/equal_value.rb Remove shared ==/=== additional equality behaviors.
core/string/shared/each_codepoint_without_block.rb Remove shared enumerator/no-block expectations for each_codepoint/codepoints.
core/string/shared/dedup.rb Remove shared dedup/-@ example group.
core/string/next_spec.rb Replace shared behavior with alias checks to succ/succ!.
core/string/length_spec.rb Inline length expectations (previously shared).
core/string/intern_spec.rb Inline intern expectations (previously shared).
core/string/equal_value_spec.rb Inline == additional equality behaviors (previously shared).
core/string/each_codepoint_spec.rb Inline no-block enumerator expectations (previously shared).
core/string/dedup_spec.rb Replace shared behavior with alias check to -@.
core/string/codepoints_spec.rb Remove now-inlined no-block shared include.
core/string/case_compare_spec.rb Replace shared behavior with alias check to ==.
core/set/union_spec.rb Replace shared union behavior by inlining `
core/set/to_s_spec.rb Replace shared behavior with alias check to inspect.
core/set/size_spec.rb Inline size expectations (previously shared).
core/set/shared/union.rb Remove shared union example group.
core/set/shared/select.rb Remove shared select!/filter! example group.
core/set/shared/length.rb Remove shared length/size example group.
core/set/shared/intersection.rb Remove shared intersection/& example group.
core/set/shared/inspect.rb Remove shared inspect/to_s example group.
core/set/shared/include.rb Remove shared include?/member?/=== example group.
core/set/shared/difference.rb Remove shared difference/- example group.
core/set/shared/collect.rb Remove shared collect!/map! example group.
core/set/shared/add.rb Remove shared add/<< example group.
core/set/select_spec.rb Inline select! expectations (previously shared).
core/set/plus_spec.rb Replace shared behavior with alias check to `
core/set/minus_spec.rb Inline - expectations (previously shared).
core/set/member_spec.rb Replace shared behavior with alias check to include?.
core/set/map_spec.rb Replace shared behavior with alias check to collect!.
core/set/lte_spec copy.rb Add alias check spec for Set#<= (new file).
core/set/lt_spec.rb Add alias check spec for Set#< (new file).
core/set/length_spec.rb Replace shared behavior with alias check to size.
core/set/intersection_spec.rb Replace shared intersection behavior by inlining & behavior and alias check for intersection.
core/set/inspect_spec.rb Inline inspect expectations (previously shared).
core/set/include_spec.rb Inline include? expectations (previously shared).
core/set/gte_spec.rb Add alias check spec for Set#>= (new file).
core/set/gt_spec copy.rb Add alias check spec for Set#> (new file).
core/set/filter_spec.rb Replace shared behavior with alias check to select!.
core/set/eql_spec.rb Split behavior by Ruby version and add alias check for Ruby 4.0.
core/set/difference_spec.rb Replace shared behavior with alias check to -.
core/set/collect_spec.rb Inline collect! expectations (previously shared).
core/set/case_equality_spec.rb Remove separate Set#=== spec file.
core/set/case_compare_spec.rb Replace shared behavior with alias check to include?.
core/set/append_spec.rb Replace shared behavior with alias check to add.
core/set/add_spec.rb Inline add expectations (previously shared).
core/regexp/shared/quote.rb Remove shared quote/escape example group.
core/regexp/shared/equal_value.rb Remove shared eql?/== equality example group.
core/regexp/quote_spec.rb Inline quote expectations (previously shared).
core/regexp/escape_spec.rb Replace shared behavior with alias check to quote.
core/regexp/equal_value_spec.rb Replace shared behavior with alias check to eql?.
core/regexp/eql_spec.rb Inline eql? expectations (previously shared).
core/refinement/target_spec.rb Inline target expectations (previously shared).
core/refinement/shared/target.rb Remove shared target example group.
core/refinement/refined_class_spec.rb Remove now-unused shared require.
core/rational/shared/abs.rb Remove shared abs/magnitude example group.
core/rational/quo_spec.rb Replace behavioral specs with alias check to /.
core/rational/magnitude_spec.rb Fix description/coverage to assert alias to abs.
core/rational/abs_spec.rb Inline abs expectations (previously shared).
core/range/shared/include.rb Remove shared include?/member? example group.
core/range/member_spec.rb Replace shared behavior with alias check to include?.
core/range/include_spec.rb Inline include? expectations for strings/custom succ/Time endpoints.
core/range/entries_spec.rb Add alias check spec for Range#entries (new file).
core/proc/yield_spec.rb Replace shared behavior with alias check to call.
core/proc/to_s_spec.rb Inline to_s expectations (previously shared).
core/proc/shared/to_s.rb Remove shared to_s/inspect example group.
core/proc/shared/equal.rb Remove shared eql?/== example group.
core/proc/shared/call.rb Remove shared call/[]/=== behavior groups.
core/proc/shared/call_arguments.rb Remove shared “block argument” behavior group.
core/proc/inspect_spec.rb Replace shared behavior with alias check to to_s.
core/proc/fixtures/proc_call.rb Add fixture for Proc#call under frozen_string_literal: false.
core/proc/fixtures/proc_call_frozen.rb Add fixture for Proc#call under frozen_string_literal: true.
core/proc/fixtures/proc_aref.rb Remove fixture for Proc#[] under frozen_string_literal: false.
core/proc/fixtures/proc_aref_frozen.rb Remove fixture for Proc#[] under frozen_string_literal: true.
core/proc/equal_value_spec.rb Replace shared behavior with alias check to eql?.
core/proc/eql_spec.rb Inline eql? expectations (previously shared).
core/proc/element_reference_spec.rb Replace shared behavior with alias check to call.
core/proc/case_compare_spec.rb Replace shared behavior with alias check to call.
core/proc/call_spec.rb Inline all Proc#call expectations and move frozen-string-literal fixture checks here.
core/numeric/shared/rect.rb Remove shared rect/rectangular expectations.
core/numeric/shared/imag.rb Remove shared imag/imaginary expectations.
core/numeric/shared/conj.rb Remove shared conj/conjugate expectations.
core/numeric/shared/arg.rb Remove shared arg/angle/phase expectations.
core/numeric/shared/abs.rb Remove shared abs/magnitude expectations.
core/numeric/rectangular_spec.rb Inline rectangular expectations (previously shared).
core/numeric/rect_spec.rb Replace shared behavior with alias check to rectangular.
core/numeric/phase_spec.rb Replace shared behavior with alias check to arg.
core/numeric/magnitude_spec.rb Replace shared behavior with alias check to abs.
core/numeric/imaginary_spec.rb Inline imaginary expectations (previously shared).
core/numeric/imag_spec.rb Replace shared behavior with alias check to imaginary.
core/numeric/conjugate_spec.rb Inline conjugate expectations (previously shared).
core/numeric/conj_spec.rb Replace shared behavior with alias check to conjugate.
core/numeric/arg_spec.rb Inline arg expectations (previously shared).
core/numeric/angle_spec.rb Replace shared behavior with alias check to arg.
core/numeric/abs_spec.rb Inline abs expectations (previously shared).

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

Comment thread core/time/tv_usec_spec.rb Outdated
Comment thread core/time/tv_usec_spec.rb Outdated
Comment thread core/numeric/phase_spec.rb
Comment thread core/proc/call_spec.rb Outdated
Comment thread core/time/xmlschema_spec.rb Outdated
Comment thread core/numeric/phase_spec.rb
Comment thread core/proc/call_spec.rb Outdated
Comment thread core/time/xmlschema_spec.rb Outdated
Comment thread core/set/lte_spec.rb
Comment thread core/set/gt_spec.rb
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 176 out of 176 changed files in this pull request and generated 1 comment.

Comment thread core/thread/to_s_spec.rb
@Earlopain Earlopain force-pushed the fewer-shared-specs-3 branch from 1fc05f8 to 082f3f3 Compare June 2, 2026 11:53
@Earlopain Earlopain requested a review from Copilot June 2, 2026 11:54
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 174 out of 174 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (4)

core/time/utc_spec.rb:1

  • This spec duplicates the exact same assertion twice (Time.now.utc.utc?). Based on the removed line, the second assertion looks like it was intended to cover Time.now.gmtime.utc?. Replace the duplicate with the missing gmtime case (or add an explicit alias check for gmtime elsewhere) so the spec still exercises both paths.
    core/set/union_spec.rb:1
  • The example description says Set#union is an alias of Set#|, but the assertion compares it to Set#+. Either update the assertion to compare against Set.instance_method(:|) or adjust the description to match what’s being asserted; keeping these consistent avoids confusion when diagnosing failures.
    core/thread/to_s_spec.rb:1
  • In the spec description, "it's" is grammatically incorrect here; it should be the possessive "its".
    core/time/month_spec.rb:1
  • This spec description is incorrect (it says it returns a 'four digit year' but the assertion checks month). Update the example text to describe the month behavior to keep the spec self-documenting.

Comment thread core/proc/fixtures/proc_call.rb Outdated
@Earlopain Earlopain force-pushed the fewer-shared-specs-3 branch from 082f3f3 to e207151 Compare June 2, 2026 11:59
@Earlopain Earlopain force-pushed the fewer-shared-specs-3 branch from e207151 to 055c832 Compare June 2, 2026 12:05
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, thank you for these cleanups!

Comment thread core/proc/eql_spec.rb
require_relative 'shared/equal'
require_relative 'fixtures/common'

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

Same note as the other PR, == is more common than eql?

Comment thread core/regexp/eql_spec.rb
require_relative '../../spec_helper'
require_relative 'shared/equal_value'

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

== more common

Comment thread core/set/to_s_spec.rb
set = Set.new
set.method(:to_s).should == set.method(:inspect)
it "is an alias of Set#inspect" do
Set.instance_method(:to_s).should == Set.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.

to_s is more frequent

Comment thread core/set/plus_spec.rb
require_relative '../../spec_helper'
require_relative 'shared/union'

describe "Set#+" 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: I think Set#| is more frequent and idiomatic, + feels more like an alias (also it's unrelated to add). Could you make | the spec and union/+ the aliases?

Comment thread core/struct/to_s_spec.rb
car = StructClasses::Car.new('Ford', 'Ranger')
car.inspect.should == car.to_s
it "is an alias of Struct#inspect" do
StructClasses::Car.instance_method(:to_s).should == StructClasses::Car.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.

to_s more frequent

Comment thread core/thread/fork_spec.rb
require_relative 'fixtures/classes'
require_relative 'shared/start'

describe "Thread.fork" 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.

Thread.fork (what a weird name) should be the alias and `start have the specs

describe "Thread#terminate" do
it_behaves_like :thread_exit, :terminate
it "is an alias of Thread#exit" do
Thread.instance_method(:terminate).should == Thread.instance_method(:exit)
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.

is an alias of kill, let's refer directly to the method having the specs

require_relative '../../spec_helper'
require_relative 'shared/gmt_offset'

describe "Time#gmt_offset" 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.

Time.instance_method(:gmt_offset) == Time.instance_method(:utc_offset) is true, so let's make this one alias of utc_offset

Comment thread core/time/iso8601_spec.rb
require_relative 'shared/to_s'
require_relative '../method/shared/aliased_inspect'

describe "UnboundMethod#inspect" 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.

to_s more frequent

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