yourub 1.1.1 → 2.0.0
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.
- checksums.yaml +4 -4
 - data/.gitignore +3 -6
 - data/Gemfile +15 -1
 - data/README.md +36 -25
 - data/Rakefile +18 -0
 - data/config/yourub.yml +1 -1
 - data/lib/yourub/client.rb +38 -10
 - data/lib/yourub/config.rb +34 -1
 - data/lib/yourub/default.rb +1 -1
 - data/lib/yourub/meta_search.rb +134 -0
 - data/lib/yourub/rest/api.rb +6 -0
 - data/lib/yourub/rest/categories.rb +39 -0
 - data/lib/yourub/rest/request.rb +22 -4
 - data/lib/yourub/rest/search.rb +11 -149
 - data/lib/yourub/rest/videos.rb +38 -0
 - data/lib/yourub/result.rb +41 -0
 - data/lib/yourub/validator.rb +4 -11
 - data/lib/yourub/version.rb +3 -3
 - data/lib/yourub.rb +2 -3
 - data/spec/fixtures/categories_list.json +1 -0
 - data/spec/fixtures/categories_list_formatted.json +1 -0
 - data/spec/fixtures/search_list.json +1 -0
 - data/spec/fixtures/single_video.json +1 -0
 - data/spec/fixtures/video_with_200_views.json +1 -0
 - data/spec/fixtures/videos_list.json +1 -0
 - data/spec/spec_helper.rb +11 -0
 - data/spec/support/shared_context_result_load_fixture.rb +11 -0
 - data/spec/support/shared_context_result_search_list.rb +16 -0
 - data/spec/support/shared_context_result_search_list_with_single_videos.rb +24 -0
 - data/spec/support/shared_context_stub_client_connection.rb +18 -0
 - data/spec/yourub/client_spec.rb +29 -72
 - data/spec/yourub/count_filter_spec.rb +4 -5
 - data/spec/yourub/count_spec.rb +39 -0
 - data/spec/yourub/integration.rb +105 -0
 - data/spec/yourub/meta_search_spec.rb +141 -0
 - data/spec/yourub/rest/categories_spec.rb +33 -0
 - data/spec/yourub/rest/request_spec.rb +32 -0
 - data/spec/yourub/rest/videos_spec.rb +24 -0
 - data/spec/yourub/validator_spec.rb +54 -57
 - data/yourub.gemspec +0 -5
 - metadata +39 -66
 - data/lib/yourub/cli.rb +0 -20
 - data/lib/yourub/reader.rb +0 -21
 - data/spec/fixtures/categories.json +0 -0
 - data/spec/fixtures/category.json +0 -0
 - data/spec/helper.rb +0 -26
 
| 
         @@ -0,0 +1,39 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'yourub'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative '../spec_helper.rb'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            describe Yourub::MetaSearch do
         
     | 
| 
      
 6 
     | 
    
         
            +
              describe '#search' do
         
     | 
| 
      
 7 
     | 
    
         
            +
                let(:client) { Yourub::Client.new() }
         
     | 
| 
      
 8 
     | 
    
         
            +
                let(:result){ double }
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                context 'integrates a view count filter' do
         
     | 
| 
      
 11 
     | 
    
         
            +
                  context 'having a search result with 4 videos with 200 views' do
         
     | 
| 
      
 12 
     | 
    
         
            +
                    include_context "stub client connection"
         
     | 
| 
      
 13 
     | 
    
         
            +
                    include_context "search list result load fixture with single video", "search_list.json"
         
     | 
| 
      
 14 
     | 
    
         
            +
                    context "searching videos with more or equal 200 views" do
         
     | 
| 
      
 15 
     | 
    
         
            +
                      it 'find 4 videos' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                        filter = { views: '>= 200' }
         
     | 
| 
      
 17 
     | 
    
         
            +
                        videos = []
         
     | 
| 
      
 18 
     | 
    
         
            +
                        client.search(query: "nasa", count_filter: filter, max_results: 2) do |v|
         
     | 
| 
      
 19 
     | 
    
         
            +
                          videos.push(v)
         
     | 
| 
      
 20 
     | 
    
         
            +
                        end
         
     | 
| 
      
 21 
     | 
    
         
            +
                        expect(videos.count).to eq(4)
         
     | 
| 
      
 22 
     | 
    
         
            +
                      end
         
     | 
| 
      
 23 
     | 
    
         
            +
                    end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    context "searching videos with more than 200 views" do
         
     | 
| 
      
 26 
     | 
    
         
            +
                      it 'find 0 video' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                        filter = { views: '> 200' }
         
     | 
| 
      
 28 
     | 
    
         
            +
                        videos = []
         
     | 
| 
      
 29 
     | 
    
         
            +
                        client.search(query: "nasa", count_filter: filter, max_results: 2) do |v|
         
     | 
| 
      
 30 
     | 
    
         
            +
                          videos.push(v)
         
     | 
| 
      
 31 
     | 
    
         
            +
                        end
         
     | 
| 
      
 32 
     | 
    
         
            +
                        expect(videos.count).to eq(0)
         
     | 
