View raise_error_spec.rb
1 2 3 4 5 6 7 8 9 10
RSpec::Matchers.define :an_exception_caused_by do |cause|
match do |exception|
cause === exception.cause
expect {
"foo".gsub # requires 2 args
rescue ArgumentError
View a_string_including.rb
1 2 3 4 5
expect {
expect(the_dbl).to have_received(:expected_method).with(:one).once
}.to raise_error(Expectations::ExpectationNotMetError,
a_string_including("expected: 1 time",
"received: 2 times"))
View Gemfile
1 2 3 4
# A sample Gemfile
source ""
gem 'rspec'
View order_spec.rb
1 2 3 4 5 6 7 8 9 10
require_relative '../order.rb'
describe Order do
def new_order(input)
order =
allow(order).to receive(:input).and_return(input)
it 'gets dish number as input' do
View transaction_spec.rb
1 2 3 4 5 6 7 8 9 10
class SomeEntity
def run
transaction do
def transaction

Haven't dived into RSpec but is it not possible for expect to accept either args or blocks, and process them internally?

First off, expect does accept either an arg or a block already. But if it's a block (or a proc/lambda arg), expect does not call the block automatically -- it just passes the block to the matcher and allows the matcher to call it if it wants. This is necessary because some matchers (the block matchers like raise_error, change, etc) must wrap the block in some extra logic to work properly because they deal in side effects, not expression return values.

View Gemfile-3-1
1 2 3 4
source ""
gem 'rspec-core', "~> 3.1.7"
gem 'allocation_stats'

I highly suspect that the RSpec core team all use black backgrounds in their terminals because sometimes the colors aren’t so nice on my white terminal

I certainly use a black background. I'm not sure about the other RSpec core folks. Regardless, if there are some color changes we can make that would make output look good on a larger variety of backgrounds, we'll certainly consider that (do you have some suggested changes?). In the meantime, the colors are configurable, so you can change the colors to fit your preferences on your machine. First, create a file at

View output
1 2 3 4 5 6 7 8 9 10
Using `an_error_other_than` as an argument to `raise_error`
failing (FAILED - 1)
1) Using `an_error_other_than` as an argument to `raise_error` failing
Failure/Error: expect {
expected an error other than SyntaxError, got #<SyntaxError: SyntaxError> with backtrace:
# ./spec/raise_error_spec.rb:12:in `block (3 levels) in <top (required)>'
Something went wrong with that request. Please try again.