indy 0.3.4 → 0.4.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ require "#{File.dirname(__FILE__)}/helper"
2
+
3
+ describe 'Indy' do
4
+
5
+ context 'Struct::Entry' do
6
+
7
+ before(:each) do
8
+ log = [ "2000-09-07 14:06:41 INFO MyApp - Entering APPLICATION.",
9
+ "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.",
10
+ "2000-09-07 14:07:43 INFO MyApp - Exiting APPLICATION."].join("\n")
11
+ @entry_struct = Indy.search(log).all[1]
12
+ end
13
+
14
+ it "should be returned by #for search" do
15
+ @entry_struct.should be_kind_of Struct::Entry
16
+ end
17
+
18
+ it "should contain entire log entry as :raw_entry" do
19
+ @entry_struct.raw_entry.should == "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION."
20
+ end
21
+
22
+ context 'using Indy::DEFAULT_LOG_FORMAT' do
23
+
24
+ it "should contain :time" do
25
+ @entry_struct.time.should == "2000-09-07 14:07:42"
26
+ end
27
+
28
+ it "should contain :severity" do
29
+ @entry_struct.severity.should == "DEBUG"
30
+ end
31
+
32
+ it "should contain :application" do
33
+ @entry_struct.application.should == "MyApp"
34
+ end
35
+
36
+ it "should contain :message" do
37
+ @entry_struct.message.should == "Initializing APPLICATION."
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,75 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../lib/indy/log_definition")
2
+
3
+ describe 'Indy::LogDefinition' do
4
+
5
+ context '#new' do
6
+
7
+ context "with a valid hash" do
8
+
9
+ before(:each) do
10
+ @ld = Indy::LogDefinition.new(:entry_regexp => /foo/, :entry_fields => [:field_one], :time_format => '%M-%d-%Y')
11
+ end
12
+
13
+ it "should set entry_regexp" do
14
+ @ld.entry_regexp.should eq /foo/
15
+ end
16
+
17
+ it "should set entry_fields" do
18
+ @ld.entry_fields.should eq [:field_one]
19
+ end
20
+
21
+ it "should set time_format" do
22
+ @ld.time_format.should eq '%M-%d-%Y'
23
+ end
24
+
25
+ end
26
+
27
+ it "should raise ArgumentError when missing entry_fields" do
28
+ lambda{ Indy::LogDefinition.new(:entry_regexp => /foo/) }.should raise_error ArgumentError
29
+ end
30
+
31
+ it "should raise ArgumentError when missing entry_regexp" do
32
+ lambda{ Indy::LogDefinition.new(:entry_fields => [:field_one]) }.should raise_error ArgumentError
33
+ end
34
+
35
+ end
36
+
37
+ context 'private method' do
38
+
39
+ before(:each) do
40
+ @ld = Indy::LogDefinition.new(:entry_regexp => /^(\S+) (\S+) (.+)$/,
41
+ :entry_fields => [:time, :severity, :message],
42
+ :time_format => '%M-%d-%Y')
43
+ @field_captures = "2000-09-07 INFO The message!".match(@ld.entry_regexp).to_a
44
+ end
45
+
46
+ context "#parse_entry" do
47
+
48
+ it "should return a hash" do
49
+ @ld.send(:parse_entry, "2000-09-07 INFO The message!").class.should == Hash
50
+ end
51
+
52
+ it "should return correct key/value pairs" do
53
+ hash = @ld.send(:parse_entry, "2000-09-07 INFO The message!")
54
+ hash[:time].should == "2000-09-07"
55
+ hash[:message].should == "The message!"
56
+ end
57
+
58
+ end
59
+
60
+ context "#parse_entry_captures" do
61
+
62
+ it "should return a hash" do
63
+ @ld.send(:parse_entry_captures, @field_captures).class.should == Hash
64
+ end
65
+
66
+ it "should contain key/value pairs" do
67
+ hash = @ld.send(:parse_entry_captures, @field_captures)
68
+ hash[:time].should == "2000-09-07"
69
+ hash[:message].should == "The message!"
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+ end
@@ -2,57 +2,69 @@ require "#{File.dirname(__FILE__)}/helper"
2
2
 
3
3
  describe Indy do
4
4
 
5
- context "common logging format" do
6
-
7
- common_log_format = {
8
- :name => 'common_log_format',
9
- :source => ["127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb1.gif HTTP/1.0\" 200 2326",
10
- "127.0.0.1 - louie [10/Oct/2000:13:55:37 -0700] \"GET /apache_pb2.gif HTTP/1.0\" 200 2327",
11
- "127.0.0.1 - frank [10/Oct/2000:13:55:38 -0700] \"GET /apache_pb3.gif HTTP/1.0\" 404 300"].join("\n"),
12
- :regexp => Indy::LogFormats::COMMON_REGEXP,
13
- :fields => Indy::LogFormats::COMMON_FIELDS,
14
- :test_field => :authuser
15
- }
16
-
17
- combined_log_format = {
18
- :name => 'combined_log_format',
19
- :source => ["127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb1.gif HTTP/1.0\" 200 2326 \"http://www.example.com/start.html\" \"Mozilla/4.08 [en] (Win98; I ;Nav)\"",
20
- "127.0.0.1 - louie [10/Oct/2000:13:55:37 -0700] \"GET /apache_pb2.gif HTTP/1.0\" 200 2327 \"http://www.example.com/start.html\" \"Mozilla/4.08 [en] (Win98; I ;Nav)\"",
21
- "127.0.0.1 - frank [10/Oct/2000:13:55:38 -0700] \"GET /apache_pb3.gif HTTP/1.0\" 404 300 \"http://www.example.com/start.html\" \"Mozilla/4.08 [en] (Win98; I ;Nav)\""].join("\n"),
22
- :regexp => Indy::LogFormats::COMBINED_REGEXP,
23
- :fields => Indy::LogFormats::COMBINED_FIELDS,
24
- :test_field => :authuser
25
- }
26
-
27
- log4r_default_format = {
28
- :name => 'log4r_default_format',
29
- :source => ["DEBUG mylog: This is a message with level DEBUG",
30
- " INFO mylog: This is a message with level INFO",
31
- " WARN louie: This is a message with level WARN",
32
- "ERROR mylog: This is a message with level ERROR",
33
- "FATAL mylog: This is a message with level FATAL"].join("\n"),
34
- :regexp => Indy::LogFormats::LOG4R_DEFAULT_REGEXP,
35
- :fields => Indy::LogFormats::LOG4R_DEFAULT_FIELDS,
36
- :test_field => :application
37
- }
38
-
39
- [ common_log_format,
40
- combined_log_format,
41
- log4r_default_format ].each do |format|
42
-
43
- it "#{format[:name]} should work" do
44
- indy = Indy.new(:source => format[:source], :log_format => [format[:regexp],format[:fields]].flatten)
45
- result = indy.for(format[:test_field] => 'louie')
46
- result.length.should == 1
47
- end
48
-
49
- it "#{format[:name]} @pattern can be set to the Indy::LogFormat const" do
50
- indy = Indy.new(:source => format[:source], :log_format => eval('Indy::' + format[:name].upcase))
51
- result = indy.for(format[:test_field] => 'louie')
52
- result.length.should == 1
53
-
54
- end
5
+ context "log format can be set to" do
6
+
7
+ it 'Indy::COMMON_LOG_FORMAT' do
8
+ source = ["127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb1.gif HTTP/1.0\" 200 2326",
9
+ "127.0.0.1 - frank [10/Oct/2000:13:55:37 -0700] \"GET /apache_pb1.gif HTTP/1.0\" 200 2326",
10
+ "127.0.0.1 - louie [10/Oct/2000:13:55:37 -0700] \"GET /apache_pb2.gif HTTP/1.0\" 200 2327",
11
+ "127.0.0.1 - frank [10/Oct/2000:13:55:38 -0700] \"GET /apache_pb3.gif HTTP/1.0\" 404 300"].join("\n")
12
+ indy = Indy.new(:source => source).with(Indy::COMMON_LOG_FORMAT)
13
+ result = indy.for(:authuser => 'louie')
14
+ result.length.should == 1
15
+ end
16
+
17
+ it 'Indy::COMBINED_LOG_FORMAT' do
18
+ source = ["127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb1.gif HTTP/1.0\" 200 2326 \"http://www.example.com/start.html\" \"Mozilla/4.08 [en] (Win98; I ;Nav)\"",
19
+ "127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb1.gif HTTP/1.0\" 200 2326 \"http://www.example.com/start.html\" \"Mozilla/4.08 [en] (Win98; I ;Nav)\"",
20
+ "127.0.0.1 - louie [10/Oct/2000:13:55:37 -0700] \"GET /apache_pb2.gif HTTP/1.0\" 200 2327 \"http://www.example.com/start.html\" \"Mozilla/4.08 [en] (Win98; I ;Nav)\"",
21
+ "127.0.0.1 - frank [10/Oct/2000:13:55:38 -0700] \"GET /apache_pb3.gif HTTP/1.0\" 404 300 \"http://www.example.com/start.html\" \"Mozilla/4.08 [en] (Win98; I ;Nav)\""].join("\n")
22
+ indy = Indy.new(:source => source).with(Indy::COMBINED_LOG_FORMAT)
23
+ result = indy.for(:authuser => 'louie')
24
+ result.length.should == 1
55
25
  end
