How to raise ActiveResource ResourceInvalid exception?

1.3k views Asked by At

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.

1

There are 1 answers

0
spickermann On

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.