Method: RSpec::Matchers#match

Defined in:
lib/rspec/matchers.rb

#match(expected) ⇒ Object Also known as: match_regex, an_object_matching, a_string_matching, matching

Note:

The match_regex alias is deprecated and is not recommended for use. It was added in 2.12.1 to facilitate its use from within custom matchers (due to how the custom matcher DSL was evaluated in 2.x, match could not be used there), but is no longer needed in 3.x.

Given a Regexp or String, passes if actual.match(pattern) Given an arbitrary nested data structure (e.g. arrays and hashes), matches if expected === actual || actual == expected for each pair of elements.

Examples:

expect(email).to match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
expect(email).to match("@example.com")
hash = {
  :a => {
    :b => ["foo", 5],
    :c => { :d => 2.05 }
  }
}

expect(hash).to match(
  :a => {
    :b => a_collection_containing_exactly(
      a_string_starting_with("f"),
      an_instance_of(Integer)
    ),
    :c => { :d => (a_value < 3) }
  }
)


697
698
699
# File 'lib/rspec/matchers.rb', line 697

def match(expected)
  BuiltIn::Match.new(expected)
end