indy 0.3.4 → 0.4.0.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,17 +2,17 @@ require "#{File.dirname(__FILE__)}/helper"
2
2
 
3
3
  describe "Search Performance" do
4
4
 
5
- context "with a 10000 line log file" do
5
+ context "with a 50000 line log file" do
6
6
 
7
7
  large_file = File.open("#{File.dirname(__FILE__)}/large.log", 'r')
8
8
  before(:all) do
9
- @indy = Indy.search(large_file).with([/^\[([^\|]+)\|([^\]]+)\] (.*)$/,:severity, :time, :message])
9
+ @indy = Indy.search(large_file).with(:entry_regexp => /^\[([^\|]+)\|([^\]]+)\] (.*)$/, :entry_fields => [:severity, :time, :message])
10
10
  end
11
11
 
12
12
  profile :file => STDOUT, :printer => :flat, :min_percent => 1 do
13
13
 
14
- it "should profile code using #for(:all)" do
15
- @indy.for(:all)
14
+ it "should profile code using #all" do
15
+ @indy.all
16
16
  end
17
17
 
18
18
  it "should profile code using #for(:field => 'value')" do
@@ -24,14 +24,14 @@ describe "Search Performance" do
24
24
  end
25
25
 
26
26
  it "should profile code using #after()" do
27
- @indy.after(:time => "29-12-2010 12:11:32").for(:all)
27
+ @indy.after(:time => "29-12-2010 12:11:32").all
28
28
  end
29
29
 
30
30
  end
31
31
 
32
32
  end
33
33
 
34
- context "with a 10000 line log file" do
34
+ context "with a 50000 line log file" do
35
35
 
36
36
  large_file = File.open("#{File.dirname(__FILE__)}/large.log", 'r')
37
37
  before(:all) do
@@ -44,7 +44,7 @@ describe "Search Performance" do
44
44
  profile :file => STDOUT, :printer => :flat, :min_percent => 1 do
45
45
 
46
46
  it "should profile code using #after() and an explicit @time_format" do
47
- @indy.after(:time => "29-12-2010 12:11:32").for(:all)
47
+ @indy.after(:time => "29-12-2010 12:11:32").all
48
48
  end
49
49
 
50
50
  end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'indy'
3
+
4
+ describe '50000 entry file' do
5
+ it 'should find 130 entries using #within time scope' do
6
+ large_file = File.open("#{File.dirname(__FILE__)}/large.log", 'r')
7
+
8
+ start_time = Time.now
9
+ indy = Indy.new(
10
+ :source => large_file,
11
+ :log_format => [/^\[([^\|]+)\|([^\]]+)\] (.*)$/,:severity, :time, :message])
12
+
13
+ result = indy.within(:start_time => "27-12-2010 10:14:25", :end_time => "29-12-2010 12:10:19").all
14
+ puts "#{(Time.now - start_time).seconds} \tElapsed seconds to parse 50k line file for all entries in time scope"
15
+ result.size.should == 130
16
+ end
17
+ end
18
+
@@ -5,7 +5,9 @@ rescue Exception => e
5
5
  puts 'Run "gem install simplecov" to enable code coverage reporting'
6
6
  end
7
7
 
8
- require File.expand_path("#{File.dirname(__FILE__)}/../lib/indy") unless
9
- $:.include? File.expand_path("#{File.dirname(__FILE__)}/../lib/indy")
8
+ def is_windows?
9
+ RUBY_PLATFORM =~ /mingw|mswin/
10
+ end
10
11
 
11
- # require 'rspec'
12
+ require File.expand_path("#{File.dirname(__FILE__)}/../lib/indy") unless
13
+ $:.include? File.expand_path("#{File.dirname(__FILE__)}/../lib/indy")
@@ -0,0 +1,24 @@
1
+ require "#{File.dirname(__FILE__)}/helper"
2
+
3
+ describe 'Indy' do
4
+
5
+ context 'instance private method' do
6
+
7
+ before(:all) do
8
+ log = [ "2000-09-07 14:07: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
+ @indy = Indy.search(log)
12
+ end
13
+
14
+ it "#last_entries should return an array of Struct::Entry object" do
15
+ @indy.send(:last_entries, 2).class.should == Array
16
+ @indy.send(:last_entries, 2).first.class.should == Struct::Entry
17
+ end
18
+
19
+ it "#last_entries should return correct Struct::Entry objects" do
20
+ @indy.send(:last_entries, 2).first.time.should == '2000-09-07 14:07:43'
21
+ end
22
+
23
+ end
24
+ end
@@ -2,66 +2,100 @@ require "#{File.dirname(__FILE__)}/helper"
2
2
 
3
3
  describe 'Indy' do
4
4
 
5
- context ':initialize' do
5
+ context '#new' do
6
6
 
7
- # http://log4r.rubyforge.org/rdoc/Log4r/rdoc/patternformatter.html
8
- it "should accept a log4r pattern string without error" do
9
- Indy.new(:log_format => ["(%d) (%i) (%c) - (%m)", :time, :info, :class, :message]).class.should == Indy
10
- end
11
-
12
- # http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html
13
- it "should accept a log4j pattern string without error" do
14
- Indy.new(:log_format => ["%d [%M] %p %C{1} - %m", :time, :info, :class, :message]).class.should == Indy
7
+ it "should accept v0.3.4 initialization params" do
8
+ indy_obj = Indy.new(:source => "foo\nbar\n").with(Indy::DEFAULT_LOG_FORMAT)
9
+ search_obj = indy_obj.search
10
+ search_obj.log_definition.class.should eq Indy::LogDefinition
11
+ search_obj.log_definition.entry_regexp.class.should eq Regexp
12
+ search_obj.log_definition.entry_fields.class.should eq Array
15
13
  end
16
14
 
17
15
  it "should not raise error with non-conforming data" do
18
- @indy = Indy.new(:source => " \nfoobar\n\n baz", :log_format => ['([^\s]+) (\w+)', :time, :message])
19
- @indy.for(:all).class.should == Array
16
+ @indy = Indy.new(:source => " \nfoobar\n\n baz", :entry_regexp => '([^\s]+) (\w+)', :entry_fields => [:time, :message])
17
+ @indy.all.class.should == Array
20
18
  end
21
19
 
22
20
  it "should accept time_format parameter" do
23
- @indy = Indy.new(:time_format => '%d-%m-%Y', :source => "1-13-2000 yes", :log_format => ['^([^\s]+) (\w+)$', :time, :message])
24
- @indy.for(:all).class.should == Array
25
- @indy.instance_variable_get(:@time_format).should == '%d-%m-%Y'
21
+ @indy = Indy.new(:time_format => '%d-%m-%Y', :source => "1-13-2000 yes", :entry_regexp => '^([^\s]+) (\w+)$', :entry_fields => [:time, :message])
22
+ @indy.all.class.should == Array
23
+ @indy.search.log_definition.time_format.should == '%d-%m-%Y'
26
24
  end
27
25
 
28
26
  it "should accept an initialization hash passed to #search" do
29
27
  hash = {:time_format => '%d-%m-%Y',
30
28
  :source => "1-13-2000 yes",
31
- :log_format => ['^([^\s]+) (\w+)$', :time, :message]}
29
+ :entry_regexp => '^([^\s]+) (\w+)$',
30
+ :entry_fields => [:time, :message]}
32
31
  @indy = Indy.search(hash)
33
32
  @indy.class.should == Indy
34
- @indy.for(:all).length.should == 1
33
+ @indy.all.length.should == 1
35
34
  end
36
35
 
37
-
38
36
  end
39
37
 
40
38
  context 'instance' do
41
39
 
42
- before(:all) do
43
- @indy = Indy.new(:source => '1/2/2002 string', :log_format => ['([^\s]+) (\w+)', :time, :message])
40
+ before(:each) do
41
+ log = [ "2000-09-07 14:06:41 INFO MyApp - Entering APPLICATION.",
42
+ "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.",
43
+ "2000-09-07 14:07:43 INFO MyApp - Exiting APPLICATION."].join("\n")
44
+ @indy = Indy.search(log)
44
45
  end
45
46
 
46
47
  context "method" do
47
48
 
48
- it "parse_line() should return a hash" do
49
- @indy.send(:parse_line, "1/2/2002 string").class.should == Hash
49
+ it "#with should return self" do
50
+ @indy.with().class.should == Indy
50
51
  end
51
52
 
52
- it "parse_line() should return :time and :message" do
53
- hash = @indy.send(:parse_line, "1/2/2002 string")
54
- hash[:time] == "1/2/2002"
55
- hash[:message] == "string"
53
+ it "#with should use default log pattern when passed :default" do
54
+ @indy.with(:default).all.length.should == 3
56
55
  end
57
56
 
58
- end
57
+ it "should raise ArgumentError when regexp captures don't match fields" do
58
+ log = [ "2000-09-07 14:06:41 INFO MyApp - Entering APPLICATION.",
59
+ "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION."].join("\n")
60
+ lambda{ Indy.search(log).
61
+ with(:entry_regexp => Indy::LogFormats::DEFAULT_ENTRY_REGEXP, :entry_fields => [:field_one]).
62
+ all.length.should > 0
63
+ }.should raise_error ArgumentError
64
+ end
59
65
 
60
- end
66
+ [:for, :like, :matching].each do |method|
67
+ it "##{method} should exist" do
68
+ @indy.should respond_to(method)
69
+ end
70
+
71
+ it "##{method} should accept a hash of search criteria" do
72
+ @indy.send(method,:severity => "INFO").should be_kind_of(Array)
73
+ end
74
+
75
+ it "##{method} should return a set of results" do
76
+ @indy.send(method,:severity => "DEBUG").should be_kind_of(Array)
77
+ end
78
+ end
79
+
80
+ it "#last should return self" do
81
+ @indy.last(:span => 1).should be_kind_of Indy
82
+ end
83
+
84
+ it "#last should set the time scope to the correct number of minutes" do
85
+ @indy.last(:span => 1).all.count.should == 2
86
+ end
61
87
 
62
- context ':search' do
88
+ it "#last should raise an error if passed an invalid parameter" do
89
+ lambda{ @indy.last('a') }.should raise_error( ArgumentError )
90
+ lambda{ @indy.last() }.should raise_error( ArgumentError )
91
+ lambda{ @indy.last(nil) }.should raise_error( ArgumentError )
92
+ lambda{ @indy.last({}) }.should raise_error( ArgumentError )
93
+ end
63
94
 
64
- let(:log_file) { "#{File.dirname(__FILE__)}/data.log" }
95
+ end
96
+ end
97
+
98
+ context '#search' do
65
99
 
66
100
  it "should be a class method" do
67
101
  Indy.should respond_to(:search)
@@ -71,55 +105,41 @@ describe 'Indy' do
71
105
  Indy.search("String Log").class.should == Indy
72
106
  end
73
107
 
74
- it "should accept a :cmd symbol and a command string parameter" do
75
- Indy.search(:cmd =>"ls").class.should == Indy
76
- end
77
-
78
- it "should return an instance of Indy" do
79
- Indy.search("source string").should be_kind_of(Indy)
80
- Indy.search(:cmd => "ls").should be_kind_of(Indy)
108
+ it "should accept a hash with :cmd key" do
109
+ Indy.search(:cmd => "ls").class.should == Indy
81
110
  end
82
111
 
83
- it "should return an instance of Indy" do
84
- Indy.search(:source => {:cmd => 'ls'}, :log_format => Indy::DEFAULT_LOG_FORMAT).class.should == Indy
112
+ it "should accept a hash with :file => filepath" do
113
+ Indy.search(:file => "#{File.dirname(__FILE__)}/data.log").all.length.should == 2
85
114
  end
86
115
 
87
-
88
- it "should create an instance of Indy::Source" do
89
- Indy.search("source string").instance_variable_get(:@source).should be_kind_of(Indy::Source)
116
+ it "should accept a hash with :file => File" do
117
+ Indy.search(:file => File.open("#{File.dirname(__FILE__)}/data.log")).all.length.should == 2
90
118
  end
91
119
 
92
- it "the instance should have the source specified" do
93
- Indy.search("source string").source.should_not be_nil
94
- Indy.search(:cmd => "ls").source.should_not be_nil
120
+ it "should accept a valid :source hash" do
121
+ Indy.search(:source => {:cmd => 'ls'}).class.should == Indy
95
122
  end
96
123
 
97
- it "the instance should raise an exception when passed an invalid source" do
98
- lambda{ Indy.search(nil) }.should raise_error Indy::Source::Invalid
124
+ it "should create an instance of Indy::Source in Search object" do
125
+ Indy.search("source string").search.source.should be_kind_of(Indy::Source)
99
126
  end
100
127
 
101
- it "the instance should raise an exception when passed an invalid source: nil" do
102
- lambda{ Indy.search(nil) }.should raise_error Indy::Source::Invalid
128
+ it "should raise an exception when passed an invalid source: nil" do
129
+ lambda{ Indy.search(nil) }.should raise_error(Indy::Source::Invalid, /No source specified/)
103
130
  end
104
131
 
105
- it "the instance should raise an exception when the arity is incorrect" do
132
+ it "should raise an exception when the arity is incorrect" do
106
133
  lambda{ Indy.search( ) }.should raise_error Indy::Source::Invalid
107
134
  end
108
135
 
109
- context "treat it second like a string" do
110
-
111
- it "should attempt to treat it as a string" do
112
- string = "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION."
113
- string_io = StringIO.new(string)
114
- StringIO.should_receive(:new).with(string).ordered.and_return(string_io)
115
- Indy.search(string).for(:application => 'MyApp').length.should == 1
116
- end
117
-
118
- end
119
-
120
136
  context "with explicit source hash" do
121
137
 
122
- context ":cmd" do
138
+ context "using :cmd" do
139
+
140
+ before(:all) do
141
+ Dir.chdir(File.dirname(__FILE__))
142
+ end
123
143
 
124
144
  it "should attempt open the command" do
125
145
  IO.stub!(:popen).with('ssh user@system "bash --login -c \"cat /var/log/standard.log\" "')
@@ -131,56 +151,80 @@ describe 'Indy' do
131
151
  Indy.search(:cmd => "an invalid command").class.should == Indy
132
152
  end
133
153
 
134
- it "should return an IO object upon a successful command" do
154
+ it "should use IO.popen on cmd value" do
135
155
  IO.stub!(:popen).with("a command").and_return(StringIO.new("2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION."))
136
156
  Indy.search(:cmd => "a command").for(:application => 'MyApp').length.should == 1
137
157
  end
138
158
 
139
159
  it "should handle a real command" do
140
- Indy.search(:cmd => "cat #{log_file}").for(:application => 'MyApp').length.should == 2
160
+ log_file = "data.log"
161
+ cat_cmd = (is_windows? ? 'type' : 'cat')
162
+ Indy.search(:cmd => "#{cat_cmd} #{log_file}").for(:application => 'MyApp').length.should == 2
141
163
  end
142
164
 
143
- it "should return an IO object upon a successful command" do
165
+ it "should raise Source::Invalid for an invalid command" do
144
166
  IO.stub!(:popen).with("zzzzzzzzzzzz").and_return('Invalid command')
145
- lambda{ Indy.search(:cmd => "zzzzzzzzzzzz").for(:all) }.should raise_error( Indy::Source::Invalid, /Unable to open log source/)
146
- end
147
-
148
- it "should raise error for an invalid command" do
149
- lambda{ Indy.search(:cmd => "zzzzzzzzzzzz").for(:all) }.should raise_error( Indy::Source::Invalid, /Unable to open log source/)
167
+ lambda{ Indy.search(:cmd => "zzzzzzzzzzzz").all }.should raise_error( Indy::Source::Invalid, /Unable to open log source/)
150
168
  end