26
+
27
+ it 'Indy::LOG4R_DEFAULT_FORMAT' do
28
+ # http://log4r.rubyforge.org/rdoc/Log4r/rdoc/patternformatter.html
29
+ source = ["DEBUG mylog: This is a message with level DEBUG",
30
+ " INFO mylog: This is a message with level INFO",
31
+ " WARN louie: This is a message with level WARN",
32
+ "ERROR mylog: This is a message with level ERROR",
33
+ "FATAL mylog: This is a message with level FATAL"].join("\n")
34
+ indy = Indy.new(:source => source)
35
+ indy.with(Indy::LOG4R_DEFAULT_FORMAT)
36
+ result = indy.for(:application => 'louie')
37
+ result.length.should == 1
38
+ end
39
+
40
+ it 'Indy::LOG4J_DEFAULT_FORMAT' do
41
+ # http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html
42
+ source = ["This is a message with level DEBUG",
43
+ "This is a message with level INFO",
44
+ "This is a message with level WARN",
45
+ "This is a message with level ERROR",
46
+ "This is a message with level FATAL"].join("\n")
47
+ indy = Indy.new(:source => source).with(Indy::LOG4J_DEFAULT_FORMAT)
48
+ indy.all.length.should == 5
49
+ end
50
+
51
+ end
52
+
53
+ # http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/TTCCLayout.html
54
+ # example:
55
+ # 176 [main] INFO org.apache.log4j.examples.Sort - Populating an array of 2 elements in reverse order.
56
+ it "should accept a log4j TTCC layout regex without error" do
57
+ log_data =
58
+ "343 [main] INFO org.apache.log4j.examples.Sort - The next log statement should be an error message.
59
+ 346 [main] ERROR org.apache.log4j.examples.SortAlgo.DUMP - Tried to dump an uninitialized array.
60
+ at org.apache.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
61
+ at org.apache.log4j.examples.Sort.main(Sort.java:64)
62
+ 467 [main] INFO org.apache.log4j.examples.Sort - Exiting main method."
63
+
64
+ Indy.new( :source => log_data,
65
+ :entry_regexp => /^(\d{3})\s+\[(\S+)\]\s+(\S+)\s+(\S+)\s*([^-]*)\s*-\s+(.+?)(?=\n\d{3}|\Z)/m,
66
+ :entry_fields => [:time, :thread, :level, :category, :diagnostic, :message]
67
+ ).class.should == Indy
56
68
  end
57
69
 
58
70
  end
@@ -3,7 +3,7 @@ require 'tempfile'
3
3
 
4
4
  describe Indy do
5
5
 
6
- context "search with string" do
6
+ context "#search with string param" do
7
7
 
8
8
  before(:each) do
