user4086616
user4086616

Reputation:

How to raise ActiveResource ResourceInvalid exception?

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.

Upvotes: 0

Views: 1381

Answers (1)

spickermann
spickermann

Reputation: 107077

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.

Upvotes: 1

Related Questions