151
169
 
152
170
  end
153
171
 
154
- it ":file" do
172
+ it "using :file" do
155
173
  require 'tempfile'
156
174
  file = stub!(:size).and_return(1)
157
175
  lambda{ Indy.search(:file => file) }
158
176
  end
159
177
 
160
- it ":string" do
178
+ it "using :string" do
161
179
  string = "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION."
162
180
  string_io = StringIO.new(string)
163
181
  StringIO.should_receive(:new).with(string).ordered.and_return(string_io)
164
182
  Indy.search(:string => string).for(:application => 'MyApp').length.should == 1
165
183
  end
166
184
 
167
- it "should raise error when invalid" do
168
- lambda{ Indy.search(:foo => "a string").for(:all) }.should raise_error( Indy::Source::Invalid )
185
+ it "should raise error when given an invalid key" do
186
+ lambda{ Indy.search(:foo => "a string").all }.should raise_error( Indy::Source::Invalid )
169
187
  end
170
188
 
171
189
  end
172
190
 
173
191
  end
174
192
 
175
- context "bad data" do
193
+ context "data handling" do
176
194
 
177
- before(:each) do
178
- log = "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.\n \n2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.\n bad \n2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.\n\n"
179
- @indy = Indy.search(log)
195
+ it "should return all entries using #all" do
196
+ log = [ "2000-09-07 14:06:41 INFO MyApp - Entering APPLICATION.",
197
+ "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.",
198
+ "2000-09-07 14:07:43 INFO MyApp - Exiting APPLICATION."].join("\n")
199
+ Indy.search(log).all.length.should == 3
200
+ end
201
+
202
+ it "should ignore invalid entries" do
203
+ log = ["2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.\n \n",
204
+ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.\n",
205
+ " bad \n",
206
+ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.\n\n"].join("\n")
207
+ Indy.search(log).all.length.should == 3
180
208
  end
181
209
 
182
- it "should find all 3 rows" do
183
- @indy.for(:all).length.should == 3
210
+ it "should handle no matching entries" do
211
+ log = ["2000-09-07 MyApp - Entering APPLICATION.\n \n",
212
+ "2000-09-07 14:07:41\n"].join
213
+ Indy.search(log).all.length.should == 0
214
+ end
215
+
216
+ context "with explicit time format" do
217
+
218
+ it "returns correct number of records" do
219
+ log = ["09-2000-07 INFO MyApp - Entering APPLICATION.\n \n",
220
+ "09-2000-07 INFO MyApp - Opening APPLICATION.\n",
221
+ "2000-09-07 INFO MyApp - Invalid Entry\n"].join
222
+ indy = Indy.new(:source => log,
223
+ :time_format => '%d-%Y-%m',
224
+ :entry_regexp => /^(\d\d-\d\d\d\d-\d\d)\s+(#{Indy::LogFormats::DEFAULT_SEVERITY_PATTERN})\s+(#{Indy::LogFormats::DEFAULT_APPLICATION})\s+-\s+(#{Indy::LogFormats::DEFAULT_MESSAGE})$/,
225
+ :entry_fields => Indy::LogFormats::DEFAULT_ENTRY_FIELDS)
226
+ indy.all.length.should == 2
227
+ end
184
228
  end
185
229
 
186
230
  end
@@ -188,29 +232,29 @@ describe 'Indy' do
188
232
  context "multiline log mode" do
189
233
 
190
234
  before(:each) do
191
- log = [ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION with data:\nfirst Application data.",
192
- "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.",
193
- " ",
194
- "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION with data:\nApplication data.",
195
- "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.",
196
- "2000-09-07 14:07:43 INFO MyApp - Exiting APPLICATION with data:\nApplications data\nMore data\n\tlast Application data."].join("\n")
235
+ log = [ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION with data:\nfirst Application data. AAA",
236
+ "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION. BBB",
237
+ "2000-09-07 14:07:43 INFO MyApp - Entering APPLICATION with data:\nApplication data. CCC",
238
+ "2000-09-07 14:07:44 DEBUG MyApp - Initializing APPLICATION. DDD",
239
+ "2000-09-07 14:07:45 INFO MyApp - Exiting APPLICATION with data:\nApplications data\nMore data\n\tlast Application data. EEE"].join("\n")
197
240
  regexp = "^((#{Indy::LogFormats::DEFAULT_DATE_TIME})\\s+(#{Indy::LogFormats::DEFAULT_SEVERITY_PATTERN})\\s+(#{Indy::LogFormats::DEFAULT_APPLICATION})\\s+-\\s+(.*?)(?=#{Indy::LogFormats::DEFAULT_DATE_TIME}|\\z))"
198
241
  @indy = Indy.new(:source => log, :log_format => [regexp, :time,:severity,:application,:message], :multiline => true )
199
242
  end
200
243
 
201
- it "should find the first row" do
202
- results = @indy.for(:all)
203
- results.first.message.should match(/first Application data.$/)
244
+ it "should return all entries using #all" do
245
+ @indy.all.count.should == 5
246
+ end
247
+
248
+ it "should return correct number of entries with #for" do
249
+ @indy.for(:severity => 'INFO').count.should == 3
204
250
  end
205
251
 
206
- it "should find the last row" do
207
- results = @indy.for(:all)
208
- results.last.message.should match(/\tlast Application data.$/)
209
- results.length.should == 5
252
+ it "should return correct number of entries with #like" do
253
+ @indy.like(:message => 'ntering').count.should == 2
210
254
  end
211
255
 
212
- it "should find using time based search" do
213
- results = @indy.before(:time => '2000-09-07 14:07:42', :inclusive => false).for(:all)
256
+ it "should return correct number of entries using #after time scope" do
257
+ results = @indy.after(:time => '2000-09-07 14:07:43', :inclusive => false).all
214
258
  results.length.should == 2
215
259
  end
216
260
 
@@ -220,156 +264,39 @@ describe 'Indy' do
220
264
 
221
265
  def log
222
266
  [ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
223
- "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.",
224
- "2000-09-07 14:07:43 INFO MyApp - Exiting APPLICATION."].join("\n")
267
+ "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.",
268
+ "2000-09-07 14:07:43 INFO MyApp - Exiting APPLICATION."].join("\n")
225
269
  end
226
270
 
227
- it "should allow a block with :for and yield on each line of the results using :all" do
271
+ it "with #for should yield Struct::Entry" do
272
+ Indy.search(log).all do |result|
273
+ result.should be_kind_of(Struct::Entry)
274
+ end
275
+ end
276
+
277
+ it "with #for using :all should yield each entry" do
228
278
  actual_yield_count = 0
229
- Indy.search(log).for(:all) do |result|
230
- result.should be_kind_of(Struct::Line)
231
- actual_yield_count = actual_yield_count + 1
279
+ Indy.search(log).all do |result|
280
+ actual_yield_count += 1
232
281
  end
233
282
  actual_yield_count.should == 3
234
283
  end
235
284
 
236
- it "should allow a block with :for and yield on each line of the results" do
285
+ it "with #for should yield each entry" do
237
286
  actual_yield_count = 0
238
287
  Indy.search(log).for(:severity => 'INFO') do |result|
239
- result.should be_kind_of(Struct::Line)
240
- actual_yield_count = actual_yield_count + 1
288
+ actual_yield_count += 1
241
289
  end
242
290
  actual_yield_count.should == 2
243
291
  end
244
292
 
245
- it "should allow a block with :like and yield on each line of the results" do
293
+ it "with #like should yield each entry" do
246
294
  actual_yield_count = 0
247
295
  Indy.search(log).like(:message => '\be\S+ing') do |result|
248
- result.should be_kind_of(Struct::Line)
249
- actual_yield_count = actual_yield_count + 1
296
+ actual_yield_count += 1
250
297
  end
251
298
  actual_yield_count.should == 2
252
299
  end
253
300
 
254
301
  end
255
-
256
-
257
- context "instance" do
258
-
259
- before(:each) do
260
- log = [ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
261
- "2000-09-07 14:07:42 DEBUG MyApp - Initializing APPLICATION.",
262
- "2000-09-07 14:07:43 INFO MyApp - Exiting APPLICATION."].join("\n")
263
- @indy = Indy.search(log)
264
- end
265
-
266
- it "with() should be a method" do
267
- @indy.should respond_to(:with)
268
- end
269
-
270
- it "with() should accept the log4r default pattern const without error" do
271
- @indy.with(Indy::LOG4R_DEFAULT_FORMAT).class.should == Indy
272
- end
273
-
274
- it "with() should accept :default without error" do
275
- @indy.with(:default).class.should == Indy
276
- end
277
-
278
- it "with() should use default log pattern when passed :default" do
279
- @indy.with(:default).for(:all).length.should == 3
280
- end
281
-
282
- it "with() should accept no params without error" do
283
- @indy.with().class.should == Indy
284
- end
285
-
286
- it "should return itself" do
287
- @indy.with(:default).should == @indy
288
- end
289
-
290
- [:for, :like, :matching].each do |method|
291
- it "#{method}() should exist" do
292
- @indy.should respond_to(method)
293
- end
294
-
295
- it "#{method}() should accept a hash of search criteria" do
296
- @indy.send(method,:severity => "INFO").class.should == Array
297
- end
298
-
299
- it "#{method}() should return a set of results" do
300
- @indy.send(method,:severity => "DEBUG").should be_kind_of(Array)
301
- end
302
-
303
- end
304
-
305
- context "_search" do
306
-
307
- before(:each) do
308
- @results = @indy.send(:_search) {|result| result if result[:application] == "MyApp" }
309
- end
310
-
311
- it "should not return nil" do
312
- @results.should_not be_nil
313
- @results.should be_kind_of(Array)
314
- @results.should_not be_empty
315
- end
316
-
317
- it "should return an array of results" do
318
- @results.length.should == 3
319
- @results.first[:application].should == "MyApp"
320
- end
321
-
322
- end
323
- end
324
-
325
- context 'last_entry method' do
326
-
327
- before(:all) do
328
- @indy = Indy.search("2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.\n2000-09-07 14:07:42 INFO MyApp - Entering APPLICATION.")
329
- end
330
-
331
- it "should return a Struct::Line object" do
332
- @indy.send(:last_entry).class.should == Struct::Line
333
- end
334
-
335
- it "should return correct Struct::Line objects" do
336
- @indy.send(:last_entry).time.should == '2000-09-07 14:07:42'
337
- end
338
-
339
- end
340
-
341
- context 'last_entries method' do
342
-
343
- before(:all) do
344
- @indy = Indy.search("2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.\n2000-09-07 14:07:42 INFO MyApp - Entering APPLICATION.")
345
- end
346
-
347
- it "should return a an array of Struct::Line object" do
348
- @indy.send(:last_entries, 2).class.should == Array
349
- @indy.send(:last_entries, 2).first.class.should == Struct::Line
350
- end
351
-
352
- it "should return correct Struct::Line objects" do
353
- @indy.send(:last_entries, 2).first.time.should == '2000-09-07 14:07:42'
354
- end
355
-
356
- end
357
-
358
- context 'source' do
359
- before(:each) do
360
- @indy = Indy.search(
361
- [ "2000-09-07 14:07:41 INFO MyApp - Entering APPLICATION.",
362
- "2000-09-07 14:08:41 INFO MyApp - Initializing APPLICATION.",
363
- "2000-09-07 14:09:41 INFO MyApp - Configuring APPLICATION.",
364
- "2000-09-07 14:10:50 INFO MyApp - Running APPLICATION.",
365
- "2000-09-07 14:11:42 INFO MyApp - Exiting APPLICATION.",
366
- "2000-09-07 14:12:15 INFO MyApp - Exiting APPLICATION."
367
- ].join("\n") )
368
- end
369
-
370
- it "should know how many lines it contains" do
371
- @indy.source.send(:num_lines).should == 6
372
- end
373
- end
374
-
375
302
  end