| 
      
 33 
     | 
    
         
            +
                      end
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,105 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'yourub'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            #That is an integration test where the client is not stubbed, this test can
         
     | 
| 
      
 4 
     | 
    
         
            +
            #pass only with an internet connection and a valid developer key. Use this test
         
     | 
| 
      
 5 
     | 
    
         
            +
            #at the end of your changes, and add new tests if you have added new
         
     | 
| 
      
 6 
     | 
    
         
            +
            #functionalities. This file is not run in the default spec suite
         
     | 
| 
      
 7 
     | 
    
         
            +
            describe Yourub::Client do
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              context "on initialize" do
         
     | 
| 
      
 10 
     | 
    
         
            +
                let(:subject) { Yourub::Client.new }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                before do
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                it "return an error if the given country does not exist" do
         
     | 
| 
      
 16 
     | 
    
         
            +
                  subject.search(country: "MOON")
         
     | 
| 
      
 17 
     | 
    
         
            +
                  expect(lambda{subject}).not_to raise_error()
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                it "give me a list of valid countries" do
         
     | 
| 
      
 21 
     | 
    
         
            +
                  expect(subject.countries).to be_a_kind_of(Array)
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                it "retrieves videos that have more than 100 views" do
         
     | 
| 
      
 25 
     | 
    
         
            +
                  filter = {views: ">= 100"}
         
     | 
| 
      
 26 
     | 
    
         
            +
                  videos = []
         
     | 
| 
      
 27 
     | 
    
         
            +
                  subject.search(country: "US", category: "Sports", count_filter: filter) do |v|
         
     | 
| 
      
 28 
     | 
    
         
            +
                    videos.push(v)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
                  expect(videos).to_not be_empty
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                it "retrieves videos for all the categories" do
         
     | 
| 
      
 34 
     | 
    
         
            +
                  videos = []
         
     | 
| 
      
 35 
     | 
    
         
            +
                  subject.search(country: "US", category: "all") do |v|
         
     | 
| 
      
 36 
     | 
    
         
            +
                    videos.push(v)
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
                  expect(videos).to_not be_empty
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                it "accept an 'order' parameter within the others" do
         
     | 
| 
      
 42 
     | 
    
         
            +
                  videos = []
         
     | 
| 
      
 43 
     | 
    
         
            +
                  subject.search(country: "US", category: "Sports", order: 'date') do |v|
         
     | 
| 
      
 44 
     | 
    
         
            +
                    videos.push(v)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  end
         
     | 
| 
      
 46 
     | 
    
         
            +
                  expect(videos).to_not be_empty
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                it "retrieves 5 videos for each given category" do
         
     | 
| 
      
 50 
     | 
    
         
            +
                  videos = []
         
     | 
| 
      
 51 
     | 
    
         
            +
                  subject.search(country: "US, DE", category: "Sports", max_results: 5) do |v|
         
     | 
| 
      
 52 
     | 
    
         
            +
                    videos.push(v)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
                  expect(videos.count).to eq(10)
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                it "retrieves 5 videos for each given category, also if they are passed as array" do
         
     | 
| 
      
 58 
     | 
    
         
            +
                  videos = []
         
     | 
| 
      
 59 
     | 
    
         
            +
                  subject.search(country: ["US", "DE"], category: "Sports", max_results: 5) do |v|
         
     | 
| 
      
 60 
     | 
    
         
            +
                    videos.push(v)
         
     | 
| 
      
 61 
     | 
    
         
            +
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
                  expect(videos.count).to eq(10)
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                it "retrieves the given number of video for the given category" do
         
     | 
| 
      
 66 
     | 
    
         
            +
                  videos = []
         
     | 
| 
      
 67 
     | 
    
         
            +
                  subject.search(category: "Sports", max_results: 2) do |v|
         
     | 
| 
      
 68 
     | 
    
         
            +
                    videos.push(v)
         
     | 
| 
      
 69 
     | 
    
         
            +
                  end
         
     | 
| 
      
 70 
     | 
    
         
            +
                  expect(videos.count).to eq(2)
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                it "retrieves the given number of video for the given word" do
         
     | 
| 
      
 74 
     | 
    
         
            +
                  videos = []
         
     | 
| 
      
 75 
     | 
    
         
            +
                  subject.search(query: "casa", max_results: 3) do |v|
         
     | 
| 
      
 76 
     | 
    
         
            +
                    videos.push(v)
         
     | 
| 
      
 77 
     | 
    
         
            +
                  end
         
     | 
| 
      
 78 
     | 
    
         
            +
                  expect(videos.count).to eq(3)
         
     | 
| 
      
 79 
     | 
    
         
            +
                end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                it "retrieves the given number of video for the given country" do
         
     | 
| 
      
 82 
     | 
    
         
            +
                  videos = []
         
     | 
| 
      
 83 
     | 
    
         
            +
                  subject.search(country: "US", max_results: 5) do |v|
         
     | 
| 
      
 84 
     | 
    
         
            +
                    videos.push(v)
         
     | 
| 
      
 85 
     | 
    
         
            +
                  end
         
     | 
| 
      
 86 
     | 
    
         
            +
                  expect(videos.count).to eq(5)
         
     | 
| 
      
 87 
     | 
    
         
            +
                end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                # it "retrieves a video for the given id" do
         
     | 
| 
      
 90 
     | 
    
         
            +
                #   subject.search(id: "mN0Dbj-xHY0")
         
     | 
| 
      
 91 
     | 
    
         
            +
                #   expect(videos.first["id"]).to eql("mN0Dbj-xHY0")
         
     | 
| 
      
 92 
     | 
    
         
            +
                # end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                # it "retrieves the view count for given id" do
         
     | 
| 
      
 95 
     | 
    
         
            +
                #   expect(subject.get_views("mN0Dbj-xHY0")).to be_a_kind_of(Integer)
         
     | 
| 
      
 96 
     | 
    
         
            +
                # end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                # it "return nil for a not existing video" do
         
     | 
| 
      
 99 
     | 
    
         
            +
                #   subject.search(id: "fffffffffffffffffffff")
         
     | 
| 
      
 100 
     | 
    
         
            +
                #   expect(subject.videos).to be_empty
         
     | 
| 
      
 101 
     | 
    
         
            +
                # end
         
     | 
| 
      
 102 
     | 
    
         
            +
              end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
            end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
         @@ -0,0 +1,141 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'yourub'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative '../spec_helper.rb'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe Yourub::MetaSearch do
         
     | 
| 
      
 5 
     | 
    
         
            +
              context 'Initialize the Request class if the given parameter are valid' do
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                let(:client) { Yourub::Client.new() }
         
     | 
| 
      
 8 
     | 
    
         
            +
                # let(:discovered_api) { double("youtube_api")}
         
     | 
| 
      
 9 
     | 
    
         
            +
                #let(:discovered_api) { double("youtube_api")}
         
     | 
| 
      
 10 
     | 
    
         
            +
                let(:response) {OpenStruct.new(data: {items: [{"statistics" => {"viewCount" => 2}}]}, status: 200)}
         
     | 
| 
      
 11 
     | 
    
         
            +
                let(:videos_list_response) { fixture("videos_list.json")}
         
     | 
| 
      
 12 
     | 
    
         
            +
                let(:search_list_response) { fixture("search_list.json")}
         
     | 
| 
      
 13 
     | 
    
         
            +
                let(:categories_formatted) { fixture("categories_list_formatted.json") }
         
     | 
| 
      
 14 
     | 
    
         
            +
                let(:single_video_response) { fixture("video_with_200_views.json") }
         
     | 
| 
      
 15 
     | 
    
         
            +
                let(:result){ double }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                before do
         
     | 
| 
      
 18 
     | 
    
         
            +
                    # discovered_api.stub_chain(:data, :items).and_return(categories)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    # discovered_api.stub_chain(:search, :list).and_return("search.list")
         
     | 
| 
      
 20 
     | 
    
         
            +
                    # discovered_api.stub_chain(:video_categories, :list).and_return("video_categories.list")
         
     | 
| 
      
 21 
     | 
    
         
            +
                    # allow(client).to receive(:youtube_api).and_return(discovered_api)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    #allow(client).to receive(:execute!).and_return(response)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    #allow(Yourub::REST::Request).to receive(:new).and_return(response)
         
     | 
| 
      
 24 
     | 
    
         
            +
                    allow(result).to receive(:status).and_return(200)
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                describe '#search' do
         
     | 
| 
      
 28 
     | 
    
         
            +
                  context 'forward the parameters to the request' do
         
     | 
| 
      
 29 
     | 
    
         
            +
                    include_context "search list result load fixture", "search_list.json"
         
     | 
| 
      
 30 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 31 
     | 
    
         
            +
                      allow(Yourub::REST::Categories).to receive(
         
     | 
| 
      
 32 
     | 
    
         
            +
                        :for_country).and_return(categories_formatted)
         
     | 
| 
      
 33 
     | 
    
         
            +
                      allow(Yourub::REST::Videos).to receive(:list).and_return(response)
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                    it 'creates a search list request with the expected parameters' do
         
     | 
| 
      
 37 
     | 
    
         
            +
                      expect(Yourub::REST::Search).to receive(:list).with(
         
     | 
| 
      
 38 
     | 
    
         
            +
                            client,
         
     | 
| 
      
 39 
     | 
    
         
            +
                            {:part => "snippet",
         
     | 
| 
      
 40 
     | 
    
         
            +
                             :type => "video",
         
     | 
| 
      
 41 
     | 
    
         
            +
                             :order => "date",
         
     | 
| 
      
 42 
     | 
    
         
            +
                             :safeSearch => "none",
         
     | 
| 
      
 43 
     | 
    
         
            +
                             :category => "Sports",
         
     | 
| 
      
 44 
     | 
    
         
            +
                             :maxResults => 5,
         
     | 
| 
      
 45 
     | 
    
         
            +
                             :regionCode => "US",
         
     | 
| 
      
 46 
     | 
    
         
            +
                             :videoCategoryId => 17}
         
     | 
| 
      
 47 
     | 
    
         
            +
                      )
         
     | 
| 
      
 48 
     | 
    
         
            +
                      client.search(
         
     | 
| 
      
 49 
     | 
    
         
            +
                        country: 'US', category: 'Sports', order: 'date', max_results: 5
         
     | 
| 
      
 50 
     | 
    
         
            +
                      ) { |v| v }
         
     | 
| 
      
 51 
     | 
    
         
            +
                    end
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  context 'integrates a view count filter' do
         
     | 
| 
      
 55 
     | 
    
         
            +
                    include_context 'result load fixture', 'video_with_200_views.json'
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                    let(:search_result) { double }
         
     | 
| 
      
 58 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 59 
     | 
    
         
            +
                      allow(search_result).to receive_message_chain(
         
     | 
| 
      
 60 
     | 
    
         
            +
                        :data, :items).and_return(search_list_response)
         
     | 
| 
      
 61 
     | 
    
         
            +
                      search_result.data.items.each do |single_video|
         
     | 
| 
      
 62 
     | 
    
         
            +
                        allow(single_video).to receive_message_chain(
         
     | 
| 
      
 63 
     | 
    
         
            +
                        :id, :videoId).and_return(1)
         
     | 
| 
      
 64 
     | 
    
         
            +
                      end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                      allow(Yourub::REST::Search).to receive(:list).and_return(search_result)
         
     | 
| 
      
 67 
     | 
    
         
            +
                      allow(Yourub::REST::Videos).to receive(:single_video).and_return(result)
         
     | 
| 
      
 68 
     | 
    
         
            +
                    end
         
     | 
| 
      
 69 
     | 
    
         
            +
                    it 'retrieves videos that have more than 100 views' do
         
     | 
| 
      
 70 
     | 
    
         
            +
                      filter = { views: '>= 100' }
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                      videos = []
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                      client.search(query: "nasa", count_filter: filter) do |v|
         
     | 
| 
      
 75 
     | 
    
         
            +
                        videos.push(v)
         
     | 
| 
      
 76 
     | 
    
         
            +
                      end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                      expect(videos.count).to eq(4)
         
     | 
| 
      
 79 
     | 
    
         
            +
                    end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                   it 'retrieves no videos with more than 200 views' do
         
     | 
| 
      
 82 
     | 
    
         
            +
                      filter = { views: '< 200' }
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                      videos = []
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                      client.search(query: "nasa", count_filter: filter ) do |v|
         
     | 
| 
      
 87 
     | 
    
         
            +
                        videos.push(v)
         
     | 
| 
      
 88 
     | 
    
         
            +
                      end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                      expect(videos.count).to eq(0)
         
     | 
| 
      
 91 
     | 
    
         
            +
                    end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                  end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                  # TODO
         
     | 
| 
      
 96 
     | 
    
         
            +
                  # context 'iterates through the given nation' do
         
     | 
| 
      
 97 
     | 
    
         
            +
                  #   it "retrieves 5 videos for each given category, also if they are passed as array" do
         
     | 
| 
      
 98 
     | 
    
         
            +
                  #     videos = []
         
     | 
| 
      
 99 
     | 
    
         
            +
                  #     subject.search(country: ["US", "DE"], category: "Sports", max_results: 5) do |v|
         
     | 
| 
      
 100 
     | 
    
         
            +
                  #       videos.push v
         
     | 
| 
      
 101 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 102 
     | 
    
         
            +
                  #     expect(videos.count).to eq(10)
         
     | 
| 
      
 103 
     | 
    
         
            +
                  #   end
         
     | 
| 
      
 104 
     | 
    
         
            +
                  # end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                  # context 'when the parameter category is == "all"' do
         
     | 
| 
      
 107 
     | 
    
         
            +
                  #   it 'it iterates through all the categories' do
         
     | 
| 
      
 108 
     | 
    
         
            +
                  #     videos = []
         
     | 
| 
      
 109 
     | 
    
         
            +
                  #     client.search(country: 'US', category: 'all') do |v|
         
     | 
| 
      
 110 
     | 
    
         
            +
                  #       videos.push v
         
     | 
| 
      
 111 
     | 
    
         
            +
                  #     end
         
     | 
| 
      
 112 
     | 
    
         
            +
                  #     expect(videos).to_not be_empty
         
     | 
| 
      
 113 
     | 
    
         
            +
                  #   end
         
     | 
| 
      
 114 
     | 
    
         
            +
                  # end
         
     | 
| 
      
 115 
     | 
    
         
            +
                end
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
                describe "methods used only for single video" do
         
     | 
| 
      
 118 
     | 
    
         
            +
                  include_context "result load fixture", "video_with_200_views.json"
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                  describe '#get' do
         
     | 
| 
      
 121 
     | 
    
         
            +
                    it 'send the request with the correct parameters' do
         
     | 
| 
      
 122 
     | 
    
         
            +
                      expect(Yourub::REST::Request).to receive(:new)
         
     | 
| 
      
 123 
     | 
    
         
            +
                        .with(client, 'videos', 'list', :id => "mN0Dbj-xHY0", :part=>"snippet,statistics")
         
     | 
| 
      
 124 
     | 
    
         
            +
                      client.get('mN0Dbj-xHY0')
         
     | 
