request-log-analyzer 1.2.1 → 1.2.6

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.
Files changed (44) hide show
  1. data/.gitignore +10 -0
  2. data/Rakefile +3 -1
  3. data/lib/request_log_analyzer/aggregator/database.rb +79 -46
  4. data/lib/request_log_analyzer/controller.rb +12 -7
  5. data/lib/request_log_analyzer/file_format/merb.rb +5 -7
  6. data/lib/request_log_analyzer/line_definition.rb +9 -0
  7. data/lib/request_log_analyzer/request.rb +2 -2
  8. data/lib/request_log_analyzer/source/log_parser.rb +4 -0
  9. data/lib/request_log_analyzer.rb +1 -1
  10. data/request-log-analyzer.gemspec +36 -0
  11. data/spec/fixtures/header_and_footer.log +6 -0
  12. data/spec/fixtures/merb_prefixed.log +9 -0
  13. data/spec/integration/command_line_usage_spec.rb +0 -2
  14. data/spec/lib/{helper.rb → helpers.rb} +1 -3
  15. data/spec/lib/macros.rb +2 -0
  16. data/spec/lib/matchers.rb +63 -0
  17. data/spec/lib/mocks.rb +12 -1
  18. data/spec/lib/testing_format.rb +6 -0
  19. data/spec/spec.opts +3 -0
  20. data/spec/spec_helper.rb +13 -4
  21. data/spec/unit/aggregator/database_spec.rb +234 -0
  22. data/spec/unit/aggregator/summarizer_spec.rb +0 -2
  23. data/spec/unit/controller/controller_spec.rb +0 -2
  24. data/spec/unit/controller/log_processor_spec.rb +0 -2
  25. data/spec/unit/file_format/file_format_api_spec.rb +50 -71
  26. data/spec/unit/file_format/line_definition_spec.rb +49 -45
  27. data/spec/unit/file_format/merb_format_spec.rb +20 -2
  28. data/spec/unit/file_format/rails_format_spec.rb +0 -2
  29. data/spec/unit/filter/anonymize_filter_spec.rb +0 -1
  30. data/spec/unit/filter/field_filter_spec.rb +0 -3
  31. data/spec/unit/filter/filter_spec.rb +17 -0
  32. data/spec/unit/filter/timespan_filter_spec.rb +0 -3
  33. data/spec/unit/source/log_parser_spec.rb +5 -4
  34. data/spec/unit/source/request_spec.rb +91 -52
  35. data/spec/unit/tracker/duration_tracker_spec.rb +0 -6
  36. data/spec/unit/tracker/frequency_tracker_spec.rb +0 -6
  37. data/spec/unit/tracker/hourly_spread_spec.rb +0 -4
  38. data/spec/unit/tracker/timespan_tracker_spec.rb +0 -4
  39. data/spec/unit/tracker/tracker_api_spec.rb +0 -2
  40. data/tasks/github-gem.rake +199 -192
  41. metadata +120 -92
  42. data/RELEASE_NOTES.rdoc +0 -10
  43. data/spec/unit/aggregator/database_inserter_spec.rb +0 -106
  44. data/tasks/rspec.rake +0 -12
@@ -0,0 +1,234 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RequestLogAnalyzer::Aggregator::Database do
4
+
5
+ before(:all) do
6
+ log_parser = RequestLogAnalyzer::Source::LogParser.new(testing_format)
7
+ @database_inserter = RequestLogAnalyzer::Aggregator::Database.new(log_parser, :database => ':memory:')
8
+
9
+ @line_definition = RequestLogAnalyzer::LineDefinition.new(:test, { :regexp => /Testing (\w+), tries\: (\d+)/,
10
+ :captures => [{ :name => :what, :type => :string }, { :name => :tries, :type => :integer },
11
+ { :name => :evaluated, :type => :hash, :provides => {:evaluated_field => :duration} }]})
12
+ end
13
+
14
+ # The prepare method is called before the parsing starts. It should establish a connection
15
+ # to a database that is suitable for inserting requests later on.
16
+ describe '#prepare' do
17
+
18
+ before(:each) do
19
+ @database_inserter.stub!(:initialize_orm_module!)
20
+ @database_inserter.stub!(:establish_database_connection!)
21
+ @database_inserter.stub!(:create_database_schema!)
22
+ end
23
+
24
+ it 'should create the ORM mdoule in which the classes can be created' do
25
+ @database_inserter.should_receive(:initialize_orm_module!)
26
+ @database_inserter.prepare
27
+ end
28
+
29
+ it 'should establish the database connection' do
30
+ @database_inserter.should_receive(:establish_database_connection!)
31
+ @database_inserter.prepare
32
+ end
33
+
34
+ it 'should create the database schema during preparation' do
35
+ @database_inserter.should_receive(:create_database_schema!)
36
+ @database_inserter.prepare
37
+ end
38
+ end
39
+
40
+ # The database inserter creates is own "Database" module within the file format
41
+ # class to create all the classes that are needed.
42
+ describe '#initialize_orm_module!' do
43
+
44
+ before(:all) { @database_inserter.send(:deinitialize_orm_module!) }
45
+ after(:all) { @database_inserter.send(:initialize_orm_module!) }
46
+
47
+ before(:each) { @database_inserter.send(:initialize_orm_module!) }
48
+ after(:each) { @database_inserter.send(:deinitialize_orm_module!) }
49
+
50
+ it "should create a Database module under the file format's class" do
51
+ testing_format.class.should be_const_defined('Database')
52
+ end
53
+
54
+ it "should define a Base class in the Database module" do
55
+ testing_format.class::Database.should be_const_defined('Base')
56
+ end
57
+
58
+ it "should create a ActiveRecord::Base class in the Database module" do
59
+ testing_format.class::Database::Base.ancestors.should include(ActiveRecord::Base)
60
+ end
61
+
62
+ end
63
+
64
+ # The create_database_table method should create a database table according to the line definition,
65
+ # so that parsed lines can be stored in it later on.
66
+ describe '#create_database_table' do
67
+
68
+ before(:each) do
69
+ @connection = mock_migrator
70
+ @database_inserter.stub!(:connection).and_return(@connection)
71
+ end
72
+
73
+ it "should create a table based on the line type name" do
74
+ @connection.should_receive(:create_table).with('test_lines')
75
+ @database_inserter.send(:create_database_table, @line_definition)
76
+ end
77
+
78
+ it "should create an index on the request_id field" do
79
+ @connection.should_receive(:add_index).with('test_lines', [:request_id])
80
+ @database_inserter.send(:create_database_table, @line_definition)
81
+ end
82
+
83
+ it "should create a request_id field to link the requests together" do
84
+ @connection.table_creator.should_receive(:column).with(:request_id, :integer)
85
+ @database_inserter.send(:create_database_table, @line_definition)
86
+ end
87
+
88
+ it "should create a lineno field to save the location of the line in the original file" do
89
+ @connection.table_creator.should_receive(:column).with(:lineno, :integer)
90
+ @database_inserter.send(:create_database_table, @line_definition)
91
+ end
92
+
93
+ it "should create a field of the correct type for every defined field" do
94
+ @connection.table_creator.should_receive(:column).with(:what, :string)
95
+ @connection.table_creator.should_receive(:column).with(:tries, :integer)
96
+ # :hash capture type should map on a :text field type
97
+ @connection.table_creator.should_receive(:column).with(:evaluated, :text)
98
+ @database_inserter.send(:create_database_table, @line_definition)
99
+ end
100
+
101
+ it "should create a field of the correct type for every provided field" do
102
+ # :duration capture type should map on a :double field type
103
+ @connection.table_creator.should_receive(:column).with(:evaluated_field, :double)
104
+ @database_inserter.send(:create_database_table, @line_definition)
105
+ end
106
+ end
107
+
108
+ describe '#create_activerecord_class' do
109
+ before(:each) do
110
+ # Make sure the ORM module exists
111
+ @database_inserter.send(:initialize_orm_module!)
112
+
113
+ # Mockthe request ORM class
114
+ @request_class = mock('Request ActiveRecord::Base class')
115
+ @request_class.stub!(:has_many)
116
+ @database_inserter.stub!(:request_class).and_return(@request_class)
117
+ end
118
+
119
+ it "should register the constant for the line type AR class" do
120
+ @database_inserter.send(:create_activerecord_class, @line_definition)
121
+ @database_inserter.orm_module.const_defined?('TestLine').should be_true
122
+ end
123
+
124
+ it "should create a class that inherits from ActiveRecord::Base and the base class of the ORM module" do
125
+ @database_inserter.send(:create_activerecord_class, @line_definition)
126
+ @database_inserter.orm_module.const_get('TestLine').ancestors.should include(ActiveRecord::Base, @database_inserter.orm_module::Base)
127
+ end
128
+
129
+ describe 'defining the new ORM class' do
130
+ before(:each) do
131
+ # Mock the newly created ORM class for the test_line
132
+ @orm_class = mock('Line ActiveRecord::Base class')
133
+ @orm_class.stub!(:belongs_to)
134
+ @orm_class.stub!(:serialize)
135
+ Class.stub!(:new).and_return(@orm_class)
136
+ end
137
+
138
+ it "should create a has_many relation on the Request class" do
139
+ @request_class.should_receive(:has_many).with(:test_lines)
140
+ @database_inserter.send(:create_activerecord_class, @line_definition)
141
+ end
142
+
143
+ it "should create a belongs_to relation to the request class" do
144
+ @orm_class.should_receive(:belongs_to).with(:request)
145
+ @database_inserter.send(:create_activerecord_class, @line_definition)
146
+ end
147
+
148
+ it "should serialize the :evaluate field into the database" do
149
+ @orm_class.should_receive(:serialize).with(:evaluated, Hash)
150
+ @database_inserter.send(:create_activerecord_class, @line_definition)
151
+ end
152
+ end
153
+ end
154
+
155
+ describe '#create_database_schema!' do
156
+
157
+ before(:each) do
158
+ @line_type_cnt = testing_format.line_definitions.length
159
+
160
+ @connection = mock_migrator
161
+ @database_inserter.stub!(:connection).and_return(@connection)
162
+
163
+ # Stub the expected method calls for the preparation
164
+ @database_inserter.stub!(:create_database_table)
165
+ @database_inserter.stub!(:create_activerecord_class)
166
+
167
+ # Make sure the ORM module exists
168
+ @database_inserter.send(:initialize_orm_module!)
169
+ end
170
+
171
+ it "should create a requests table to join request lines" do
172
+ @connection.should_receive(:create_table).with("requests")
173
+ @database_inserter.send :create_database_schema!
174
+ end
175
+
176
+ it "should create a Request class inheriting from ActiveRecord and the base class of the ORM module" do
177
+ @database_inserter.send :create_database_schema!
178
+ @database_inserter.request_class.ancestors.should include(ActiveRecord::Base, @database_inserter.orm_module::Base)
179
+ end
180
+
181
+ it "should create a warnings table for logging parse warnings" do
182
+ @connection.should_receive(:create_table).with("warnings")
183
+ @database_inserter.send :create_database_schema!
184
+ end
185
+
186
+ it "should create a Warnng class inheriting from ActiveRecord and the base class of the ORM module" do
187
+ @database_inserter.send :create_database_schema!
188
+ @database_inserter.warning_class.ancestors.should include(ActiveRecord::Base, @database_inserter.orm_module::Base)
189
+ end
190
+
191
+ it "should create a table for every line type" do
192
+ @database_inserter.should_receive(:create_database_table).with(an_instance_of(RequestLogAnalyzer::LineDefinition)).exactly(@line_type_cnt).times
193
+ @database_inserter.send :create_database_schema!
194
+ end
195
+
196
+ it "should create a ORM for every line type" do
197
+ @database_inserter.should_receive(:create_activerecord_class).with(an_instance_of(RequestLogAnalyzer::LineDefinition)).exactly(@line_type_cnt).times
198
+ @database_inserter.send :create_database_schema!
199
+ end
200
+ end
201
+
202
+ describe '#aggregate' do
203
+ before(:each) do
204
+ @database_inserter.prepare
205
+
206
+ @incomplete_request = testing_format.request( {:line_type => :first, :request_no => 564})
207
+ @completed_request = testing_format.request( {:line_type => :first, :request_no => 564},
208
+ {:line_type => :test, :test_capture => "awesome"},
209
+ {:line_type => :test, :test_capture => "indeed"},
210
+ {:line_type => :eval, :evaluated => { :greating => 'howdy'}, :greating => 'howdy' },
211
+ {:line_type => :last, :request_no => 564})
212
+ end
213
+
214
+ it "should insert a record in the request table" do
215
+ TestingFormat::Database::Request.count.should == 0
216
+ @database_inserter.aggregate(@incomplete_request)
217
+ TestingFormat::Database::Request.count.should == 1
218
+ end
219
+
220
+ it "should insert records in all relevant line tables" do
221
+ @database_inserter.aggregate(@completed_request)
222
+ request = TestingFormat::Database::Request.first
223
+ request.should have(2).test_lines
224
+ request.should have(1).first_lines
225
+ request.should have(1).eval_lines
226
+ request.should have(1).last_lines
227
+ end
228
+
229
+ it "should log a warning in the warnings table" do
230
+ TestingFormat::Database::Warning.should_receive(:create!).with(hash_including(:warning_type => 'test_warning'))
231
+ @database_inserter.warning(:test_warning, "Testing the warning system", 12)
232
+ end
233
+ end
234
+ end
@@ -1,8 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Aggregator::Summarizer do
4
-
5
- include RequestLogAnalyzer::Spec::Helper
6
4
 
