virility 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Virility::Pinterest" do
4
+ before(:each) do
5
+ @url = "http://creativeallies.com"
6
+ end
7
+
8
+ describe "poll" do
9
+ context "when there is not a valid result" do
10
+ before(:each) do
11
+ response = double("HTTParty::Response", :parsed_response => {"fake_return_value"=> "OICU812"})
12
+ Virility::Pinterest.stub(:get).and_return(response)
13
+ @virility = Virility::Pinterest.new(@url)
14
+ end
15
+
16
+ it_should_behave_like "no context results"
17
+ end
18
+
19
+ context "when there is no result" do
20
+ before(:each) do
21
+ response = double("HTTParty::Response")
22
+ Virility::Pinterest.stub(:get).and_return(response)
23
+ @virility = Virility::Pinterest.new(@url)
24
+ end
25
+
26
+ it_should_behave_like "no context results"
27
+ end
28
+
29
+ context "when there is a result but no specific hash value" do
30
+ before(:each) do
31
+ response = double("HTTParty::Response", :parsed_response => {})
32
+ Virility::Pinterest.stub(:get).and_return(response)
33
+ @virility = Virility::Pinterest.new(@url)
34
+ end
35
+
36
+ it_should_behave_like "no context results"
37
+ end
38
+
39
+ context "when there is a result but parsed_response is weird" do
40
+ before(:each) do
41
+ response = double("HTTParty::Response", :parsed_response => Object.new)
42
+ Virility::Pinterest.stub(:get).and_return(response)
43
+ @virility = Virility::Pinterest.new(@url)
44
+ end
45
+
46
+ it_should_behave_like "no context results"
47
+ end
48
+
49
+ context "when there is a valid result" do
50
+ before(:each) do
51
+ response = double("HTTParty::Response", :parsed_response => {"count"=>1, "url"=>"http://creativeallies.com"})
52
+ Virility::Pinterest.stub(:get).and_return(response)
53
+ @virility = Virility::Pinterest.new(@url)
54
+ end
55
+
56
+ it "should not raise an error" do
57
+ lambda { @virility.poll }.should_not raise_error
58
+ end
59
+
60
+ it "should return 1 for the count" do
61
+ @virility.count.should == 1
62
+ end
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,66 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Virility::PlusOne" do
4
+ before(:each) do
5
+ @url = "http://creativeallies.com"
6
+ end
7
+
8
+ describe "poll" do
9
+ context "when there is not a valid result" do
10
+ before(:each) do
11
+ response = double("HTTParty::Response", :parsed_response => {"fake_return_value"=> "OICU812"})
12
+ Virility::PlusOne.stub(:get).and_return(response)
13
+ @virility = Virility::PlusOne.new(@url)
14
+ end
15
+
16
+ it_should_behave_like "no context results"
17
+ end
18
+
19
+ context "when there is no result" do
20
+ before(:each) do
21
+ response = double("HTTParty::Response")
22
+ Virility::PlusOne.stub(:get).and_return(response)
23
+ @virility = Virility::PlusOne.new(@url)
24
+ end
25
+
26
+ it_should_behave_like "no context results"
27
+ end
28
+
29
+ context "when there is a result but no specific hash value" do
30
+ before(:each) do
31
+ response = double("HTTParty::Response", :parsed_response => {})
32
+ Virility::PlusOne.stub(:get).and_return(response)
33
+ @virility = Virility::PlusOne.new(@url)
34
+ end
35
+
36
+ it_should_behave_like "no context results"
37
+ end
38
+
39
+ context "when there is a result but parsed_response is weird" do
40
+ before(:each) do
41
+ response = double("HTTParty::Response", :parsed_response => Object.new)
42
+ Virility::PlusOne.stub(:get).and_return(response)
43
+ @virility = Virility::PlusOne.new(@url)
44
+ end
45
+
46
+ it_should_behave_like "no context results"
47
+ end
48
+
49
+ context "when there is a valid result" do
50
+ before(:each) do
51
+ response = double("HTTParty::Response", :parsed_response => {"shares"=>"8"})
52
+ Virility::PlusOne.stub(:get).and_return(response)
53
+ @virility = Virility::PlusOne.new(@url)
54
+ end
55
+
56
+ it "should not raise an error" do
57
+ lambda { @virility.poll }.should_not raise_error
58
+ end
59
+
60
+ it "should return 8 for the count" do
61
+ @virility.count.should == 8
62
+ end
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,66 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Virility::StumbleUpon" do
4
+ before(:each) do
5
+ @url = "http://creativeallies.com"
6
+ end
7
+
8
+ describe "poll" do
9
+ context "when there is not a valid result" do
10
+ before(:each) do
11
+ response = double("HTTParty::Response", :parsed_response => {"fake_return_value"=> "OICU812"})
12
+ Virility::StumbleUpon.stub(:get).and_return(response)
13
+ @virility = Virility::StumbleUpon.new(@url)
14
+ end
15
+
16
+ it_should_behave_like "no context results"
17
+ end
18
+
19
+ context "when there is no result" do
20
+ before(:each) do
21
+ response = double("HTTParty::Response")
22
+ Virility::StumbleUpon.stub(:get).and_return(response)
23
+ @virility = Virility::StumbleUpon.new(@url)
24
+ end
25
+
26
+ it_should_behave_like "no context results"
27
+ end
28
+
29
+ context "when there is a result but no specific hash value" do
30
+ before(:each) do
31
+ response = double("HTTParty::Response", :parsed_response => {})
32
+ Virility::StumbleUpon.stub(:get).and_return(response)
33
+ @virility = Virility::StumbleUpon.new(@url)
34
+ end
35
+
36
+ it_should_behave_like "no context results"
37
+ end
38
+
39
+ context "when there is a result but parsed_response is weird" do
40
+ before(:each) do
41
+ response = double("HTTParty::Response", :parsed_response => Object.new)
42
+ Virility::StumbleUpon.stub(:get).and_return(response)
43
+ @virility = Virility::StumbleUpon.new(@url)
44
+ end
45
+
46
+ it_should_behave_like "no context results"
47
+ end
48
+
49
+ context "when there is a valid result" do
50
+ before(:each) do
51
+ response = double("HTTParty::Response", :parsed_response => {"url"=>"http://creativeallies.com/", "in_index"=>true, "publicid"=>"2UhTwK", "views"=>4731, "title"=>"Creative Allies | Create Art For Rockstars | Upload For A Chance To Win", "thumbnail"=>"http://cdn.stumble-upon.com/mthumb/388/49348388.jpg", "thumbnail_b"=>"http://cdn.stumble-upon.com/images/nobthumb.png", "submit_link"=>"http://www.stumbleupon.com/submit/?url=http://creativeallies.com/", "badge_link"=>"http://www.stumbleupon.com/badge/?url=http://creativeallies.com/", "info_link"=>"http://www.stumbleupon.com/url/creativeallies.com/"})
52
+ Virility::StumbleUpon.stub(:get).and_return(response)
53
+ @virility = Virility::StumbleUpon.new(@url)
54
+ end
55
+
56
+ it "should not raise an error" do
57
+ lambda { @virility.poll }.should_not raise_error
58
+ end
59
+
60
+ it "should return 4731 for the count" do
61
+ @virility.count.should == 4731
62
+ end
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,66 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Virility::Twitter" do
4
+ before(:each) do
5
+ @url = "http://creativeallies.com"
6
+ end
7
+
8
+ describe "poll" do
9
+ context "when there is not a valid result" do
10
+ before(:each) do
11
+ response = double("HTTParty::Response", :parsed_response => {"fake_return_value"=> "OICU812"})
12
+ Virility::Twitter.stub(:get).and_return(response)
13
+ @virility = Virility::Twitter.new(@url)
14
+ end
15
+
16
+ it_should_behave_like "no context results"
17
+ end
18
+
19
+ context "when there is no result" do
20
+ before(:each) do
21
+ response = double("HTTParty::Response")
22
+ Virility::Twitter.stub(:get).and_return(response)
23
+ @virility = Virility::Twitter.new(@url)
24
+ end
25
+
26
+ it_should_behave_like "no context results"
27
+ end
28
+
29
+ context "when there is a result but no specific hash value" do
30
+ before(:each) do
31
+ response = double("HTTParty::Response", :parsed_response => {})
32
+ Virility::Twitter.stub(:get).and_return(response)
33
+ @virility = Virility::Twitter.new(@url)
34
+ end
35
+
36
+ it_should_behave_like "no context results"
37
+ end
38
+
39
+ context "when there is a result but parsed_response is weird" do
40
+ before(:each) do
41
+ response = double("HTTParty::Response", :parsed_response => Object.new)
42
+ Virility::Twitter.stub(:get).and_return(response)
43
+ @virility = Virility::Twitter.new(@url)
44
+ end
45
+
46
+ it_should_behave_like "no context results"
47
+ end
48
+
49
+ context "when there is a valid result" do
50
+ before(:each) do
51
+ response = double("HTTParty::Response", :parsed_response => {"count"=>121, "url"=>"http://creativeallies.com/"})
52
+ Virility::Twitter.stub(:get).and_return(response)
53
+ @virility = Virility::Twitter.new(@url)
54
+ end
55
+
56
+ it "should not raise an error" do
57
+ lambda { @virility.poll }.should_not raise_error
58
+ end
59
+
60
+ it "should return 121 for the count" do
61
+ @virility.count.should == 121
62
+ end
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,102 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Strategy" do
4
+ before(:each) do
5
+ @url = "http://creativeallies.com"
6
+ end
7
+
8
+ #
9
+ # Initialization
10
+ #
11
+
12
+ context "initialization" do
13
+ it "should raise an error if a URL is not set" do
14
+ lambda {Virility::Strategy.new}.should raise_error
15
+ end
16
+
17
+ it "should set and encode the url" do
18
+ Virility::Facebook.new(@url).url.should == "http%3A%2F%2Fcreativeallies.com"
19
+ end
20
+ end
21
+
22
+ #
23
+ # Interface
24
+ #
25
+
26
+ context "interface" do
27
+ it "should raise an error on poll" do
28
+ lambda { Virility::Strategy.new(@url).poll }.should raise_error
29
+ end
30
+
31
+ it "should raise an error on count" do
32
+ lambda { Virility::Strategy.new(@url).count }.should raise_error
33
+ end
34
+ end
35
+
36
+ #
37
+ # Dynamic Methods
38
+ #
39
+
40
+ describe "dynamic methods" do
41
+ before(:each) do
42
+ @virility = Virility::Facebook.new(@url)
43
+ @virility.stub(:results).and_return(Virility::FB_RESULTS)
44
+ end
45
+
46
+ context "overall testing" do
47
+ Virility::FB_RESULTS.each do |key, value|
48
+ it "should return #{value} when get_result is called with #{key}" do
49
+ @virility.send(key).should == value
50
+ end
51
+ end
52
+
53
+ Virility::FAKE_FB_RESULTS.each do |key|
54
+ it "should_not raise an error if the result (#{key}) does not exist" do
55
+ lambda { @virility.send(key) }.should_not raise_error
56
+ end
57
+
58
+ it "should return 0 if the result (#{key}) does not exist" do
59
+ @virility.send(key).should == 0
60
+ end
61
+ end
62
+ end
63
+
64
+ context "result_exists?" do
65
+ before(:each) do
66
+ @virility = Virility::Facebook.new(@url)
67
+ @virility.stub(:results).and_return(Virility::FB_RESULTS)
68
+ end
69
+
70
+ Virility::FB_RESULTS.keys.each do |result|
71
+ it "should return true for #{result}" do
72
+ @virility.result_exists?(result).should be true
73
+ end
74
+ end
75
+
76
+ Virility::FAKE_FB_RESULTS.each do |result|
77
+ it "should return false for #{result}" do
78
+ @virility.result_exists?(result).should be false
79
+ end
80
+ end
81
+ end
82
+
83
+ context "get_result" do
84
+ Virility::FB_RESULTS.each do |key, value|
85
+ it "should return #{value} when get_result is called with #{key}" do
86
+ @virility.get_result(key).should == value
87
+ end
88
+ end
89
+
90
+ Virility::FAKE_FB_RESULTS.each do |key|
91
+ it "should_not raise an error if the result (#{key}) does not exist" do
92
+ lambda { @virility.send(key) }.should_not raise_error
93
+ end
94
+
95
+ it "should return 0 if the result (#{key}) does not exist" do
96
+ @virility.send(key).should == 0
97
+ end
98
+ end
99
+ end
100
+
101
+ end
102
+ end
@@ -1,5 +1,74 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Virility" do
4
- it "should test the Virility API from beginning to end"
4
+
5
+ #
6
+ # Factory
7
+ #
8
+
9
+ describe "factory" do
10
+ context "valid strategies" do
11
+ Virility::TESTING_STRATEGIES.each do |strategy, object|
12
+ it "#{strategy} should create and return a #{object} object" do
13
+ Virility.factory(strategy, "http://creativeallies.com").should be_a_kind_of object
14
+ end
15
+ end
16
+ end
17
+
18
+ context "invalid strategies" do
19
+ Virility::FAKE_TESTING_STRATEGIES.each do |strategy|
20
+ it "#{strategy} should raise an error" do
21
+ lambda { Virility.factory(strategy, "http://creativeallies.com") }.should raise_error
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ #
28
+ # Public API
29
+ #
30
+
31
+ describe "Public API testing" do
32
+ before(:each) do
33
+ @url = "http://creativeallies.com"
34
+ Virility::Delicious.stub(:get).and_return(double("HTTParty::Response", :parsed_response => {"url"=>"http://creativeallies.com/", "total_posts"=>50, "top_tags"=>{"graphic"=>1, "art"=>1, "contest"=>1, "photography"=>1, "creativity"=>1, "design"=>1, "online"=>1, "music"=>1, "contests"=>1, "freelance"=>1}, "hash"=>"f9468b2d2842d4a9685af46e1b8e9349", "title"=>"Creative Allies | Create Art For Rockstars"}))
35
+ Virility::Facebook.stub(:get).and_return(double("HTTParty::Response", :parsed_response => {"fql_query_response"=>{"list"=>"true", "link_stat"=>{"like_count"=>"977662", "click_count"=>"265614", "share_count"=>"3020040", "comment_count"=>"1118601", "commentsbox_count"=>"0", "total_count"=>"5116303"}}}))
36
+ Virility::Pinterest.stub(:get).and_return(double("HTTParty::Response", :parsed_response => {"count"=>1, "url"=>"http://creativeallies.com"}))
37
+ Virility::PlusOne.stub(:get).and_return(double("HTTParty::Response", :parsed_response => {"shares"=>"8"}))
38
+ Virility::StumbleUpon.stub(:get).and_return(double("HTTParty::Response", :parsed_response => {"url"=>"http://creativeallies.com/", "in_index"=>true, "publicid"=>"2UhTwK", "views"=>4731, "title"=>"Creative Allies | Create Art For Rockstars | Upload For A Chance To Win", "thumbnail"=>"http://cdn.stumble-upon.com/mthumb/388/49348388.jpg", "thumbnail_b"=>"http://cdn.stumble-upon.com/images/nobthumb.png", "submit_link"=>"http://www.stumbleupon.com/submit/?url=http://creativeallies.com/", "badge_link"=>"http://www.stumbleupon.com/badge/?url=http://creativeallies.com/", "info_link"=>"http://www.stumbleupon.com/url/creativeallies.com/"}))
39
+ Virility::Twitter.stub(:get).and_return(double("HTTParty::Response", :parsed_response => {"count"=>121, "url"=>"http://creativeallies.com/"}))
40
+ end
41
+
42
+ it "Virility.counts should return a hash of counts" do
43
+ Virility.counts(@url).should == {:delicious=>50, :facebook=>5116303, :pinterest=>1, :plus_one=>8, :stumble_upon=>4731, :twitter=>121}
44
+ end
45
+
46
+ it "Virility.total should return the total count" do
47
+ Virility.total(@url).should == 5121214
48
+ end
49
+
50
+ it "Virility.poll should return all of the hashed responses" do
51
+ Virility.poll(@url).should == {:delicious=>{"url"=>"http://creativeallies.com/", "total_posts"=>50, "top_tags"=>{"graphic"=>1, "art"=>1, "contest"=>1, "photography"=>1, "creativity"=>1, "design"=>1, "online"=>1, "music"=>1, "contests"=>1, "freelance"=>1}, "hash"=>"f9468b2d2842d4a9685af46e1b8e9349", "title"=>"Creative Allies | Create Art For Rockstars"}, :facebook=>{"like_count"=>"977662", "click_count"=>"265614", "share_count"=>"3020040", "comment_count"=>"1118601", "commentsbox_count"=>"0", "total_count"=>"5116303"}, :pinterest=>{"count"=>1, "url"=>"http://creativeallies.com"}, :plus_one=>{"shares"=>"8"}, :stumble_upon=>{"url"=>"http://creativeallies.com/", "in_index"=>true, "publicid"=>"2UhTwK", "views"=>4731, "title"=>"Creative Allies | Create Art For Rockstars | Upload For A Chance To Win", "thumbnail"=>"http://cdn.stumble-upon.com/mthumb/388/49348388.jpg", "thumbnail_b"=>"http://cdn.stumble-upon.com/images/nobthumb.png", "submit_link"=>"http://www.stumbleupon.com/submit/?url=http://creativeallies.com/", "badge_link"=>"http://www.stumbleupon.com/badge/?url=http://creativeallies.com/", "info_link"=>"http://www.stumbleupon.com/url/creativeallies.com/"}, :twitter=>{"count"=>121, "url"=>"http://creativeallies.com/"}}
52
+ end
53
+
54
+ it "Virility.url should return a Virility::Excitation object" do
55
+ Virility.url(@url).should be_a_kind_of Virility::Excitation
56
+ end
57
+ end
58
+
59
+ #
60
+ # Error Proofing
61
+ #
62
+
63
+ describe "Error Proofing" do
64
+ it "should not raise an error with a bad URL" do
65
+ lambda { Virility.counts("http://this.is.a.crap.url") }.should_not raise_error
66
+ end
67
+
68
+ it "should return 0 for all strategy counts" do
69
+ @virility = Virility.url("http://this.is.a.crap.url")
70
+ @virility.total.should == 0
71
+ @virility.counts.should == {:delicious=>0, :facebook=>0, :pinterest=>0, :plus_one=>0, :stumble_upon=>0, :twitter=>0}
72
+ end
73
+ end
5
74
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.email = ["mindtonic@gmail.com"]
12
12
  gem.description = "Virility leverages the API's of many popular social services to collect data about the virility of a particular URL."
13
13
  gem.summary = "Virility calls upon the API's of many popular social services such as Facebook, Twitter and Pinterest to collect the number of likes, tweets and pins of a particular URL. Written with a modular construction, Virility makes it easy to drop new data collection strategies into the framework so that you can collect all of your statistics in one easy location."
14
- gem.homepage = ""
14
+ gem.homepage = "http://github.com/mindtonic/virility"
15
15
  # Files
16
16
  gem.files = `git ls-files`.split($/)
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }