virility 0.1.0 → 0.1.1
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.
- data/lib/virility.rb +29 -29
- data/lib/virility/exceptions.rb +1 -1
- data/lib/virility/excitation.rb +102 -102
- data/lib/virility/strategies/delicious.rb +8 -8
- data/lib/virility/strategies/facebook.rb +19 -16
- data/lib/virility/strategies/pinterest.rb +13 -13
- data/lib/virility/strategies/plus_one.rb +17 -17
- data/lib/virility/strategies/stumble_upon.rb +16 -16
- data/lib/virility/strategies/twitter.rb +11 -11
- data/lib/virility/strategy.rb +83 -83
- data/lib/virility/supporter.rb +53 -53
- data/lib/virility/version.rb +1 -1
- data/spec/excitation_spec.rb +111 -111
- data/spec/spec_helper.rb +11 -11
- data/spec/strategies/delicious_spec.rb +51 -51
- data/spec/strategies/facebook_spec.rb +93 -93
- data/spec/strategies/pinterest_spec.rb +51 -51
- data/spec/strategies/plus_one_spec.rb +51 -51
- data/spec/strategies/stumble_upon_spec.rb +51 -51
- data/spec/strategies/twitter_spec.rb +51 -51
- data/spec/strategy_spec.rb +98 -98
- data/spec/virility_spec.rb +64 -64
- data/virility.gemspec +1 -1
- metadata +3 -3
@@ -1,66 +1,66 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "Virility::PlusOne" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
15
|
|
16
|
-
|
17
|
-
|
16
|
+
it_should_behave_like "no context results"
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
25
|
|
26
|
-
|
27
|
-
|
26
|
+
it_should_behave_like "no context results"
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
35
|
|
36
|
-
|
37
|
-
|
36
|
+
it_should_behave_like "no context results"
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
45
|
|
46
|
-
|
47
|
-
|
46
|
+
it_should_behave_like "no context results"
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
it "should not raise an error" do
|
57
|
+
lambda { @virility.poll }.should_not raise_error
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
it "should return 8 for the count" do
|
61
|
+
@virility.count.should == 8
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
65
|
|
66
66
|
end
|
@@ -1,66 +1,66 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "Virility::StumbleUpon" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
15
|
|
16
|
-
|
17
|
-
|
16
|
+
it_should_behave_like "no context results"
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
25
|
|
26
|
-
|
27
|
-
|
26
|
+
it_should_behave_like "no context results"
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
35
|
|
36
|
-
|
37
|
-
|
36
|
+
it_should_behave_like "no context results"
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
45
|
|
46
|
-
|
47
|
-
|
46
|
+
it_should_behave_like "no context results"
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
it "should not raise an error" do
|
57
|
+
lambda { @virility.poll }.should_not raise_error
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
it "should return 4731 for the count" do
|
61
|
+
@virility.count.should == 4731
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
65
|
|
66
66
|
end
|
@@ -1,66 +1,66 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe "Virility::Twitter" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
15
|
|
16
|
-
|
17
|
-
|
16
|
+
it_should_behave_like "no context results"
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
25
|
|
26
|
-
|
27
|
-
|
26
|
+
it_should_behave_like "no context results"
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
35
|
|
36
|
-
|
37
|
-
|
36
|
+
it_should_behave_like "no context results"
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
45
|
|
46
|
-
|
47
|
-
|
46
|
+
it_should_behave_like "no context results"
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
it "should not raise an error" do
|
57
|
+
lambda { @virility.poll }.should_not raise_error
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
it "should return 121 for the count" do
|
61
|
+
@virility.count.should == 121
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
65
|
|
66
66
|
end
|
data/spec/strategy_spec.rb
CHANGED
@@ -1,102 +1,102 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "Strategy" do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
102
|
end
|