Where to write a test case for this file in initializers in rails?

I created the common.rb file in the intializer folder in rails 2.x application. Code 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 a test case. I think it should be in a functional test. If it is true. I don’t know what to call it, so I'm confused (controller name <<Base). Are the rails running this test case, like other controller tests? Or do we need to add it anywhere? Since the above code does not have a class that is inherited from the controller, etc., I will add additional information if you do not understand my question.

+4
source share
1 answer

I assume that handle_exception is a global function, so you can just test it with 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 
+1
source

Source: https://habr.com/ru/post/1398797/


All Articles