7
5
  before(:each) do
8
6
  @summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(mock_source, :output => mock_output)
@@ -2,8 +2,6 @@ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Controller do
4
4
 
5
- include RequestLogAnalyzer::Spec::Helper
6
-
7
5
  it "should use a custom output generator correctly" do
8
6
 
9
7
  mock_output = mock('RequestLogAnalyzer::Output::Base')
@@ -4,8 +4,6 @@ require 'request_log_analyzer/log_processor'
4
4
 
5
5
  describe RequestLogAnalyzer::LogProcessor, 'stripping log files' do
6
6
 
7
- include RequestLogAnalyzer::Spec::Helper
8
-
9
7
  before(:each) do
10
8
  @log_stripper = RequestLogAnalyzer::LogProcessor.new(testing_format, :strip, {})
11
9
  end
@@ -1,90 +1,69 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
- describe RequestLogAnalyzer::FileFormat, :format_definition do
3
+ describe RequestLogAnalyzer::FileFormat do
4
+
5
+ describe ".format_definition" do
4
6
 
5
- before(:each) do
6
- @first_file_format = Class.new(RequestLogAnalyzer::FileFormat::Base)
7
- @second_file_format = Class.new(RequestLogAnalyzer::FileFormat::Base)
8
- end
9
-
10
- it "should specify lines with a hash" do
11
-
12
- @first_file_format.new.should have(0).line_definitions
13
-
14
- @first_file_format.format_definition do |line|
15
- line.hash_test :regexp => /test/, :captures => []
7
+ before(:each) do
8
+ @first_file_format = Class.new(RequestLogAnalyzer::FileFormat::Base)
9
+ @second_file_format = Class.new(RequestLogAnalyzer::FileFormat::Base)
16
10
  end
17
11
 
18
- @format_instance = @first_file_format.new
19
- @format_instance.should have(1).line_definitions
20
- @format_instance.line_definitions[:hash_test].should_not be_nil
21
- end
22
-
23
- it "should specift lines directly" do
24
- @first_file_format.new.should have(0).line_definitions
25
-
26
- @first_file_format.format_definition.direct_test do |line|
27
- line.regexp = /test/
28
- end
29
-
30
- @first_file_format.new.line_definitions[:direct_test].should_not be_nil
31
- end
12
+ it "should specify line definitions directly within the file_format" do
13
+ @first_file_format.format_definition.direct_test :regexp => /test/
14
+ @first_file_format.should have_line_definition(:direct_test)
15
+ end
32
16
 
33
- it "specify lines with a block" do
34
-
35
- @first_file_format.new.should have(0).line_definitions
17
+ it "specify lines with a block for the format definition" do
18
+ @first_file_format.format_definition do |format|
19
+ format.block_test :regexp => /test (\w+)/, :captures => [:tester]
20
+ end
21
+
22
+ @first_file_format.should have_line_definition(:block_test).capturing(:tester)
23
+ end
36
24
 
37
- @first_file_format.format_definition do |format|
38
- format.block_test do |line|
25
+ it "should specify a line with a block" do
26
+ @first_file_format.format_definition.hash_test do |line|
39
27
  line.regexp = /test/
