rmd 0.1.1 → 0.1.2

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.
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RMD::NCT::Playlist do
4
- let(:playlist) { described_class.new(link) }
5
- let(:link) { 'www.nhaccuatui.com/bai-hat/playlist.mp3' }
6
- let(:element_css) { '.item_content .name_song' }
7
-
8
- it_behaves_like 'RMD::Base::Playlist'
9
-
10
- describe '#fetch' do
11
- before do
12
- allow(playlist).to receive(:song_elements)
13
- .and_return(song_elements)
14
- end
15
-
16
- context 'when there are song elements' do
17
- let(:element) { double('Element') }
18
- let(:errors) { 'errors' }
19
- let(:song_link) { 'song_link' }
20
- let(:song_elements) { [element, element] }
21
- let(:song_1) { instance_double('RMD::NCT::Song', success?: true, fetch: nil, data_link: song_link) }
22
- let(:song_2) { instance_double('RMD::NCT::Song', success?: false, fetch: nil, errors: errors) }
23
-
24
- before do
25
- allow(element).to receive(:attr).with('href').and_return(link)
26
- expect(RMD::NCT::Song).to receive(:new).with(link).and_return(song_1, song_2)
27
- end
28
-
29
- it 'fetchs all the song from the playlist' do
30
- capture_io { playlist.fetch }
31
- expect(playlist.songs).to eq [song_link]
32
- expect(playlist.errors).to eq [errors]
33
- end
34
- end
35
-
36
- context 'when there are no song elements' do
37
- let(:song_elements) { [] }
38
-
39
- it 'does not do anything' do
40
- playlist.fetch
41
- expect(playlist.songs).to eq []
42
- expect(playlist.errors).to eq ['Can not get song lists from this playlist page.']
43
- end
44
- end
45
- end
46
- end
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RMD::NCT::Song do
4
- let(:song) { described_class.new(link) }
5
- let(:link) { 'www.nhaccuatui/bai-hat/song.mp3' }
6
-
7
- describe '#fetch' do
8
- let(:data_link) { 'data_link' }
9
- let(:errors) { 'errors' }
10
- let(:getter_1) { instance_double('RMD::NCT::Getter::KeyFromPage',
11
- data_link: data_link,
12
- errors: errors) }
13
- let(:getter_2) { instance_double('RMD::NCT::Getter::KeyFromPage',
14
- data_link: data_link,
15
- errors: nil) }
16
- let(:getter_3) { instance_double('RMD::NCT::Getter::KeyFromPage',
17
- data_link: data_link,
18
- errors: errors) }
19
- let(:getters) { [getter_1, getter_2, getter_3] }
20
-
21
- it 'fetchs songs' do
22
- expect(song).to receive(:getters).and_return(getters)
23
- expect(getter_1).to receive(:fetch)
24
- expect(getter_2).to receive(:fetch)
25
- expect(getter_3).not_to receive(:fetch)
26
- song.fetch
27
- end
28
- end
29
-
30
- describe '#success?' do
31
- subject { song.success? }
32
-
33
- before do
34
- allow(song).to receive(:data_link).and_return(data_link)
35
- end
36
-
37
- context 'when datalink is present' do
38
- let(:data_link) { 'data_link' }
39
- it { is_expected.to eq true }
40
- end
41
-
42
- context 'when datalink is not present' do
43
- let(:data_link) { nil }
44
- it { is_expected.to eq false }
45
- end
46
- end
47
-
48
- describe '#getters' do
49
- let(:getters) { song.send(:getters) }
50
- let(:getter_classes) { getters.map(&:class) }
51
-
52
- it 'contains getter' do
53
- expect(getter_classes).to include(RMD::NCT::Getter::KeyFromUrl)
54
- expect(getter_classes).to include(RMD::NCT::Getter::KeyFromPage)
55
- end
56
- end
57
- end
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RMD::Processor do
4
- let(:processor) { described_class.new(link) }
5
- let(:link) { 'www.example/xyz/abc.mp3' }
6
-
7
- describe '.process' do
8
- let(:link) { 'www.example/xyz/abc.mp3' }
9
- let(:processor) { double('RMD::processor') }
10
-
11
- it 'processes' do
12
- expect(described_class).to receive(:new).with(link, {}).and_return(processor)
13
- expect(processor).to receive(:process)
14
- described_class.process(link)
15
- end
16
- end
17
-
18
- describe '#process' do
19
- let(:errors) { ['errors'] }
20
- let(:songs) { [song] }
21
- let(:song) { 'song.mp3' }
22
- let(:playlist) { instance_double('RMD::NCT::Playlist', songs: songs,
23
- errors: errors,
24
- success?: success) }
25
-
26
- before do
27
- expect(RMD::Factory).to receive(:build).with(link).and_return(playlist)
28
- expect(playlist).to receive(:fetch)
29
- end
30
-
31
- context 'when fetching songs is success' do
32
- let(:success) { true }
33
-
34
- it 'downloads the songs' do
35
- expect(processor).to receive(:download).with(song)
36
- expect {
37
- processor.process
38
- }.to output("\e[0;32;49mStart processing #{link}...\e[0m\n\e[0;31;49merrors\e[0m\n").to_stdout
39
- end
40
- end
41
-
42
- context 'when fetching songs is not success' do
43
- let(:success) { false }
44
-
45
- it 'does not download the songs' do
46
- expect(processor).not_to receive(:download)
47
- expect {
48
- processor.process
49
- }.to output("\e[0;32;49mStart processing #{link}...\e[0m\n\e[0;31;49merrors\e[0m\n").to_stdout
50
- end
51
- end
52
- end
53
-
54
- describe '#download' do
55
- let(:data_link) { 'data_link' }
56
-
57
- it 'downloads data' do
58
- expect(RMD::Downloader).to receive(:download).with(data_link, {})
59
- processor.send(:download, data_link)
60
- end
61
- end
62
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RMD::SongPlaylistAdapter do
4
- let(:adapter) { described_class.new(song) }
5
-
6
- describe '#songs' do
7
- let(:song) { instance_double('RMD::NCT::Song', data_link: data_link) }
8
- subject { adapter.songs }
9
-
10
- context 'when song has the link' do
11
- let(:data_link) { 'data_link' }
12
- it { is_expected.to eq [data_link] }
13
- end
14
-
15
- context 'when song does not have the link' do
16
- let(:data_link) { nil }
17
- it { is_expected.to eq [] }
18
- end
19
- end
20
-
21
- describe '#errors' do
22
- let(:song) { instance_double('RMD::NCT::Song', errors: errors) }
23
- subject { adapter.errors }
24
-
25
- context 'when song has the error' do
26
- let(:errors) { 'errors' }
27
- it { is_expected.to eq [errors] }
28
- end
29
-
30
- context 'when song does not have the error' do
31
- let(:errors) { nil }
32
- it { is_expected.to eq [] }
33
- end
34
- end
35
- end
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RMD::Zing::Playlist do
4
- let(:playlist) { described_class.new(link) }
5
- let(:link) { 'mp3.zing.vn/bai-hat/playlist.mp3' }
6
- let(:element_css) { '._btnDownload' }
7
-
8
- it_behaves_like 'RMD::Base::Playlist'
9
-
10
- describe '#fetch' do
11
- before do
12
- allow(playlist).to receive(:song_elements)
13
- .and_return(song_elements)
14
- end
15
-
16
- context 'when there are song elements' do
17
- let(:element) { double('Element') }
18
- let(:errors) { 'errors' }
19
- let(:song_link) { 'song_link' }
20
- let(:song_elements) { [element] }
21
-
22
- before do
23
- expect(element).to receive(:attr).with('href').and_return(link)
24
- expect(RMD::Zing::Utils::CorrectUrl).to receive(:correct).with(link).and_return(song_link)
25
- end
26
-
27
- it 'fetchs all the song from the playlist' do
28
- capture_io { playlist.fetch }
29
- expect(playlist.songs).to eq [song_link]
30
- expect(playlist.errors).to eq []
31
- end
32
- end
33
-
34
- context 'when there are no song elements' do
35
- let(:song_elements) { [] }
36
-
37
- it 'does not do anything' do
38
- playlist.fetch
39
- expect(playlist.songs).to eq []
40
- expect(playlist.errors).to eq ['Can not get song lists from this playlist page.']
41
- end
42
- end
43
- end
44
- end
@@ -1,92 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RMD::Zing::Song do
4
- let(:link) { 'mp3.zing.vn/bai-hat/abc.mp3' }
5
- let(:song) { described_class.new(link) }
6
-
7
- describe '#fetch' do
8
- before do
9
- expect(song).to receive(:new_link)
10
- .and_return(new_link).at_least(:once)
11
- end
12
-
13
- context 'when new link exists' do
14
- let(:new_link) { 'mp3.zing.vn' }
15
- let(:data_link) { 'mp3.zing.vn/data/mp3' }
16
-
17
- before do
18
- expect(RMD::Zing::Utils::CorrectUrl).to receive(:correct)
19
- .with(new_link).and_return(data_link)
20
- end
21
-
22
- it 'returns correct new link' do
23
- song.fetch
24
- expect(song.data_link).to eq data_link
25
- expect(song.errors).to be_nil
26
- end
27
- end
28
-
29
- context 'when new link does not exist' do
30
- let(:new_link) { nil }
31
-
32
- it 'returns error' do
33
- song.fetch
34
- expect(song.data_link).to eq nil
35
- expect(song.errors).to eq 'Can not get song from this link!'
36
- end
37
- end
38
- end
39
-
40
- describe '#new_link' do
41
- let(:page) { double('Page') }
42
- let(:elements) { [element] }
43
- let(:element) { double('Element', text: text) }
44
- subject { song.send(:new_link) }
45
-
46
- before do
47
- expect(song).to receive(:page).and_return(page)
48
- expect(page).to receive(:search).with('.detail-function script').and_return(elements)
49
- end
50
-
51
- context 'when match data exists' do
52
- let(:text) { 'abc http://mp3.zing.vn/download/song/abc/xyz' }
53
- it { is_expected.to eq 'http://mp3.zing.vn/download/song/abc/xyz' }
54
- end
55
-
56
- context 'when match data is not exists' do
57
- let(:text) { 'abc http://mp3.zing.vn' }
58
- it { is_expected.to eq nil }
59
- end
60
- end
61
-
62
- describe '#page' do
63
- let(:agent) { instance_double('Mechanize') }
64
- let(:page) { double('Page') }
65
- subject { song.send(:page) }
66
-
67
- before do
68
- expect(song).to receive(:agent).and_return(agent)
69
- expect(agent).to receive(:get).with(link).and_return(page)
70
- end
71
-
72
- it { is_expected.to eq page }
73
- end
74
-
75
- describe '#success?' do
76
- subject { song.success? }
77
-
78
- before do
79
- allow(song).to receive(:data_link).and_return(data_link)
80
- end
81
-
82
- context 'when datalink is present' do
83
- let(:data_link) { 'data_link' }
84
- it { is_expected.to eq true }
85
- end
86
-
87
- context 'when datalink is not present' do
88
- let(:data_link) { nil }
89
- it { is_expected.to eq false }
90
- end
91
- end
92
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RMD::Zing::Utils::CorrectUrl do
4
- describe '#correct' do
5
- let(:util) { described_class.new(url) }
6
-
7
- context 'when url is normal' do
8
- let(:url) { 'http://www.nhaccuatui.com/download/song/tFBwsJKDGQX9' }
9
-
10
- it 'returns that url' do
11
- VCR.use_cassette('utils correct_url correct') do
12
- expect(util.correct).to eq url
13
- end
14
- end
15
- end
16
-
17
- context 'when url is a redirect' do
18
- let(:url) { 'http://mp3.zing.vn/download/song/Bird-TV-Size-Yuya-Matsushita/ZHJntZGsBidFQQQTLDxyDHkG' }
19
- let(:redirect_url) { 'http://dl2.mp3.zdn.vn/fsdd1131lwwjA/74548e9982bf8c91fdbf7939139a5bb0/54ba2490/2011/06/05/d/f/dfed7ed9a9ed91387af6062db606e72f.mp3?filename=Bird%20TV%20Size%20-%20Yuya%20Matsushita.mp3' }
20
-
21
- it 'returns that url' do
22
- VCR.use_cassette('utils correct_url redirect') do
23
- expect(util.correct).to eq redirect_url
24
- end
25
- end
26
- end
27
- end
28
- end
data/spec/spec_helper.rb DELETED
@@ -1,124 +0,0 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
- # file to always be loaded, without a need to explicitly require it in any files.
5
- #
6
- # Given that it is always loaded, you are encouraged to keep this file as
7
- # light-weight as possible. Requiring heavyweight dependencies from this file
8
- # will add to the boot time of your test suite on EVERY test run, even for an
9
- # individual file that may not need all of that loaded. Instead, consider making
10
- # a separate helper file that requires the additional dependencies and performs
11
- # the additional setup, and require it from the spec files that actually need it.
12
- #
13
- # The `.rspec` file also contains a few flags that are not defaults but that
14
- # users commonly want.
15
- #
16
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
- require 'byebug'
18
- require 'webmock/rspec'
19
- require 'vcr'
20
- require 'simplecov'
21
- require 'coveralls'
22
- require 'rmd'
23
- Dir[__dir__ + '/support/**/*.rb'].each { |f| require f }
24
-
25
- Coveralls.wear!
26
- SimpleCov.start
27
-
28
- VCR.configure do |config|
29
- config.cassette_library_dir = "fixtures/vcr_cassettes"
30
- config.hook_into :webmock
31
- end
32
-
33
- RSpec.configure do |config|
34
- # rspec-expectations config goes here. You can use an alternate
35
- # assertion/expectation library such as wrong or the stdlib/minitest
36
- # assertions if you prefer.
37
- config.expect_with :rspec do |expectations|
38
- # This option will default to `true` in RSpec 4. It makes the `description`
39
- # and `failure_message` of custom matchers include text for helper methods
40
- # defined using `chain`, e.g.:
41
- # be_bigger_than(2).and_smaller_than(4).description
42
- # # => "be bigger than 2 and smaller than 4"
43
- # ...rather than:
44
- # # => "be bigger than 2"
45
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
46
- end
47
-
48
- # rspec-mocks config goes here. You can use an alternate test double
49
- # library (such as bogus or mocha) by changing the `mock_with` option here.
50
- config.mock_with :rspec do |mocks|
51
- # Prevents you from mocking or stubbing a method that does not exist on
52
- # a real object. This is generally recommended, and will default to
53
- # `true` in RSpec 4.
54
- mocks.verify_partial_doubles = true
55
- end
56
-
57
- # The settings below are suggested to provide a good initial experience
58
- # with RSpec, but feel free to customize to your heart's content.
59
- =begin
60
- # These two settings work together to allow you to limit a spec run
61
- # to individual examples or groups you care about by tagging them with
62
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
63
- # get run.
64
- config.filter_run :focus
65
- config.run_all_when_everything_filtered = true
66
-
67
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
68
- # For more details, see:
69
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
70
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
72
- config.disable_monkey_patching!
73
-
74
- # This setting enables warnings. It's recommended, but in some cases may
75
- # be too noisy due to issues in dependencies.
76
- config.warnings = true
77
-
78
- # Many RSpec users commonly either run the entire suite or an individual
79
- # file, and it's useful to allow more verbose output when running an
80
- # individual spec file.
81
- if config.files_to_run.one?
82
- # Use the documentation formatter for detailed output,
83
- # unless a formatter has already been configured
84
- # (e.g. via a command-line flag).
85
- config.default_formatter = 'doc'
86
- end
87
-
88
- # Print the 10 slowest examples and example groups at the
89
- # end of the spec run, to help surface which specs are running
90
- # particularly slow.
91
- config.profile_examples = 10
92
-
93
- # Run specs in random order to surface order dependencies. If you find an
94
- # order dependency and want to debug it, you can fix the order by providing
95
- # the seed, which is printed after each run.
96
- # --seed 1234
97
- config.order = :random
98
-
99
- # Seed global randomization in this process using the `--seed` CLI option.
100
- # Setting this allows you to use `--seed` to deterministically reproduce
101
- # test failures related to randomization by passing the same `--seed` value
102
- # as the one that triggered the failure.
103
- Kernel.srand config.seed
104
- =end
105
- end
106
-
107
- def capture_io(&block)
108
- original_stdout = $stdout
109
- original_progressbar_stdout = ProgressBar::Output::DEFAULT_OUTPUT_STREAM
110
- $stdout = fake = StringIO.new
111
- redef_without_warning(ProgressBar::Output, 'DEFAULT_OUTPUT_STREAM', $stdout)
112
- begin
113
- yield
114
- ensure
115
- redef_without_warning(ProgressBar::Output, 'DEFAULT_OUTPUT_STREAM', original_progressbar_stdout)
116
- $stdout = original_stdout
117
- end
118
- fake.string
119
- end
120
-
121
- def redef_without_warning(klass, const, value)
122
- klass.send(:remove_const, const) if klass.const_defined?(const)
123
- klass.const_set(const, value)
124
- end