title: How to test RSpec custom matchers
body: <p>I am developing RSpec custom matchers like <a href="https://github.com/spotify/rspec-dns" rel="nofollow">rspec-dns</a> and <a href="https://github.com/otahi/rspec-ssltls" rel="nofollow">rspec-ssltls</a>. </p>
  
  <p>What is the most effective way for testing RSpec custom matchers?</p>
  
  <p>I tests custom matchers(means a test target is a custom matcher). I can tests normal cases of custom matchers like as follows.</p>
  
  <p><a href="https://github.com/otahi/rspec-ssltls/blob/master/spec/rspec_ssltls/have_certificate_spec.rb" rel="nofollow">rspec_ssltls/have_certificate_spec.rb</a></p>
  
  <pre><code>## Having certificate
  it 'can evaluate having certificate' do
    stub_ssl_socket(peer_cert_chain: [nil])
    expect('www.example.com:443').not_to have_certificate
    stub_ssl_socket(peer_cert_chain: [example_cert])
    expect('www.example.com:443').to have_certificate
  end
  </code></pre>
  
  <p>But the RSpec test cases fail if I test error cases. I want to test error cases can be errors.</p>