I have the following I’m trying to test:
def initialize(secret, guess)
raise ArgumentError, “secret and guess must be the same length”,
caller if guess.length != secret.length
@secret, @guess = secret, guess
In my spec test, how do I capture that exception? I’m trying to test
that it raises appropriately when secret and guess are different
What I’ve tried:
context "unequal lengths" do it 'returns "secret and guess must be the same length"' do Marker.new('1234','').should raise_error("secret and guess
must be the same length")
But it doesn’t actually catch the error, calling it a failed test.
I’ve also tried raise_error(ArgumentError) with the same result. (I’ve
also tried calling Maker::new, but that also has the same result.