I am very new to rails and I am writing test cases for my rails application. Suppose I have a code like this -
class EmailController < ApplicationController
def new
render :layout => false
end
def create
begin
process_email = ProcessEmail.new(params)
process_email.perform
rescue EmailHelper::HtmlSanitizerTimeoutError, EmailHelper::NokogiriTimeoutError => e
NewRelic::Agent.notice_error(e, account_id: Account.current.id, subject: params[:subject])
process_email.mark_email_on_timeout
end
render layout: 'email'
end
def update
----
end
I have written test cases for create and update. But how do I write test cases that will execute the rescue part??
This is my db
(class abc < ActiveRecord::Base)
this is my controller class
(class abcsController < ApiApplicationController).
I have written minitest like this `
def test_raise_exception
params = {"a":"b"}
item = abc.new(params)
raises_exception = -> { raise ArgumentError.new }
item.stub :create, raises_exception do
assert_raises(ArgumentError) { post :create }
end
end`
This is error which is coming -
NameError: NameError: undefined method create' for class