40
28
  line.captures = []
41
29
  end
42
- end
43
-
44
- @first_file_format.new.line_definitions[:block_test].should_not be_nil
45
- end
46
-
47
- it "should define lines only for itself" do
48
30
 
49
- @first_file_format.format_definition do |line|
50
- line.first_test :regexp => /test/, :captures => []
31
+ @first_file_format.should have_line_definition(:hash_test)
51
32
  end
52
-
53
-
54
- @second_file_format.format_definition do |line|
55
- line.second_test :regexp => /test/, :captures => []
56
- end
57
-
58
- @first_file_format.line_definer.should_not eql(@second_file_format.line_definer)
59
- @first_file_format.new.should have(1).line_definitions
60
- @second_file_format.new.line_definitions[:second_test].should_not be_nil
61
- end
62
- end
63
-
64
- describe RequestLogAnalyzer::FileFormat, :load do
65
-
66
- include RequestLogAnalyzer::Spec::Helper
67
-
68
- it "should return an instance of a FileFormat class" do
69
- @file_format = RequestLogAnalyzer::FileFormat.load(TestingFormat)
70
- @file_format.should be_kind_of(TestingFormat)
33
+
34
+ it "should define lines only for its own language" do
35
+ @first_file_format.format_definition.first :regexp => /test 123/
36
+ @second_file_format.format_definition.second :regexp => /test 456/
37
+
38
+ @first_file_format.should have_line_definition(:first)
39
+ @first_file_format.should_not have_line_definition(:second)
40
+ @second_file_format.should_not have_line_definition(:first)
41
+ @second_file_format.should have_line_definition(:second)
42
+ end
71
43
  end
72
44
 
45
+ describe ".load" do
73
46
 
74
- it "should return itself if it already is a FileFormat::Base instance" do
75
- @file_format = RequestLogAnalyzer::FileFormat.load(testing_format)
76
- @file_format.should be_kind_of(TestingFormat)
77
- end
47
+ it "should return an instance of a FileFormat class" do
48
+ @file_format = RequestLogAnalyzer::FileFormat.load(TestingFormat)
49
+ @file_format.should be_kind_of(TestingFormat)
50
+ end
78
51
 
79
- it "should load a predefined file format from the /file_format dir" do
80
- @file_format = RequestLogAnalyzer::FileFormat.load(:rails)
81
- @file_format.should be_kind_of(RequestLogAnalyzer::FileFormat::Rails)
82
- end
52
+ it "should return itself if it already is a FileFormat::Base instance" do
53
+ @file_format = RequestLogAnalyzer::FileFormat.load(testing_format)
54
+ @file_format.should be_kind_of(TestingFormat)
55
+ end
56
+
57
+ it "should load a predefined file format from the /file_format dir" do
58
+ @file_format = RequestLogAnalyzer::FileFormat.load(:rails)
59
+ @file_format.should be_kind_of(RequestLogAnalyzer::FileFormat::Rails)
60
+ end
83
61
 
