Skip to content

Instantly share code, notes, and snippets.

@nruth
Created May 12, 2011 10:23
Show Gist options
  • Save nruth/968289 to your computer and use it in GitHub Desktop.
Save nruth/968289 to your computer and use it in GitHub Desktop.
controller spec describing rails log contents
describe "logger" do
before(:each) do
@old_flush = controller.logger.auto_flushing
@old_level = controller.logger.level
controller.logger.auto_flushing=0
controller.logger.level = ActiveSupport::BufferedLogger::Severity::ERROR
end
it "logs an error" do
#would prefer to test this with a test-spy / mock expectations but there's a lot of level-0 logging noise to ignore, so went with reading the log itself
post :create, valid_notification_params
controller.logger.send(:buffer).join.should include("expected log contents")
end
after(:each) do
controller.logger.auto_flushing= @old_flush
controller.logger.level = @old_level
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment