module RSpec::Matchers::FailMatchers

Matchers for testing RSpec matchers. Include them with:

require 'rspec/matchers/fail_matchers'
RSpec.configure do |config|
  config.include RSpec::Matchers::FailMatchers
end

Public Instance Methods

Matches if an expectation fails

@example

expect { some_expectation }.to fail
# File rspec-expectations/lib/rspec/matchers/fail_matchers.rb, line 17
def fail(&block)
  raise_error(RSpec::Expectations::ExpectationNotMetError, &block)
end

Matches if an expectation fails including the provided message

@example

expect { some_expectation }.to fail_including("portion of some failure message")
# File rspec-expectations/lib/rspec/matchers/fail_matchers.rb, line 34
def fail_including(*snippets)
  raise_error(
    RSpec::Expectations::ExpectationNotMetError,
    a_string_including(*snippets)
  )
end

Matches if an expectation fails with the provided message

@example

expect { some_expectation }.to fail_with("some failure message")
expect { some_expectation }.to fail_with(/some failure message/)
# File rspec-expectations/lib/rspec/matchers/fail_matchers.rb, line 26
def fail_with(message)
  raise_error(RSpec::Expectations::ExpectationNotMetError, message)
end