Skip to content

Instantly share code, notes, and snippets.

@jmazzi
Last active August 29, 2015 14:18
Show Gist options
  • Save jmazzi/abfa9fdbf848eb95a69b to your computer and use it in GitHub Desktop.
Save jmazzi/abfa9fdbf848eb95a69b to your computer and use it in GitHub Desktop.
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
@jmazzi
Copy link
Author

jmazzi commented Apr 3, 2015

~/tmp❯ rspec handler_spec.rb
..

Finished in 0.0021 seconds (files took 0.75384 seconds to load)
2 examples, 0 failures
~/tmp❯ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment