Skip to content

Instantly share code, notes, and snippets.

@aspiers
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspiers/8786515 to your computer and use it in GitHub Desktop.
Save aspiers/8786515 to your computer and use it in GitHub Desktop.
rspec expectations bug?
require_relative 'spec_helper'
# The following fails with output which is not as helpful as it
# could be:
#
# expected RuntimeError, got #<RuntimeError: foo> with backtrace:
#
# It would be much better if it said something like:
#
# expected: #<RuntimeError: bar>
# got: #<RuntimeError: foo>
# with backtrace:
#
# which includes the expected message, not just the obtained message.
# The alignment makes it a lot easier to see where the messages don't match up.
# Also, if either of the messages were multi-line, a unified diff would be useful.
describe "rspec-expectations bug?" do
it "should fail showing the difference in error messages" do
expect { raise RuntimeError, "foo" }.to raise_error(RuntimeError, "bar")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment