lugg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ require 'lugg/filter'
2
+ require 'lugg/request'
3
+
4
+ module Lugg
5
+ describe Filter do
6
+ let(:records) { [Request.new('example')] }
7
+
8
+ it 'matches all records by default' do
9
+ expect(subject.call(records)).to eql(records)
10
+ end
11
+
12
+ it 'allows adding matchers to filter records' do
13
+ subject.use { |record| false }
14
+ expect(subject.call(records)).to be_empty
15
+ end
16
+
17
+ it 'combines matchers using OR' do
18
+ subject.use { |record| false }
19
+ subject.use { |record| true }
20
+ expect(subject.call(records)).to eql(records)
21
+ end
22
+
23
+ it 'allows adding lambdas as matchers' do
24
+ subject.use ->(record) { false }
25
+ expect(subject.call(records)).to be_empty
26
+ end
27
+
28
+ it 'disallows using both a block and a callable' do
29
+ expect { subject.use ->(record) { false } { true } }.to raise_error(ArgumentError)
30
+ end
31
+
32
+ it 'disallows callables that are not callable' do
33
+ expect { subject.use 'foo' }.to raise_error(ArgumentError)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require 'lugg/request_matcher'
2
+
3
+ module Lugg
4
+ describe RequestMatcher do
5
+ it 'starts as inactive' do
6
+ expect(subject).not_to be_active
7
+ end
8
+
9
+ it 'starts as unfinished' do
10
+ expect(subject).not_to be_finished
11
+ end
12
+
13
+ context 'after matching a "Started" line' do
14
+ before do
15
+ subject =~ 'Started'
16
+ end
17
+
18
+ it 'becomes active' do
19
+ expect(subject).to be_active
20
+ end
21
+
22
+ context 'and then a "Completed" line' do
23
+ before do
24
+ subject =~ 'Completed'
25
+ end
26
+
27
+ it 'becomes inactive' do
28
+ expect(subject).not_to be_active
29
+ end
30
+
31
+ it 'becomes finished' do
32
+ expect(subject).to be_finished
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ require 'lugg/request'
2
+
3
+ module Lugg
4
+ describe Request do
5
+ subject { described_class.new('test') }
6
+
7
+ it 'considers two objects with the same source equal' do
8
+ other = Request.new('test')
9
+ expect(subject).to eql(other)
10
+ expect(subject == other).to be_true
11
+ end
12
+
13
+ it 'can not modify the contents of the source' do
14
+ expect { subject.source.downcase! }.not_to change { subject.source }
15
+ end
16
+
17
+ context 'for an actual request' do
18
+ let(:fixture) { File.open(File.expand_path('../../fixtures/example.log', __FILE__)).each_line.first(6).join("\n") }
19
+ subject { described_class.new(fixture) }
20
+
21
+ its(:method) { should eql('GET') }
22
+ its(:path) { should eql('/offenses/search') }
23
+ its(:uri) { should eql('/offenses/search?q=r315twe&_=1385727839720') }
24
+ its(:query) { should eql('q=r315twe&_=1385727839720') }
25
+ its(:ip) { should eql('212.78.221.106') }
26
+ its(:timestamp) { should eql(Time.new(2013, 11, 29, 13, 24, 16, '+01:00')) }
27
+ its(:controller) { should eql('OffensesController') }
28
+ its(:action) { should eql('OffensesController#search') }
29
+ its(:status) { should eql('OK') }
30
+ its(:code) { should eql(200) }
31
+ its(:duration) { should eql(37) }
32
+ its(:params) { should eql('q' => 'r315twe', '_' => '1385727839720') }
33
+ its(:format) { should eql('JSON') }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,71 @@
1
+ require 'stringio'
2
+ require 'lugg/runner'
3
+
4
+ module Lugg
5
+ describe Runner do
6
+ before { $stdout = stdout }
7
+ after { $stdout = STDOUT }
8
+ let(:stdout) { StringIO.new }
9
+ let(:options) { [] }
10
+ subject { described_class.new(options) }
11
+
12
+ context 'without any options' do
13
+ let(:input) { "Started\nCompleted\n" }
14
+
15
+ it 'outputs requests from input without conditions' do
16
+ subject.run(StringIO.new(input))
17
+ expect(stdout.string).to eql("Started\nCompleted\n")
18
+ end
19
+ end
20
+
21
+ context 'with --get' do
22
+ let(:options) { ['--get'] }
23
+ let(:input) { "Started GET\nCompleted 1\nStarted POST\nCompleted 2\n" }
24
+
25
+ it 'limits requests to GET requests' do
26
+ subject.run(StringIO.new(input))
27
+ expect(stdout.string).to eql("Started GET\nCompleted 1\n")
28
+ end
29
+ end
30
+
31
+ context 'with --post --and --controller PostsController' do
32
+ let(:options) { %w(--post --and --controller PostsController) }
33
+ let(:input) { "Started GET\nProcessing by PostsController#index as HTML\nCompleted 1\nStarted POST\nProcessing by BlogController#create as HTML\nCompleted 2\n" }
34
+
35
+ it 'limits requests to GET requests' do
36
+ subject.run(StringIO.new(input))
37
+ expect(stdout.string).to eql("Started POST\nProcessing by BlogController#create as HTML\nCompleted 2\n")
38
+ end
39
+ end
40
+
41
+ context 'with --controller PostsController' do
42
+ let(:options) { %w(--controller PostsController) }
43
+ let(:input) { "Started GET\nProcessing by PostsController#index as HTML\nCompleted 1\nStarted POST\nProcessing by BlogController#create as HTML\nCompleted 2\n" }
44
+
45
+ it 'limits requests to GET requests' do
46
+ subject.run(StringIO.new(input))
47
+ expect(stdout.string).to eql("Started GET\nProcessing by PostsController#index as HTML\nCompleted 1\n")
48
+ end
49
+ end
50
+
51
+ context 'with --since 2012-03-20' do
52
+ let(:options) { %w(--since 2012-03-20) }
53
+ let(:input) { "Started GET at 2012-03-21 12:00 +0100\nCompleted 1\nStarted GET at 2012-03-19\nProcessing by BlogController#create as HTML\nCompleted 2\n" }
54
+
55
+ it 'limits requests to GET requests' do
56
+ subject.run(StringIO.new(input))
57
+ expect(stdout.string).to eql("Started GET at 2012-03-21 12:00 +0100\nCompleted 1\n")
58
+ end
59
+ end
60
+
61
+ context 'with --param foo=bar' do
62
+ let(:options) { ['--param', 'foo=val'] }
63
+ let(:input) { "Started GET\n Parameters: {\"foo\"=>\"val\"}\nCompleted 1\nStarted POST\nProcessing by BlogController#create as HTML\nCompleted 2\n" }
64
+
65
+ it 'limits requests to GET requests' do
66
+ subject.run(StringIO.new(input))
67
+ expect(stdout.string).to eql("Started GET\n Parameters: {\"foo\"=>\"val\"}\nCompleted 1\n")
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,27 @@
1
+ require 'lugg/streamer'
2
+
3
+ module Lugg
4
+ describe Streamer do
5
+ let(:fixture) { File.open(File.expand_path('../../fixtures/example.log', __FILE__)) }
6
+ subject { described_class.new(fixture) }
7
+ it { should have(555).records }
8
+
9
+ it 'returns an enumerator' do
10
+ expect(subject.records).to be_a(Enumerator)
11
+ end
12
+
13
+ it 'yields Request objects' do
14
+ request = subject.records.first
15
+ expect(request).to be_a(Request)
16
+ end
17
+
18
+ it 'creates Request objects with the full request source' do
19
+ request = subject.records.first
20
+ expect(request.source).to have(6).lines
21
+ end
22
+
23
+ context 'using request data' do
24
+
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lugg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Arjan van der Gaag
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |
84
+ A tiny command line utility to search through Rails server log files and
85
+ display requests that meet certain criteria.
86
+ email:
87
+ - arjan@kabisa.nl
88
+ executables:
89
+ - lugg
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".rubocop.yml"
96
+ - ".travis.yml"
97
+ - ".yardopts"
98
+ - Gemfile
99
+ - HISTORY.md
100
+ - LICENSE
101
+ - README.md
102
+ - Rakefile
103
+ - bin/lugg
104
+ - lib/lugg.rb
105
+ - lib/lugg/filter.rb
106
+ - lib/lugg/request.rb
107
+ - lib/lugg/request_matcher.rb
108
+ - lib/lugg/runner.rb
109
+ - lib/lugg/streamer.rb
110
+ - lib/lugg/version.rb
111
+ - lugg.gemspec
112
+ - spec/fixtures/example.log
113
+ - spec/lugg/filter_spec.rb
114
+ - spec/lugg/request_matcher_spec.rb
115
+ - spec/lugg/request_spec.rb
116
+ - spec/lugg/runner_spec.rb
117
+ - spec/lugg/streamer_spec.rb
118
+ homepage: http://avdgaa.github.io/lugg
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Query Rails log files from the command line.
142
+ test_files:
143
+ - spec/fixtures/example.log
144
+ - spec/lugg/filter_spec.rb
145
+ - spec/lugg/request_matcher_spec.rb
146
+ - spec/lugg/request_spec.rb
147
+ - spec/lugg/runner_spec.rb
148
+ - spec/lugg/streamer_spec.rb
149
+ has_rdoc: