Reputation: 3243
I created a common.rb file in intializer folder in rails 2.x app. The code is below
def handle_exception &block
begin
yield block
rescue Exception => ex
logger.error(ex)
HoptoadNotifier.notify(ex)
end
end
For the above I want to write test case. I guess it should be in functional test. If this is the case. I don't know how should I name it, means I'm confused with (controller name << Base). Do rails run this test case as like other controller test ? Or do we need to add it any where? Since the above code doesn't have class which is inherited from controller, etc.. I will add more info, if you are not clear with my question.
Upvotes: 4
Views: 492
Reputation: 4925
I assume that handle_exception
is a global function, so you could just test it using RSpec as follows:
require 'spec_helper'
describe "common" do
it "handles exceptions" do
logger.should_receive( :error )
HoptaodNotifier.should_receive( :notify )
handle_exception { raise Exception.new( "This is the error") }
end
end
Upvotes: 1