Last active
August 29, 2015 14:11
-
-
Save skwp/41778311b0581dddb4b4 to your computer and use it in GitHub Desktop.
Logger that logs to a string
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
describe "something with a logger" do | |
let(:logger) { TestLogger.new } | |
before { Rails.logger = logger } | |
specify do | |
# ... call your code ... | |
logger.messages.should include("my message") | |
end | |
end |
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
class TestLogger < Logger | |
def initialize | |
@strio = StringIO.new | |
super(@strio) | |
end | |
def messages | |
@strio.string | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment