Matching arguments - Setting constraints - RSpec Mocks

To match… …use an expression like: …which matches calls like:
Literal arguments with(1, true) foo(1, true)
Any list of args with(any_args) foo() / foo(1) / foo(:bar, 2)
Anything for a given positional arg with(3, anything) foo(3, nil) / foo(3, :bar)
A boolean with(3, boolean) foo(3, true)
An instance of a specific class with(instance_of(Fixnum)) foo(3)
An object with a given module in its ancestors list with(kind_of(Numeric)) foo(3)

include matcher - Built in matchers - RSpec Expectations - RSpec - Relish

include matcher で Hash にたいして柔軟にテストを実行できる。

The matcher also provides flexible handling for hashes:

expect(:a => 1, :b => 2).to include(:a)
expect(:a => 1, :b => 2).to include(:a, :b)
expect(:a => 1, :b => 2).to include(:a => 1)
expect(:a => 1, :b => 2).to include(:b => 2, :a => 1)
expect(:a => 1, :b => 2).to include(match(/b/) => 2)
expect(:a => 1, :b => 2).to include(match(/b/) => be_even)
expect(:a => 1, :b => 2).not_to include(:c)
expect(:a => 1, :b => 2).not_to include(:a => 2)
expect(:a => 1, :b => 2).not_to include(:c => 3)

Class#superclass (Ruby 3.0.0 リファレンスマニュアル)

> 3.class
=> Integer
> 3.class.superclass
=> Numeric
> 3.class.superclass.superclass
=> Object
> 3.class.superclass.superclass.superclass
=> BasicObject
> 3.class.superclass.superclass.superclass.superclass
=> nil