Skip to content

Instantly share code, notes, and snippets.

@marzzz21
Created November 15, 2016 04:35
Show Gist options
  • Save marzzz21/79de37be50b4b1429c00ebaa11d2c428 to your computer and use it in GitHub Desktop.
Save marzzz21/79de37be50b4b1429c00ebaa11d2c428 to your computer and use it in GitHub Desktop.
├── bin
│   ├── myappd
│   └──
├── conf
│   └── myapp.conf
├── Gemfile
├── Gemfile.lock
├── lib
│   ├── myapp
│   │   └── myapp_utilities
│   │   ├── configuration_management.rb
│   │   ├── file_proc.rb
│   │   ├── logging.rb
│   │   ├── mirror_sync_utilities.rb
│   │   └── notification.rb
├── README.md
└── spec
└── unit
├── lib
│   │   └── mirror_sync_utilities
│   │   └── TestMyApp.rb
===========================================================
1 require "minitest/autorun"
2
3 class TestMyApp < Minitest::Test
4
5 def setup
6 @dummy_class = Class.new do
7
8 include MyAppUtilities::Logging
9 end
10 end
11
12 def test_that_log_method_outputs_messages_in_correct_format
13 Time.stub :now, '2016-11-15 11:42:54 +0800' do
14 Process.stub :pid, 123 do
15 assert_equal "2016-11-15 11:42:54 +0800 > [123]This is a test", @dummy_class.log("This is a test")
16 end
17 end
18 end
19 end
=========================================================
1 module MyAppUtilities::Logging
2
3 LOG_DIR = BASE_DIR + '/logs'
4 DAEMON_LOG = LOG_DIR + '/myapp.log'
5
6 def log(msg)
7 puts "#{Time.now} > [#{Process.pid}] #{msg}"
8 end
9
10 def log_error(error)
11 log "#{error}\n\t#{error.backtrace.join("\n\t")}"
12 end
13 end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment