Skip to content

Instantly share code, notes, and snippets.

@abyx
Created November 24, 2011 20:43
Show Gist options
  • Save abyx/1392238 to your computer and use it in GitHub Desktop.
Save abyx/1392238 to your computer and use it in GitHub Desktop.
# When doing this:
class SomeError < Exception
def initialize(some, args); end
end
describe 'bad message' do
it 'raises an exception' do
obj = stub
obj.should_receive(:dude!).and_raise(SomeError)
obj.dude!
end
end
# We should get a failure, since RSpec can't initialize the exception,
# but I find the error a bit unhelpful:
# 1) bad message raises an exception
# Failure/Error: def initialize(some, args); end
# ArgumentError:
# wrong number of arguments (0 for 2)
# # ./bad_message.rb:2:in `initialize'
# # ./bad_message.rb:6:in `some_method'
# # ./bad_message.rb:13:in `block (2 levels) in <top (required)>'
# (especially in big projects, where you don't see the initialize() definition in the error
@abyx
Copy link
Author

abyx commented Nov 24, 2011

I want to make RSpec display something more meaningful to the user like "Dude, I can't initialize SomeError exception, wanna gimme an instance?"
Should I just make RSpec raise some new exception class that says this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment