title: Defining Custom RSpec Matchers
body: <p>I'm trying to create a matched for a hash defined in user_record. I tried creating a matcher.matches() as I did in be_a_boolean, but it only ever returns an object. be_a_boolean isn't a defined object, so it currently does not work.</p>
  
  <pre><code>  def user_record
      {
        email_address: email_address_value,
        date_of_birth: date_value,
        active:        boolean_value
      }
    end    
  
    def users(count)
      Array.new(count) { user_record }
    end
  end    
  
  RSpec.describe DataGenerator do     
  
    def match_the_shape_of_a_user_record
      # Use `be_a_boolean`, `be_a_date_before_2000` and `be_an_email_address`
      # in the hash passed to `match` below to define this matcher.    
  
      match(a_hash_including(
                   an_object_having_attributes(:active =&gt; be_a_boolean_value), 
                   # :date_of_birth =&gt; be_a_date_before_2000, 
                    #:email_address =&gt; be_an_email_address 
          ))
    end     
  
    it "generates user records" do 
      user = DataGenerator.new.user_record
      expect(user).to match_the_shape_of_a_user_record
    end     
  
    def all_match_the_shape_of_a_user_record
      # Combine the `all` matcher and `match_the_shape_of_a_user_record` here.    
  
    end    
  
    it "generates a list of user records" do 
      users = DataGenerator.new.users(4)
      expect(users.to all_match_the_shape_of_a_user_record)
    end 
  end 
  </code></pre>