Sha256: db999e8dca8eef6bc123c12e580b516bf7a63c7a868fc94aa5ff1e10ff429470

Contents?: true

Size: 1.8 KB

Versions: 15

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

describe LinkThumbnailer::Scrapers::Opengraph::Base do

  let(:node)      { double('node') }
  let(:document)  { double('document') }
  let(:instance)  { described_class.new(document) }

  describe '#applicable?' do

    let(:meta)    { [node, node] }
    let(:action)  { instance.applicable? }

    before do
      instance.stub(:meta).and_return(meta)
    end

    context 'when all node is an opengraph' do

      before do
        instance.stub(:opengraph_node?).and_return(true, true)
      end

      it { expect(action).to be_truthy }

    end

    context 'when any node is an opengraph' do

      before do
        instance.stub(:opengraph_node?).and_return(true, false)
      end

      it { expect(action).to be_truthy }

    end

    context 'when no node is an opengraph' do

      before do
        instance.stub(:opengraph_node?).and_return(false, false)
      end

      it { expect(action).to be_falsey }

    end

  end

  describe '#opengraph_node?' do

    let(:action) { instance.send(:opengraph_node?, node) }

    before do
      node.stub(:attribute).with('name').and_return(attribute_from_name)
    end

    context 'with attribute from name valid' do

      let(:attribute_from_name) { 'og:foo' }

      it { expect(action).to be_truthy }

    end

    context 'with attribute from name not valid' do

      let(:attribute_from_name) { 'foo' }

      before do
        node.stub(:attribute).with('property').and_return(attribute_from_property)
      end

      context 'and attribute from property valid' do

        let(:attribute_from_property) { 'og:bar' }

        it { expect(action).to be_truthy }

      end

      context 'and attribute from property not valid' do

        let(:attribute_from_property) { 'bar' }

        it { expect(action).to be_falsey }

      end

    end

  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
link_thumbnailer-3.3.0 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-3.2.1 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-3.2.0 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-3.1.2 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-3.1.1 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-3.1.0 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-3.0.3 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-3.0.2 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-3.0.1 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-3.0.0 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-2.6.1 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-2.6.0 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-2.5.2 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-2.5.1 spec/scrapers/opengraph/base_spec.rb
link_thumbnailer-2.5.0 spec/scrapers/opengraph/base_spec.rb