Sha256: 604dc3110c434cbcb7ab220f6293d15dadace178f292b2257296bec724449628

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

require "youtube_id"

describe YoutubeID do
  describe ".from" do
    subject { described_class.from url }

    %w(http https).each do |protocol|
      context "direct format" "/v/:id" do
        let(:url) { "#{protocol}://www.youtube.com/v/RCUkmUXMd_k" }
        it { should == "RCUkmUXMd_k" }
      end

      context "legacy embed format" "/v/:id?version=3&hl=en_US&rel=0" do
        let(:url) { "#{protocol}://www.youtube.com/v/RCUkmUXMd_k?version=3&hl=en_US&rel=0" }
        it { should == "RCUkmUXMd_k" }
      end

      context "embed format" "/embed/RCUkmUXMd_k?rel=0" do
        let(:url) { "#{protocol}://www.youtube.com/embed/RCUkmUXMd_k?rel=0" }
        it { should == "RCUkmUXMd_k" }

        context "without parameters" do
          let(:url) { "#{protocol}://www.youtube.com/embed/RCUkmUXMd_k" }
          it { should == "RCUkmUXMd_k" }
        end
      end

      context "standard format", "/watch?v=:id" do
        let(:url) { "#{protocol}://www.youtube.com/watch?v=RCUkmUXMd_k" }
        it { should == "RCUkmUXMd_k" }

        context "with additional parameters" do
          let(:url) { "#{protocol}://www.youtube.com/watch?v=RCUkmUXMd_k&feature=related" }
          it { should == "RCUkmUXMd_k" }
        end

        context "with start time specification" do
          let(:url) { "#{protocol}://www.youtube.com/watch?v=RCUkmUXMd_k#t=0m10s" }
          it { should == "RCUkmUXMd_k" }
        end
      end

      context "user video format", "/user/name#p/a/u/0/:id" do
        let(:url) { "#{protocol}://www.youtube.com/user/ForceD3strategy#p/a/u/0/8WVTOUh53QY" }
        it { should == "8WVTOUh53QY" }
      end

      context "shor url format", "//youtu.be/RCUkmUXMd_k" do
        let(:url) { "#{protocol}://youtu.be/RCUkmUXMd_k" }
        it { should == "RCUkmUXMd_k" }
      end

      context "shor url format with dashes", "//youtu.be/Hu0i--4tz0N" do
        let(:url) { "#{protocol}://youtu.be/Hu0i--4tz0N" }
        it { should == "Hu0i--4tz0N" }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
youtube_id-0.0.2 spec/youtube_id_spec.rb