sniffles 0.0.3 → 0.1.0

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.
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Sniffles::HTML" do
4
+ before(:all) do
5
+ class Klass
6
+ include Sniffles::HTML
7
+ attr_accessor :doc
8
+ end
9
+
10
+ @klass = Klass.new
11
+ @klass.parse "<html><head><title>Title!</title></head><body><h1>Body!</h1></body></html>"
12
+ end
13
+
14
+ describe "#parse" do
15
+ it "should take HTML and return a parsed Nokogiri document" do
16
+ @klass.doc.should be_kind_of(Nokogiri::HTML::Document)
17
+ end
18
+ end
19
+
20
+ describe "#text_match?" do
21
+ context "does match" do
22
+ it "should be true" do
23
+ @klass.text_match?("//title", "Title!").should be true
24
+ end
25
+ end
26
+
27
+ context "does not match" do
28
+ it "should be false" do
29
+ @klass.text_match?("//title", "Body!").should be false
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../../lib/sniffles/sniffers/analytics/google_analytics')
3
+
4
+ describe Sniffles::Sniffers::GoogleAnalytics do
5
+ describe "#output" do
6
+ context "Inline JS" do
7
+ before(:all) do
8
+ VCR.use_cassette("pearsonified_com") do
9
+ @pearsonified = Typhoeus::Request.get("http://www.pearsonified.com/")
10
+ @ga = Sniffles::Sniffers::GoogleAnalytics.new(@pearsonified.body)
11
+ end
12
+ end
13
+
14
+ it "should return as found" do
15
+ @ga.output[:found].should eq true
16
+ end
17
+
18
+ it "should return UA" do
19
+ @ga.output[:ua].should eq "UA-2916092-1"
20
+ end
21
+ end
22
+
23
+ context "Inline w/ Urchin (Old)" do
24
+ before(:all) do
25
+ VCR.use_cassette("humemes_com") do
26
+ @humemes = Typhoeus::Request.get("http://humemes.com/")
27
+ @urchin = Sniffles::Sniffers::GoogleAnalytics.new(@humemes.body)
28
+ end
29
+ end
30
+
31
+ it "should return as found" do
32
+ @urchin.output[:found].should eq true
33
+ end
34
+
35
+ it "should return UA" do
36
+ @urchin.output[:ua].should eq "UA-386965-7"
37
+ end
38
+ end
39
+
40
+ context "No Google Analytics" do
41
+ it "should return false" do
42
+ no_ga = Sniffles::Sniffers::GoogleAnalytics.new("<html><head></head><body>No analytics!</body></html>")
43
+ no_ga.output[:found].should eq false
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../../lib/sniffles/sniffers/analytics/mixpanel')
3
+
4
+ describe Sniffles::Sniffers::Mixpanel do
5
+ describe "#output" do
6
+ context "w/ Mixpanel" do
7
+ before(:all) do
8
+ VCR.use_cassette("squidoo_com") do
9
+ @squidoo = Typhoeus::Request.get("http://www.squidoo.com/", :follow_location => true)
10
+ end
11
+ end
12
+
13
+ it "should return UA" do
14
+ Sniffles::Sniffers::Mixpanel.new(@squidoo.body).output[:found].should eq true
15
+ end
16
+ end
17
+
18
+
19
+ context "w/o Mixpanel" do
20
+ it "should return false" do
21
+ Sniffles::Sniffers::Mixpanel.new("<html><head></head><body>No analytics!</body></html>").output[:found].should eq false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../../lib/sniffles/sniffers/analytics/quantcast')
3
+
4
+ describe Sniffles::Sniffers::Quantcast do
5
+ describe "#output" do
6
+ context "w/ Quantcast" do
7
+ before(:all) do
8
+ VCR.use_cassette("squidoo_com") do
9
+ @squidoo = Typhoeus::Request.get("http://www.squidoo.com/", :follow_location => true)
10
+ end
11
+ end
12
+
13
+ it "should return true for found" do
14
+ Sniffles::Sniffers::Quantcast.new(@squidoo.body).output[:found].should eq true
15
+ end
16
+ end
17
+
18
+
19
+ context "w/o Quantcast" do
20
+ it "should return false" do
21
+ Sniffles::Sniffers::Quantcast.new("<html><head></head><body>No analytics!</body></html>").output[:found].should eq false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,64 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../../lib/sniffles/sniffers/cms/wordpress')
3
+
4
+ describe "Sniffers::WordPress" do
5
+ context "WordPress Blog w/ feed, theme, and pingback" do
6
+ describe "#output" do
7
+ before(:all) do
8
+ VCR.use_cassette("pearsonified_com") do
9
+ @pearsonified = Typhoeus::Request.get("http://www.pearsonified.com/")
10
+ @wp = Sniffles::Sniffers::Wordpress.new(@pearsonified.body)
11
+ end
12
+ end
13
+
14
+ it "should return found as true" do
15
+ @wp.output[:found].should eq true
16
+ end
17
+
18
+ it "should return feed URI" do
19
+ @wp.output[:feed].should eq "http://feeds.feedburner.com/pearsonified"
20
+ end
21
+
22
+ it "should return theme" do
23
+ @wp.output[:theme].should eq "thesis_17"
24
+ end
25
+
26
+ it "should return pingback URI" do
27
+ @wp.output[:pingback].should eq "http://www.pearsonified.com/xmlrpc.php"
28
+ end
29
+
30
+ it "should return version as false" do
31
+ @wp.output[:version].should eq false
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+ context "WordPress Blog w/ version" do
38
+ describe "#output" do
39
+ before(:all) do
40
+ VCR.use_cassette("humemes_com") do
41
+ @humemes = Typhoeus::Request.get("http://humemes.com/")
42
+ @wp_version = Sniffles::Sniffers::Wordpress.new(@humemes.body)
43
+ end
44
+ end
45
+
46
+ it "should return the version" do
47
+ @wp_version.output[:version].should eq "2.3.1"
48
+ end
49
+ end
50
+ end
51
+
52
+ context "Not a WordPress Blog" do
53
+ before(:all) do
54
+ VCR.use_cassette("google_com") do
55
+ @google = Typhoeus::Request.get("http://www.google.com/")
56
+ @not_wp = Sniffles::Sniffers::Wordpress.new(@google.body)
57
+ end
58
+ end
59
+
60
+ it "should return false" do
61
+ @not_wp.output[:found].should eq false
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../../lib/sniffles/sniffers/javascript/jquery')
3
+
4
+ describe Sniffles::Sniffers::Jquery do
5
+ describe "#output" do
6
+ context "w/ jQuery" do
7
+ before(:all) do
8
+ VCR.use_cassette("squidoo_com") do
9
+ @squidoo = Typhoeus::Request.get("http://www.squidoo.com/", :follow_location => true)
10
+ end
11
+ end
12
+
13
+ it "should return true" do
14
+ Sniffles::Sniffers::Jquery.new(@squidoo.body).output[:found].should eq true
15
+ end
16
+ end
17
+
18
+
19
+ context "w/o jQuery" do
20
+ it "should return false" do
21
+ Sniffles::Sniffers::Jquery.new("<html><head></head><body>No scripts!</body></html>").output[:found].should eq false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Sniffles::Sniffers do
4
+ describe "#list_all" do
5
+ it "should list all sniffers" do
6
+ Sniffles::Sniffers.list_all.count.should eq SNIFFER_COUNT
7
+ end
8
+ end
9
+
10
+ describe "#list_groups" do
11
+ it "should list all groups" do
12
+ Sniffles::Sniffers.list_groups.count.should eq SNIFFER_GROUP_COUNT
13
+ end
14
+ end
15
+
16
+ describe "#list_all_by_group" do
17
+ it "should return a hash of all groups with collections of sniffers" do
18
+ Sniffles::Sniffers.list_all_by_group.count.should eq SNIFFER_GROUP_COUNT
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Sniffles::Text" do
4
+ before(:all) do
5
+ class Klass
6
+ include Sniffles::Text
7
+ attr_accessor :doc
8
+ end
9
+
10
+ @klass = Klass.new
11
+ @text = "This is multi-line\ntext."
12
+ @klass.parse @text
13
+ end
14
+
15
+ describe "#parse" do
16
+ it "should take text and return a string" do
17
+ @klass.doc.should eq @text
18
+ end
19
+ end
20
+
21
+ describe "#match?" do
22
+ context "does match" do
23
+ it "should return true" do
24
+ @klass.match?(/is/).should eq true
25
+ end
26
+ end
27
+
28
+ context "does not match" do
29
+ it "should return false" do
30
+ @klass.match?(/foobar/).should eq false
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "#capture" do
36
+ context "match" do
37
+ it "should return the first captured string" do
38
+ @klass.capture(/(multi\-line)/).should eq "multi-line"
39
+ end
40
+ end
41
+
42
+ context "no match" do
43
+ it "should return false" do
44
+ @klass.capture(/(foobar)/).should eq false
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Sniffles::Utils do
4
+ describe "#absolute_uri" do
5
+ context "success" do
6
+ it "should join base host with relative path" do
7
+ subject.absolute_uri("http://www.google.com","/search").should eq "http://www.google.com/search"
8
+ end
9
+
10
+
11
+ it "should join host w/ directory and relative path" do
12
+ subject.absolute_uri("http://www.google.com/search/", "/query").should eq "http://www.google.com/query"
13
+ end
14
+
15
+ it "should join host w/ directory and path" do
16
+ subject.absolute_uri("http://www.google.com/search/", "query").should eq "http://www.google.com/search/query"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,42 +1,50 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe Sniffles do
4
- it "should have a version" do
5
- subject.const_defined?("VERSION").should be true
6
- end
7
-
8
4
  describe "#sniff" do
9
5
  before(:all) do
10
- VCR.use_cassette("wordpress") do
11
- @body = Typhoeus::Request.get("http://www.wordpress.com/", :follow_location => true).body
6
+ VCR.use_cassette("squidoo_com") do
7
+ @squidoo = Typhoeus::Request.get("http://www.squidoo.com/", :follow_location => true).body
12
8
  end
13
- @wp = Sniffles.sniff(@body)
14
9
  end
15
10
 
16
- it "should identify WordPress" do
17
- @wp.should include(:wordpress => true)
11
+ context "using sniffers" do
12
+ it "returns a hash of sniffers and their responses" do
13
+ sniff = Sniffles.sniff(@squidoo, :mixpanel, :google_analytics)
14
+ sniff[:mixpanel][:found].should eq true
15
+ sniff[:google_analytics][:found].should eq true
16
+ end
18
17
  end
19
18
 
20
- it "should identify jQuery" do
21
- @wp.should include(:jquery => true)
19
+ context "using groups" do
20
+ it "returns a hash of sniffers and their responses" do
21
+ sniff = Sniffles.sniff(@squidoo, :analytics, :cms, :javascript)
22
+ sniff[:mixpanel][:found].should eq true
23
+ sniff[:google_analytics][:found].should eq true
24
+ sniff[:wordpress][:found].should eq false
25
+ sniff[:jquery][:found].should eq true
26
+ end
22
27
  end
23
28
 
24
- it "should identify Quantcast" do
25
- @wp.should include(:quantcast => true)
26
- end
27
-
28
- describe "#mixpanel" do
29
- before(:all) do
30
- VCR.use_cassette("squidoo") do
31
- @body = Typhoeus::Request.get("http://www.squidoo.com/", :follow_location => true).body
32
- end
33
- @squid = Sniffles.sniff(@body)
29
+ context "w/o supplying groups or sniffers" do
30
+ it "should sniff with all available sniffers" do
31
+ sniff = Sniffles.sniff(@squidoo)
32
+ sniff.count.should eq SNIFFER_COUNT
34
33
  end
35
-
36
- it "should identify MixPanel" do
37
- @squid.should include(:mixpanel => true)
34
+ end
35
+
36
+ context "using a non-existent sniffer" do
37
+ it "should raise an error" do
38
+ expect { Sniffles.sniff(@squidoo, :fake_ass_sniffer) }.to raise_error(Sniffles::UnknownSniffer, "fake_ass_sniffer not found!")
38
39
  end
39
40
  end
41
+ end
40
42
 
43
+ describe "convenience methods" do
44
+ it "should make it easier to see available sniffers" do
45
+ subject.list_all.count.should be SNIFFER_COUNT
46
+ subject.list_groups.count.should be SNIFFER_GROUP_COUNT
47
+ subject.list_all_by_group.count.should be SNIFFER_GROUP_COUNT
48
+ end
41
49
  end
42
50
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../lib/sniffles')
2
2
 
3
- require 'vcr'
4
3
  require 'typhoeus'
4
+ require 'vcr'
5
+
6
+ SNIFFER_COUNT = Dir.glob("lib/sniffles/sniffers/**/*.rb").count
7
+ SNIFFER_GROUP_COUNT = Dir.glob("lib/sniffles/sniffers/**").count
5
8
 
6
9
  VCR.configure do |c|
7
10
  c.cassette_library_dir = 'spec/cassettes'
@@ -14,4 +17,5 @@ RSpec.configure do |config|
14
17
  config.treat_symbols_as_metadata_keys_with_true_values = true
15
18
  config.run_all_when_everything_filtered = true
16
19
  config.filter_run :focus
20
+ config.extend VCR::RSpec::Macros
17
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sniffles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-02 00:00:00.000000000 Z
13
+ date: 2012-03-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
17
- requirement: &2152355540 !ruby/object:Gem::Requirement
17
+ requirement: &2156195740 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.5.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2152355540
25
+ version_requirements: *2156195740
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rspec
28
- requirement: &2152354760 !ruby/object:Gem::Requirement
28
+ requirement: &2156222500 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.8.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2152354760
36
+ version_requirements: *2156222500
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: typhoeus
39
- requirement: &2152375980 !ruby/object:Gem::Requirement
39
+ requirement: &2156221980 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.3.3
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2152375980
47
+ version_requirements: *2156221980
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: vcr
50
- requirement: &2152375420 !ruby/object:Gem::Requirement
50
+ requirement: &2156221420 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: 2.0.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2152375420
58
+ version_requirements: *2156221420
59
59
  description: Detects popular CMS, Javascript libraries, and other items of interest.
60
60
  email:
61
61
  - zeke@templ.in
@@ -74,10 +74,32 @@ files:
74
74
  - README.md
75
75
  - Rakefile
76
76
  - lib/sniffles.rb
77
+ - lib/sniffles/html.rb
78
+ - lib/sniffles/sniffers.rb
79
+ - lib/sniffles/sniffers/analytics/google_analytics.rb
80
+ - lib/sniffles/sniffers/analytics/mixpanel.rb
81
+ - lib/sniffles/sniffers/analytics/quantcast.rb
82
+ - lib/sniffles/sniffers/cms/wordpress.rb
83
+ - lib/sniffles/sniffers/javascript/jquery.rb
84
+ - lib/sniffles/text.rb
85
+ - lib/sniffles/utils.rb
77
86
  - lib/sniffles/version.rb
78
87
  - sniffles.gemspec
88
+ - spec/cassettes/google_com.yml
89
+ - spec/cassettes/humemes_com.yml
90
+ - spec/cassettes/pearsonified_com.yml
79
91
  - spec/cassettes/squidoo.yml
92
+ - spec/cassettes/squidoo_com.yml
80
93
  - spec/cassettes/wordpress.yml
94
+ - spec/sniffles/html_spec.rb
95
+ - spec/sniffles/sniffers/analytics/google_analytics_spec.rb
96
+ - spec/sniffles/sniffers/analytics/mixpanel_spec.rb
97
+ - spec/sniffles/sniffers/analytics/quantcast_spec.rb
98
+ - spec/sniffles/sniffers/cms/wordpress_spec.rb
99
+ - spec/sniffles/sniffers/javascript/jquery_spec.rb
100
+ - spec/sniffles/sniffers_spec.rb
101
+ - spec/sniffles/text_spec.rb
102
+ - spec/sniffles/utils_spec.rb
81
103
  - spec/sniffles_spec.rb
82
104
  - spec/spec_helper.rb
83
105
  homepage: http://documentup.com/ezkl/sniffles
@@ -105,8 +127,21 @@ signing_key:
105
127
  specification_version: 3
106
128
  summary: Sniffles helps you determine the platforms and libraries a website is running.
107
129
  test_files:
130
+ - spec/cassettes/google_com.yml
131
+ - spec/cassettes/humemes_com.yml
132
+ - spec/cassettes/pearsonified_com.yml
108
133
  - spec/cassettes/squidoo.yml
134
+ - spec/cassettes/squidoo_com.yml
109
135
  - spec/cassettes/wordpress.yml
136
+ - spec/sniffles/html_spec.rb
137
+ - spec/sniffles/sniffers/analytics/google_analytics_spec.rb
138
+ - spec/sniffles/sniffers/analytics/mixpanel_spec.rb
139
+ - spec/sniffles/sniffers/analytics/quantcast_spec.rb
140
+ - spec/sniffles/sniffers/cms/wordpress_spec.rb
141
+ - spec/sniffles/sniffers/javascript/jquery_spec.rb
142
+ - spec/sniffles/sniffers_spec.rb
143
+ - spec/sniffles/text_spec.rb
144
+ - spec/sniffles/utils_spec.rb
110
145
  - spec/sniffles_spec.rb
111
146
  - spec/spec_helper.rb
112
147
  has_rdoc: