Sha256: 19ae64abc7c6c16b62d7924c85efbbc78c8d089b69744644e4b00a8c55db2d87

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

require 'spec_helper'

describe PictureFrom::Crawlers::FacebookCrawler do

  describe '#query' do
    subject { described_class.new }

    describe 'when some profiles are found' do
      it 'returns an image url' do
        search_url = 'https://www.facebook.com/search.php?q=karreiro@gmail.com'
        search_response = 'facebook_crawler.response'
        fake(search_url, search_response)

        username = subject.query('karreiro@gmail.com')

        expect(username).to eq('karreiro')
      end
    end

    describe 'when any profile is found' do
      it 'does not return an image url' do
        search_url = 'https://www.facebook.com/search.php?q=karreiro@gmail.com'
        search_response = 'facebook_crawler_empty.response'
        fake(search_url, search_response)

        username = subject.query('karreiro@gmail.com')

        expect(username).to be_nil
      end
    end

  end

  describe '#username_from_url' do
    subject { described_class.new }

    describe 'when receives valid URLs' do
      let(:urls) do
        [
          'https://www.facebook.com/karreiro',
          'http://www.facebook.com/karreiro',
          'http://facebook.com/karreiro/',
          'http://facebook.com/karreiro'
        ]
      end

      it 'returns a valid username' do
        urls.each do |url|
          expect(subject.send(:username_from_url, url)).to eq('karreiro')
        end
      end
    end

    describe 'when receives invalid URLs' do
      let(:urls) do
        [
          'https://orkut.com/karreiro',
          'http://fb.com/karreiro'
        ]
      end

      it 'does not return any username' do
        urls.each do |url|
          expect(subject.send(:username_from_url, url)).to be_nil
        end
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
picture_from-0.0.1 spec/lib/picture_from/crawlers/facebook_crawler_spec.rb