0

I want to raise an Active Resource exception manually from RSpec and I am trying to doing something like this-

ActiveResource::ResourceInvalid.new(422, "Error Message")

Though I am able to raise ActiveRecord exception but ActiveResource is not raising.

I see the initialize method of ActiveResource is expecting two arguments.

def initialize(response, message = nil)
      @response = response
      @message  = message
end

I guess the issue is in sending the response parameter.

  • 2
    In your example code, you are creating a new instance of `ActiveResource::ResourceNotFound`, but you are not actually [`raise`](http://ruby-doc.org/core-2.4.0/Kernel.html#method-i-raise)-ing it. Please show your full RSpec example, including the current output (or error message) and the expected output. – Stefan Jan 06 '17 at 14:48

1 Answers1

1

I would try something like this:

expect { 
  raise ActiveResource::ResourceNotFound.new(404, 'Error Message') 
}.to raise_error(ActiveResource::ResourceNotFound, 404, 'Error Message')

Note the raise and the curly brackets.

spickermann
  • 100,941
  • 9
  • 101
  • 131