9
9
  log_string = ["2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
@@ -12,8 +12,8 @@ describe Indy do
12
12
  @indy = Indy.search(log_string)
13
13
  end
14
14
 
15
- it "should return 2 records" do
16
- @indy.for(:application => 'MyApp').length.should == 2
15
+ it "should return all entries" do
16
+ @indy.all.length.should == 3
17
17
  end
18
18
 
19
19
  it "should search entire string on each successive search" do
@@ -24,9 +24,9 @@ describe Indy do
24
24
 
25
25
  end
26
26
 
27
- context "search file" do
27
+ context "#search with :file param" do
28
28
 
29
- before(:all) do
29
+ before(:each) do
30
30
  @file = Tempfile.new('file_search_spec')
31
31
  @file.write([ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
32
32
  "2000-09-07 14:08:41 INFO MyOtherApp - Exiting APPLICATION.",
@@ -48,54 +48,44 @@ describe Indy do
48
48
  end
49
49
 
50
50
  it "should search reopened file on each successive search" do
51
+ @indy.for(:application => 'MyApp').length.should == 2
51
52
  @file.write("\n2000-09-07 14:10:55 INFO MyApp - really really Exiting APPLICATION.\n")
52
53
  @file.flush
53
54
  @indy.for(:application => 'MyApp').length.should == 3
54
- @indy.for(:severity => 'INFO').length.should == 4
55
- @indy.for(:application => 'MyApp').length.should == 3
56
55
  end
57
56
 
58
57
  end
59
58
 
60
- context "search using cmd" do
59
+ context "#search with :cmd param" do
61
60
 
62
- before(:all) do
61
+ before(:each) do
63
62
  @file = Tempfile.new('file_search_spec')
64
- @file_path = @file.path
63
+ file_name = File.basename(@file.path)
64
+ Dir.chdir(File.dirname(@file.path))
65
65
  @file.write([ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
66
66
  "2000-09-07 14:08:41 INFO MyOtherApp - Exiting APPLICATION.",
67
67
  "2000-09-07 14:10:55 INFO MyApp - Exiting APPLICATION."
68
68
  ].join("\n"))
69
69
  @file.flush
70
-
71
- cmd = "ruby -e 'puts File.open(\"#{@file_path}\").read'"
72
-
70
+ cmd = is_windows? ?
71
+ "type #{file_name}" :
72
+ "cat #{file_name}"
73
73
  @indy = Indy.search(:cmd => cmd)
74
74
  end
75
75
 
76
76
  it "should return 2 records" do
77
- @indy.for(:application => 'MyApp').length.should == 2
78
77
  results = @indy.for(:application => 'MyApp')
79
- results.last.time.should == '2000-09-07 14:10:55'
80
- results.last.severity.should == 'INFO'
81
- results.last.application.should == 'MyApp'
82
- results.last.message.should == 'Exiting APPLICATION.'
83
- results.last._time.class.should_not be_nil
84
-
78
+ results.length.should == 2
85
79
  end
86
80
 
87
81
  it "should execute cmd on each successive search" do
88
82
  @indy.for(:application => 'MyApp').length.should == 2
89
83
  @indy.for(:severity => 'INFO').length.should == 3
90
-
91
84
  @file.write("\n2000-09-07 14:10:55 DEBUG MyApp - really really Exiting APPLICATION.\n")
92
85
  @file.flush
93
-
94
86
  @indy.for(:application => 'MyApp').length.should == 3
95
87
  @indy.for(:severity => 'INFO').length.should == 3
96
88
  end
97
89
 
98
-
99
90
  end
100
-
101
- end
91
+ end
@@ -4,42 +4,51 @@ class Indy
4
4
 
5
5
  describe Source do
6
6
 
7
- it "should raise without parameter" do
8
- lambda{ Source.new }.should raise_error( ArgumentError )
9
- end
7
+ context "#new" do
10
8
 
11
- it "should raise with nil parameter" do
12
- lambda{ Source.new(nil) }.should raise_error( Indy::Source::Invalid )
13
- end
9
+ it "should raise without parameter" do
10
+ lambda{ Source.new }.should raise_error( ArgumentError )
11
+ end
14
12
 
15
- it "should raise with bad parameter" do
16
- class NotString;end
17
- lambda{ Source.new(NotString.new) }.should raise_error( Indy::Source::Invalid )
18
- end
13
+ it "should raise with nil parameter" do
14
+ lambda{ Source.new(nil) }.should raise_error( Indy::Source::Invalid )
15
+ end
19
16
 
20
- it "should return Indy::Source object" do
21
- Source.new('logdata').class.should == Indy::Source
22
- end
17
+ it "should raise with bad parameter" do
18
+ class NotString;end
19
+ lambda{ Source.new(NotString.new) }.should raise_error( Indy::Source::Invalid )
20
+ end
23
21
 
24
- it "should respond to :open" do
25
- Source.new('logdata').should respond_to(:open)
26
- end
22
+ it "should raise if #execute_command returns empty string" do
23
+ IO.stub!(:popen).and_return('')
24
+ lambda{ Source.new(:cmd => 'a faux command').open }.should raise_error(Indy::Source::Invalid)
25
+ end
27
26
 
28
- it "should respond to :num_lines" do
29
- Source.new('logdata').should respond_to(:num_lines)
30
- end
27
+ it "should return Indy::Source object" do
28
+ Source.new('logdata').class.should == Indy::Source
29
+ end
31
30
 
32
- it "should respond to :lines" do
33
- Source.new('logdata').should respond_to(:num_lines)
34
- end
31
+ it "should respond to :open" do
32
+ Source.new('logdata').should respond_to(:open)
33
+ end
34
+
35
+ it "should respond to :num_entries" do
36
+ Source.new('logdata').should respond_to(:num_entries)
37
+ end
38
+
39
+ it "should respond to :entries" do
40
+ Source.new('logdata').should respond_to(:entries)
41
+ end
42
+
43
+ it "should handle Files" do
44
+ require 'tempfile'
45
+ Source.new(Tempfile.new('x')).class.should == Indy::Source
46
+ end
35
47
 
36
- it "should handle Files" do
37
- require 'tempfile'
38
- Source.new(Tempfile.new('x')).class.should == Indy::Source
39
48
  end
40
49
 
41
50
  context "instance" do
42
-
51
+
43
52
  before(:each) do
44
53
  log = [ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
45
54
  "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.",
@@ -47,18 +56,18 @@ class Indy
47
56
  ].join("\n")
48
57
  @source = Source.new(log)
49
58
  end
50
-
59
+
51
60
  it "should return StringIO from :open" do
52
- @source.open.class.should == StringIO
61
+ @source.open.class.should == Array
53
62
  end
54
63
 
55
- it "should return lines array from :lines" do
56
- @source.lines.class.should == Array
57
- @source.lines.length.should == 3
64
+ it "should return entries array from :entries" do
65
+ @source.entries.class.should == Array
66
+ @source.entries.length.should == 3
58
67
  end
59
68
 
60
- it "should return 3 from :num_lines" do
61
- @source.num_lines.should == 3
69
+ it "should return 3 from :num_entries" do
70
+ @source.num_entries.should == 3
62
71
  end
63
72
 
64
73
  end
@@ -81,5 +90,4 @@ class Indy
81
90
  end
82
91
 
83
92
  end
84
-
85
- end
93
+ end
@@ -0,0 +1,162 @@
1
+ require "#{File.dirname(__FILE__)}/helper"
2
+
3
+ describe Indy do
4
+
5
+ context "search time scope" do
6
+
7
+ before(:each) do
8
+ @indy = Indy.search(
9
+ [ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
10
+ "2000-09-07 14:07:42 INFO MyApp - Initializing APPLICATION.",
11
+ "2000-09-07 14:07:43 INFO MyApp - Configuring APPLICATION.",
12
+ "2000-09-07 14:07:44 INFO MyApp - Running APPLICATION.",
13
+ "2000-09-07 14:07:45 INFO MyApp - Exiting APPLICATION."
14
+ ].join("\n") )
15
+ end
16
+
17
+ context "after method" do
18
+
19
+ it "should find the correct entries" do
20
+ @indy.after(:time => '2000-09-07 14:07:42').all.length.should == 3
21
+ end
22
+
23
+ it "should find 0 entries with a time that is past the log" do
24
+ @indy.after(:time => '2000-09-07 14:07:46').all.length.should == 0
25
+ end
26
+
27
+ it "should find all entries with a time that is before the log" do
28
+ @indy.after(:time => '2000-09-07 14:07:40').all.length.should == 5
29
+ end
30
+
31
+ it "should find entries using inclusive" do
32
+ @indy.after(:time => '2000-09-07 14:07:42', :inclusive => true).all.length.should == 4
33
+ end
34
+
35
+ end
36
+
37
+ context "before method" do
38
+
39
+ it "should find the correct entries" do
40
+ @indy.before(:time => '2000-09-07 14:07:44').all.length.should == 3
41
+ end
42
+
43
+ it "should find 0 entries with a time that is before the log" do
44
+ @indy.before(:time => '2000-09-07 14:07:40').all.length.should == 0
45
+ end
46
+
47
+ it "should find all entries with a time that is after the log" do
48
+ @indy.before(:time => '2000-09-07 14:07:47').all.length.should == 5
49
+ end
50
+
51
+ it "should find entries using inclusive" do
52
+ @indy.before(:time => '2000-09-07 14:07:44', :inclusive => true).all.length.should == 4
53
+ end
54
+
55
+ end
56
+
57
+ context "within method" do
58
+
59
+ it "should find the correct entries" do
60
+ @indy.within(:start_time => '2000-09-07 14:07:41', :end_time => '2000-09-07 14:07:43').all.length.should == 1
61
+ end
62
+
63
+ it "should find the correct entries using inclusive" do
64
+ @indy.within(:start_time => '2000-09-07 14:07:41', :end_time => '2000-09-07 14:07:43', :inclusive => true).all.length.should == 3
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ context "search time scopes with span" do
72
+
73
+ before(:each) do
74
+ @indy = Indy.search(
75
+ [ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
76
+ "2000-09-07 14:08:41 INFO MyApp - Initializing APPLICATION.",
77
+ "2000-09-07 14:09:41 INFO MyApp - Configuring APPLICATION.",
78
+ "2000-09-07 14:10:50 INFO MyApp - Running APPLICATION.",
79
+ "2000-09-07 14:11:42 INFO MyApp - Exiting APPLICATION.",
80
+ "2000-09-07 14:12:15 INFO MyApp - Exiting APPLICATION."
81
+ ].join("\n") )
82
+ end
83
+
84
+ it "using after should find the correct entries" do
85
+ @indy.after(:time => '2000-09-07 14:07:42', :span => 1).all.length.should == 1
86
+ end
87
+
88
+ it "using before should find the correct entries" do
89
+ @indy.before(:time => '2000-09-07 14:12:00', :span => 4).all.length.should == 4
90
+ end
91
+
92
+ it "using around should find the correct entries" do
93
+ @indy.around(:time => '2000-09-07 14:11:00', :span => 2).all.length.should == 2
94
+ end
95
+
96
+ it "using after and inclusive should find the correct entries" do
97
+ @indy.after(:time => '2000-09-07 14:07:41', :span => 2, :inclusive => true).all.length.should == 3
98
+ end
99
+
100
+ end
101
+
102
+ context "multiple time scope methods on the same instance" do
103
+
104
+ before(:each) do
105
+ @indy = Indy.search(
106
+ [ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
107
+ "2000-09-07 14:07:42 INFO MyApp - Initializing APPLICATION.",
108
+ "2000-09-07 14:07:43 INFO MyApp - Configuring APPLICATION.",
109
+ "2000-09-07 14:07:44 INFO MyApp - Running APPLICATION.",
110
+ "2000-09-07 14:07:45 INFO MyApp - Exiting APPLICATION."
111
+ ].join("\n") )
112
+ end
113
+
114
+ # Issue #3 (by design) assumed that the time scope.
115
+ it "should each add scope criteria to the instance" do
116
+ @indy.after(:time => '2000-09-07 14:07:42').all.length.should == 3
117
+ @indy.before(:time => '2000-09-07 14:07:45').all.length.should == 2
118
+ end
119
+
120
+ it "should specify the entire scope if #reset_scope was called" do
121
+ @indy.after(:time => '2000-09-07 14:07:42').all.length.should == 3
122
+ @indy.reset_scope
123
+ @indy.before(:time => '2000-09-07 14:07:45').all.length.should == 4
124
+ end
125
+
126
+ end
127
+
128
+ context "explicit time format" do
129
+
130
+ before(:each) do
131
+ pattern = "^([^\s]+) (.*)$"
132
+ @indy = Indy.new(:time_format => '%m-%d-%Y',
133
+ :source => "1-13-2002 message\n1-14-2002 another message\n1-15-2002 another message",
134
+ :log_format => [pattern, :time, :message])
135
+ end
136
+
137
+ it "should search within time scope using a different format than explicitly set" do
138
+ pending 'Flexible time date time formatting is not implemented'
139
+ @indy.after(:time => 'Jan 13 2002').all.length.should == 2
140
+ @indy.after(:time => 'Jan 14 2002').all.last._time.mday.should == 15
141
+ end
142
+
143
+ end
144
+
145
+ it "should parse dates when log includes non-conforming data" do
146
+ logdata = [ "12-03-2000 message1",
147
+ "13-03-2000 message2",
148
+ "14-03-2000 ",
149
+ " message4",
150
+ "a14-03-2000 message5",
151
+ "14-03-2000 message6\n\n\n\n",
152
+ "15-03-2000 message7",
153
+ "16-03-2000 message8\r\n",
154
+ "17-03-2000 message9"].join("\n")
155
+ @indy = Indy.new(
156
+ :source => logdata,
157
+ :log_format => [/^(\d[^\s]+\d) (.+)$/, :time, :message])
158
+ @indy.after(:time => '13-03-2000')
159
+ @indy.all.length.should == 4
160
+ end
161
+
162
+ end