Getting eval_block to work

I’ve run some tests and it seems to return the results I want, but when I run the spec files I get this:

  1. #eval_block when no block is given raises an error
    Failure/Error: expect { eval_block(1, 2, 3) }.to raise_error
    expected Exception but nothing was raised

    ./spec/02_eval_block_spec.rb:15:in `block (3 levels) in <top (required)>’

Here is my code for reference:

def eval_block(*args, &block)
if block

Hey Nathaniel,

Returning a string that says “NO BLOCK GIVEN” is very different than raising an error. This rspec test is expecting an Exception to be raised. In Ruby, Exception is a class in which all error classes inherit from: Ruby Exceptions

In order to raise an exception we use the adequately named method: raise and then pass it the class we want. In the case for these specs the Exception class will do fine. Try modifying your else statement to raise an error instead of returning a string. Then refactor using a guard clause.

Let me know if you have any questions! Thanks.