double_agent 0.2.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/parser_spec.rb DELETED
@@ -1,114 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- describe DoubleAgent do
4
- context 'Parser' do
5
- before do
6
- @ua_string = 'Mozilla/5.0 (X11; Ubuntu Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0'
7
- end
8
-
9
- #browser
10
- it 'returns Firefox 4 for browser' do
11
- DoubleAgent.browser(@ua_string).should == 'Firefox 4'
12
- end
13
- it 'returns Unknown for browser' do
14
- DoubleAgent.browser('froofroo').should == 'Unknown'
15
- end
16
-
17
- #browser_sym
18
- it 'returns :firefox for browser_sym' do
19
- DoubleAgent.browser_sym(@ua_string).should == :firefox
20
- end
21
- it 'returns :unknown for browser_sym' do
22
- DoubleAgent.browser_sym('froofroo').should == :unknown
23
- end
24
- it 'returns :unknown for an empty browser_sym' do
25
- DoubleAgent.browser_sym('').should == :unknown
26
- end
27
- it 'returns :unknown for a nil browser_sym' do
28
- DoubleAgent.browser_sym(nil).should == :unknown
29
- end
30
-
31
- #browser_family
32
- it 'returns Firefox for browser family' do
33
- DoubleAgent.browser_family(@ua_string).should == 'Firefox'
34
- end
35
-
36
- #browser_family_sym
37
- it 'returns :firefox for browser_family_sym' do
38
- DoubleAgent.browser_family_sym(@ua_string).should == :firefox
39
- end
40
- it 'returns :unknown for an empty browser_family_sym' do
41
- DoubleAgent.browser_family_sym('').should == :unknown
42
- end
43
- it 'returns :unknown for a nil browser_family_sym' do
44
- DoubleAgent.browser_family_sym(nil).should == :unknown
45
- end
46
-
47
- #browser_icon
48
- it 'returns :firefox for browser_sym' do
49
- DoubleAgent.browser_icon(@ua_string).should == :firefox
50
- end
51
- it 'returns :unkown for an empty browser_sym' do
52
- DoubleAgent.browser_icon('').should == :unknown
53
- end
54
- it 'returns :unkown for a nil browser_sym' do
55
- DoubleAgent.browser_icon(nil).should == :unknown
56
- end
57
-
58
- #browser_family_icon
59
- it 'returns :firefox for browser_family_sym' do
60
- DoubleAgent.browser_family_icon(@ua_string).should == :firefox
61
- end
62
- it 'returns :unkown for an empty browser_family_sym' do
63
- DoubleAgent.browser_family_icon('').should == :unknown
64
- end
65
- it 'returns :unkown for a nil browser_family_sym' do
66
- DoubleAgent.browser_family_icon(nil).should == :unknown
67
- end
68
-
69
- #os
70
- it 'returns Ubuntua for OS' do
71
- DoubleAgent.os(@ua_string).should == 'Ubuntu'
72
- end
73
- it 'returns Unknowna for OS' do
74
- DoubleAgent.os('froofroo').should == 'Unknown'
75
- end
76
- it 'returns Unknowna for OS' do
77
- DoubleAgent.os('').should == 'Unknown'
78
- end
79
-
80
- #os_sym
81
- it 'returns :ubuntu for os_sym' do
82
- DoubleAgent.os_sym(@ua_string).should == :ubuntu
83
- end
84
- it 'returns :unknown for os_sym' do
85
- DoubleAgent.os_sym('froofroo').should == :unknown
86
- end
87
- it 'returns :unknown for an empty os_sym' do
88
- DoubleAgent.os_sym('').should == :unknown
89
- end
90
- it 'returns :unknown for a nil os_sym' do
91
- DoubleAgent.os_sym(nil).should == :unknown
92
- end
93
-
94
- #os_family
95
- it 'returns GNU/Linux OS family' do
96
- DoubleAgent.os_family(@ua_string).should == 'GNU/Linux'
97
- end
98
-
99
- #os_family_sym
100
- it 'returns :linux for os_family_sym' do
101
- DoubleAgent.os_family_sym(@ua_string).should == :linux
102
- end
103
-
104
- #os_icon
105
- it 'returns :ubuntu for os_sym' do
106
- DoubleAgent.os_icon(@ua_string).should == :ubuntu
107
- end
108
-
109
- #os_family_icon
110
- it 'returns :linux for os_family_sym' do
111
- DoubleAgent.os_family_icon(@ua_string).should == :linux
112
- end
113
- end
114
- end
@@ -1,78 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- class Login
4
- include DoubleAgent::Resource
5
- attr_accessor :user_agent
6
-
7
- def initialize(ua)
8
- @user_agent = ua
9
- end
10
- end
11
-
12
- describe DoubleAgent do
13
- context 'Resource' do
14
- before do
15
- @login = Login.new 'Mozilla/5.0 (X11; Ubuntu Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0'
16
- end
17
-
18
- #browser
19
- it 'returns Firefox 4 for browser' do
20
- @login.browser.should == 'Firefox 4'
21
- end
22
-
23
- #browser_sym
24
- it 'returns :firefox for browser_sym' do
25
- @login.browser_sym.should == :firefox
26
- end
27
-
28
- #browser_family
29
- it 'returns Firefox for browser family' do
30
- @login.browser_family.should == 'Firefox'
31
- end
32
-
33
- #browser_family_sym
34
- it 'returns :firefox for browser_family_sym' do
35
- @login.browser_family_sym.should == :firefox
36
- end
37
-
38
- #browser_icon
39
- it 'returns :firefox for browser_sym' do
40
- @login.browser_icon.should == :firefox
41
- end
42
-
43
- #browser_family_icon
44
- it 'returns :firefox for browser_family_sym' do
45
- @login.browser_family_icon.should == :firefox
46
- end
47
-
48
- #os
49
- it 'returns Ubuntua for OS' do
50
- @login.os.should == 'Ubuntu'
51
- end
52
-
53
- #os_sym
54
- it 'returns :ubuntu for os_sym' do
55
- @login.os_sym.should == :ubuntu
56
- end
57
-
58
- #os_family
59
- it 'returns GNU/Linux OS family' do
60
- @login.os_family.should == 'GNU/Linux'
61
- end
62
-
63
- #os_family_sym
64
- it 'returns :linux for os_family_sym' do
65
- @login.os_family_sym.should == :linux
66
- end
67
-
68
- #os_icon
69
- it 'returns :ubuntu for os_sym' do
70
- @login.os_icon.should == :ubuntu
71
- end
72
-
73
- #os_family_icon
74
- it 'returns :linux for os_family_sym' do
75
- @login.os_family_icon.should == :linux
76
- end
77
- end
78
- end
data/spec/spec_helper.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'rspec'
2
- require File.dirname(__FILE__) + '/../lib/double_agent/parser'
3
- require File.dirname(__FILE__) + '/../lib/double_agent/resources'
4
- require File.dirname(__FILE__) + '/../lib/double_agent/stats'
5
- require File.dirname(__FILE__) + '/../lib/double_agent/logs'
6
-
7
- RSpec.configure do |c|
8
- c.mock_with :rspec
9
- end
10
-
11
- module Kernel
12
- def suppress_warnings
13
- original_verbosity = $VERBOSE
14
- $VERBOSE = nil
15
- result = yield
16
- $VERBOSE = original_verbosity
17
- return result
18
- end
19
- end
data/spec/stats_spec.rb DELETED
@@ -1,64 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- log_glob = File.dirname(__FILE__) + '/data/*.access.log*'
4
- entries = DoubleAgent::Logs::entries(log_glob, :match => /^\d/)
5
-
6
- describe DoubleAgent do
7
- context 'Logs' do
8
- it 'should have loaded n log entries' do
9
- entries.size.should == 47
10
- end
11
-
12
- it 'should have loaded n log entries' do
13
- DoubleAgent::Logs::entries(log_glob, :match => /^\d/, :ignore => %r{ /dashboard }).size.should == 44
14
- end
15
-
16
- context 'without zlib' do
17
- it 'should have loaded n log entries' do
18
- suppress_warnings { DoubleAgent::Logs::ZLIB = false }
19
- plain_entries = DoubleAgent::Logs::entries(log_glob, :match => /^\d/)
20
- suppress_warnings { DoubleAgent::Logs::ZLIB = true }
21
- plain_entries.size.should == 17
22
- end
23
- end
24
-
25
- context 'parsing other data' do
26
- before :each do
27
- @line = DoubleAgent::Logs::Entry.new '68.52.99.211 - - [04/May/2011:08:21:04 -0400] "GET / HTTP/1.1" 200 1312 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17"'
28
- end
29
-
30
- it 'should parse the IP' do
31
- @line.ip.should == '68.52.99.211'
32
- end
33
-
34
- it 'should parse datestamps' do
35
- @line.on.should == Date.new(2011, 5, 4)
36
- end
37
-
38
- it 'should parse timestamps' do
39
- @line.at.should == DateTime.new(2011, 5, 4, 8, 21, 4, '-0400')
40
- end
41
- end
42
- end
43
-
44
- context 'Stats' do
45
- it 'should calculate stats' do
46
- stats = DoubleAgent::Stats.percentages_for entries, :browser_family, :os_family
47
- answer = [["Internet Explorer", "Windows", 42.55, 20],
48
- ["Chromium", "GNU/Linux", 40.43, 19],
49
- ["Firefox", "GNU/Linux", 10.64, 5],
50
- ["Firefox", "OS X", 4.26, 2],
51
- ["Safari", "OS X", 2.13, 1]]
52
- stats.should == answer
53
- end
54
-
55
- it 'should ignore stats below the threshold' do
56
- stats = DoubleAgent::Stats.percentages_for entries, :browser_family, :os_family, :threshold => 3.0
57
- answer = [["Internet Explorer", "Windows", 42.55, 20],
58
- ["Chromium", "GNU/Linux", 40.43, 19],
59
- ["Firefox", "GNU/Linux", 10.64, 5],
60
- ["Firefox", "OS X", 4.26, 2]]
61
- stats.should == answer
62
- end
63
- end
64
- end