Skip to content

Instantly share code, notes, and snippets.

@JunichiIto
Last active March 26, 2026 16:39
Show Gist options
  • Select an option

  • Save JunichiIto/f603d3fbfcf99b914f86 to your computer and use it in GitHub Desktop.

Select an option

Save JunichiIto/f603d3fbfcf99b914f86 to your computer and use it in GitHub Desktop.
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
a_nil_value be_nil a nil value
a_value > 3 be > 3 a value > 3
a_value < 3 be < 3 a value < 3
a_value <= 3 be <= 3 a value <= 3
a_value == 3 be == 3 a value == 3
a_value === 3 be === 3 a value === 3
an_instance_of(Integer) be_an_instance_of(Integer) an instance of Integer
a_kind_of(Integer) be_a_kind_of(Integer) a kind of Integer
a_value_between(1, 10) be_between(1, 10) a value between 1 and 10 (inclusive)
a_value_within(0.1).of(3) be_within(0.1).of(3) a value within 0.1 of 3
within(0.1).of(3) be_within(0.1).of(3) within 0.1 of 3
a_block_changing change a block changing result
changing change changing result
a_collection_containing_exactly(1, 2) contain_exactly(1, 2) a collection containing exactly 1 and 2
containing_exactly(1, 2) contain_exactly(1, 2) containing exactly 1 and 2
a_range_covering(1, 2) cover(1, 2) a range covering 1 and 2
covering(1, 2) cover(1, 2) covering 1 and 2
ending_with(23) end_with(23) ending with 23
a_collection_ending_with(23) end_with(23) a collection ending with 23
a_string_ending_with("z") end_with("z") a string ending with 'z'
an_object_eq_to(3) eq 3 an object eq to 3
eq_to(3) eq 3 eq to 3
an_object_eql_to(3) eql 3 an object eql to 3
eql_to(3) eql 3 eql to 3
an_object_equal_to(3) equal 3 an object equal to 3
equal_to(3) equal 3 equal to 3
an_object_existing exist an object existing
existing exist existing
an_object_having_attributes(:age => 32) have_attributes(:age => 32) an object having attributes {:age => 32}
a_string_including("a") include("a") a string including 'a'
a_collection_including("a") include("a") a collection including 'a'
a_hash_including(:a => 5) include(:a => 5) a hash including {:a => 5}
including(3) include(3) including 3
a_string_matching(/foo/) match(/foo/) a string matching /foo/
an_object_matching(/foo/) match(/foo/) an object matching /foo/
match_regex(/foo/) match(/foo/) match regex /foo/
matching(/foo/) match(/foo/) matching /foo/
a_block_outputting('foo').to_stdout output('foo').to_stdout a block outputting 'foo' to stdout
a_block_outputting('foo').to_stderr output('foo').to_stderr a block outputting 'foo' to stderr
a_block_raising(ArgumentError) raise_error(ArgumentError) a block raising ArgumentError
raising(ArgumentError) raise_error(ArgumentError) raising ArgumentError
an_object_responding_to(:foo) respond_to(:foo) an object responding to #foo
responding_to(:foo) respond_to(:foo) responding to #foo
an_object_satisfying { } satisfy { } an object satisfying block
satisfying { } satisfy { } satisfying block
a_collection_starting_with(23) start_with(23) a collection starting with 23
a_string_starting_with("z") start_with("z") a string starting with 'z'
starting_with("d") start_with("d") starting with 'd'
a_block_throwing(:foo) throw_symbol(:foo) a block throwing :foo
throwing(:foo) throw_symbol(:foo) throwing :foo
a_block_yielding_control yield_control a block yielding control
yielding_control yield_control yielding control
a_block_yielding_with_no_args yield_with_no_args a block yielding with no args
yielding_with_no_args yield_with_no_args yielding with no args
a_block_yielding_with_args yield_with_args a block yielding with args
yielding_with_args yield_with_args yielding with args
a_block_yielding_successive_args yield_successive_args a block yielding successive args()
yielding_successive_args yield_successive_args yielding successive args()
@daguar

daguar commented Jan 13, 2016

Copy link
Copy Markdown

Thank you! This was super helpful for me. ๐Ÿ˜„

@fagiani

fagiani commented Sep 11, 2016

Copy link
Copy Markdown

Really helpful. Thanks!

@simonc

simonc commented Jan 26, 2017

Copy link
Copy Markdown

โค๏ธ

@bilus

bilus commented Jan 26, 2017

Copy link
Copy Markdown

Fantastic, thank you!

@kklimuk

kklimuk commented Sep 28, 2017

Copy link
Copy Markdown

โค๏ธ

@ianpurvis

Copy link
Copy Markdown

๐Ÿค˜

@armando-couto

Copy link
Copy Markdown

Dica muito boa.

@Drowze

Drowze commented Feb 12, 2019

Copy link
Copy Markdown

I refer to this every now and then. Thank you :)

@risacan

risacan commented May 22, 2019

Copy link
Copy Markdown

โค๏ธ

@lewispb

lewispb commented Oct 28, 2019

Copy link
Copy Markdown

Love this.

@sainu

sainu commented Feb 28, 2020

Copy link
Copy Markdown

โค๏ธ

@TimoMoss

Copy link
Copy Markdown

โค๏ธโค๏ธโค๏ธ

@rinslow

rinslow commented Apr 13, 2021

Copy link
Copy Markdown

Ahhh so good!!

@igorlvicente

Copy link
Copy Markdown

Thank you, man. It has helped me a lot.

@dawson-conway

Copy link
Copy Markdown

Looks like when you scraped this you missed that the first a_block_outputting has .to_stdout and the second has .to_stderr after.

@JunichiIto

Copy link
Copy Markdown
Author

@dawson-conway Thank you for letting me know. Corrected.

@mlincoln1205

Copy link
Copy Markdown

This is definitely amazing. Thanks for share it. Keep safe everyone.

@delexw

delexw commented Apr 26, 2022

Copy link
Copy Markdown

oh!!! it is really awesome. Thank you for sharing

@dawson-conway

Copy link
Copy Markdown

The two be_within aliases are missing the following .of(3)

@JunichiIto

Copy link
Copy Markdown
Author

@dawson-conway Fixed. Thank you for letting me know.

@nskazki

nskazki commented Aug 23, 2022

Copy link
Copy Markdown

This gist is the gift that keeps giving. I'm checking on it every time it comes to writing specs in ruby. โค๏ธ

@bakudas

bakudas commented Jan 5, 2023

Copy link
Copy Markdown

thanks man! you the real mvp ๐Ÿ‘๐Ÿพ

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