Last active
August 29, 2015 14:18
-
-
Save jmazzi/abfa9fdbf848eb95a69b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support/all' | |
class Rails | |
def self.logger=(logger) | |
@logger = logger | |
end | |
def self.logger | |
@logger | |
end | |
end | |
class Car | |
class Wheel | |
def initialize(message) | |
end | |
def perform | |
end | |
end | |
end | |
class Handler | |
def self.receive(model, action, message) | |
begin | |
"#{model.classify}::#{action.classify}".constantize.new(message).perform | |
rescue NameError | |
Rails.logger.info("No map for #{model.classify}::#{action.classify}") | |
return | |
end | |
end | |
end | |
describe Handler do | |
let(:log) { StringIO.new } | |
before do | |
Rails.logger = Logger.new(log) | |
end | |
it "should log missing classes" do | |
Handler.receive("User", "Action", "testing") | |
log.rewind | |
logged_messages = log.read | |
expect(logged_messages).to include("No map for User::Action") | |
end | |
it "should not log present classes" do | |
value = Handler.receive("Car", "Wheel", "testing") | |
log.rewind | |
logged_messages = log.read | |
expect(logged_messages).not_to include("No map for Car::Wheel") | |
end | |
end |
Author
jmazzi
commented
Apr 3, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment