popularity 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +10 -0
- data/.travis.yml +10 -3
- data/Gemfile +4 -20
- data/LICENSE.txt +18 -17
- data/README.md +10 -9
- data/Rakefile +1 -29
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/popularity/version.rb +3 -0
- data/popularity.gemspec +40 -116
- metadata +59 -58
- data/Gemfile.lock +0 -126
- data/lib/popularity/networks/twitter.rb +0 -15
- data/spec/cassettes/facebook.yml +0 -50
- data/spec/cassettes/github-valid.yml +0 -105
- data/spec/cassettes/google_plus.yml +0 -89
- data/spec/cassettes/medium-valid.yml +0 -110
- data/spec/cassettes/pinterest.yml +0 -44
- data/spec/cassettes/reddit-comment.yml +0 -207
- data/spec/cassettes/reddit-post.yml +0 -174
- data/spec/cassettes/reddit.yml +0 -183
- data/spec/cassettes/result-container-test.yml +0 -97
- data/spec/cassettes/rubygems-valid.yml +0 -66
- data/spec/cassettes/search-multi.yml +0 -1211
- data/spec/cassettes/search.yml +0 -598
- data/spec/cassettes/soundcloud-valid.yml +0 -682
- data/spec/cassettes/twitter.yml +0 -64
- data/spec/cassettes/unknown-reddit-post.yml +0 -68
- data/spec/facebook_spec.rb +0 -23
- data/spec/github_spec.rb +0 -39
- data/spec/google_plus_spec.rb +0 -27
- data/spec/medium_spec.rb +0 -47
- data/spec/pinterest_spec.rb +0 -27
- data/spec/reddit_comment_spec.rb +0 -60
- data/spec/reddit_post_spec.rb +0 -64
- data/spec/reddit_spec.rb +0 -118
- data/spec/results_container_spec.rb +0 -61
- data/spec/rubygems_spec.rb +0 -50
- data/spec/search_spec.rb +0 -79
- data/spec/soundcloud_spec.rb +0 -66
- data/spec/spec_helper.rb +0 -98
- data/spec/twitter_spec.rb +0 -19
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Popularity::ResultsContainer do
|
4
|
-
context "same results" do
|
5
|
-
use_vcr_cassette "result-container-test"
|
6
|
-
|
7
|
-
subject {
|
8
|
-
Popularity::ResultsContainer.new
|
9
|
-
}
|
10
|
-
|
11
|
-
it "should add first result" do
|
12
|
-
subject.add_result Popularity::Facebook.new("http://google.com")
|
13
|
-
expect(1).to equal(subject.results.size)
|
14
|
-
|
15
|
-
subject.add_result Popularity::Facebook.new("http://facebook.com")
|
16
|
-
expect(2).to equal(subject.results.size)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "same results" do
|
21
|
-
use_vcr_cassette "result-container-test"
|
22
|
-
|
23
|
-
subject {
|
24
|
-
Popularity::ResultsContainer.new
|
25
|
-
}
|
26
|
-
|
27
|
-
it "should reject different types" do
|
28
|
-
subject.add_result Popularity::Facebook.new("http://google.com")
|
29
|
-
expect(1).to equal(subject.results.size)
|
30
|
-
|
31
|
-
expect{
|
32
|
-
subject.add_result(Popularity::Twitter.new("http://google.com"))
|
33
|
-
} .to raise_error(TypeError)
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "adding results" do
|
39
|
-
use_vcr_cassette "result-container-test"
|
40
|
-
|
41
|
-
subject {
|
42
|
-
Popularity::ResultsContainer.new
|
43
|
-
}
|
44
|
-
|
45
|
-
it "should add methods together" do
|
46
|
-
subject.add_result Popularity::Facebook.new("http://google.com")
|
47
|
-
subject.add_result Popularity::Facebook.new("http://yahoo.com")
|
48
|
-
|
49
|
-
expect(subject.results.collect(&:shares).reduce(:+)).to eq(subject.shares)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should add methods together" do
|
53
|
-
subject.add_result Popularity::Facebook.new("http://google.com")
|
54
|
-
subject.add_result Popularity::Facebook.new("http://yahoo.com")
|
55
|
-
|
56
|
-
expect(subject.results.collect(&:shares).reduce(:+)).to eq(subject.shares)
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
data/spec/rubygems_spec.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Popularity::Rubygems do
|
4
|
-
context "non-rubygems url" do
|
5
|
-
use_vcr_cassette "rubygems-invalid"
|
6
|
-
|
7
|
-
subject {
|
8
|
-
Popularity::Rubygems.new('http://google.com')
|
9
|
-
}
|
10
|
-
|
11
|
-
it "should be invalid" do
|
12
|
-
expect(subject.valid?).to eq(false)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should have no resposne" do
|
16
|
-
expect(subject.response).to eq(false)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "rubygems url" do
|
21
|
-
use_vcr_cassette "rubygems-valid"
|
22
|
-
|
23
|
-
subject {
|
24
|
-
Popularity::Rubygems.new('https://rubygems.org/gems/popularity')
|
25
|
-
}
|
26
|
-
|
27
|
-
it "should be valid" do
|
28
|
-
expect(subject.valid?).to be_truthy
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should have response" do
|
32
|
-
expect(subject.response).to_not eq(false)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should have correct number of downloads" do
|
36
|
-
expect(85).to eq(subject.downloads)
|
37
|
-
end
|
38
|
-
|
39
|
-
context "json" do
|
40
|
-
let(:json) { subject.as_json }
|
41
|
-
|
42
|
-
it "should have required attributes in json" do
|
43
|
-
[:downloads].each do |att|
|
44
|
-
expect(subject.send(att)).to eq(json[att.to_s])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
data/spec/search_spec.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
# require 'spec_helper'
|
2
|
-
|
3
|
-
describe Popularity::Search do
|
4
|
-
context "single url" do
|
5
|
-
use_vcr_cassette "search"
|
6
|
-
|
7
|
-
subject {
|
8
|
-
Popularity.search('http://google.com')
|
9
|
-
}
|
10
|
-
|
11
|
-
it "should return correct total" do
|
12
|
-
expect(23422376).to equal subject.total
|
13
|
-
end
|
14
|
-
|
15
|
-
context "json" do
|
16
|
-
let(:json) { subject.as_json }
|
17
|
-
|
18
|
-
it "should have each url as root json key" do
|
19
|
-
subject.sources.each do |source|
|
20
|
-
expect(json[source.to_s]).to_not be_nil
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should have each network as root json key" do
|
25
|
-
subject.searches.each do |search|
|
26
|
-
expect(json[search.url.to_s]).to_not be_nil
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should have each total as root json key" do
|
31
|
-
expect(json["total"]).to_not be_nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "multiple url" do
|
37
|
-
use_vcr_cassette "search-multi"
|
38
|
-
|
39
|
-
subject {
|
40
|
-
Popularity.search("http://google.com", "http://yahoo.com")
|
41
|
-
}
|
42
|
-
|
43
|
-
it "should return correct aggregates" do
|
44
|
-
shares = subject.searches.collect do |search|
|
45
|
-
search.facebook.shares
|
46
|
-
end
|
47
|
-
|
48
|
-
expect(subject.facebook.shares).to eq(shares.reduce(:+))
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should combine results" do
|
52
|
-
expect(subject.searches.collect(&:results).reduce(:+).size).to eq(subject.results.size)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should allow access to individual results" do
|
56
|
-
expect(subject.facebook.results.size).to eq(2)
|
57
|
-
end
|
58
|
-
|
59
|
-
context "json" do
|
60
|
-
let(:json) { subject.as_json }
|
61
|
-
|
62
|
-
it "should have each url as root json key" do
|
63
|
-
subject.sources.each do |source|
|
64
|
-
expect(json[source.to_s]).to_not be_nil
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should have each network as root json key" do
|
69
|
-
subject.searches.each do |search|
|
70
|
-
expect(json[search.url.to_s]).to_not be_nil
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should have each total as root json key" do
|
75
|
-
expect(json["total"]).to_not be_nil
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
data/spec/soundcloud_spec.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Popularity::Soundcloud do
|
4
|
-
context "non-soundcloud url" do
|
5
|
-
use_vcr_cassette "soundcloud-invalid"
|
6
|
-
|
7
|
-
subject {
|
8
|
-
Popularity::Soundcloud.new('http://google.com')
|
9
|
-
}
|
10
|
-
|
11
|
-
it "should be invalid" do
|
12
|
-
expect(subject.valid?).to eq(false)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should have no resposne" do
|
16
|
-
expect(subject.response).to eq(false)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context "soundcloud url" do
|
21
|
-
use_vcr_cassette "soundcloud-valid"
|
22
|
-
|
23
|
-
subject {
|
24
|
-
Popularity::Soundcloud.new('http://soundcloud.com/jeffkeen/i-know-its-you')
|
25
|
-
}
|
26
|
-
|
27
|
-
it "should be valid" do
|
28
|
-
expect(subject.valid?).to eq(true)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should have response" do
|
32
|
-
expect(subject.response).to_not eq(false)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should have correct number of plays" do
|
36
|
-
expect(14710).to eq(subject.plays)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should have correct number of likes" do
|
40
|
-
expect(12).to eq(subject.likes)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should have correct number of downloads" do
|
44
|
-
expect(0).to eq(subject.downloads)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should have correct number of comments" do
|
48
|
-
expect(2).to eq(subject.comments)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should have the correct total" do
|
52
|
-
expect(subject.comments + subject.downloads + subject.likes + subject.plays).to eq(subject.total)
|
53
|
-
end
|
54
|
-
|
55
|
-
context "json" do
|
56
|
-
let(:json) { subject.as_json }
|
57
|
-
|
58
|
-
it "should have required attributes in json" do
|
59
|
-
[:plays, :likes, :downloads, :comments].each do |att|
|
60
|
-
expect(subject.send(att)).to eq(json[att.to_s])
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
Bundler.setup
|
3
|
-
|
4
|
-
require 'simplecov'
|
5
|
-
SimpleCov.start
|
6
|
-
|
7
|
-
require 'popularity'
|
8
|
-
require 'vcr'
|
9
|
-
|
10
|
-
VCR.configure { |c|
|
11
|
-
c.hook_into :webmock
|
12
|
-
c.cassette_library_dir = 'spec/cassettes'
|
13
|
-
# c.default_cassette_options = { :record => :new_episodes }
|
14
|
-
}
|
15
|
-
|
16
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
-
RSpec.configure do |config|
|
18
|
-
config.extend VCR::RSpec::Macros
|
19
|
-
config.expect_with :rspec do |c|
|
20
|
-
c.syntax = :expect
|
21
|
-
end
|
22
|
-
|
23
|
-
# config.order = 'random'
|
24
|
-
# config.treat_symbols_as_metadata_keys_with_true_values = true
|
25
|
-
|
26
|
-
# rspec-expectations config goes here. You can use an alternate
|
27
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
28
|
-
# assertions if you prefer.
|
29
|
-
config.expect_with :rspec do |expectations|
|
30
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
31
|
-
# and `failure_message` of custom matchers include text for helper methods
|
32
|
-
# defined using `chain`, e.g.:
|
33
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
34
|
-
# # => "be bigger than 2 and smaller than 4"
|
35
|
-
# ...rather than:
|
36
|
-
# # => "be bigger than 2"
|
37
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
38
|
-
end
|
39
|
-
|
40
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
41
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
42
|
-
config.mock_with :rspec do |mocks|
|
43
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
44
|
-
# a real object. This is generally recommended, and will default to
|
45
|
-
# `true` in RSpec 4.
|
46
|
-
mocks.verify_partial_doubles = true
|
47
|
-
end
|
48
|
-
|
49
|
-
# The settings below are suggested to provide a good initial experience
|
50
|
-
# with RSpec, but feel free to customize to your heart's content.
|
51
|
-
=begin
|
52
|
-
# These two settings work together to allow you to limit a spec run
|
53
|
-
# to individual examples or groups you care about by tagging them with
|
54
|
-
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
55
|
-
# get run.
|
56
|
-
config.filter_run :focus
|
57
|
-
config.run_all_when_everything_filtered = true
|
58
|
-
|
59
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
60
|
-
# recommended. For more details, see:
|
61
|
-
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
62
|
-
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
63
|
-
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
64
|
-
config.disable_monkey_patching!
|
65
|
-
|
66
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
67
|
-
# be too noisy due to issues in dependencies.
|
68
|
-
config.warnings = true
|
69
|
-
|
70
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
71
|
-
# file, and it's useful to allow more verbose output when running an
|
72
|
-
# individual spec file.
|
73
|
-
if config.files_to_run.one?
|
74
|
-
# Use the documentation formatter for detailed output,
|
75
|
-
# unless a formatter has already been configured
|
76
|
-
# (e.g. via a command-line flag).
|
77
|
-
config.default_formatter = 'doc'
|
78
|
-
end
|
79
|
-
|
80
|
-
# Print the 10 slowest examples and example groups at the
|
81
|
-
# end of the spec run, to help surface which specs are running
|
82
|
-
# particularly slow.
|
83
|
-
config.profile_examples = 10
|
84
|
-
|
85
|
-
# Run specs in random order to surface order dependencies. If you find an
|
86
|
-
# order dependency and want to debug it, you can fix the order by providing
|
87
|
-
# the seed, which is printed after each run.
|
88
|
-
# --seed 1234
|
89
|
-
config.order = :random
|
90
|
-
|
91
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
92
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
93
|
-
# test failures related to randomization by passing the same `--seed` value
|
94
|
-
# as the one that triggered the failure.
|
95
|
-
Kernel.srand config.seed
|
96
|
-
=end
|
97
|
-
|
98
|
-
end
|
data/spec/twitter_spec.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Popularity::Twitter do
|
4
|
-
context "valid url" do
|
5
|
-
use_vcr_cassette "twitter"
|
6
|
-
|
7
|
-
subject {
|
8
|
-
Popularity::Twitter.new('http://google.com')
|
9
|
-
}
|
10
|
-
|
11
|
-
it "should return correct tweet" do
|
12
|
-
expect(11551).to equal subject.tweets
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should calculate the correct total" do
|
16
|
-
expect(subject.tweets).to equal subject.total
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|