84
- it "should load a provided format file" do
85
- format_filename = File.dirname(__FILE__) + '/../../lib/testing_format.rb'
86
- @file_format = RequestLogAnalyzer::FileFormat.load(format_filename)
87
- @file_format.should be_kind_of(TestingFormat)
88
- end
62
+ it "should load a provided format file" do
63
+ format_filename = File.dirname(__FILE__) + '/../../lib/testing_format.rb'
64
+ @file_format = RequestLogAnalyzer::FileFormat.load(format_filename)
65
+ @file_format.should be_kind_of(TestingFormat)
66
+ end
89
67
 
68
+ end
90
69
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
- describe RequestLogAnalyzer::LineDefinition, :parsing do
4
-
3
+ describe RequestLogAnalyzer::LineDefinition do
4
+
5
5
  before(:each) do
6
6
  @line_definition = RequestLogAnalyzer::LineDefinition.new(:test, {
7
7
  :teaser => /Testing /,
@@ -10,55 +10,59 @@ describe RequestLogAnalyzer::LineDefinition, :parsing do
10
10
  })
11
11
  end
12
12
 
13
- it "should return false on an unmatching line" do
14
- (@line_definition =~ "nonmatching").should be_false
15
- end
16
-
17
- it "should return false when only the teaser matches" do
18
- (@line_definition =~ "Testing LineDefinition").should be_false
19
- end
13
+ describe '#matches' do
20
14
 
21
- it "should return a hash if the line matches" do
22
- (@line_definition =~ "Testing LineDefinition, tries: 123").should be_kind_of(Hash)
23
- end
15
+ it "should return false on an unmatching line" do
16
+ @line_definition.should_not parse("nonmatching")
17
+ end
24
18
 
25
- it "should return a hash with :captures set to an array" do
26
- hash = @line_definition.matches("Testing LineDefinition, tries: 123")
27
- hash[:captures][0].should == "LineDefinition"
28
- hash[:captures][1].should == "123"
29
- end
19
+ it "should return false when only the teaser matches" do
20
+ @line_definition.should_not parse("Testing LineDefinition")
21
+ end
30
22
 
31
- it "should return a hash with :line_definition set" do
32
- @line_definition.matches("Testing LineDefinition, tries: 123")[:line_definition].should == @line_definition
23
+ it "should parse a line and capture the expected values" do
24
+ @line_definition.should parse("Testing LineDefinition, tries: 123").capturing('LineDefinition', '123')
25
+ end
33
26
  end
34
- end
35
27
 
36
- describe RequestLogAnalyzer::LineDefinition, :converting do
28
+ describe '#convert_captured_values' do
37
29
 
38
- include RequestLogAnalyzer::Spec::Helper
39
-
40
- before(:each) do
41
- @file_format = testing_format
42
- @request = @file_format.request
43
- end
44
-
45
- it "should convert captures to a hash of converted values" do
46
- hash = @file_format.line_definitions[:first].convert_captured_values(["456"], @request)
47
- hash[:request_no].should == 456
48
- end
30
+ before(:each) do
31
+ @request = mock('request')
32
+ @request.stub!(:convert_value).and_return('foo')
33
+ end
34
+
35
+ it "should call convert_value for every captured value" do
36
+ @request.should_receive(:convert_value).twice
37
+ @line_definition.convert_captured_values(['test', '123'], @request)
38
+ end
39
+
40
+ it "should set the converted values" do
41
+ @line_definition.convert_captured_values(['test', '123'], @request).should == {:what => 'foo', :tries => 'foo'}
42
+ end
43
+
44
+ context 'when using :provides option' do
45
+ before(:each) do
46
+ @ld = RequestLogAnalyzer::LineDefinition.new(:test, :regexp => /Hash\: (\{.+\})/,
47
+ :captures => [{ :name => :hash, :type => :hash, :provides => {:bar => :string}}])
48
+
49
+ @request = mock('request')
49
50
 
50
- it "should convert captures to a hash" do
51
- hash = @file_format.line_definitions[:test].convert_captured_values(["great", nil], @request)
52
- hash[:test_capture].should == 'Testing is great'
53
- hash[:duration].should be_nil
51
+ @request.stub!(:convert_value).with("{:bar=>'baz'}", anything).and_return(:bar => 'baz')
52
+ @request.stub!(:convert_value).with('baz', anything).and_return('foo')
53
+ end
54
+
55
+ it "should call Request#convert_value for the initial hash and the value in the hash" do
56
+ @request.should_receive(:convert_value).with("{:bar=>'baz'}", anything).and_return(:bar => 'baz')
57
+ @request.should_receive(:convert_value).with("baz", anything)
58
+ @ld.convert_captured_values(["{:bar=>'baz'}"], @request)
59
+ end
60
+
61
+ it "should set the provides fields" do
62
+ # The captures field must be set and converted as well
63
+ @ld.convert_captured_values(["{:bar=>'baz'}"], @request)[:bar].should eql('foo')
64
+ end
65
+ end
66
+
54
67
  end
55
-
56
- it "should merge a hash capture into the line hash" do
57
- hash = @file_format.line_definitions[:eval].convert_captured_values(["{ 'greating' => 'hello', 'what' => 'world'}"], @request)
58
- hash[:evaluated].should == { :greating => "hello", :what => "world"}
59
- hash[:greating].should == 'hello'
60
- hash[:what].should == 'world'
61
- end
62
-
63
-
64
68
  end
@@ -1,7 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Source::LogParser, :merb do
4
- include RequestLogAnalyzer::Spec::Helper
5
4
 
6
5
  before(:each) do
7
6
  @log_parser = RequestLogAnalyzer::Source::LogParser.new(RequestLogAnalyzer::FileFormat.load(:merb))
@@ -24,15 +23,34 @@ describe RequestLogAnalyzer::Source::LogParser, :merb do
24
23
  @log_parser.parse_file(log_fixture(:merb))
25
24
  end
26
25
 
27
- it "should parse all details from a request correctly" do
26
+ it "should parse all details from the first request correctly" do
28
27
  request = nil
29
28
  @log_parser.parse_file(log_fixture(:merb)) { |found_request| request ||= found_request }
30
29
 
31
30
  request.should be_completed
31
+ request[:controller].should == 'session'
32
+ request[:action].should == 'destroy'
33
+ request[:method].should == 'delete'
34
+ request[:params].should be_kind_of(Hash)
32
35
  request[:timestamp].should == 20080829111023 # 'Fri Aug 29 11:10:23 +0200 2008'
33
36
  request[:dispatch_time].should == 0.243424
34
37
  request[:after_filters_time].should == 6.9e-05
35
38
  request[:before_filters_time].should == 0.213213
36
39
  request[:action_time].should == 0.241652
40
+
41
+ end
42
+
43
+ it "should parse a prefixed Merb file correctly" do
44
+ request = nil
45
+ @log_parser.parse_file(log_fixture(:merb_prefixed)) { |found_request| request ||= found_request }
46
+
47
+ request.should be_completed
48
+ request[:timestamp].should == 20090831183525
49
+ request[:controller].should == 'home'
50
+ request[:action].should == 'index'
51
+ request[:dispatch_time].should == 0.012001
52
+ request[:after_filters_time].should == 0.0
53
+ request[:before_filters_time].should == 0.0
54
+ request[:action_time].should == 0.012001
37
55
  end
38
56
  end
@@ -1,7 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Source::LogParser, "Rails" do
4
- include RequestLogAnalyzer::Spec::Helper
5
4
 
6
5
  before(:each) do
7
6
  @log_parser = RequestLogAnalyzer::Source::LogParser.new(
@@ -79,7 +78,6 @@ describe RequestLogAnalyzer::Source::LogParser, "Rails" do
79
78
  end
80
79
 
81
80
  describe RequestLogAnalyzer::FileFormat::RailsDevelopment, "Rails with development details" do
82
- include RequestLogAnalyzer::Spec::Helper
83
81
 
84
82
  before(:each) do
85
83
  @file_format = RequestLogAnalyzer::FileFormat.load(:rails_development)
@@ -1,7 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Filter::Anonymize, 'anonymize request' do
4
- include RequestLogAnalyzer::Spec::Helper
5
4
 
6
5
  before(:each) do
7
6
  @filter = RequestLogAnalyzer::Filter::Anonymize.new(testing_format)
@@ -1,7 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Filter::Field, 'string in accept mode' do
4
- include RequestLogAnalyzer::Spec::Helper
5
4
 
6
5
  before(:each) do
7
6
  @filter = RequestLogAnalyzer::Filter::Field.new(testing_format, :field => :test, :value => 'test', :mode => :select)
@@ -25,7 +24,6 @@ describe RequestLogAnalyzer::Filter::Field, 'string in accept mode' do
25
24
  end
26
25
 
27
26
  describe RequestLogAnalyzer::Filter::Field, 'string in reject mode' do
28
- include RequestLogAnalyzer::Spec::Helper
29
27
 
30
28
  before(:each) do
31
29
  @filter = RequestLogAnalyzer::Filter::Field.new(testing_format, :field => :test, :value => 'test', :mode => :reject)
@@ -49,7 +47,6 @@ describe RequestLogAnalyzer::Filter::Field, 'string in reject mode' do
49
47
  end
50
48
 
51
49
  describe RequestLogAnalyzer::Filter::Field, 'regexp in accept mode' do
52
- include RequestLogAnalyzer::Spec::Helper
53
50
 
54
51
  before(:each) do
55
52
  @filter = RequestLogAnalyzer::Filter::Field.new(testing_format, :field => :test, :value => '/test/', :mode => :select)
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RequestLogAnalyzer::Filter::Base, 'base filter' do
4
+
5
+ before(:each) do
6
+ @filter = RequestLogAnalyzer::Filter::Base.new(testing_format)
7
+ end
8
+
9
+ it "should return everything" do
10
+ @filter.filter(request(:ip => '123.123.123.123'))[:ip].should eql('123.123.123.123')
11
+ end
12
+
13
+ it "should return nil on nil request" do
14
+ @filter.filter(nil).should be_nil
15
+ end
16
+
17
+ end
@@ -1,7 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  describe RequestLogAnalyzer::Filter::Timespan, 'both before and after' do
4
- include RequestLogAnalyzer::Spec::Helper
5
4
 
6
5
  before(:each) do
7
6
  @filter = RequestLogAnalyzer::Filter::Timespan.new(testing_format, :after => DateTime.parse('2009-01-01'), :before => DateTime.parse('2009-02-02'))
@@ -21,7 +20,6 @@ describe RequestLogAnalyzer::Filter::Timespan, 'both before and after' do
21
20
  end
22
21
 
23
22
  describe RequestLogAnalyzer::Filter::Timespan, 'only before' do
24
- include RequestLogAnalyzer::Spec::Helper
25
23
 
26
24
  before(:each) do
27
25
  @filter = RequestLogAnalyzer::Filter::Timespan.new(testing_format, :before => DateTime.parse('2009-02-02'))
@@ -41,7 +39,6 @@ describe RequestLogAnalyzer::Filter::Timespan, 'only before' do
41
39
  end
42
40
 
43
41
  describe RequestLogAnalyzer::Filter::Timespan, 'only after' do
44
- include RequestLogAnalyzer::Spec::Helper
45
42
 
46
43
  before(:each) do
47
44
  @filter = RequestLogAnalyzer::Filter::Timespan.new(testing_format, :after => DateTime.parse('2009-01-01'))