| 
      
 125 
     | 
    
         
            +
                    end
         
     | 
| 
      
 126 
     | 
    
         
            +
                  end
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
                  describe '#get_views' do
         
     | 
| 
      
 129 
     | 
    
         
            +
                    it 'send the request with the correct parameters' do
         
     | 
| 
      
 130 
     | 
    
         
            +
                      expect(Yourub::REST::Request).to receive(:new)
         
     | 
| 
      
 131 
     | 
    
         
            +
                        .with(client, 'videos', 'list', :id => "mN0Dbj-xHY0", :part => "statistics")
         
     | 
| 
      
 132 
     | 
    
         
            +
                      client.get_views('mN0Dbj-xHY0')
         
     | 
| 
      
 133 
     | 
    
         
            +
                    end
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
                    it 'return the number of view for the given video' do
         
     | 
| 
      
 136 
     | 
    
         
            +
                      expect(client.get_views('mN0Dbj-xHY0')).to eq(200)
         
     | 
| 
      
 137 
     | 
    
         
            +
                    end
         
     | 
| 
      
 138 
     | 
    
         
            +
                  end
         
     | 
| 
      
 139 
     | 
    
         
            +
                end
         
     | 
| 
      
 140 
     | 
    
         
            +
              end
         
     | 
| 
      
 141 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,33 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'yourub'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative '../../spec_helper.rb'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe Yourub::REST::Categories do
         
     | 
| 
      
 5 
     | 
    
         
            +
              context 'Initialize the Request class if the given parameter are valid' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                let(:category_request)     { double }
         
     | 
| 
      
 7 
     | 
    
         
            +
                let(:client)               { Yourub::Client.new }
         
     | 
| 
      
 8 
     | 
    
         
            +
                let(:categories)           { fixture('categories_list.json') }
         
     | 
| 
      
 9 
     | 
    
         
            +
                let(:categories_formatted) { fixture('categories_list_formatted.json') }
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                before do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  allow(category_request).to receive_message_chain(
         
     | 
| 
      
 13 
     | 
    
         
            +
                    :data, :items
         
     | 
| 
      
 14 
     | 
    
         
            +
                  ).and_return(categories)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  allow(Yourub::REST::Request).to receive(:new).and_return(category_request)
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                describe '.for_country' do
         
     | 
| 
      
 19 
     | 
    
         
            +
                  it 'create a request with the correct parameters' do
         
     | 
| 
      
 20 
     | 
    
         
            +
                    expect(Yourub::REST::Request).to receive(:new)
         
     | 
| 
      
 21 
     | 
    
         
            +
                      .with(client, 'video_categories', 'list',
         
     | 
| 
      
 22 
     | 
    
         
            +
                            'part' => 'snippet', 'regionCode' => ['US'])
         
     | 
| 
      
 23 
     | 
    
         
            +
                    subject.for_country(client, ['US'])
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  it 'return an hash containing the id and the title for each category' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                    expect(subject.for_country(client, ['US'])).to eq(
         
     | 
| 
      
 28 
     | 
    
         
            +
                      categories_formatted
         
     | 
| 
      
 29 
     | 
    
         
            +
                    )
         
     | 
| 
      
 30 
     | 
    
         
            +
                  end
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,32 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'yourub'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative '../../spec_helper'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe Yourub::REST::Request do
         
     | 
| 
      
 5 
     | 
    
         
            +
              context 'during requests initialization' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                include_context "stub client connection"
         
     | 
| 
      
 7 
     | 
    
         
            +
                let(:param) { { 'part' => 'snippet', 'regionCode' => 'de' } }
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                describe 'the request object calls the execute! method on the client' do
         
     | 
| 
      
 10 
     | 
    
         
            +
                  it 'execute the video list request on the client' do
         
     | 
| 
      
 11 
     | 
    
         
            +
                    expect(client).to receive(:execute!).with(
         
     | 
| 
      
 12 
     | 
    
         
            +
                      api_method: 'video_categories.list', parameters: param
         
     | 
| 
      
 13 
     | 
    
         
            +
                    )
         
     | 
| 
      
 14 
     | 
    
         
            +
                    Yourub::REST::Request.new(client, 'video_categories', 'list', param)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  it 'execute the search list request on the client' do
         
     | 
| 
      
 18 
     | 
    
         
            +
                    expect(client).to receive(:execute!).with(
         
     | 
| 
      
 19 
     | 
    
         
            +
                      api_method: 'search.list', parameters: param
         
     | 
| 
      
 20 
     | 
    
         
            +
                    )
         
     | 
| 
      
 21 
     | 
    
         
            +
                    Yourub::REST::Request.new(client, 'search', 'list', param)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  it 'execute the video list request on the client' do
         
     | 
| 
      
 25 
     | 
    
         
            +
                    expect(client).to receive(:execute!).with(
         
     | 
| 
      
 26 
     | 
    
         
            +
                      api_method: 'videos.list', parameters: param
         
     | 
| 
      
 27 
     | 
    
         
            +
                    )
         
     | 
| 
      
 28 
     | 
    
         
            +
                    Yourub::REST::Request.new(client, 'videos', 'list', param)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'yourub'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative '../../spec_helper.rb'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe Yourub::REST::Videos do
         
     | 
| 
      
 5 
     | 
    
         
            +
              context "Initialize the Request class if the given parameter are valid" do
         
     | 
| 
      
 6 
     | 
    
         
            +
                let(:video_request) { double }
         
     | 
| 
      
 7 
     | 
    
         
            +
                let(:client) { Yourub::Client.new() }
         
     | 
| 
      
 8 
     | 
    
         
            +
                let(:videos) { fixture("videos_list.json") }
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                before do
         
     | 
| 
      
 11 
     | 
    
         
            +
                  allow(video_request).to receive_message_chain(:data, :items).and_return(videos)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  allow(Yourub::REST::Request).to receive(:new).and_return(video_request)
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                describe ".list" do
         
     | 
| 
      
 16 
     | 
    
         
            +
                  it "create a request with the correct parameters" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                    expect(Yourub::REST::Request).to receive(:new)
         
     | 
| 
      
 18 
     | 
    
         
            +
                      .with(client, "videos", "list", {"part"=>"snippet", "regionCode" => ['US']})
         
     | 
| 
      
 19 
     | 
    
         
            +
                    subject.list(client, {"part"=>"snippet", "regionCode" => ['US']})
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
         @@ -3,107 +3,104 @@ require 'yourub' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            describe Yourub::Validator do
         
     | 
| 
       4 
4 
     | 
    
         
             
              let(:subject) { Yourub::Validator.confirm(criteria) }
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
              context  
     | 
| 
       7 
     | 
    
         
            -
                context  
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                     
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                      expect(subject).to eq({country: ['US'], category: 'Sport'})
         
     | 
| 
      
 6 
     | 
    
         
            +
              context 'passing an hash containing the search criteria' do
         
     | 
| 
      
 7 
     | 
    
         
            +
                context 'with some valid criteria' do
         
     | 
| 
      
 8 
     | 
    
         
            +
                  context 'with an old hash syntax' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                    let(:criteria) { { 'country' => 'US', 'category' => 'Sport' } }
         
     | 
| 
      
 10 
     | 
    
         
            +
                    it 'return the criteria in the sym: val format' do
         
     | 
| 
      
 11 
     | 
    
         
            +
                      expect(subject).to eq(country: ['US'], category: 'Sport')
         
     | 
| 
       13 
12 
     | 
    
         
             
                    end
         
     | 
| 
       14 
13 
     | 
    
         
             
                  end
         
     | 
| 
       15 
14 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
                  context  
     | 
| 
       17 
     | 
    
         
            -
                    let(:criteria) { {country: 'US', city: 'Berlin'} }
         
     | 
| 
       18 
     | 
    
         
            -
                    it  
     | 
