indy 0.4.0.pre → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/History.txt +9 -2
- data/README.md +75 -53
- data/features/{file.feature → file_object.feature} +1 -1
- data/features/file_path.feature +30 -0
- data/features/log_format_combined.feature +15 -0
- data/features/log_format_common.feature +19 -0
- data/features/step_definitions/find_by.steps.rb +1 -1
- data/features/step_definitions/log_file.steps.rb +10 -2
- data/features/step_definitions/support/transforms.rb +1 -1
- data/indy.gemspec +20 -21
- data/lib/indy/indy.rb +15 -13
- data/lib/indy/log_definition.rb +6 -4
- data/lib/indy/log_formats.rb +6 -5
- data/lib/indy/search.rb +28 -16
- data/lib/indy/source.rb +21 -5
- data/lib/indy/time.rb +7 -27
- data/lib/indy/version.rb +1 -1
- data/spec/indy_private_spec.rb +3 -3
- data/spec/indy_spec.rb +59 -59
- data/spec/indy_struct_spec.rb +6 -6
- data/spec/log_definition_spec.rb +11 -11
- data/spec/log_format_spec.rb +25 -13
- data/spec/search_spec.rb +15 -15
- data/spec/source_spec.rb +17 -17
- data/spec/time_scope_spec.rb +39 -34
- data/spec/time_spec.rb +7 -16
- data/spec/tmp/rspec_guard_result +1 -0
- metadata +115 -88
data/spec/indy_struct_spec.rb
CHANGED
@@ -12,29 +12,29 @@ describe 'Indy' do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should be returned by #for search" do
|
15
|
-
@entry_struct.
|
15
|
+
expect(@entry_struct).to be_kind_of Struct::Entry
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should contain entire log entry as :raw_entry" do
|
19
|
-
@entry_struct.raw_entry.
|
19
|
+
expect(@entry_struct.raw_entry).to eq("2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.")
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'using Indy::DEFAULT_LOG_FORMAT' do
|
23
23
|
|
24
24
|
it "should contain :time" do
|
25
|
-
@entry_struct.time.
|
25
|
+
expect(@entry_struct.time).to eq("2000-09-07 14:07:42")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should contain :severity" do
|
29
|
-
@entry_struct.severity.
|
29
|
+
expect(@entry_struct.severity).to eq("DEBUG")
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should contain :application" do
|
33
|
-
@entry_struct.application.
|
33
|
+
expect(@entry_struct.application).to eq("MyApp")
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should contain :message" do
|
37
|
-
@entry_struct.message.
|
37
|
+
expect(@entry_struct.message).to eq("Initializing APPLICATION.")
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
data/spec/log_definition_spec.rb
CHANGED
@@ -11,25 +11,25 @@ describe 'Indy::LogDefinition' do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should set entry_regexp" do
|
14
|
-
@ld.entry_regexp.
|
14
|
+
expect(@ld.entry_regexp).to eq /foo/
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should set entry_fields" do
|
18
|
-
@ld.entry_fields.
|
18
|
+
expect(@ld.entry_fields).to eq [:field_one]
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should set time_format" do
|
22
|
-
@ld.time_format.
|
22
|
+
expect(@ld.time_format).to eq '%M-%d-%Y'
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should raise ArgumentError when missing entry_fields" do
|
28
|
-
|
28
|
+
expect{ Indy::LogDefinition.new(:entry_regexp => /foo/) }.to raise_error ArgumentError
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should raise ArgumentError when missing entry_regexp" do
|
32
|
-
|
32
|
+
expect{ Indy::LogDefinition.new(:entry_fields => [:field_one]) }.to raise_error ArgumentError
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -46,13 +46,13 @@ describe 'Indy::LogDefinition' do
|
|
46
46
|
context "#parse_entry" do
|
47
47
|
|
48
48
|
it "should return a hash" do
|
49
|
-
@ld.send(:parse_entry, "2000-09-07 INFO The message!").class.
|
49
|
+
expect(@ld.send(:parse_entry, "2000-09-07 INFO The message!").class).to eq(Hash)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should return correct key/value pairs" do
|
53
53
|
hash = @ld.send(:parse_entry, "2000-09-07 INFO The message!")
|
54
|
-
hash[:time].
|
55
|
-
hash[:message].
|
54
|
+
expect(hash[:time]).to eq("2000-09-07")
|
55
|
+
expect(hash[:message]).to eq("The message!")
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
@@ -60,13 +60,13 @@ describe 'Indy::LogDefinition' do
|
|
60
60
|
context "#parse_entry_captures" do
|
61
61
|
|
62
62
|
it "should return a hash" do
|
63
|
-
@ld.send(:parse_entry_captures, @field_captures).class.
|
63
|
+
expect(@ld.send(:parse_entry_captures, @field_captures).class).to eq(Hash)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should contain key/value pairs" do
|
67
67
|
hash = @ld.send(:parse_entry_captures, @field_captures)
|
68
|
-
hash[:time].
|
69
|
-
hash[:message].
|
68
|
+
expect(hash[:time]).to eq("2000-09-07")
|
69
|
+
expect(hash[:message]).to eq("The message!")
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
data/spec/log_format_spec.rb
CHANGED
@@ -2,26 +2,36 @@ require "#{File.dirname(__FILE__)}/helper"
|
|
2
2
|
|
3
3
|
describe Indy do
|
4
4
|
|
5
|
-
context "log format
|
5
|
+
context "log format" do
|
6
6
|
|
7
|
-
it 'Indy::COMMON_LOG_FORMAT' do
|
7
|
+
it 'can be set to Indy::COMMON_LOG_FORMAT' do
|
8
8
|
source = ["127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb1.gif HTTP/1.0\" 200 2326",
|
9
|
-
|
10
|
-
|
11
|
-
|
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
12
|
indy = Indy.new(:source => source).with(Indy::COMMON_LOG_FORMAT)
|
13
13
|
result = indy.for(:authuser => 'louie')
|
14
|
-
result.length.
|
14
|
+
expect(result.length).to eq(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'configuration can be set using: Indy.search(string).with(FORMAT_CLASS)' do
|
18
|
+
source = ["127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb1.gif HTTP/1.0\" 200 2326",
|
19
|
+
"127.0.0.1 - frank [10/Oct/2000:13:55:37 -0700] \"GET /apache_pb1.gif HTTP/1.0\" 200 2326",
|
20
|
+
"127.0.0.1 - louie [10/Oct/2000:13:55:37 -0700] \"GET /apache_pb2.gif HTTP/1.0\" 200 2327",
|
21
|
+
"127.0.0.1 - frank [10/Oct/2000:13:55:38 -0700] \"GET /apache_pb3.gif HTTP/1.0\" 404 300"].join("\n")
|
22
|
+
indy = Indy.search(source).with(Indy::COMMON_LOG_FORMAT)
|
23
|
+
result = indy.for(:authuser => 'louie')
|
24
|
+
expect(result.length).to eq(1)
|
15
25
|
end
|
16
26
|
|
17
27
|
it 'Indy::COMBINED_LOG_FORMAT' do
|
18
28
|
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
29
|
"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.
|
21
|
-
"127.0.0.
|
30
|
+
"127.0.0.2 - 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)\"",
|
31
|
+
"127.0.0.3 - 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
32
|
indy = Indy.new(:source => source).with(Indy::COMBINED_LOG_FORMAT)
|
23
33
|
result = indy.for(:authuser => 'louie')
|
24
|
-
result.length.
|
34
|
+
expect(result.length).to eq(1)
|
25
35
|
end
|
26
36
|
|
27
37
|
it 'Indy::LOG4R_DEFAULT_FORMAT' do
|
@@ -34,7 +44,7 @@ describe Indy do
|
|
34
44
|
indy = Indy.new(:source => source)
|
35
45
|
indy.with(Indy::LOG4R_DEFAULT_FORMAT)
|
36
46
|
result = indy.for(:application => 'louie')
|
37
|
-
result.length.
|
47
|
+
expect(result.length).to eq(1)
|
38
48
|
end
|
39
49
|
|
40
50
|
it 'Indy::LOG4J_DEFAULT_FORMAT' do
|
@@ -45,7 +55,7 @@ describe Indy do
|
|
45
55
|
"This is a message with level ERROR",
|
46
56
|
"This is a message with level FATAL"].join("\n")
|
47
57
|
indy = Indy.new(:source => source).with(Indy::LOG4J_DEFAULT_FORMAT)
|
48
|
-
indy.all.length.
|
58
|
+
expect(indy.all.length).to eq(5)
|
49
59
|
end
|
50
60
|
|
51
61
|
end
|
@@ -61,10 +71,12 @@ describe Indy do
|
|
61
71
|
at org.apache.log4j.examples.Sort.main(Sort.java:64)
|
62
72
|
467 [main] INFO org.apache.log4j.examples.Sort - Exiting main method."
|
63
73
|
|
64
|
-
Indy.new( :source => log_data,
|
74
|
+
result = Indy.new( :source => log_data,
|
65
75
|
:entry_regexp => /^(\d{3})\s+\[(\S+)\]\s+(\S+)\s+(\S+)\s*([^-]*)\s*-\s+(.+?)(?=\n\d{3}|\Z)/m,
|
66
76
|
:entry_fields => [:time, :thread, :level, :category, :diagnostic, :message]
|
67
|
-
)
|
77
|
+
)
|
78
|
+
expect(result.class).to eq(Indy)
|
79
|
+
expect(result.all.first.level).to eq('INFO')
|
68
80
|
end
|
69
81
|
|
70
82
|
end
|
data/spec/search_spec.rb
CHANGED
@@ -13,13 +13,13 @@ describe Indy do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should return all entries" do
|
16
|
-
@indy.all.length.
|
16
|
+
expect(@indy.all.length).to eq(3)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should search entire string on each successive search" do
|
20
|
-
@indy.for(:application => 'MyApp').length.
|
21
|
-
@indy.for(:severity => 'INFO').length.
|
22
|
-
@indy.for(:application => 'MyApp').length.
|
20
|
+
expect(@indy.for(:application => 'MyApp').length).to eq(2)
|
21
|
+
expect(@indy.for(:severity => 'INFO').length).to eq(3)
|
22
|
+
expect(@indy.for(:application => 'MyApp').length).to eq(2)
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -38,20 +38,20 @@ describe Indy do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should return 2 records" do
|
41
|
-
@indy.for(:application => 'MyApp').length.
|
41
|
+
expect(@indy.for(:application => 'MyApp').length).to eq(2)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should search entire file on each successive search" do
|
45
|
-
@indy.for(:application => 'MyApp').length.
|
46
|
-
@indy.for(:severity => 'INFO').length.
|
47
|
-
@indy.for(:application => 'MyApp').length.
|
45
|
+
expect(@indy.for(:application => 'MyApp').length).to eq(2)
|
46
|
+
expect(@indy.for(:severity => 'INFO').length).to eq(3)
|
47
|
+
expect(@indy.for(:application => 'MyApp').length).to eq(2)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should search reopened file on each successive search" do
|
51
|
-
@indy.for(:application => 'MyApp').length.
|
51
|
+
expect(@indy.for(:application => 'MyApp').length).to eq(2)
|
52
52
|
@file.write("\n2000-09-07 14:10:55 INFO MyApp - really really Exiting APPLICATION.\n")
|
53
53
|
@file.flush
|
54
|
-
@indy.for(:application => 'MyApp').length.
|
54
|
+
expect(@indy.for(:application => 'MyApp').length).to eq(3)
|
55
55
|
end
|
56
56
|
|
57
57
|
end
|
@@ -75,16 +75,16 @@ describe Indy do
|
|
75
75
|
|
76
76
|
it "should return 2 records" do
|
77
77
|
results = @indy.for(:application => 'MyApp')
|
78
|
-
results.length.
|
78
|
+
expect(results.length).to eq(2)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should execute cmd on each successive search" do
|
82
|
-
@indy.for(:application => 'MyApp').length.
|
83
|
-
@indy.for(:severity => 'INFO').length.
|
82
|
+
expect(@indy.for(:application => 'MyApp').length).to eq(2)
|
83
|
+
expect(@indy.for(:severity => 'INFO').length).to eq(3)
|
84
84
|
@file.write("\n2000-09-07 14:10:55 DEBUG MyApp - really really Exiting APPLICATION.\n")
|
85
85
|
@file.flush
|
86
|
-
@indy.for(:application => 'MyApp').length.
|
87
|
-
@indy.for(:severity => 'INFO').length.
|
86
|
+
expect(@indy.for(:application => 'MyApp').length).to eq(3)
|
87
|
+
expect(@indy.for(:severity => 'INFO').length).to eq(3)
|
88
88
|
end
|
89
89
|
|
90
90
|
end
|
data/spec/source_spec.rb
CHANGED
@@ -7,42 +7,42 @@ class Indy
|
|
7
7
|
context "#new" do
|
8
8
|
|
9
9
|
it "should raise without parameter" do
|
10
|
-
|
10
|
+
expect{ Source.new }.to raise_error( ArgumentError )
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should raise with nil parameter" do
|
14
|
-
|
14
|
+
expect{ Source.new(nil) }.to raise_error( Indy::Source::Invalid )
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should raise with bad parameter" do
|
18
18
|
class NotString;end
|
19
|
-
|
19
|
+
expect{ Source.new(NotString.new) }.to raise_error( Indy::Source::Invalid )
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should raise if #execute_command returns empty string" do
|
23
|
-
IO.
|
24
|
-
|
23
|
+
allow(IO).to receive(:popen).and_return('')
|
24
|
+
expect{ Source.new(:cmd => 'a faux command').open }.to raise_error(Indy::Source::Invalid)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should return Indy::Source object" do
|
28
|
-
Source.new('logdata').class.
|
28
|
+
expect(Source.new('logdata').class).to eq(Indy::Source)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should respond to :open" do
|
32
|
-
Source.new('logdata').
|
32
|
+
expect(Source.new('logdata')).to respond_to(:open)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should respond to :num_entries" do
|
36
|
-
Source.new('logdata').
|
36
|
+
expect(Source.new('logdata')).to respond_to(:num_entries)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should respond to :entries" do
|
40
|
-
Source.new('logdata').
|
40
|
+
expect(Source.new('logdata')).to respond_to(:entries)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should handle Files" do
|
44
44
|
require 'tempfile'
|
45
|
-
Source.new(Tempfile.new('x')).class.
|
45
|
+
expect(Source.new(Tempfile.new('x')).class).to eq(Indy::Source)
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|
@@ -58,16 +58,16 @@ class Indy
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should return StringIO from :open" do
|
61
|
-
@source.open.class.
|
61
|
+
expect(@source.open.class).to eq(Array)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should return entries array from :entries" do
|
65
|
-
@source.entries.class.
|
66
|
-
@source.entries.length.
|
65
|
+
expect(@source.entries.class).to eq(Array)
|
66
|
+
expect(@source.entries.length).to eq(3)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should return 3 from :num_entries" do
|
70
|
-
@source.num_entries.
|
70
|
+
expect(@source.num_entries).to eq(3)
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
@@ -75,18 +75,18 @@ class Indy
|
|
75
75
|
it "should handle a :file hash key with File object value" do
|
76
76
|
require 'tempfile'
|
77
77
|
file = Tempfile.new('x')
|
78
|
-
Source.new(:file => file).class.
|
78
|
+
expect(Source.new(:file => file).class).to eq(Indy::Source)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should handle a bare File object" do
|
82
82
|
require 'tempfile'
|
83
83
|
file = Tempfile.new('y')
|
84
|
-
Source.new(file).class.
|
84
|
+
expect(Source.new(file).class).to eq(Indy::Source)
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should handle a real file" do
|
88
88
|
log_file = "#{File.dirname(__FILE__)}/data.log"
|
89
|
-
Indy.search(:file => File.open(log_file, 'r')).for(:application => 'MyApp').length.
|
89
|
+
expect(Indy.search(:file => File.open(log_file, 'r')).for(:application => 'MyApp').length).to eq(2)
|
90
90
|
end
|
91
91
|
|
92
92
|
end
|
data/spec/time_scope_spec.rb
CHANGED
@@ -17,19 +17,19 @@ describe Indy do
|
|
17
17
|
context "after method" do
|
18
18
|
|
19
19
|
it "should find the correct entries" do
|
20
|
-
@indy.after(:time => '2000-09-07 14:07:42').all.length.
|
20
|
+
expect(@indy.after(:time => '2000-09-07 14:07:42').all.length).to eq(3)
|
21
21
|
end
|
22
22
|
|
23
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.
|
24
|
+
expect(@indy.after(:time => '2000-09-07 14:07:46').all.length).to eq(0)
|
25
25
|
end
|
26
26
|
|
27
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.
|
28
|
+
expect(@indy.after(:time => '2000-09-07 14:07:40').all.length).to eq(5)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should find entries using inclusive" do
|
32
|
-
@indy.after(:time => '2000-09-07 14:07:42', :inclusive => true).all.length.
|
32
|
+
expect(@indy.after(:time => '2000-09-07 14:07:42', :inclusive => true).all.length).to eq(4)
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
@@ -37,19 +37,19 @@ describe Indy do
|
|
37
37
|
context "before method" do
|
38
38
|
|
39
39
|
it "should find the correct entries" do
|
40
|
-
@indy.before(:time => '2000-09-07 14:07:44').all.length.
|
40
|
+
expect(@indy.before(:time => '2000-09-07 14:07:44').all.length).to eq(3)
|
41
41
|
end
|
42
42
|
|
43
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.
|
44
|
+
expect(@indy.before(:time => '2000-09-07 14:07:40').all.length).to eq(0)
|
45
45
|
end
|
46
46
|
|
47
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.
|
48
|
+
expect(@indy.before(:time => '2000-09-07 14:07:47').all.length).to eq(5)
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should find entries using inclusive" do
|
52
|
-
@indy.before(:time => '2000-09-07 14:07:44', :inclusive => true).all.length.
|
52
|
+
expect(@indy.before(:time => '2000-09-07 14:07:44', :inclusive => true).all.length).to eq(4)
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
@@ -57,11 +57,11 @@ describe Indy do
|
|
57
57
|
context "within method" do
|
58
58
|
|
59
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.
|
60
|
+
expect(@indy.within(:start_time => '2000-09-07 14:07:41', :end_time => '2000-09-07 14:07:43').all.length).to eq(1)
|
61
61
|
end
|
62
62
|
|
63
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.
|
64
|
+
expect(@indy.within(:start_time => '2000-09-07 14:07:41', :end_time => '2000-09-07 14:07:43', :inclusive => true).all.length).to eq(3)
|
65
65
|
end
|
66
66
|
|
67
67
|
end
|
@@ -82,19 +82,19 @@ describe Indy do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
it "using after should find the correct entries" do
|
85
|
-
@indy.after(:time => '2000-09-07 14:07:42', :span => 1).all.length.
|
85
|
+
expect(@indy.after(:time => '2000-09-07 14:07:42', :span => 1).all.length).to eq(1)
|
86
86
|
end
|
87
87
|
|
88
88
|
it "using before should find the correct entries" do
|
89
|
-
@indy.before(:time => '2000-09-07 14:12:00', :span => 4).all.length.
|
89
|
+
expect(@indy.before(:time => '2000-09-07 14:12:00', :span => 4).all.length).to eq(4)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "using around should find the correct entries" do
|
93
|
-
@indy.around(:time => '2000-09-07 14:11:00', :span => 2).all.length.
|
93
|
+
expect(@indy.around(:time => '2000-09-07 14:11:00', :span => 2).all.length).to eq(2)
|
94
94
|
end
|
95
95
|
|
96
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.
|
97
|
+
expect(@indy.after(:time => '2000-09-07 14:07:41', :span => 2, :inclusive => true).all.length).to eq(3)
|
98
98
|
end
|
99
99
|
|
100
100
|
end
|
@@ -113,14 +113,14 @@ describe Indy do
|
|
113
113
|
|
114
114
|
# Issue #3 (by design) assumed that the time scope.
|
115
115
|
it "should each add scope criteria to the instance" do
|
116
|
-
@indy.after(:time => '2000-09-07 14:07:42').all.length.
|
117
|
-
@indy.before(:time => '2000-09-07 14:07:45').all.length.
|
116
|
+
expect(@indy.after(:time => '2000-09-07 14:07:42').all.length).to eq(3)
|
117
|
+
expect(@indy.before(:time => '2000-09-07 14:07:45').all.length).to eq(2)
|
118
118
|
end
|
119
119
|
|
120
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.
|
121
|
+
expect(@indy.after(:time => '2000-09-07 14:07:42').all.length).to eq(3)
|
122
122
|
@indy.reset_scope
|
123
|
-
@indy.before(:time => '2000-09-07 14:07:45').all.length.
|
123
|
+
expect(@indy.before(:time => '2000-09-07 14:07:45').all.length).to eq(4)
|
124
124
|
end
|
125
125
|
|
126
126
|
end
|
@@ -128,35 +128,40 @@ describe Indy do
|
|
128
128
|
context "explicit time format" do
|
129
129
|
|
130
130
|
before(:each) do
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
131
|
+
@indy = Indy.new(
|
132
|
+
:time_format => '[%m %d %Y]',
|
133
|
+
:source => "[1 13 2002] message\n[1 14 2002] another message\n[1 15 2002] another message",
|
134
|
+
:entry_regexp => "^(\\[.+\\]) (.*)$",
|
135
|
+
:entry_fields => [:time, :message])
|
135
136
|
end
|
136
137
|
|
137
|
-
it "
|
138
|
-
|
139
|
-
|
140
|
-
|
138
|
+
it "using before finds correct number of entries" do
|
139
|
+
expect(@indy.before(:time => '[1 14 2002]').all.length).to eq(1)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "using default (not explicit) time format finds correct number of entries" do
|
143
|
+
expect(@indy.after(:time => '2002-01-13').all.length).to eq(2)
|
141
144
|
end
|
142
145
|
|
143
146
|
end
|
144
147
|
|
145
|
-
it "should
|
148
|
+
it "should raise ParseException when log includes non-conforming data" do
|
146
149
|
logdata = [ "12-03-2000 message1",
|
147
150
|
"13-03-2000 message2",
|
148
151
|
"14-03-2000 ",
|
149
152
|
" message4",
|
150
|
-
"
|
151
|
-
"
|
152
|
-
"
|
153
|
-
"
|
154
|
-
"
|
153
|
+
"16-03-2000 message6\n\n\n\n",
|
154
|
+
"a17-03-2000 message5",
|
155
|
+
"18-03-2000 message7",
|
156
|
+
"19-03-2000 message8\r\n",
|
157
|
+
"20-03-2000 message9"].join("\n")
|
155
158
|
@indy = Indy.new(
|
156
159
|
:source => logdata,
|
157
160
|
:log_format => [/^(\d[^\s]+\d) (.+)$/, :time, :message])
|
158
|
-
@indy.after(:time => '
|
159
|
-
|
161
|
+
@indy.after(:time => '16-03-2000')
|
162
|
+
expect{
|
163
|
+
@indy.all
|
164
|
+
}.to raise_exception( Indy::Time::ParseException )
|
160
165
|
end
|
161
166
|
|
162
167
|
end
|