spec/unit/wgif/downloader_spec.rb in wgif-0.5.1 vs spec/unit/wgif/downloader_spec.rb in wgif-0.5.2

- old
+ new

@@ -7,50 +7,50 @@ let(:clip_url) { 'http://lol.wut/watch?v=roflcopter' } before do FileUtils.rm_rf('/tmp/wgif') download_bar = double(WGif::DownloadBar).as_null_object - WGif::DownloadBar.stub(:new).and_return(download_bar) + allow(WGif::DownloadBar).to receive(:new).and_return(download_bar) end it 'retrieves a YouTube download URL' do - ViddlRb.should_receive(:get_urls).with(clip_url).and_return(['clip url']) - downloader.video_url(clip_url).should eq('clip url') + expect(ViddlRb).to receive(:get_urls).with(clip_url).and_return(['clip url']) + expect(downloader.video_url clip_url).to eq('clip url') end it 'retrieves a YouTube video ID' do - downloader.video_id(clip_url).should eq('roflcopter') + expect(downloader.video_id clip_url).to eq('roflcopter') end it 'throws an error if the video is not found' do - ViddlRb.should_receive(:get_urls).with(clip_url) + expect(ViddlRb).to receive(:get_urls).with(clip_url) .and_return(['http://lol.wut']) expect { downloader.get_video(clip_url) } .to raise_error(WGif::VideoNotFoundException) end it 'extracts a YouTube ID from a URL' do - downloader.video_id('http://lol.wut?v=id').should eq('id') + expect(downloader.video_id 'http://lol.wut?v=id').to eq('id') end context 'downloading videos' do before do - ViddlRb.stub(:get_urls).and_return([clip_url]) + allow(ViddlRb).to receive(:get_urls).and_return([clip_url]) fake_request = double('Typhoeus::Request') fake_response = double('Typhoeus::Response') - Typhoeus::Request.should_receive(:new).once + expect(Typhoeus::Request).to receive(:new).once .with(clip_url).and_return(fake_request) - fake_request.should_receive(:on_headers) - fake_request.should_receive(:on_body) - fake_request.should_receive(:run).and_return(fake_response) - fake_response.should_receive(:response_code).and_return(200) + expect(fake_request).to receive(:on_headers) + expect(fake_request).to receive(:on_body) + expect(fake_request).to receive(:run).and_return(fake_response) + expect(fake_response).to receive(:response_code).and_return(200) end it 'downloads a clip' do video = double(name: 'video') - WGif::Video.should_receive(:new) + expect(WGif::Video).to receive(:new) .with('roflcopter', '/tmp/wgif/roflcopter').and_return(video) downloader.get_video(clip_url) end it 'does not download the clip when already cached' do @@ -60,10 +60,10 @@ end context 'errors' do it 'throws an exception when the download URL is not found' do - ViddlRb.stub(:get_urls).and_raise(RuntimeError) + allow(ViddlRb).to receive(:get_urls).and_raise(RuntimeError) expect { downloader.video_url('invalid url') } .to raise_error(WGif::VideoNotFoundException) end it 'throws an exception when the download URL is invalid' do