| 
       19 
     | 
    
         
            -
                      expect(subject).to eq( 
     | 
| 
      
 15 
     | 
    
         
            +
                  context 'with valid nation but unknown parameter city' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                    let(:criteria) { { country: 'US', city: 'Berlin' } }
         
     | 
| 
      
 17 
     | 
    
         
            +
                    it 'return criteria including nation but excluding the city' do
         
     | 
| 
      
 18 
     | 
    
         
            +
                      expect(subject).to eq(country: ['US'])
         
     | 
| 
       20 
19 
     | 
    
         
             
                    end
         
     | 
| 
       21 
20 
     | 
    
         
             
                  end
         
     | 
| 
       22 
21 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                  context  
     | 
| 
       24 
     | 
    
         
            -
                    let(:criteria) { {order: 'banane', query: 'roberto baggio'} }
         
     | 
| 
      
 22 
     | 
    
         
            +
                  context 'with an invalid :order value' do
         
     | 
| 
      
 23 
     | 
    
         
            +
                    let(:criteria) { { order: 'banane', query: 'roberto baggio' } }
         
     | 
| 
       25 
24 
     | 
    
         
             
                    it 'raise an argument error' do
         
     | 
| 
       26 
     | 
    
         
            -
                      expect(lambda{subject}).to raise_error(ArgumentError)
         
     | 
| 
      
 25 
     | 
    
         
            +
                      expect(lambda{ subject }).to raise_error(ArgumentError)
         
     | 
| 
       27 
26 
     | 
    
         
             
                    end
         
     | 
| 
       28 
27 
     | 
    
         
             
                  end
         
     | 
| 
       29 
28 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
                  context  
     | 
| 
       31 
     | 
    
         
            -
                    let(:criteria) { {country: '', category: 'Sport'} }
         
     | 
| 
       32 
     | 
    
         
            -
                    it  
     | 
| 
       33 
     | 
    
         
            -
                      expect(subject).to eq( 
     | 
| 
      
 29 
     | 
    
         
            +
                  context 'with a given category without a country' do
         
     | 
| 
      
 30 
     | 
    
         
            +
                    let(:criteria) { { country: '', category: 'Sport' } }
         
     | 
| 
      
 31 
     | 
    
         
            +
                    it 'add the default country' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                      expect(subject).to eq(category: 'Sport', :country => ['US'])
         
     | 
| 
       34 
33 
     | 
    
         
             
                    end
         
     | 
| 
       35 
34 
     | 
    
         
             
                  end
         
     | 
| 
       36 
35 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
                  context  
     | 
| 
       38 
     | 
    
         
            -
                    let(:criteria)  
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                      expect(subject).to eq({country: ["IT"], category: 'Sport', max_results: 2 })
         
     | 
| 
      
 36 
     | 
    
         
            +
                  context 'with all the available parameters present' do
         
     | 
| 
      
 37 
     | 
    
         
            +
                    let(:criteria) do
         
     | 
| 
      
 38 
     | 
    
         
            +
                      { country: 'IT',
         
     | 
| 
      
 39 
     | 
    
         
            +
                        category: 'Sport',
         
     | 
| 
      
 40 
     | 
    
         
            +
                        max_results: 2,
         
     | 
| 
      
 41 
     | 
    
         
            +
                        count_filter: {},
         
     | 
| 
      
 42 
     | 
    
         
            +
                        query: ''
         
     | 
| 
      
 43 
     | 
    
         
            +
                      }
         
     | 
| 
       46 
44 
     | 
    
         
             
                    end
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                    it "ignore the other params and leave only the id" do 
         
     | 
| 
       52 
     | 
    
         
            -
                      expect(subject).to eq({ id: '1111111111' })
         
     | 
| 
      
 45 
     | 
    
         
            +
                    it 'return only them params that has a value' do
         
     | 
| 
      
 46 
     | 
    
         
            +
                      expect(subject).to eq(
         
     | 
| 
      
 47 
     | 
    
         
            +
                        country: ['IT'], category: 'Sport', max_results: 2
         
     | 
| 
      
 48 
     | 
    
         
            +
                      )
         
     | 
| 
       53 
49 
     | 
    
         
             
                    end
         
     | 
| 
       54 
50 
     | 
    
         
             
                  end
         
     | 
| 
       55 
51 
     | 
    
         
             
                end
         
     | 
| 
       56 
52 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
                context  
     | 
| 
       58 
     | 
    
         
            -
                  context  
     | 
| 
       59 
     | 
    
         
            -
                    let(:criteria) { {big: 1, bang: 2} }
         
     | 
| 
      
 53 
     | 
    
         
            +
                context 'if none of the criteria are valid' do
         
     | 
| 
      
 54 
     | 
    
         
            +
                  context 'with non valid criteria' do
         
     | 
| 
      
 55 
     | 
    
         
            +
                    let(:criteria) { { big: 1, bang: 2 } }
         
     | 
| 
       60 
56 
     | 
    
         
             
                    it 'raise an argument error' do
         
     | 
| 
       61 
     | 
    
         
            -
                      expect(lambda{subject}).to raise_error(ArgumentError)
         
     | 
| 
      
 57 
     | 
    
         
            +
                      expect(lambda{ subject }).to raise_error(ArgumentError)
         
     | 
| 
       62 
58 
     | 
    
         
             
                    end
         
     | 
| 
       63 
59 
     | 
    
         
             
                  end
         
     | 
| 
       64 
60 
     | 
    
         | 
| 
       65 
     | 
    
         
            -
                  context  
     | 
| 
       66 
     | 
    
         
            -
                    let(:criteria) {  
     | 
| 
      
 61 
     | 
    
         
            +
                  context 'with criteria in the wrong format, like a string' do
         
     | 
| 
      
 62 
     | 
    
         
            +
                    let(:criteria) { 'country = US' }
         
     | 
| 
       67 
63 
     | 
    
         
             
                    it 'raise an argument error' do
         
     | 
| 
       68 
     | 
    
         
            -
                      expect(lambda{subject}).to raise_error(ArgumentError)
         
     | 
| 
      
 64 
     | 
    
         
            +
                      expect(lambda{ subject }).to raise_error(ArgumentError)
         
     | 
| 
       69 
65 
     | 
    
         
             
                    end
         
     | 
| 
       70 
66 
     | 
    
         
             
                  end
         
     | 
| 
       71 
67 
     | 
    
         | 
| 
       72 
     | 
    
         
            -
                  context  
     | 
| 
       73 
     | 
    
         
            -
                    let(:criteria) { {country: 'MOON'} }
         
     | 
| 
      
 68 
     | 
    
         
            +
                  context 'with an invalid country' do
         
     | 
| 
      
 69 
     | 
    
         
            +
                    let(:criteria) { { country: 'MOON' } }
         
     | 
| 
       74 
70 
     | 
    
         
             
                    it 'raise an argument error' do
         
     | 
| 
       75 
     | 
    
         
            -
                      expect(lambda{subject}).to raise_error(ArgumentError)
         
     | 
| 
      
 71 
     | 
    
         
            +
                      expect(lambda{ subject }).to raise_error(ArgumentError)
         
     | 
| 
       76 
72 
     | 
    
         
             
                    end
         
     | 
| 
       77 
73 
     | 
    
         
             
                  end
         
     | 
| 
       78 
74 
     | 
    
         
             
                end
         
     | 
| 
       79 
75 
     | 
    
         | 
| 
       80 
     | 
    
         
            -
                context  
     | 
| 
       81 
     | 
    
         
            -
                  context  
     | 
| 
       82 
     | 
    
         
            -
                    let(:criteria)  
     | 
| 
      
 76 
     | 
    
         
            +
                context 'with valid criteria but not enough to start a search' do
         
     | 
| 
      
 77 
     | 
    
         
            +
                  context 'only with maximum and count filter' do
         
     | 
| 
      
 78 
     | 
    
         
            +
                    let(:criteria) do
         
     | 
| 
      
 79 
     | 
    
         
            +
                      { max_results: 10, count_filter: { views: '>= 100' } }
         
     | 
| 
      
 80 
     | 
    
         
            +
                    end
         
     | 
| 
       83 
81 
     | 
    
         
             
                    it 'raise an argument error' do
         
     | 
| 
       84 
     | 
    
         
            -
                      expect(lambda{subject}).to raise_error(ArgumentError)
         
     | 
| 
      
 82 
     | 
    
         
            +
                      expect(lambda{ subject }).to raise_error(ArgumentError)
         
     | 
| 
       85 
83 
     | 
    
         
             
                    end
         
     | 
| 
       86 
84 
     | 
    
         
             
                  end
         
     | 
| 
       87 
     | 
    
         
            -
                end 
     | 
| 
      
 85 
     | 
    
         
            +
                end
         
     | 
| 
       88 
86 
     | 
    
         
             
              end
         
     | 
| 
       89 
87 
     | 
    
         | 
| 
       90 
     | 
    
         
            -
              context  
     | 
| 
      
 88 
     | 
    
         
            +
              context 'passing a list of available categories and the selected one' do
         
     | 
| 
       91 
89 
     | 
    
         
             
                let(:subject) { Yourub::Validator.valid_category(categories, selected_one) }
         
     | 
| 
       92 
     | 
    
         
            -
                let(:categories) { [{ 
     | 
| 
      
 90 
     | 
    
         
            +
                let(:categories) { [{'10'=>'music'}, {'15'=>'pets&animals'}, {'17'=>'sports'}, {'18'=>'shortmovies'}] }
         
     | 
| 
       93 
91 
     | 
    
         | 
| 
       94 
     | 
    
         
            -
                context  
     | 
| 
       95 
     | 
    
         
            -
                  let(:selected_one) { 
     | 
| 
      
 92 
     | 
    
         
            +
                context 'with an invalid category' do
         
     | 
| 
      
 93 
     | 
    
         
            +
                  let(:selected_one) {"spaghetti"}
         
     | 
| 
       96 
94 
     | 
    
         
             
                  it 'raise an argument error' do
         
     | 
| 
       97 
95 
     | 
    
         
             
                    expect(lambda{subject}).to raise_error(ArgumentError)
         
     | 
| 
       98 
96 
     | 
    
         
             
                  end
         
     | 
| 
       99 
97 
     | 
    
         
             
                end
         
     | 
| 
       100 
98 
     | 
    
         | 
| 
       101 
     | 
    
         
            -
                context  
     | 
| 
       102 
     | 
    
         
            -
                  let(:selected_one) {  
     | 
| 
      
 99 
     | 
    
         
            +
                context 'with a valid category' do
         
     | 
| 
      
 100 
     | 
    
         
            +
                  let(:selected_one) { 'sports' }
         
     | 
| 
       103 
101 
     | 
    
         
             
                  it 'return it' do
         
     | 
| 
       104 
     | 
    
         
            -
                    expect(subject.first.has_value? "sports").to  
     | 
| 
      
 102 
     | 
    
         
            +
                    expect(subject.first.has_value? "sports").to eq true
         
     | 
| 
       105 
103 
     | 
    
         
             
                  end
         
     | 
| 
       106 
104 
     | 
    
         
             
                end
         
     | 
| 
       107 
105 
     | 
    
         
             
              end
         
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
            end
         
     | 
| 
      
 106 
     | 
    
         
            +
            end
         
     | 
    
        data/yourub.gemspec
    CHANGED
    
    | 
         @@ -19,11 +19,6 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       19 
19 
     | 
    
         
             
              spec.require_paths = ["lib"]
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
              spec.add_runtime_dependency 'google-api-client', '~> 0.7'
         
     | 
| 
       22 
     | 
    
         
            -
              spec.add_runtime_dependency "thor" , '~> 0.18'
         
     | 
| 
       23 
22 
     | 
    
         
             
              spec.add_development_dependency "bundler", "~> 1.3"
         
     | 
| 
       24 
     | 
    
         
            -
              spec.add_development_dependency "byebug", "~> 3.1"
         
     | 
| 
       25 
     | 
    
         
            -
              spec.add_development_dependency "rake", "~> 10.1"
         
     | 
| 
       26 
     | 
    
         
            -
              spec.add_development_dependency "rspec", "~> 2.14"
         
     | 
| 
       27 
     | 
    
         
            -
              #spec.add_development_dependency "webmock", "~> 1.20"
         
     | 
| 
       28 
23 
     | 
    
         | 
| 
       29 
24 
     | 
    
         
             
            end
         
     |