Skip to content
Emilio Gutter edited this page Mar 30, 2017 · 17 revisions

Built in matchers

Equivalence

expect any_type, to:     eq(another)
expect any_type, to_not: eq(another)
expect a_float, to:     eq(another)
                within: delta
expect a_float, to_not: eq(another)
                within: delta

Collection membership

expect a_string, to:     include(substring)
expect a_string, to_not: include(substring)
expect a_list, to:     include(element)
expect a_list, to_not: include(element)
expect a_range, to:     include(element)
expect a_range, to_not: include(element)
expect a_map_or_tuple, to:     include(key)
expect a_map_or_tuple, to_not: include(key)
expect a_map, to:     include(key)
              with:   value
expect a_map, to_not: include(key)
              with:   value

Collection size

expect a_string, to:     be_empty()
expect a_string, to_not: be_empty()
expect a_map_or_tuple, to:     be_empty()
expect a_map_or_tuple, to_not: be_empty()
expect a_list, to:     be_empty()
expect a_list, to_not: be_empty()
expect a_range, to:     be_empty()
expect a_range, to_not: be_empty()
expect a_list, to:     have_items(number)
expect a_list, to_not: have_items(number)
expect a_range, to:     have_items(number)
expect a_range, to_not: have_items(number)
expect a_map_or_tuple, to:     have_items(number)
expect a_map_or_tuple, to_not: have_items(number)
expect a_string, to:     have_items(number)
expect a_string, to_not: have_items(number)

Regex

expect a_string, to:     match(regex)
expect a_string, to_not: match(regex)

Expecting errors

expect a_function, to:   raise_error(an_error)
expect a_function, to:   raise_error(an_error)
                   with: a_message

Comparisons

expect a_number, to:     be_less_than(another)
expect a_number, to_not: be_less_than(another)
expect a_number, to:     be_less_or_equal_than(another)
expect a_number, to_not: be_less_or_equal_than(another)
expect a_number, to:     be_greater_than(another)
expect a_number, to_not: be_greater_than(another)
expect a_number, to:     be_greater_or_equal_than(another)
expect a_number, to_not: be_greater_or_equal_than(another)
expect a_string, to:     start_with(another)
expect a_string, to_not: start_with(another)
expect a_list, to:     start_with(another)
expect a_list, to_not: start_with(another)
expect a_range, to:     start_with(another)
expect a_range, to_not: start_with(another)
expect a_string, to:     end_with(another)
expect a_string, to_not: end_with(another)
expect a_list, to:     end_with(another)
expect a_list, to_not: end_with(another)
expect a_range, to:     end_with(another)
expect a_range, to_not: end_with(another)