simplelog 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/simplelog.rb +4 -2
  2. data/test/simplelogtest.rb +19 -6
  3. metadata +2 -2
data/lib/simplelog.rb CHANGED
@@ -9,6 +9,7 @@
9
9
  # existing application grows and you need to save output in a hurry.
10
10
 
11
11
  require 'date'
12
+ require 'ftools'
12
13
 
13
14
  # Here we redefine puts
14
15
  module Kernel
@@ -26,6 +27,7 @@ end
26
27
  # require 'simplelog'
27
28
  #
28
29
  class Simplelog
30
+
29
31
  @@dir = "."
30
32
  @@name = "LOG_"
31
33
  @@logtext = ""
@@ -54,7 +56,7 @@ class Simplelog
54
56
 
55
57
  # Allows you to clear your log if you so wish
56
58
  def Simplelog.clear
57
- @logtext = ""
59
+ @@logtext = ""
58
60
  end
59
61
 
60
62
  def Simplelog.puts(text)
@@ -69,7 +71,7 @@ class Simplelog
69
71
 
70
72
  def Simplelog.save
71
73
  if !@@logtext.empty?
72
- Dir::mkdir(@@dir) if !FileTest.directory?(@@dir)
74
+ File.makedirs(@@dir) if !File.directory?(@@dir)
73
75
  File.open(filename, "w") do |f|
74
76
  f.puts @@logtext
75
77
  end
@@ -14,6 +14,9 @@ class Simplelogtest < Test::Unit::TestCase
14
14
  assert_equal(Simplelog.name, @logname)
15
15
  end
16
16
 
17
+ def test_unknown_dir
18
+ end
19
+
17
20
  def test_dir
18
21
  assert_equal(Simplelog.dir, @dirname)
19
22
  Simplelog.dir= @dirname + "\\\\\\"
@@ -33,7 +36,15 @@ class Simplelogtest < Test::Unit::TestCase
33
36
  assert_match(/But log this/, Simplelog.logtext)
34
37
  end
35
38
 
36
- #Make sure that file.puts works as it
39
+ def test_clear
40
+ txt = "Log this text please"
41
+ puts txt
42
+ assert_match(txt, Simplelog.logtext)
43
+ Simplelog.clear
44
+ assert( Simplelog.logtext.empty?)
45
+ end
46
+
47
+ #Make sure that file.puts is unaffected
37
48
  def test_file_puts
38
49
  output_file = "output.txt"
39
50
  File.open(output_file, "w") do |file|
@@ -57,13 +68,15 @@ class Simplelogtest < Test::Unit::TestCase
57
68
 
58
69
  def test_save
59
70
  puts "Oh test, how we love thy"
71
+ unknown = @dirname + "/unknown/directory"
72
+ Simplelog.dir = unknown
73
+ assert !File.directory?(unknown)
60
74
  Simplelog.save
61
- assert(FileTest.directory?(Simplelog.dir))
62
75
  assert(FileTest.file?(Simplelog.filename))
63
76
  File.delete(Simplelog.filename)
64
- Dir.delete(Simplelog.dir)
65
- Simplelog.dir
66
- assert(!FileTest.directory?(Simplelog.dir))
67
- assert(!FileTest.file?(Simplelog.filename))
77
+ Dir.delete(@dirname + "/unknown/directory")
78
+ Dir.delete(@dirname + "/unknown")
79
+ Dir.delete(@dirname)
80
+ assert(!FileTest.directory?(@dirname))
68
81
  end
69
82
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: simplelog
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.2
7
- date: 2006-07-20 00:00:00 +02:00
6
+ version: 0.2.0
7
+ date: 2006-09-07 00:00:00 +02:00
8
8
  summary: The simplest logger ever. Just require 'simplelog' and all puts statements are logged to .txt as well as shown on screen.
9
9
  require_paths:
10
10
  - lib